def create_certificate_authority(keypair, dn, request, serial,
                                 validity_period, digest, start=None):
    if start is None:
        start = datetime.datetime.utcnow()
    expire = start + datetime.timedelta(seconds=validity_period)
    start = start.strftime(b"%Y%m%d%H%M%SZ")
    expire = expire.strftime(b"%Y%m%d%H%M%SZ")
    req = request.original
    cert = crypto.X509()
    cert.set_subject(req.get_subject())
    cert.set_pubkey(req.get_pubkey())
    cert.set_notBefore(start)
    cert.set_notAfter(expire)
    cert.set_serial_number(serial)
    cert.add_extensions([
        crypto.X509Extension("basicConstraints", True,
                             "CA:TRUE, pathlen:0"),
        crypto.X509Extension("keyUsage", True,
                             "keyCertSign, cRLSign"),
        crypto.X509Extension("subjectKeyIdentifier", False, "hash",
                             subject=cert),
    ])
    cert.add_extensions([
        crypto.X509Extension(
            "authorityKeyIdentifier", False,
            "keyid:always", issuer=cert
        )
    ])
    cert.set_issuer(cert.get_subject())
    cert.sign(keypair.original, digest)
    return Certificate(cert)
Connecting with a non-existing cert file
dataset/ETHPy150Open ClusterHQ/flocker/flocker/ca/_ca.py/create_certificate_authority--crossover with--dataset/ETHPy150Open azoft-dev-team/imagrium/env/Lib/test/test_ssl.py/ThreadedTests.test_nonexisting_cert