Beispiel #1
0
 def test_server_certificate_from_bytes(self):
     parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(
         self.SERVER_CERTIFICATE_BYTES)
     assert len(parsed_record.subprotocol_messages) == 1
     assert parsed_record.subprotocol_messages[
         0].handshake_type == TlsHandshakeTypeByte.CERTIFICATE
     assert len_consumed == len(self.SERVER_CERTIFICATE_BYTES)
Beispiel #2
0
 def test_server_hello_done_from_bytes(self):
     parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(
         self.SERVER_HELLO_DONE_BYTES)
     assert len(parsed_record.subprotocol_messages) == 1
     assert parsed_record.subprotocol_messages[
         0].handshake_type == TlsHandshakeTypeByte.SERVER_DONE
     assert len_consumed == len(self.SERVER_HELLO_DONE_BYTES)
 def test_server_hello_done_from_bytes(self):
     parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(
         self.SERVER_HELLO_DONE_BYTES)
     self.assertEqual(len(parsed_record.subprotocol_messages), 1)
     self.assertEqual(parsed_record.subprotocol_messages[0].handshake_type,
                      TlsHandshakeTypeByte.SERVER_DONE)
     self.assertEqual(len_consumed, len(self.SERVER_HELLO_DONE_BYTES))
 def test_server_certificate_from_bytes(self):
     parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(
         self.SERVER_CERTIFICATE_BYTES)
     self.assertEqual(len(parsed_record.subprotocol_messages), 1)
     self.assertEqual(parsed_record.subprotocol_messages[0].handshake_type,
                      TlsHandshakeTypeByte.CERTIFICATE)
     self.assertEqual(len_consumed, len(self.SERVER_CERTIFICATE_BYTES))
Beispiel #5
0
 def test_multiple_messages_from_bytes(self):
     parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(
         self.MULTIPLE_MESSAGES_BYTES)
     assert len(parsed_record.subprotocol_messages) == 4
     assert parsed_record.subprotocol_messages[
         0].handshake_type == TlsHandshakeTypeByte.SERVER_HELLO
     assert parsed_record.subprotocol_messages[
         1].handshake_type == TlsHandshakeTypeByte.CERTIFICATE
     assert parsed_record.subprotocol_messages[
         2].handshake_type == TlsHandshakeTypeByte.SERVER_KEY_EXCHANGE
     assert parsed_record.subprotocol_messages[
         3].handshake_type == TlsHandshakeTypeByte.SERVER_DONE
     assert len_consumed == len(self.MULTIPLE_MESSAGES_BYTES)
Beispiel #6
0
    def parse_bytes(raw_bytes: bytes) -> Tuple[TlsRecord, int]:
        record_header, len_consumed = TlsRecordHeader.from_bytes(raw_bytes)

        # Try to parse the record
        if record_header.type == TlsRecordTypeByte.HANDSHAKE:
            return TlsHandshakeRecord.from_bytes(raw_bytes)
        if record_header.type == TlsRecordTypeByte.ALERT:
            return TlsAlertRecord.from_bytes(raw_bytes)
        if record_header.type in TlsRecordTypeByte:
            # Valid record type but we don't have the code to parse it right now
            return TlsRecord.from_bytes(raw_bytes)
        # Unknown type
        raise UnknownTypeByte()
 def test_multiple_messages_from_bytes(self):
     parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(
         self.MULTIPLE_MESSAGES_BYTES)
     self.assertEqual(len(parsed_record.subprotocol_messages), 4)
     self.assertEqual(parsed_record.subprotocol_messages[0].handshake_type,
                      TlsHandshakeTypeByte.SERVER_HELLO)
     self.assertEqual(parsed_record.subprotocol_messages[1].handshake_type,
                      TlsHandshakeTypeByte.CERTIFICATE)
     self.assertEqual(parsed_record.subprotocol_messages[2].handshake_type,
                      TlsHandshakeTypeByte.SERVER_KEY_EXCHANGE)
     self.assertEqual(parsed_record.subprotocol_messages[3].handshake_type,
                      TlsHandshakeTypeByte.SERVER_DONE)
     self.assertEqual(len_consumed, len(self.MULTIPLE_MESSAGES_BYTES))
Beispiel #8
0
from tls_parser.handshake_protocol import TlsHandshakeRecord

# Parse a server hello message
SERVER_HELLO_BYTES = (
    b"\x16\x03\x03\x00F\x02\x00\x00B\x03\x03\xf2\x00\xfd\x10\xea\x9e\x02\xe5\xc0\x83\x02T7"
    b"\xa7o\xf1\xdb\xd4\x8e\xc8>/\x9c\xeei\xb5\x9fi\xf9\x9e s\x00\xc0/\x00\x00\x1a\x00\x00"
    b"\x00\x00\xff\x01\x00\x01\x00\x00\x0b\x00\x04\x03\x00\x01\x02\x00#\x00\x00\x00\x0f\x00"
    b"\x01\x01")

parsed_record, len_consumed = TlsHandshakeRecord.from_bytes(SERVER_HELLO_BYTES)
print(parsed_record.header.tls_version)
print(parsed_record.header.type)
print(parsed_record.header.length)
print(parsed_record.subprotocol_messages[0].handshake_type)