Beispiel #1
0
    def unpack(self, data: bytes) -> bytes:
        ticket_lifetime_int = PackableInt(4, 0)
        data = ticket_lifetime_int.unpack(data)
        self.ticket_lifetime = ticket_lifetime_int.value

        ticket_age_add_int = PackableInt(4, 0)
        data = ticket_age_add_int.unpack(data)
        self.ticket_age_add = ticket_age_add_int.value

        ticket_nonce_vec = Vector(1)
        data = ticket_nonce_vec.unpack(data)
        self.ticket_nonce = ticket_nonce_vec.data

        ticket_vec = Vector(2)
        data = ticket_vec.unpack(data)
        self.ticket = ticket_vec.data

        ext_vec = Vector(2)
        data = ext_vec.unpack(data)
        ext_data: bytes = ext_vec.data

        extensions = []
        while len(ext_data) > 0:
            ext = Extension()
            ext_data = ext.unpack(ext_data)
            extension = Extension.construct(ext.ext_type)
            if extension:
                ext.ext: Vector
                extension.unpack(ext.ext.data)
                ext.ext = extension
            extensions.append(ext)
        self.extensions = tuple(extensions)
        return data
Beispiel #2
0
 def unpack(self, data: bytes) -> bytes:
     self.handshake_type, data = HandshakeType.unpack(data)
     size = PackableInt(3, 0)
     data = size.unpack(data)
     assert len(data) >= size.value, f"incomplete handshake"
     self.handshake_data = data[:size.value]
     return data[size.value:]
Beispiel #3
0
 def unpack(self, data: bytes) -> bytes:
     self.content_type, data = ContentType.unpack(data)
     data = self.legacy_record_version.unpack(data)
     size = PackableInt(2, 0)
     data = size.unpack(data)
     assert len(data) >= size.value, "TLSPlaintext length not match body"
     self.data = data[:size.value]
     return data[size.value:]
Beispiel #4
0
 def unpack(self, data: bytes) -> bytes:
     self.content_type, data = ContentType.unpack(data)
     assert self.content_type in (ContentType.application_data, ContentType.change_cipher_spec), \
         f"TLSCiphertext error type:{self.content_type}"
     data = self.legacy_record_version.unpack(data)
     size = PackableInt(2, 0)
     data = size.unpack(data)
     assert len(data) >= size.value, "TLSCiphertext length not match body"
     self.encrypted_record = data[:size.value]
     return data[size.value:]
Beispiel #5
0
 def max_early_data_size(self):
     size = PackableInt(4, 0)
     if len(self.early_data_size) == 4:
         size.unpack(self.early_data_size)
     return size.value