def create_csr(key_file, organization_name, common_name, serial_number, file_):
    """Create a CSR for a key, and save it into ``file``."""
    key = crypto.load_privatekey(crypto.FILETYPE_PEM, key_file.read())

    req = crypto.X509Req()
    subj = req.get_subject()

    subj.O = organization_name  # noqa: E741 (we can't do anything about this)
    subj.CN = common_name
    subj.serialNumber = serial_number

    req.set_pubkey(key)
    req.sign(key, 'md5')

    file_.write(crypto.dump_certificate_request(crypto.FILETYPE_PEM, req))
def create_csr ( key_file , organization_name , common_name , serial_number , file_ ) : key = crypto . load_privatekey ( crypto . FILETYPE_PEM , key_file . read ( ) ) req = crypto . X509Req ( ) subj = req . get_subject ( ) subj . O = organization_name subj . CN = common_name subj . serialNumber = serial_number req . set_pubkey ( key ) req . sign ( key , 'md5' ) file_ . write ( crypto . dump_certificate_request ( crypto . FILETYPE_PEM , req ) )
Create a CSR for a key, and save it into ``file``.