def _generate_cert(self, cn, san, path):
        """Generate a certificate using cn and san and store it at 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))
        # Use a huge range so we dont have to worry about bad clocks
        cert.set_notBefore("20200101000000Z")
        cert.set_notAfter("20210101000000Z")
        cert.set_issuer(self.cert.get_subject())
        if san:
            cert.add_extensions([san])
        cert.sign(self.key, 'sha256')

        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))
Generate a certificate using cn and san and store it at path
nogotofail/mitm/util/ca.py