That's how i create certificate
from OpenSSL import crypto
cert = crypto.X509()
cert.get_subject().C = countryName
cert.get_subject().ST = stateOrProvinceName
...
Here what generation looks like.
Now, how do I extract those values fomr certificate using PyOpenSSL backwards from plain files?
So here's what I cameup with
def certext(certstr):
p1 = Popen(['printf', certstr], stdout=PIPE)
p2 = Popen(['openssl', 'x509', '-text'], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
return output
You can load a PEM certificate as follows:
import OpenSSL.crypto
st_cert=open(certfile, 'rt').read()
c=OpenSSL.crypto
cert=c.load_certificate(c.FILETYPE_PEM, st_cert)
and a private key with:
st_key=open(keyfile, 'rt').read()
key=c.load_privatekey(c.FILETYPE_PEM, st_key)
where certfile and keyfile are the filenames.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With