mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-10-01 03:15:44 -04:00
Improved malformed packet detection
This commit is contained in:
parent
4253175627
commit
fdaa58a6fa
@ -765,7 +765,7 @@ class Link:
|
|||||||
return plaintext
|
return plaintext
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Decryption failed on link "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Decryption failed on link "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
RNS.log(traceback.format_exc(), RNS.LOG_ERROR)
|
# RNS.log(traceback.format_exc(), RNS.LOG_ERROR)
|
||||||
# TODO: Think long about implications here
|
# TODO: Think long about implications here
|
||||||
# self.teardown()
|
# self.teardown()
|
||||||
|
|
||||||
|
@ -185,27 +185,33 @@ class Packet:
|
|||||||
|
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
self.flags = self.raw[0]
|
try:
|
||||||
self.hops = self.raw[1]
|
self.flags = self.raw[0]
|
||||||
|
self.hops = self.raw[1]
|
||||||
|
|
||||||
self.header_type = (self.flags & 0b11000000) >> 6
|
self.header_type = (self.flags & 0b11000000) >> 6
|
||||||
self.transport_type = (self.flags & 0b00110000) >> 4
|
self.transport_type = (self.flags & 0b00110000) >> 4
|
||||||
self.destination_type = (self.flags & 0b00001100) >> 2
|
self.destination_type = (self.flags & 0b00001100) >> 2
|
||||||
self.packet_type = (self.flags & 0b00000011)
|
self.packet_type = (self.flags & 0b00000011)
|
||||||
|
|
||||||
if self.header_type == Packet.HEADER_2:
|
if self.header_type == Packet.HEADER_2:
|
||||||
self.transport_id = self.raw[2:12]
|
self.transport_id = self.raw[2:12]
|
||||||
self.destination_hash = self.raw[12:22]
|
self.destination_hash = self.raw[12:22]
|
||||||
self.context = ord(self.raw[22:23])
|
self.context = ord(self.raw[22:23])
|
||||||
self.data = self.raw[23:]
|
self.data = self.raw[23:]
|
||||||
else:
|
else:
|
||||||
self.transport_id = None
|
self.transport_id = None
|
||||||
self.destination_hash = self.raw[2:12]
|
self.destination_hash = self.raw[2:12]
|
||||||
self.context = ord(self.raw[12:13])
|
self.context = ord(self.raw[12:13])
|
||||||
self.data = self.raw[13:]
|
self.data = self.raw[13:]
|
||||||
|
|
||||||
self.packed = False
|
self.packed = False
|
||||||
self.update_hash()
|
self.update_hash()
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Received malformed packet, dropping it. The contained exception was: "+str(e), RNS.LOG_EXTREME)
|
||||||
|
return False
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
"""
|
"""
|
||||||
|
@ -585,7 +585,9 @@ class Transport:
|
|||||||
Transport.jobs_locked = True
|
Transport.jobs_locked = True
|
||||||
|
|
||||||
packet = RNS.Packet(None, raw)
|
packet = RNS.Packet(None, raw)
|
||||||
packet.unpack()
|
if not packet.unpack():
|
||||||
|
return
|
||||||
|
|
||||||
packet.receiving_interface = interface
|
packet.receiving_interface = interface
|
||||||
packet.hops += 1
|
packet.hops += 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user