Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
    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)
Пример #4
0
 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'
Пример #5
0
 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'
Пример #6
0
 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()
Пример #7
0
 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()
Пример #8
0
    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
            )
Пример #9
0
 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
Пример #10
0
 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
Пример #11
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()
Пример #12
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()
Пример #13
0
 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
Пример #14
0
 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
Пример #15
0
 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
Пример #16
0
 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