def make_csr(key_str, domains, must_staple=False):
 assert domains, 'Must provide one or more hostnames for the CSR.'
 pkey = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, key_str)
 req = OpenSSL.crypto.X509Req()
 req.get_subject().CN = domains[0]
 extensions = [OpenSSL.crypto.X509Extension('subjectAltName', critical=False, value=', '.join((('DNS:%s' % d) for d in domains)).encode('ascii'))]
 if must_staple:
  extensions.append(OpenSSL.crypto.X509Extension('1.3.6.1.5.5.7.1.24', critical=False, value='DER:30:03:02:01:05'))
 req.add_extensions(extensions)
 req.set_version(2)
 req.set_pubkey(pkey)
 req.sign(pkey, 'sha256')
 return tuple((OpenSSL.crypto.dump_certificate_request(method, req) for method in (OpenSSL.crypto.FILETYPE_PEM, OpenSSL.crypto.FILETYPE_ASN1)))

def make_csr ( key_str , domains , must_staple = False ) : assert domains , 'Must provide one or more hostnames for the CSR.' pkey = OpenSSL . crypto . load_privatekey ( OpenSSL . crypto . FILETYPE_PEM , key_str ) req = OpenSSL . crypto . X509Req ( ) req . get_subject ( ) . CN = domains [ 0 ] extensions = [ OpenSSL . crypto . X509Extension ( 'subjectAltName' , critical = False , value = ', ' . join ( ( ( 'DNS:%s' % d ) for d in domains ) ) . encode ( 'ascii' ) ) ] if must_staple : extensions . append ( OpenSSL . crypto . X509Extension ( '1.3.6.1.5.5.7.1.24' , critical = False , value = 'DER:30:03:02:01:05' ) ) req . add_extensions ( extensions ) req . set_version ( 2 ) req . set_pubkey ( pkey ) req . sign ( pkey , 'sha256' ) return tuple ( ( OpenSSL . crypto . dump_certificate_request ( method , req ) for method in ( OpenSSL . crypto . FILETYPE_PEM , OpenSSL . crypto . FILETYPE_ASN1 ) ) )
generate a csr .