def new_domain(conf):
    """
    Create new domain Certificate Authority Cert.
    Return path and filename of new domain certificate.

    Equivalent of:
    echo "Creating a certificate authority for a new domain."
    mkdir -p -m 700 $private_dir
    mkdir -p -m 700 $crl_dir
    chmod 700 $private_dir #Because mkdir -p -m is not recursive
    echo 1000 > $dir/serial
    touch $dir/index.txt
    openssl rand -out $private_dir/ca_password 20
    openssl req -new -x509 -config $OPENSSL_CONF \
            -keyout $private_key -out $certificate \
            -passout file:$private_dir/ca_password
    """
    outpath = conf.configuration["CA_default"]["new_certs_dir"]
    private = conf.configuration["CA_default"]["private_dir"]
    crlpath = conf.configuration["CA_default"]["crl_dir"]
    private_key = conf.configuration["CA_default"]["private_key"]
    out = conf.configuration["CA_default"]["certificate"]

    password_file = os.path.join(private, "ca_password")

    os.umask(0077)
    try:
        os.mkdir(crlpath, 0700)
    except OSError:
        pass

    try:
        os.mkdir(outpath, 0700)
    except OSError:
        pass

    try:
        os.mkdir(private, 0700)
    except __HOLE__:
        pass

    touch(conf.configuration["CA_default"]["database"])
    serialfd = open(conf.configuration["CA_default"]["serial"], 'w')
    serialfd.write("1000")
    serialfd.close()

    organization = conf.domain
    commonname = conf.domain
    subject = "/O={}/CN={}".format(organization, commonname)

    log = subprocess.Popen(["openssl", "rand",
                            "-out", password_file, "20"],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
    stdout, stderr = log.communicate()
    if log.returncode != 0:
        raise IOError(stderr)

    log = subprocess.Popen(["openssl", "req",
                            "-new",
                            "-config", conf.configfile,
                            "-x509",
                            "-utf8",
                            "-subj", subject,
                            "-passout",
                            "file:{}".format(password_file),
                            "-out", out,
                            "-keyout", private_key],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
    stdout, stderr = log.communicate()
    if log.returncode != 0:
        raise IOError(stderr)
    return out
dataset/ETHPy150Open EricssonResearch/calvin-base/calvin/utilities/certificate.py/new_domain