def _sign_csr(csr_text, ca_folder): with utils.tempdir() as tmpdir: inbound = os.path.join(tmpdir, 'inbound.csr') outbound = os.path.join(tmpdir, 'outbound.csr') with open(inbound, 'w') as csrfile: csrfile.write(csr_text) LOG.debug(_('Flags path: %s'), ca_folder) start = os.getcwd() # Change working dir to CA if not os.path.exists(ca_folder): os.makedirs(ca_folder) os.chdir(ca_folder) utils.execute('openssl', 'ca', '-batch', '-out', outbound, '-config', './openssl.cnf', '-infiles', inbound) out, _err = utils.execute('openssl', 'x509', '-in', outbound, '-serial', '-noout') serial = string.strip(out.rpartition('=')[2]) os.chdir(start) with open(outbound, 'r') as crtfile: return (serial, crtfile.read())
def generate_fingerprint(public_key): with utils.tempdir() as tmpdir: try: pubfile = os.path.join(tmpdir, 'temp.pub') with open(pubfile, 'w') as f: f.write(public_key) return _generate_fingerprint(pubfile) except exception.ProcessExecutionError: raise exception.InvalidKeypair()
def generate_key_pair(bits=1024): # what is the magic 65537? with utils.tempdir() as tmpdir: keyfile = os.path.join(tmpdir, 'temp') utils.execute('ssh-keygen', '-q', '-b', bits, '-N', '', '-t', 'rsa', '-f', keyfile) fingerprint = _generate_fingerprint('%s.pub' % (keyfile)) private_key = open(keyfile).read() public_key = open(keyfile + '.pub').read() return (private_key, public_key, fingerprint)