From a614df5d3a25a4d37ff639c344d2c8eeca5399fe Mon Sep 17 00:00:00 2001 From: David Klaftenegger Date: Mon, 11 Jan 2016 21:38:09 +0100 Subject: [PATCH] Add checks for errors during certificate creation --- acertmgr.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/acertmgr.py b/acertmgr.py index c6759a2..e257bdf 100755 --- a/acertmgr.py +++ b/acertmgr.py @@ -80,12 +80,16 @@ def cert_get(domain, settings): raise FileExistsError("A temporary file already exists!") - cr = subprocess.check_output(['openssl', 'req', '-new', '-sha256', '-key', key_file, '-out', csr_file, '-subj', '/CN=%s' % domain]) + try: + cr = subprocess.check_output(['openssl', 'req', '-new', '-sha256', '-key', key_file, '-out', csr_file, '-subj', '/CN=%s' % domain]) - # get certificate - crt = acme_tiny.get_crt(acc_file, csr_file, CHALLENGE_DIR, CA = LE_CA) - with open(crt_file, "w") as crt_fd: - crt_fd.write(crt) + # get certificate + crt = acme_tiny.get_crt(acc_file, csr_file, CHALLENGE_DIR, CA = LE_CA) + with open(crt_file, "w") as crt_fd: + crt_fd.write(crt) + except Exception: + os.remove(csr_file) + raise # TODO check if resulting certificate is valid