class TLSInnerPlaintext(_GenericTLSSessionInheritance):
    name = "TLS Inner Plaintext"
    fields_desc = [
        _TLSMsgListField("msg", []),
        ByteEnumField("type", None, _tls_type),
        XStrField("pad", "")
    ]

    def pre_dissect(self, s):
        """
        We need to parse the padding and type as soon as possible,
        else we won't be able to parse the message list...
        """
        if len(s) < 1:
            raise Exception("Invalid InnerPlaintext (too short).")

        l = len(s) - 1
        if s[-1] != b"\x00":
            msg_len = l
        else:
            n = 1
            while s[-n] != b"\x00" and n < l:
                n += 1
            msg_len = l - n
        self.fields_desc[0].length_from = lambda pkt: msg_len

        self.type = struct.unpack("B", s[msg_len:msg_len + 1])[0]

        return s
示例#2
0
class TLSInnerChangeCipherSpec(_GenericTLSSessionInheritance):
    __slots__ = ["type"]
    name = "TLS Inner Plaintext (CCS)"
    fields_desc = [_TLSMsgListField("msg", [], length_from=lambda x: 1)]

    def __init__(self, _pkt=None, *args, **kwargs):
        self.type = 0x14
        super(TLSInnerChangeCipherSpec, self).__init__(_pkt, *args, **kwargs)