python - Extract the value of a X.509 certificate custom extension using PyOpenSSL -
Using Python and PO OpenSSL, is there a way to recover the value of a custom extension? With custom extensions, I mean an extension encoded using the arbitrary extension format described under the Arbitration Extension.
Also, is it possible to create such a certificate that has such an extension using PyOpenSSL?
If the answer to any of these is "no", then I also indicate how to do it with any other Python Library. I do not want to call the system on the OpenSSL command line app.
You can get to any and all you have loaded using pyOpenSSL. Extensions on 509 certificates for example:
& gt; & Gt; & Gt; OpenSSL import crypto from c & gt; & Gt; & Gt; Cert = c.load_certificate (c.FILETYPE_PEM, file ('server.pem') read ()) & gt; & Gt; & Gt; Cert.get_extension_count () 4L & gt; & Gt; & Gt; Ext = cert.get_extension (0)> gt; & Gt; & Gt; Ext.get_short_name () 'Basic Consultants' & gt; & Gt; & Gt; Ext.get_data () '0 \ x00' & gt; & Gt; & Gt; The data comes in its raw format (some encodings ASN.1, perhaps based on specific extensions).
You can also add extensions.
& gt; & Gt; & Gt; Newsletter = CX509 Extension ('NS Coment', 0, 'Taco are Tasty') & gt; & Gt; & Gt; Cert.add_extensions ([newext]) & gt; & Gt; & Gt; Cert.get_extension_count () 5L & gt; & Gt; & Gt; Cert.get_extension (4) & lt; X509 Extension Object 0x7f74db7c2290 & gt; & Gt; & Gt; & Gt; Cert.get_extension (4) .get_data () '\ x16 \ x13tacos are tasty' & gt; & Gt; & Gt; However, pay attention to minor inequality. Extension data should be a string and automatically encoded by ASN 1. It seems like stopping the possibility of adding such arbitrary non-string extension data.
Comments
Post a Comment