Skip to content

Instantly share code, notes, and snippets.

@wbond
Created October 20, 2015 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbond/20d2a3daf43747288ca6 to your computer and use it in GitHub Desktop.
Save wbond/20d2a3daf43747288ca6 to your computer and use it in GitHub Desktop.
X.509 Name TypeNameAndValue Decoding in Python
from asn1crypto import x509, pem
with open('path/to/my.crt', 'rb') as f:
data = f.read()
if pem.detect(data):
_, _, data = pem.unarmor(data)
cert = x509.Certificate.load(data)
for rdn in cert.subject.chosen:
for type_value in rdn:
type_name = type_value['type'].native
value_class = type_value['value'].chosen.__class__.__name__
print('%s: %s' % (type_name, value_class))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment