コード例 #1
0
ファイル: test_hello_message.py プロジェクト: ashfall/tls
 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
ファイル: test_hello_messages.py プロジェクト: adamchainz/tls
 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
ファイル: test_hello_message.py プロジェクト: ashfall/tls
 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
ファイル: test_hello_message.py プロジェクト: ashfall/tls
    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
ファイル: test_hello_message.py プロジェクト: ashfall/tls
 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
ファイル: test_hello_message.py プロジェクト: ashfall/tls
    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
ファイル: test_hello_message.py プロジェクト: ashfall/tls
 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
ファイル: test_hello_message.py プロジェクト: ashfall/tls
 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