import os
from OpenSSL import crypto, SSL
# Generate a private key
key = crypto.PKey()
key.generate_key(crypto.TYPE_RSA, 2048)
# Create a certificate request
req = crypto.X509Req()
subj = req.get_subject()
subj.countryName = "US"
subj.stateOrProvinceName = "California"
subj.localityName = "San Francisco"
subj.organizationName = "MyOrg"
subj.organizationalUnitName = "MyOU"
subj.commonName = "example.com"
req.set_pubkey(key)
req.sign(key, "sha256")