Obrigado pelas respostas. Eu pensei sobre isso um pouco e decidi procurar uma maneira nativa de Python para fazer isso. Havia informações suficientes no site de cheatsheet de criptografia do python e outras que eu consegui juntar o código python para gerar o CSR.
requires pyOpenSSL
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend())
with open('mycert.key', 'wb') as f:
f.write(key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption()))
from OpenSSL import crypto
# load private key
ftype = crypto.FILETYPE_PEM
with open('mycert.key', 'rb') as f: key = f.read()
key = crypto.load_privatekey(ftype, key)
req = crypto.X509Req()
alt_name = [ b"DNS:mynode",
b"DNS:myF5",
b"email:[email protected]" ]
key_usage = [ b"Digital Signature",
b"Key Encipherment" ]
key_usage = [ b"digitalSignature",
b"keyEncipherment" ]
ext_key_usage = [ b"serverAuth",
b"clientAuth" ]
# country (countryName, C)
# state or province name (stateOrProvinceName, ST)
# locality (locality, L)
# organization (organizationName, O)
# organizational unit (organizationalUnitName, OU)
# common name (commonName, CN)
req.get_subject().C = "US"
req.get_subject().ST = "Florida"
req.get_subject().L = "St Petersburg"
req.get_subject().O = "myCompany"
req.get_subject().OU = "MyOU"
req.get_subject().CN = "mynode"
req.add_extensions([
crypto.X509Extension( b"basicConstraints",
False,
b"CA:FALSE"),
crypto.X509Extension( b"keyUsage",
False,
b",".join(key_usage)),
crypto.X509Extension( b"subjectAltName",
False,
b",".join(alt_name))
])
req.set_pubkey(key)
req.sign(key, "sha256")
csr = crypto.dump_certificate_request(ftype, req)
with open("mycert.csr", 'wb') as f: f.write(csr)