'Generate a certificate using cn and san and store it at path'

def _generate_cert(self, cn, san, path):

    key = OpenSSL.crypto.PKey()
    key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
    cert = OpenSSL.crypto.X509()
    cert.set_version(2)
    cert.get_subject().CN = cn
    cert.set_pubkey(key)
    cert.set_serial_number(random.randint(0, (2 ** 20)))
    cert.set_notBefore('19300101000000+0000')
    cert.set_notAfter('20301231000000+0000')
    cert.set_issuer(self.cert.get_subject())
    if san:
        cert.add_extensions([san])
    cert.sign(self.key, 'sha1')
    with open(path, 'w') as f:
        f.write(OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key))
        f.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert))
        f.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, self.cert))
