Created
October 20, 2015 04:30
-
-
Save wbond/20d2a3daf43747288ca6 to your computer and use it in GitHub Desktop.
X.509 Name TypeNameAndValue Decoding in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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