def test_parse_server_hello_extensions(self): """ :func:`parse_server_hello` fails to parse when SIGNATURE_ALGORITHMS extension bytes are present in the packet """ with pytest.raises(UnsupportedExtensionException): ServerHello.from_bytes(self.extensions_packet)
def test_server_hello_fails_with_server_name_extension(self): """ :py:func:`tls.hello_message.ServerHello` does not parse a packet with a server_name extension, and raises an error. """ server_name_extension_data = ( b'\x00\x00' # Extension Type: Server Name b'\x00\x0e' # Length b'\x00\x0c' # Server Name Indication Length b'\x00' # Server Name Type: host_name b'\x00\x09' # Length of hostname data b'localhost') server_hello_packet = self.common_server_hello_data + ( b'\x00\x12') + server_name_extension_data with pytest.raises(UnsupportedExtensionException): ServerHello.from_bytes(server_hello_packet)
def test_parse_server_hello_extensions(self): """ :func:`parse_server_hello` returns an instance of :class:`ServerHello`. """ record = ServerHello.from_bytes(self.extensions_packet) assert len(record.extensions) == 1 assert record.extensions[0].type == ExtensionType.SIGNATURE_ALGORITHMS assert record.extensions[0].data == b'abcd'
def test_from_bytes_with_truncated_hmac_extension(self): """ :py:func:`tls.hello_message.ServerHello` parses a packet with a truncated_hmac extension. """ record = ServerHello.from_bytes( self.server_hello_with_truncated_hmac_ext) assert len(record.extensions) == 1 assert record.extensions[0].type == enums.ExtensionType.TRUNCATED_HMAC assert record.extensions[0].data == Container()
def test_from_bytes_with_truncated_hmac_extension(self): """ :py:func:`tls.hello_message.ServerHello` parses a packet with a truncated_hmac extension. """ record = ServerHello.from_bytes( self.server_hello_with_truncated_hmac_ext ) assert len(record.extensions) == 1 assert record.extensions[0].type == enums.ExtensionType.TRUNCATED_HMAC assert record.extensions[0].data == Container()
def test_server_hello_fails_with_server_name_extension(self): """ :py:func:`tls.hello_message.ServerHello` does not parse a packet with a server_name extension, and raises an error. """ server_name_extension_data = ( b'\x00\x00' # Extension Type: Server Name b'\x00\x0e' # Length b'\x00\x0c' # Server Name Indication Length b'\x00' # Server Name Type: host_name b'\x00\x09' # Length of hostname data b'localhost' ) server_hello_packet = self.common_server_hello_data + ( b'\x00\x12' ) + server_name_extension_data with pytest.raises(UnsupportedExtensionException): ServerHello.from_bytes( server_hello_packet )
def test_parse_server_hello(self): """ :func:`parse_server_hello` returns an instance of :class:`ServerHello`. """ record = ServerHello.from_bytes(self.no_extensions_packet) assert isinstance(record, ServerHello) assert record.server_version.major == 3 assert record.server_version.minor == 0 assert record.random.gmt_unix_time == 16909060 assert record.random.random_bytes == b'0123456789012345678901234567' assert record.session_id == b'01234567890123456789012345678901' assert record.cipher_suite == b'\x00\x6B' assert record.compression_method == enums.CompressionMethod.NULL assert len(record.extensions) == 0
def test_as_bytes_unsupported_extension(self): """ :func:`ServerHello.as_bytes` fails to serialize a message that contains invalid extensions """ extensions_data = ( b'\x00\x12' b'\x00\x00' # Extension Type: Server Name b'\x00\x0e' # Length b'\x00\x0c' # Server Name Indication Length b'\x00' # Server Name Type: host_name b'\x00\x09' # Length of hostname data b'localhost') record = ServerHello.from_bytes(self.no_extensions_packet) extensions = _constructs.Extensions.parse(extensions_data) record.extensions = extensions with pytest.raises(UnsupportedExtensionException): record.as_bytes()
def test_as_bytes_unsupported_extension(self): """ :func:`ServerHello.as_bytes` fails to serialize a message that contains invalid extensions """ extensions_data = ( b'\x00\x12' b'\x00\x00' # Extension Type: Server Name b'\x00\x0e' # Length b'\x00\x0c' # Server Name Indication Length b'\x00' # Server Name Type: host_name b'\x00\x09' # Length of hostname data b'localhost' ) record = ServerHello.from_bytes(self.no_extensions_packet) extensions = _constructs.Extensions.parse(extensions_data) record.extensions = extensions with pytest.raises(UnsupportedExtensionException): record.as_bytes()
def test_as_bytes_with_truncated_hmac_extension(self): record = ServerHello.from_bytes( self.server_hello_with_truncated_hmac_ext) assert record.as_bytes() == self.server_hello_with_truncated_hmac_ext
def test_as_bytes_no_extensions(self): """ :func:`ServerHello.as_bytes` returns the bytes it was created with """ record = ServerHello.from_bytes(self.no_extensions_packet) assert record.as_bytes() == self.no_extensions_packet
def test_as_bytes_with_truncated_hmac_extension(self): record = ServerHello.from_bytes( self.server_hello_with_truncated_hmac_ext ) assert record.as_bytes() == self.server_hello_with_truncated_hmac_ext