1
0
mirror of https://github.com/moepman/acertmgr.git synced 2025-01-04 03:45:23 +01:00

Use pyopenssl key format consistently

Replaces a case where keys were handled manually instead of using
pyopenssl wrappers.
This commit is contained in:
David Klaftenegger 2016-04-07 02:23:21 +02:00 committed by Markus Hauschild
parent af17847cac
commit c4e1152ed4
2 changed files with 4 additions and 7 deletions

View File

@ -94,9 +94,7 @@ def cert_get(domains, settings):
server = acertmgr_web.ACMEHTTPServer(port) server = acertmgr_web.ACMEHTTPServer(port)
server.start() server.start()
try: try:
key_fd = open(key_file, "r") key = acertmgr_ssl.read_key(key_file)
key = key_fd.read()
key_fd.close()
cr = acertmgr_ssl.cert_request(domains.split(), key) cr = acertmgr_ssl.cert_request(domains.split(), key)
print("Reading account key...") print("Reading account key...")
acc_key = acertmgr_ssl.read_key(acc_file) acc_key = acertmgr_ssl.read_key(acc_file)

View File

@ -36,15 +36,14 @@ def cert_valid_times(cert_file):
# @brief create a certificate signing request # @brief create a certificate signing request
# @param names list of domain names the certificate should be valid for # @param names list of domain names the certificate should be valid for
# @param key_data the key to use with the certificate in PEM format # @param key the key to use with the certificate in pyopenssl format
# @return the CSR in PEM format # @return the CSR in pyopenssl format
def cert_request(names, key_data): def cert_request(names, key):
req = crypto.X509Req() req = crypto.X509Req()
req.get_subject().commonName = names[0] req.get_subject().commonName = names[0]
entries = ['DNS:'+name for name in names] entries = ['DNS:'+name for name in names]
extensions = [crypto.X509Extension('subjectAltName'.encode('utf8'), False, ', '.join(entries).encode('utf8'))] extensions = [crypto.X509Extension('subjectAltName'.encode('utf8'), False, ', '.join(entries).encode('utf8'))]
req.add_extensions(extensions) req.add_extensions(extensions)
key = crypto.load_privatekey(crypto.FILETYPE_PEM, key_data)
req.set_pubkey(key) req.set_pubkey(key)
req.sign(key, 'sha256') req.sign(key, 'sha256')
#return crypto.dump_certificate_request(crypto.FILETYPE_PEM, req) #return crypto.dump_certificate_request(crypto.FILETYPE_PEM, req)