I generated a certificate signing request (csr)
from OpenSSL import crypto
cert = crypto.X509()
cert.get_subject().C = "US"
cert.get_subject().ST = "Minnesota"
cert.get_subject().L = "Minnetonka"
cert.get_subject().O = "my company"
cert.get_subject().OU = "my organization"
cert.get_subject().CN = "aaa.com"
Then saved it.
# Save the csr
name = 'cert.crt'
pem = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
with open(name, 'wb') as f:
f.write(pem)
I would like to load the csr, sign it, and then save it.
Here is my try
# Read it
with open(name, 'rb') as pem:
cert_pem = pem.read()
The next step would probably be to load the csr using a build in function of the crypto libray. Hence, I tried it with the functions dump_certificate, dump_certificate_request, load_certificate and load_certificate_request, using them as follows:
# Load
load_cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_pem)
But I get Errors.
The load_certificate creates the error:
Error: [('asn1 encoding routines', 'asn1_item_embed_d2i', 'field missing'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('PEM routines', 'PEM_ASN1_read_bio', 'ASN1 lib')]
whereas the load_certificate_request creates the error:
Error: [('PEM routines', 'get_name', 'no start line')]
The dump_certificate and the dump_certificate_request create the error:
AttributeError: 'bytes' object has no attribute '_x509'
How could I load the csr, to be ready for the signature ?