From 37f414b89e3ea1abeb77b2dca3d567312845dd6c Mon Sep 17 00:00:00 2001 From: Daniel Roesler Date: Fri, 12 Jun 2015 21:39:34 -0700 Subject: fixed #2, made loading file errors more friendly --- sign_csr.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sign_csr.py b/sign_csr.py index 85cc260..f9727f8 100644 --- a/sign_csr.py +++ b/sign_csr.py @@ -29,6 +29,8 @@ def sign_csr(pubkey, csr): proc = subprocess.Popen(["openssl", "rsa", "-pubin", "-in", pubkey, "-noout", "-text"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() + if proc.returncode != 0: + raise IOError("Error loading {}".format(pubkey)) pub_hex, pub_exp = re.search("\ Modulus\:\s+00:([a-f0-9\:\s]+?)\ Exponent\: ([0-9]+)\ @@ -55,6 +57,8 @@ Exponent\: ([0-9]+)\ proc = subprocess.Popen(["openssl", "req", "-in", csr, "-noout", "-text"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() + if proc.returncode != 0: + raise IOError("Error loading {}".format(csr)) domain = re.search("Subject:.*? CN=([^\s,;/]+).*?", out, re.MULTILINE|re.DOTALL).groups()[0] sys.stderr.write("Found domain '{}'\n".format(domain)) -- cgit v1.2.3