Skip to content

Instantly share code, notes, and snippets.

@William-Hill
Created April 19, 2018 22:34
Show Gist options
  • Save William-Hill/2f7e2be3c6ab133a48ce0cf42a3c5007 to your computer and use it in GitHub Desktop.
Save William-Hill/2f7e2be3c6ab133a48ce0cf42a3c5007 to your computer and use it in GitHub Desktop.
Get X509 subject name as string using Pyopenssl
import OpenSSL
def get_x509_subject_string(cert_name):
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(cert_name).read())
subject_components = x509.get_subject().get_components()
subject_string = ""
for component in subject_components:
subject_string = subject_string + "/" + component[0] + "=" + component[1]
return subject_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment