Beispiel #1
0
 def encodePacket(self, addr, data):
     sessionKey = self.makeSession(addr, True)
     if not sessionKey:
         print('Unknown address', addr, 'trying introduction...')
         sessionKey = self.introducer.makeIntroduction(addr, self.sock)
         if not sessionKey:
             print('Introduction failed.')
             return
     packet = DataPacket()
     packet.createDataPacket(sessionKey, data, self.keys.entropy)
     return packet
Beispiel #2
0
 def decodePacket(self, addr, data):
     sessionKey = self.makeSession(
         addr, False
     )  # Don't introduce yourself when you receive a packet from an unknown host, that's not the protocol
     if sessionKey:  # Must be a data packet
         packet = DataPacket()
         packet.decodeDataPacket(sessionKey, data)
         if packet.checkMac() and packet.checkTimestamp():
             return packet
         else:
             print('Integrity failed', packet.checkMac(),
                   packet.checkTimestamp())
             return None
     else:  # Must be an intro packet
         print('Unknown address', addr)
         if self.introducer:
             intro = self.introducer.acceptIntroduction(data, addr)
             if intro:
                 return intro
             else:
                 return None