def test_pull_server_hello_with_unknown_extension(self): buf = Buffer(data=load("tls_server_hello_with_unknown_extension.bin")) hello = pull_server_hello(buf) self.assertTrue(buf.eof()) self.assertEqual( hello, ServerHello( random=binascii.unhexlify( "ada85271d19680c615ea7336519e3fdf6f1e26f3b1075ee1de96ffa8884e8280" ), session_id=binascii.unhexlify( "9aee82a2d186c1cb32a329d9dcfe004a1a438ad0485a53c6bfcf55c132a23235" ), cipher_suite=tls.CipherSuite.AES_256_GCM_SHA384, compression_method=tls.CompressionMethod.NULL, key_share=( tls.Group.SECP256R1, binascii.unhexlify( "048b27d0282242d84b7fcc02a9c4f13eca0329e3c7029aa34a33794e6e7ba189" "5cca1c503bf0378ac6937c354912116ff3251026bca1958d7f387316c83ae6cf" "b2" ), ), supported_version=tls.TLS_VERSION_1_3, other_extensions=[(12345, b"foo")], ), ) # serialize buf = Buffer(1000) push_server_hello(buf, hello) self.assertEqual(buf.data, load("tls_server_hello_with_unknown_extension.bin"))
def test_pull_server_hello(self): buf = Buffer(data=load("tls_server_hello.bin")) hello = pull_server_hello(buf) self.assertTrue(buf.eof()) self.assertEqual( hello.random, binascii.unhexlify( "ada85271d19680c615ea7336519e3fdf6f1e26f3b1075ee1de96ffa8884e8280" ), ) self.assertEqual( hello.session_id, binascii.unhexlify( "9aee82a2d186c1cb32a329d9dcfe004a1a438ad0485a53c6bfcf55c132a23235" ), ) self.assertEqual(hello.cipher_suite, tls.CipherSuite.AES_256_GCM_SHA384) self.assertEqual(hello.compression_method, tls.CompressionMethod.NULL) self.assertEqual( hello.key_share, ( tls.Group.SECP256R1, binascii.unhexlify( "048b27d0282242d84b7fcc02a9c4f13eca0329e3c7029aa34a33794e6e7ba189" "5cca1c503bf0378ac6937c354912116ff3251026bca1958d7f387316c83ae6cf" "b2" ), ), ) self.assertEqual(hello.pre_shared_key, None) self.assertEqual(hello.supported_version, tls.TLS_VERSION_1_3)
def test_pull_server_hello_with_psk(self): buf = Buffer(data=load("tls_server_hello_with_psk.bin")) hello = pull_server_hello(buf) self.assertTrue(buf.eof()) self.assertEqual( hello.random, binascii.unhexlify( "ccbaaf04fc1bd5143b2cc6b97520cf37d91470dbfc8127131a7bf0f941e3a137" ), ) self.assertEqual( hello.session_id, binascii.unhexlify( "9483e7e895d0f4cec17086b0849601c0632662cd764e828f2f892f4c4b7771b0" ), ) self.assertEqual(hello.cipher_suite, tls.CipherSuite.AES_256_GCM_SHA384) self.assertEqual(hello.compression_method, tls.CompressionMethod.NULL) self.assertEqual( hello.key_share, ( tls.Group.SECP256R1, binascii.unhexlify( "0485d7cecbebfc548fc657bf51b8e8da842a4056b164a27f7702ca318c16e488" "18b6409593b15c6649d6f459387a53128b164178adc840179aad01d36ce95d62" "76" ), ), ) self.assertEqual(hello.pre_shared_key, 0) self.assertEqual(hello.supported_version, tls.TLS_VERSION_1_3) # serialize buf = Buffer(1000) push_server_hello(buf, hello) self.assertEqual(buf.data, load("tls_server_hello_with_psk.bin"))