def __init__(self): """ Setup keys, secret message and encryption/decryption schemes. """ self._key = generateRSAKey(1024) self._secret = b'This is how Daniel Bleichenbachers adaptive chosen-ciphertext attack works...' self._pkcsmsg = bytes(self._key.encrypt(self._secret))
def GenerateKey(public_keyfile, private_keyfile, key_bits=2048): """Generate an RSA key pair.""" public = open(public_keyfile, 'w') os.fchmod(public.fileno(), 0400) private = open(private_keyfile, 'w') os.fchmod(private.fileno(), 0400) key = keyfactory.generateRSAKey(key_bits) public.write(key.writeXMLPublicKey() + '\n') private.write(key.write() + '\n')
def test_generate_TLS_1_1(self): priv_key = generateRSAKey(1024) cert_ver_g = CertificateVerifyGenerator(priv_key) state = ConnectionState() state.version = (3, 2) msg = cert_ver_g.generate(state) self.assertIsNotNone(msg) self.assertEqual(len(msg.signature), 128)
def test_generate_TLS_1_2(self): priv_key = generateRSAKey(1024) cert_ver_g = CertificateVerifyGenerator(priv_key) state = ConnectionState() state.version = (3, 3) msg = cert_ver_g.generate(state) self.assertIsNotNone(msg) self.assertEqual(len(msg.signature), 128) self.assertEqual(msg.signatureAlgorithm, (constants.HashAlgorithm.sha1, constants.SignatureAlgorithm.rsa))
def test_generate_TLS_1_2_with_cert_request(self): priv_key = generateRSAKey(1024) cert_ver_g = CertificateVerifyGenerator(priv_key) state = ConnectionState() state.version = (3, 3) req = CertificateRequest((3, 3)).create([], [], [(constants.HashAlgorithm.sha256, constants.SignatureAlgorithm.rsa), (constants.HashAlgorithm.sha1, constants.SignatureAlgorithm.rsa)]) state.handshake_messages = [req] msg = cert_ver_g.generate(state) self.assertIsNotNone(msg) self.assertEqual(len(msg.signature), 128) self.assertEqual(msg.signatureAlgorithm, (constants.HashAlgorithm.sha256, constants.SignatureAlgorithm.rsa))
def setUpClass(cls): cls.priv_key = keyfactory.generateRSAKey(1024)