def test_create(self): session = Session() session.create(masterSecret=1, sessionID=2, cipherSuite=3, srpUsername=4, clientCertChain=5, serverCertChain=6, tackExt=7, tackInHelloExt=8, serverName=9) self.assertEqual(session.masterSecret, 1) self.assertEqual(session.sessionID, 2) self.assertEqual(session.cipherSuite, 3) self.assertEqual(session.srpUsername, 4) self.assertEqual(session.clientCertChain, 5) self.assertEqual(session.serverCertChain, 6) self.assertEqual(session.tackExt, 7) self.assertEqual(session.tackInHelloExt, 8) self.assertEqual(session.serverName, 9) self.assertTrue(session.resumable) self.assertFalse(session.encryptThenMAC) self.assertFalse(session.extendedMasterSecret)
def test_create_with_new_additions(self): session = Session() session.create(1, 2, 3, 4, 5, 6, 7, 8, 9, encryptThenMAC=10, extendedMasterSecret=11) self.assertEqual(session.encryptThenMAC, 10) self.assertEqual(session.extendedMasterSecret, 11)
def test___init__(self): session = Session() self.assertIsNotNone(session) self.assertFalse(session.resumable) self.assertFalse(session.encryptThenMAC) self.assertFalse(session.extendedMasterSecret)
def test_keyingMaterialExporter_invalid_label(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._clientRandom = bytearray(b'012345678901234567890123456789ab') conn._serverRandom = bytearray(b'987654321098765432109876543210ab') conn._recordLayer.version = (3, 1) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA with self.assertRaises(ValueError): conn.keyingMaterialExporter(bytearray(b'server finished'), 20)
def test_keyingMaterialExporter_tls1_3(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._clientRandom = bytearray(b'012345678901234567890123456789ab') conn._serverRandom = bytearray(b'987654321098765432109876543210ab') conn._recordLayer.version = (3, 4) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 with self.assertRaises(AssertionError): conn.keyingMaterialExporter(bytearray(b'test'), 20)
def test_keyingMaterialExporter_tls1_2_sha384(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._clientRandom = bytearray(b'012345678901234567890123456789ab') conn._serverRandom = bytearray(b'987654321098765432109876543210ab') conn._recordLayer.version = (3, 3) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 mat = conn.keyingMaterialExporter(bytearray(b'test'), 20) self.assertEqual(mat, bytearray(b'1\xb8X\xef\x9b\xa5\n9p\x13\xfaxXI\\$\xdf\xb5\xc7i'))
def test_keyingMaterialExporter_tls1_3_sha384(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._recordLayer.version = (3, 4) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 conn.session.exporterMasterSecret = \ bytearray(b'0123456789abcdef0123456789abcdef0123456789abcdef' + b'0123456789abcdef0123456789abcdef0123456789abcdef') mat = conn.keyingMaterialExporter(bytearray(b'test'), 20) self.assertEqual( mat, bytearray(b';\x96;\x08U*\xbd1\x0fL5^0\xe1*I\x9e\xd3\xcb0'))
def test_keyingMaterialExporter_tls1_1(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._clientRandom = bytearray(b'012345678901234567890123456789ab') conn._serverRandom = bytearray(b'987654321098765432109876543210ab') conn._recordLayer.version = (3, 2) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA mat = conn.keyingMaterialExporter(bytearray(b'test'), 20) self.assertEqual(mat, bytearray(b'\x1f\xf8\x18\x01:\x9f\x15a\xd5x\xaa;Y>' + b'\xafG\x92AH\xa4'))
def test_keyingMaterialExporter_tls1_2_sha256(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._clientRandom = bytearray(b'012345678901234567890123456789ab') conn._serverRandom = bytearray(b'987654321098765432109876543210ab') conn._recordLayer.version = (3, 3) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 mat = conn.keyingMaterialExporter(bytearray(b'test'), 20) self.assertEqual(mat, bytearray(b'\xe6EQ\x93\xcb!\xe7\x87\x1e\xdd\x85' + b'\xb2\x08|\xc9\xbfDh\r\x90'))
def test_keyingMaterialExporter_tls1_3_sha256(self): sock = MockSocket(bytearray(0)) conn = TLSConnection(sock) conn._recordLayer.version = (3, 4) conn.session = Session() conn.session.cipherSuite = \ CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 conn.session.exporterMasterSecret = \ bytearray(b'0123456789abcdef0123456789abcdef' + b'0123456789abcdef0123456789abcdef') mat = conn.keyingMaterialExporter(bytearray(b'test'), 20) self.assertEqual( mat, bytearray( b'W_h\x10\x83\xc0XD\x0fw\x0e\xfc/\x92\x8f\xb3\xfd\x13\x96\xd9') )