Esempio n. 1
0
def sign_csr(csr_text, intermediate=None):  
    if not intermediate:
        return _sign_csr(csr_text, FLAGS.ca_path)
    user_ca = "%s/INTER/%s" % (FLAGS.ca_path, intermediate)
    if not os.path.exists(user_ca):
        start = os.getcwd()
        os.chdir(FLAGS.ca_path)
        utils.runthis("Generating intermediate CA: %s", "sh geninter.sh %s" % (intermediate))
        os.chdir(start)
    return _sign_csr(csr_text, user_ca)
Esempio n. 2
0
def sign_csr(csr_text, intermediate=None):
    if not intermediate:
        return _sign_csr(csr_text, FLAGS.ca_path)
    user_ca = "%s/INTER/%s" % (FLAGS.ca_path, intermediate)
    if not os.path.exists(user_ca):
        start = os.getcwd()
        os.chdir(FLAGS.ca_path)
        utils.runthis("Generating intermediate CA: %s",
                      "sh geninter.sh %s" % (intermediate))
        os.chdir(start)
    return _sign_csr(csr_text, user_ca)
Esempio n. 3
0
def generate_x509_cert(subject, bits=1024):
    tmpdir = tempfile.mkdtemp()
    keyfile = os.path.abspath(os.path.join(tmpdir, 'temp.key'))
    csrfile = os.path.join(tmpdir, 'temp.csr')
    logging.debug("openssl genrsa -out %s %s" % (keyfile, bits))
    utils.runthis("Generating private key: %s", "openssl genrsa -out %s %s" % (keyfile, bits))
    utils.runthis("Generating CSR: %s", "openssl req -new -key %s -out %s -batch -subj %s" % (keyfile, csrfile, subject))
    private_key = open(keyfile).read()
    csr = open(csrfile).read()
    shutil.rmtree(tmpdir)
    return (private_key, csr)
Esempio n. 4
0
def generate_x509_cert(subject="/C=US/ST=California/L=The Mission/O=CloudFed/OU=NOVA/CN=foo", bits=1024):
    tmpdir = tempfile.mkdtemp()
    keyfile = os.path.abspath(os.path.join(tmpdir, 'temp.key'))
    csrfile = os.path.join(tmpdir, 'temp.csr')
    logging.debug("openssl genrsa -out %s %s" % (keyfile, bits))
    utils.runthis("Generating private key: %s", "openssl genrsa -out %s %s" % (keyfile, bits))
    utils.runthis("Generating CSR: %s", "openssl req -new -key %s -out %s -batch -subj %s" % (keyfile, csrfile, subject))
    private_key = open(keyfile).read()
    csr = open(csrfile).read()
    shutil.rmtree(tmpdir)
    return (private_key, csr)
Esempio n. 5
0
def _sign_csr(csr_text, ca_folder):
    tmpfolder = tempfile.mkdtemp()
    csrfile = open("%s/inbound.csr" % (tmpfolder), "w")
    csrfile.write(csr_text)
    csrfile.close()
    logging.debug("Flags path: %s" % ca_folder)
    start = os.getcwd()
    # Change working dir to CA
    os.chdir(ca_folder)
    utils.runthis("Signing cert: %s", "openssl ca -batch -out %s/outbound.crt -config ./openssl.cnf -infiles %s/inbound.csr" % (tmpfolder, tmpfolder))
    os.chdir(start)
    with open("%s/outbound.crt" % (tmpfolder), "r") as crtfile:
        return crtfile.read()
Esempio n. 6
0
def _sign_csr(csr_text, ca_folder):
    tmpfolder = tempfile.mkdtemp()
    csrfile = open("%s/inbound.csr" % (tmpfolder), "w")
    csrfile.write(csr_text)
    csrfile.close()
    logging.debug("Flags path: %s" % ca_folder)
    start = os.getcwd()
    # Change working dir to CA
    os.chdir(ca_folder)
    utils.runthis("Signing cert: %s", "openssl ca -batch -out %s/outbound.crt -config ./openssl.cnf -infiles %s/inbound.csr" % (tmpfolder, tmpfolder))
    os.chdir(start)
    with open("%s/outbound.crt" % (tmpfolder), "r") as crtfile:
        return crtfile.read()
Esempio n. 7
0
def ensure_ca_filesystem():
    """Ensure the CA filesystem exists."""
    ca_dir = ca_folder()
    if not os.path.exists(ca_path()):
        genrootca_sh_path = os.path.join(os.path.dirname(__file__),
                                         'CA',
                                         'genrootca.sh')

        start = os.getcwd()
        if not os.path.exists(ca_dir):
            os.makedirs(ca_dir)
        os.chdir(ca_dir)
        utils.runthis(_("Generating root CA: %s"), "sh", genrootca_sh_path)
        os.chdir(start)