Exemple #1
0
 def doProcessInboxPacket(self, arg):
     """
     Action method.
     """
     newpacket, info, _, _ = arg
     block = encrypted.Unserialize(newpacket.Payload)
     if block is None:
         lg.out(
             2,
             'proxy_receiver.doProcessInboxPacket ERROR reading data from %s'
             % newpacket.CreatorID)
         return
     try:
         session_key = key.DecryptLocalPrivateKey(block.EncryptedSessionKey)
         padded_data = key.DecryptWithSessionKey(session_key,
                                                 block.EncryptedData)
         inpt = cStringIO.StringIO(padded_data[:int(block.Length)])
         data = inpt.read()
     except:
         lg.out(
             2,
             'proxy_receiver.doProcessInboxPacket ERROR reading data from %s'
             % newpacket.CreatorID)
         lg.exc()
         try:
             inpt.close()
         except:
             pass
         return
     inpt.close()
     routed_packet = signed.Unserialize(data)
     if not routed_packet:
         lg.out(
             2,
             'proxy_receiver.doProcessInboxPacket ERROR unserialize packet from %s'
             % newpacket.CreatorID)
         return
     if _Debug:
         lg.out(
             _DebugLevel, '<<<Relay-IN %s from %s://%s' % (
                 str(routed_packet),
                 info.proto,
                 info.host,
             ))
     packet_in.process(routed_packet, info)
     del block
     del data
     del padded_data
     del inpt
     del session_key
     del routed_packet
Exemple #2
0
 def doProcessInboxPacket(self, arg):
     """
     Action method.
     """
     newpacket, info, _, _ = arg
     block = encrypted.Unserialize(newpacket.Payload)
     if block is None:
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR reading data from %s' % newpacket.CreatorID)
         return
     try:
         session_key = key.DecryptLocalPrivateKey(block.EncryptedSessionKey)
         padded_data = key.DecryptWithSessionKey(session_key, block.EncryptedData)
         inpt = cStringIO.StringIO(padded_data[:int(block.Length)])
         data = inpt.read()
     except:
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR reading data from %s' % newpacket.CreatorID)
         lg.exc()
         try:
             inpt.close()
         except:
             pass
         return
     inpt.close()
     routed_packet = signed.Unserialize(data)
     if not routed_packet:
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR unserialize packet failed from %s' % newpacket.CreatorID)
         return
     if routed_packet.Command == commands.Identity():
         newidentity = identity.identity(xmlsrc=routed_packet.Payload)
         idurl = newidentity.getIDURL()
         if not identitycache.HasKey(idurl):
             lg.warn('received new identity: %s' % idurl)
         if not identitycache.UpdateAfterChecking(idurl, routed_packet.Payload):
             lg.warn("ERROR has non-Valid identity")
             return
     if not routed_packet.Valid():
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR invalid packet from %s' % newpacket.CreatorID)
         return
     self.traffic_in += len(data)
     if _Debug:
         lg.out(_DebugLevel, '<<<Relay-IN %s from %s://%s with %d bytes' % (
             str(routed_packet), info.proto, info.host, len(data)))
     packet_in.process(routed_packet, info)
     del block
     del data
     del padded_data
     del inpt
     del session_key
     del routed_packet
 def doProcessInboxPacket(self, arg):
     """
     Action method.
     """
     newpacket, info, _, _ = arg
     block = encrypted.Unserialize(newpacket.Payload)
     if block is None:
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR reading data from %s' % newpacket.CreatorID)
         return
     try:
         session_key = key.DecryptLocalPK(block.EncryptedSessionKey)
         padded_data = key.DecryptWithSessionKey(session_key, block.EncryptedData)
         inpt = cStringIO.StringIO(padded_data[:int(block.Length)])
         data = inpt.read()
     except:
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR reading data from %s' % newpacket.CreatorID)
         lg.exc()
         try:
             inpt.close()
         except:
             pass
         return
     inpt.close()
     routed_packet = signed.Unserialize(data)
     if not routed_packet:
         lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR unserialize packet from %s' % newpacket.CreatorID)
         return
     if _Debug:
         lg.out(_DebugLevel, '<<<Relay-IN %s from %s://%s' % (
             str(routed_packet), info.proto, info.host,))
     packet_in.process(routed_packet, info)
     del block
     del data
     del padded_data
     del inpt
     del session_key
     del routed_packet
    def doProcessInboxPacket(self, arg):
        """
        Action method.
        """
        newpacket, info, status, error_message = arg
        block = encrypted.Unserialize(newpacket.Payload)
        if block is None:
            lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR reading data from %s' % newpacket.RemoteID)
            return
        try:
            session_key = key.DecryptLocalPK(block.EncryptedSessionKey)
            padded_data = key.DecryptWithSessionKey(session_key, block.EncryptedData)
            inpt = cStringIO.StringIO(padded_data[:int(block.Length)])
            data = inpt.read()
        except:
            lg.out(2, 'proxy_receiver.doProcessInboxPacket ERROR reading data from %s' % newpacket.RemoteID)
            lg.out(2, '\n' + padded_data)
            lg.exc()
            try:
                inpt.close()
            except:
                pass
            return
        inpt.close()
        routed_packet = signed.Unserialize(data)
#        transfer_id = gateway.make_transfer_ID()
#        pkt_in = packet_in.create(transfer_id)
#        pkt_in.setup(pkt_in)
#        pkt_in.automat('valid-inbox-packet', routed_packet)
        packet_in.process(routed_packet, info)
        del block
        del data
        del padded_data
        del inpt
        del session_key
        del routed_packet
Exemple #5
0
    def _do_process_inbox_packet(self, *args, **kwargs):
        newpacket, info, _, _ = args[0]
        block = encrypted.Unserialize(newpacket.Payload)
        if block is None:
            lg.err('reading data from %s' % newpacket.CreatorID)
            return
        try:
            session_key = key.DecryptLocalPrivateKey(block.EncryptedSessionKey)
            padded_data = key.DecryptWithSessionKey(session_key, block.EncryptedData, session_key_type=block.SessionKeyType)
            inpt = BytesIO(padded_data[:int(block.Length)])
            data = inpt.read()
        except:
            lg.err('reading data from %s' % newpacket.CreatorID)
            lg.exc()
            try:
                inpt.close()
            except:
                pass
            return
        inpt.close()

        if newpacket.Command == commands.RelayAck():
            try:
                ack_info = serialization.BytesToDict(data, keys_to_text=True, values_to_text=True)
            except:
                lg.exc()
                return
            if _Debug:
                lg.out(_DebugLevel, '<<<Relay-ACK %s:%s from %s://%s with %d bytes %s' % (
                    ack_info['command'], ack_info['packet_id'], info.proto, info.host, len(data), ack_info['error'], ))
            if _PacketLogFileEnabled:
                lg.out(0, '                \033[0;49;33mRELAY ACK %s(%s) with %d bytes from %s to %s TID:%s\033[0m' % (
                    ack_info['command'], ack_info['packet_id'], info.bytes_received,
                    global_id.UrlToGlobalID(ack_info['from']), global_id.UrlToGlobalID(ack_info['to']),
                    info.transfer_id), log_name='packet', showtime=True)
            from transport.proxy import proxy_sender
            if proxy_sender.A():
                proxy_sender.A('relay-ack', ack_info, info)
            return True

        if newpacket.Command == commands.RelayFail():
            try:
                fail_info = serialization.BytesToDict(data, keys_to_text=True, values_to_text=True)
            except:
                lg.exc()
                return
            if _Debug:
                lg.out(_DebugLevel, '<<<Relay-FAIL %s:%s from %s://%s with %d bytes %s' % (
                    fail_info['command'], fail_info['packet_id'], info.proto, info.host, len(data), fail_info['error'], ))
            if _PacketLogFileEnabled:
                lg.out(0, '                \033[0;49;33mRELAY FAIL %s(%s) with %d bytes from %s to %s TID:%s\033[0m' % (
                    fail_info['command'], fail_info['packet_id'], info.bytes_received,
                    global_id.UrlToGlobalID(fail_info['from']), global_id.UrlToGlobalID(fail_info['to']),
                    info.transfer_id), log_name='packet', showtime=True)
            from transport.proxy import proxy_sender
            if proxy_sender.A():
                proxy_sender.A('relay-failed', fail_info, info)
            return True

        routed_packet = signed.Unserialize(data)
        if not routed_packet:
            lg.err('unserialize packet failed from %s' % newpacket.CreatorID)
            return

        if _Debug:
            lg.out(_DebugLevel, '<<<Relay-IN %s from %s://%s with %d bytes' % (
                str(routed_packet), info.proto, info.host, len(data)))
        if _PacketLogFileEnabled:
            lg.out(0, '                \033[0;49;33mRELAY IN %s(%s) with %d bytes from %s to %s TID:%s\033[0m' % (
                routed_packet.Command, routed_packet.PacketID, info.bytes_received,
                global_id.UrlToGlobalID(info.sender_idurl), global_id.UrlToGlobalID(routed_packet.RemoteID),
                info.transfer_id), log_name='packet', showtime=True)

        if routed_packet.Command == commands.Identity():
            if _Debug:
                lg.out(_DebugLevel, '    found identity in relay packet %s' % routed_packet)
            newidentity = identity.identity(xmlsrc=routed_packet.Payload)
            idurl = newidentity.getIDURL()
            if not identitycache.HasKey(idurl):
                lg.info('received new identity %s rev %r' % (idurl.original(), newidentity.getRevisionValue(), ))
            if not identitycache.UpdateAfterChecking(idurl, routed_packet.Payload):
                lg.warn("ERROR has non-Valid identity")
                return

        if routed_packet.Command in [commands.Relay(), commands.RelayIn(), ] and routed_packet.PacketID.lower().startswith('identity:'):
            if _Debug:
                lg.out(_DebugLevel, '    found routed identity in relay packet %s' % routed_packet)
            try:
                routed_identity = signed.Unserialize(routed_packet.Payload)
                newidentity = identity.identity(xmlsrc=routed_identity.Payload)
                idurl = newidentity.getIDURL()
                if not identitycache.HasKey(idurl):
                    lg.warn('received new "routed" identity: %s' % idurl)
                if not identitycache.UpdateAfterChecking(idurl, routed_identity.Payload):
                    lg.warn("ERROR has non-Valid identity")
                    return
            except:
                lg.exc()

        if newpacket.Command == commands.RelayIn() and routed_packet.Command == commands.Fail():
            if routed_packet.Payload == b'route not exist' or routed_packet.Payload == b'route already closed':
                for pout in packet_out.search_by_packet_id(routed_packet.PacketID):
                    lg.warn('received %r from %r, outgoing packet is failed: %r' % (routed_packet.Payload, newpacket.CreatorID, pout, ))
                    pout.automat('request-failed')
                return

        self.traffic_in += len(data)
        packet_in.process(routed_packet, info)
        del block
        del data
        del padded_data
        del inpt
        del session_key
        del routed_packet
Exemple #6
0
    def _do_process_inbox_packet(self, *args, **kwargs):
        newpacket, info, _, _ = args[0]
        block = encrypted.Unserialize(newpacket.Payload)
        if block is None:
            lg.err('reading data from %s' % newpacket.CreatorID)
            return
        try:
            session_key = key.DecryptLocalPrivateKey(block.EncryptedSessionKey)
            padded_data = key.DecryptWithSessionKey(session_key, block.EncryptedData)
            inpt = BytesIO(padded_data[:int(block.Length)])
            data = inpt.read()
        except:
            lg.err('reading data from %s' % newpacket.CreatorID)
            lg.exc()
            try:
                inpt.close()
            except:
                pass
            return
        inpt.close()
        routed_packet = signed.Unserialize(data)
        if not routed_packet:
            lg.err('unserialize packet failed from %s' % newpacket.CreatorID)
            return
        if _Debug:
            lg.out(_DebugLevel, '<<<Relay-IN %s from %s://%s with %d bytes' % (
                str(routed_packet), info.proto, info.host, len(data)))
        if routed_packet.Command == commands.Identity():
            if _Debug:
                lg.out(_DebugLevel, '    found identity in relay packet %s' % routed_packet)
            newidentity = identity.identity(xmlsrc=routed_packet.Payload)
            idurl = newidentity.getIDURL()
            if not identitycache.HasKey(idurl):
                lg.info('received new identity: %s' % idurl)
            if not identitycache.UpdateAfterChecking(idurl, routed_packet.Payload):
                lg.warn("ERROR has non-Valid identity")
                return
        if routed_packet.Command == commands.Relay() and routed_packet.PacketID.lower() == 'identity':
            if _Debug:
                lg.out(_DebugLevel, '    found routed identity in relay packet %s' % routed_packet)
            try:
                routed_identity = signed.Unserialize(routed_packet.Payload)
                newidentity = identity.identity(xmlsrc=routed_identity.Payload)
                idurl = newidentity.getIDURL()
                if not identitycache.HasKey(idurl):
                    lg.warn('received new "routed" identity: %s' % idurl)
                if not identitycache.UpdateAfterChecking(idurl, routed_identity.Payload):
                    lg.warn("ERROR has non-Valid identity")
                    return
            except:
                lg.exc()
#         if not routed_packet.Valid():
#             lg.err('invalid packet %s from %s' % (
#                 routed_packet, newpacket.CreatorID, ))
#             return
        self.traffic_in += len(data)
        packet_in.process(routed_packet, info)
        del block
        del data
        del padded_data
        del inpt
        del session_key
        del routed_packet
Exemple #7
0
    def _do_process_inbox_packet(self, *args, **kwargs):
        newpacket, info, _, _ = args[0]
        block = encrypted.Unserialize(newpacket.Payload)
        if block is None:
            lg.err('reading data from %s' % newpacket.CreatorID)
            return
        try:
            session_key = key.DecryptLocalPrivateKey(block.EncryptedSessionKey)
            padded_data = key.DecryptWithSessionKey(
                session_key,
                block.EncryptedData,
                session_key_type=block.SessionKeyType)
            inpt = BytesIO(padded_data[:int(block.Length)])
            data = inpt.read()
        except:
            lg.err('reading data from %s' % newpacket.CreatorID)
            lg.exc()
            try:
                inpt.close()
            except:
                pass
            return
        inpt.close()
        routed_packet = signed.Unserialize(data)
        if not routed_packet:
            lg.err('unserialize packet failed from %s' % newpacket.CreatorID)
            return
        if _Debug:
            lg.out(
                _DebugLevel, '<<<Relay-IN %s from %s://%s with %d bytes' %
                (str(routed_packet), info.proto, info.host, len(data)))
        if _PacketLogFileEnabled:
            lg.out(
                0,
                '                \033[0;49;33mRELAY IN %s(%s) with %d bytes from %s to %s TID:%s\033[0m'
                % (routed_packet.Command, routed_packet.PacketID,
                   info.bytes_received,
                   global_id.UrlToGlobalID(info.sender_idurl),
                   global_id.UrlToGlobalID(
                       routed_packet.RemoteID), info.transfer_id),
                log_name='packet',
                showtime=True)
        if routed_packet.Command == commands.Identity():
            if _Debug:
                lg.out(_DebugLevel,
                       '    found identity in relay packet %s' % routed_packet)
            newidentity = identity.identity(xmlsrc=routed_packet.Payload)
            idurl = newidentity.getIDURL()
            if not identitycache.HasKey(idurl):
                lg.info('received new identity %s rev %r' % (
                    idurl.original(),
                    newidentity.getRevisionValue(),
                ))
            if not identitycache.UpdateAfterChecking(idurl,
                                                     routed_packet.Payload):
                lg.warn("ERROR has non-Valid identity")
                return
        if routed_packet.Command == commands.Relay(
        ) and routed_packet.PacketID.lower().startswith('identity:'):
            if _Debug:
                lg.out(
                    _DebugLevel,
                    '    found routed identity in relay packet %s' %
                    routed_packet)
            try:
                routed_identity = signed.Unserialize(routed_packet.Payload)
                newidentity = identity.identity(xmlsrc=routed_identity.Payload)
                idurl = newidentity.getIDURL()
                if not identitycache.HasKey(idurl):
                    lg.warn('received new "routed" identity: %s' % idurl)
                if not identitycache.UpdateAfterChecking(
                        idurl, routed_identity.Payload):
                    lg.warn("ERROR has non-Valid identity")
                    return
            except:
                lg.exc()
#         if not routed_packet.Valid():
#             lg.err('invalid packet %s from %s' % (
#                 routed_packet, newpacket.CreatorID, ))
#             return
        self.traffic_in += len(data)
        packet_in.process(routed_packet, info)
        del block
        del data
        del padded_data
        del inpt
        del session_key
        del routed_packet