Пример #1
0
    def decode(self, data):
        self._raw_stream_data += data
        while True:
            try:
                (obj, data) = SSLv3Record.decode(
                    self._raw_stream_data,
                    connection=self,
                    payload_auto_decode=False
                )
                version = helper.get_version_by_version_id((
                    obj.version.major,
                    obj.version.minor
                ))

                self._raw_stream_data = data

                if version != self._cur_protocol_version:
                    raise WrongProtocolVersion(
                        record=obj
                    )

                if self._cur_record_type is None:
                    self._cur_record_type = obj.content_Type

                if self._cur_record_type != obj.content_type:
                    self._decode_record_payload()
                    self._cur_record_data = b""
                    self._cur_record_type = obj.content_type

                self._cur_record_data += obj.payload

                self._decode_record_payload()

            except NotEnoughData:
                break
Пример #2
0
    def decode(self, data):
        while True and len(data) > 0:
            try:
                (obj, data) = DTLSv10Record.decode(
                    data,
                    connection=self,
                    payload_auto_decode=False
                )

                version = helper.get_version_by_version_id((
                    obj.version.major,
                    obj.version.minor
                ))

                if version != self._cur_protocol_version:
                    # ToDo: Save data before exit?
                    raise WrongProtocolVersion(
                        record=obj
                    )
                (record, tmp_data) = DTLSv10Record.decode_raw_payload(
                    obj.content_type,
                    obj.payload,
                    connection=self,
                    payload_auto_decode=False
                )

                self._process(record)

            except NotEnoughData as e:
                print(e)
                break
Пример #3
0
    def __init__(self, msg=None, record=None, protocol_version=None):
        if msg is None:
            msg = "Wrong protocol version"
            msg_info = []
            if protocol_version:
                msg_info.append("Expected: %s" %
                                helper.get_version_name(protocol_version))
            if record:
                tmp_version = helper.get_version_by_version_id(
                    (record.version.major, record.version.minor))
                msg_info.append("Got: %s" %
                                helper.get_version_name(tmp_version))

            if len(msg_info) > 0:
                msg += " (%s)" % ", ".join(msg_info)

        IOError.__init__(self, msg)
        self.record = record
        self.protocol_version = protocol_version
Пример #4
0
    def __init__(self, msg=None, record=None, protocol_version=None):
        if msg is None:
            msg = "Wrong protocol version"
            msg_info = []
            if protocol_version:
                msg_info.append(
                    "Expected: %s" % helper.get_version_name(protocol_version)
                )
            if record:
                tmp_version = helper.get_version_by_version_id((
                    record.version.major,
                    record.version.minor
                ))
                msg_info.append(
                    "Got: %s" % helper.get_version_name(tmp_version)
                )

            if len(msg_info) > 0:
                msg += " (%s)" % ", ".join(msg_info)

        IOError.__init__(self, msg)
        self.record = record
        self.protocol_version = protocol_version