def new_runtime(conf, name, nodeid=None):
    """
    Create new runtime certificate.
    Return name of certificate signing request file.

    Equivalent of:
    mkdir -p $new_certs_dir
    openssl req -config $OPENSSL_CONF -new \
                -newkey rsa:2048 -nodes \
                -out $new_certs_dir/runtime.csr \
                -keyout $private_dir/runtime.key
    """
    outpath = conf.configuration["CA_default"]["new_certs_dir"]
    name_dir = os.path.join(conf.configuration["CA_default"]["runtimes_dir"], name)
    private_key = os.path.join(name_dir, "private", "private.key")
    private = os.path.dirname(private_key)

    out = os.path.join(outpath, "{}.csr".format(name))

    os.umask(0077)

    try:
        os.makedirs(outpath, 0755)
    except OSError:
        pass

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

    organization = conf.domain
    commonname = name
    dnQualifier =  "any" if nodeid is None else nodeid
    subject = "/O={}/CN={}/dnQualifier={}".format(organization, commonname, dnQualifier)
    # Creates ECC-based certificate
    log = subprocess.Popen(["openssl", "ecparam", "-genkey",
                            "-name", "prime256v1",
                            "-out", private_key],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
    stdout, stderr = log.communicate()
    if log.returncode != 0:
        raise IOError(stderr)

    log = subprocess.Popen(["openssl", "req", "-new",
                            "-subj", subject,
                            "-key", private_key,
                            "-nodes",
                            "-utf8",
                            "-out", out],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
    stdout, stderr = log.communicate()
    if log.returncode != 0:
        raise IOError(stderr)
    return out
    # Creates RSA-based certificate
    # log = subprocess.Popen(["openssl", "req", "-new",
    #                         "-subj", subject,
    #                         "-newkey", "rsa:2048",
    #                         "-nodes",
    #                         "-utf8",
    #                         "-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_runtime