PyOpenSSL convert certificate object to .pem file

I want to send a certificate from a "certification authority" to node via sockets. I have a certificate created using this example. https://skippylovesmalorie.wordpress.com/2010/02/12/how-to-generate-a-self-signed-certificate-using-pyopenssl/ How would I convert this to a .pem file so that I can send it as a string through the socket, then convert it on the other end back to .pem and use get_certificate to extract this certificate from it. Python: reading pkcs12 certificate with pyOpenSSL.crypto This is probably a hacker way to do this, but I want to simplify it for myself. (or not)

I am raising a question about this person that I haven’t answered. How to convert the PyOpenSSL object to a string encoded in PEM?

+4
source share
1 answer

This is to create a certificate signing request, but the concept should be the same

from OpenSSL import crypto req = crypto.X509Req() pkey = crypto.PKey() pkey.generate_key(crypto.TYPE_RSA, 2048) req.set_pubkey(pkey) req.sign(pkey, 'sha1') certreq = crypto.dump_certificate_request(crypto.FILETYPE_PEM, req) certreq = certreq.replace('-----BEGIN CERTIFICATE REQUEST-----\n', '').replace('-----END CERTIFICATE REQUEST-----\n', '') private_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey) 

for the certificate you can use:

 crypto.dump_certificate(type, cert) 
+7
source

Source: https://habr.com/ru/post/1402567/


All Articles