def test_finished(self): record = Handshake.from_bytes(self.finished_handshake) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.FINISHED assert record.length == 20 assert isinstance(record.body, Finished) assert record.body.verify_data == b'some-encrypted-bytes'
def test_as_bytes_certificate_status(self): """ :py:class:`tls.message.Handshake` serializes a record containing a ``CertificateStatus`` message. """ record = Handshake.from_bytes(self.certificate_status_handshake) assert record.as_bytes() == self.certificate_status_handshake
def test_as_bytes_certificate_url(self): """ :py:meth:`tls.message.Handshake.as_bytes` returns a valid packet when the body contains a ``CertificateURL`` message. """ record = Handshake.from_bytes(self.certificate_url_handshake_packet) assert record.as_bytes() == self.certificate_url_handshake_packet
def test_parse_certificate_request_in_handshake(self): record = Handshake.from_bytes( self.certificate_request_handshake ) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.CERTIFICATE_REQUEST assert record.length == 8 assert isinstance(record.body, CertificateRequest)
def test_from_bytes_certificate_status(self): """ :py:class:`tls.message.Handshake` parses a valid packet with ``CertificateStatus`` message. """ record = Handshake.from_bytes(self.certificate_status_handshake) assert isinstance(record, Handshake) assert record.msg_type == enums.HandshakeType.CERTIFICATE_STATUS assert record.length == 9 assert isinstance(record.body, CertificateStatus) assert record.body.status_type == enums.CertificateStatusType.OCSP assert record.body.response == b'12345'
def test_from_bytes_certificate_url(self): """ :py:class:`tls.messages.Handshake` parses a valid packet with a ``CertificateURL`` message. """ record = Handshake.from_bytes(self.certificate_url_handshake_packet) assert isinstance(record, Handshake) assert record.msg_type == enums.HandshakeType.CERTIFICATE_URL assert record.length == 42 assert isinstance(record.body, CertificateURL) assert record.body.type == enums.CertChainType.INDIVIDUAL_CERTS assert len(record.body.url_and_hash_list) == 1 assert isinstance(record.body.url_and_hash_list[0], URLAndHash) assert record.body.url_and_hash_list[0].url == b'cert.example.com' assert record.body.url_and_hash_list[0].padding == 1 assert (record.body.url_and_hash_list[0].sha1_hash == b'abcdefghijklmnopqrst')
def test_from_bytes_certificate_url(self): """ :py:class:`tls.message.Handshake` parses a valid packet with a ``CertificateURL`` message. """ record = Handshake.from_bytes(self.certificate_url_handshake_packet) assert isinstance(record, Handshake) assert record.msg_type == enums.HandshakeType.CERTIFICATE_URL assert record.length == 42 assert isinstance(record.body, CertificateURL) assert record.body.type == enums.CertChainType.INDIVIDUAL_CERTS assert len(record.body.url_and_hash_list) == 1 assert isinstance(record.body.url_and_hash_list[0], URLAndHash) assert record.body.url_and_hash_list[0].url == b'cert.example.com' assert record.body.url_and_hash_list[0].padding == 1 assert (record.body.url_and_hash_list[0].sha1_hash == b'abcdefghijklmnopqrst')
def test_parse_server_hello_in_handshake(self): record = Handshake.from_bytes(self.server_hello_handshake_packet) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.SERVER_HELLO assert record.length == 80 assert isinstance(record.body, ServerHello)
def test_parse_client_hello_in_handshake(self): record = Handshake.from_bytes(self.client_hello_handshake_packet) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.CLIENT_HELLO assert record.length == 51 assert isinstance(record.body, ClientHello)
def test_not_implemented(self): record = Handshake.from_bytes(self.server_key_exchange_handshake) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.SERVER_KEY_EXCHANGE assert record.length == 0 assert record.body is None
def test_parse_hello_request(self): record = Handshake.from_bytes(self.hello_request_handshake) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.HELLO_REQUEST assert record.length == 0 assert isinstance(record.body, HelloRequest)
def test_as_bytes_not_implemented(self): record = Handshake.from_bytes(self.server_key_exchange_handshake) assert record.as_bytes() == self.server_key_exchange_handshake
def test_as_bytes_client_hello_packet(self): record = Handshake.from_bytes(self.client_hello_handshake_packet) assert record.as_bytes() == self.client_hello_handshake_packet
def test_server_hello_done(self): record = Handshake.from_bytes(self.server_hello_done_handshake) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.SERVER_HELLO_DONE assert record.length == 0 assert isinstance(record.body, ServerHelloDone)
def test_parse_certificate_request_in_handshake(self): record = Handshake.from_bytes(self.certificate_request_handshake) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.CERTIFICATE_REQUEST assert record.length == 8 assert isinstance(record.body, CertificateRequest)
def test_as_bytes_server_hello_done(self): record = Handshake.from_bytes(self.server_hello_done_handshake) assert record.as_bytes() == self.server_hello_done_handshake
def test_parse_certificate_in_handshake(self): record = Handshake.from_bytes(self.certificate_handshake_packet) assert isinstance(record, Handshake) assert record.msg_type == HandshakeType.CERTIFICATE assert record.length == 11 assert isinstance(record.body, Certificate)
def test_as_bytes_finished(self): record = Handshake.from_bytes(self.finished_handshake) assert record.as_bytes() == self.finished_handshake
def test_as_bytes_certificate_request_packet(self): record = Handshake.from_bytes(self.certificate_request_handshake) assert record.as_bytes() == self.certificate_request_handshake
def test_as_bytes_hello_request(self): record = Handshake.from_bytes(self.hello_request_handshake) assert record.as_bytes() == self.hello_request_handshake