+ os.remove(csrfilename)
+
+def openssl_genrsa(keyfilename):
+ with subprocess.Popen(["openssl", "genrsa", str(int(config['DEFAULT']['key-length']))], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as f:
+ (stdout, stderr) = f.communicate()
+ if f.returncode:
+ sys.stderr.write(stderr)
+ raise Exception("Error while generating private key")
+ # Now we have a key, save it. This should never overwrite anything.
+ assert not os.path.exists(keyfilename)
+ with open(keyfilename, 'wb') as f:
+ f.write(stdout)