Exemplo n.º 1
0
 def subjectPrincipalCheck(self, addr, certTuple):
     subject = certTuple['S']
     # subject = cert_tuple['S']
     # cp = 1
     # length = struct.unpack('>I', subject[cp: cp + 4])[0]
     # cp += 4
     # subject_nodeID = packet.xxhashUser(subject[cp: cp + length].decode("utf-8"))
     # cp += length
     # ip_data = subject[cp:]
     # subject = ip_data
     # print(subject)
     try:
         if subject[0] == 0:
             cp = 1
             length = struct.unpack('>I', subject[cp:cp + 4])[0]
             cp += 4
             # subject_nodeID = packet.xxhashUser(subject[cp: cp + length].decode("utf-8"))
             cp += length
             ip_data = subject[cp:]
             # print('SUBJECT NODEID', packet.xxhashUser(subject_nodeID))
             if ip_data[0] == 4:
                 ip = packet.constructIP(ip_data[1:5])
                 port = struct.unpack('>H', ip_data[5:7])[0]
                 # length = struct.unpack('>I', ip_data[7:11])[0]
                 # node_id = struct.unpack('>H', ip_data[11: length + 11])[0]
                 # print('IP DETAILS', packet.constructIP(ip), port, node_id)
                 # if subject_nodeID != node_id:
                 #     print('Wrong node ID')
                 #     return False
                 if ip != addr[0]:
                     print('Wrong node IP')
                     return False
                 if port != addr[1]:
                     print('Wrong node PORT')
                     return False
             # TODO IPV6 check
             else:
                 return False
         elif subject[0] == 4:
             ip_data = subject
             ip = packet.constructIP(ip_data[1:5])
             port = struct.unpack('>H', ip_data[5:7])[0]
             if ip != addr[0]:
                 print('Wrong node IP')
                 return False
             if port != addr[1]:
                 print('Wrong node PORT')
                 return False
         else:
             print('Wrong Principal format / IPv6')
             return False
     except:
         print('Exception while verifying the subject principal')
         return False
     return True
Exemplo n.º 2
0
def recursiveLookup(STS, nodeTuple):
    global recursiveNodes
    results = request.KademliaProtocol(STS).findNode(
        packet.xxhashUser('netsec41'),
        (packet.constructIP(nodeTuple[0]), nodeTuple[1]))
    time.sleep(3)
    nodeData = message.Messages().returnResponse(results)
    if nodeData is not None:
        message.Messages().removeRequest(results)
        for key, value in RT.PopulateRoutingTable(nodeData).items():
            recursiveNodes[key] = value
    else:
        message.Messages().removeRequest(results)
Exemplo n.º 3
0
 def subjectPrincipalCheck(self, addr, certTuple):
     subject = certTuple['S']
     try:
         if subject[0] == 0:
             cp = 1
             length = struct.unpack('>I', subject[cp:cp + 4])[0]
             cp += 4
             cp += length
             ip_data = subject[cp:]
             if ip_data[0] == 4:
                 ip = packet.constructIP(ip_data[1:5])
                 port = struct.unpack('>H', ip_data[5:7])[0]
                 if ip != addr[0]:
                     print('Wrong node IP')
                     return False
                 if port != addr[1]:
                     print('Wrong node PORT')
                     return False
             # TODO IPV6 check
             else:
                 return False
         elif subject[0] == 4:
             ip_data = subject
             ip = packet.constructIP(ip_data[1:5])
             port = struct.unpack('>H', ip_data[5:7])[0]
             if ip != addr[0]:
                 print('Wrong node IP')
                 return False
             if port != addr[1]:
                 print('Wrong node PORT')
                 return False
         else:
             print('Wrong Principal format / IPv6')
             return False
     except:
         print('Exception while verifying the subject principal')
         return False
     return True
Exemplo n.º 4
0
    def getAliveNodes(self, nodeTuple):
        LRU = nodeTuple[0]
        index = nodeTuple.index(LRU)
        for node in nodeTuple:
            if node[4] < LRU[4]:
                LRU = node
                index = nodeTuple.index(LRU)
        if self.pingCheck(packet.constructIP(LRU[0]), LRU[1]):
            LRU[4] = time.time()
            nodeTuple.pop(index)
            nodeTuple.append(LRU)
        else:
            nodeTuple.pop(index)

        return nodeTuple
Exemplo n.º 5
0
def storeOnNodes(STS):
    global StoreData
    while True:
        file = open("/home/netsec41/dht_data", "r")
        StoreData.expireCache()
        for line in file:
            data = base64.b64decode(line.strip())
            key = packet.hashData(data)
            kClosestNodes = RT.Kclosest(key)
            for nodeTuple in kClosestNodes:
                server = packet.constructIP(nodeTuple[0])
                port = nodeTuple[1]
                result = request.KademliaProtocol(STS).store(
                    data, (server, port))
                message.Messages().removeRequest(result)
        file.close()
        STS.cleanConnectionStates()
        time.sleep(300)