Exemplo n.º 1
0
def calc_rendezvous_point_data(rendezvous_point):
    # print rendezvous_point #testing,currently not being passed, no item error
    rp_ip = consensus.getRouter(rendezvous_point)["ip"]
    rp_or_port = consensus.getRouter(rendezvous_point)["orport"]
    rp_id = consensus.getRouter(rendezvous_point)["identity"]
    router_descriptor = consensus.getRouterDescriptor((consensus.getRouter(rendezvous_point))["identityhash"])
    onion_key = consensus.getRouterOnionKey(router_descriptor)
    return rp_id, rp_ip, rp_or_port, onion_key
Exemplo n.º 2
0
def buildExtendPayload(nm):
    r = consensus.getRouter(nm)
    ip = map(int,r['ip'].split("."))
    extend = struct.pack(">BBBBH", ip[0], ip[1], ip[2], ip[3], int(r['orport']))
    (x, extendcc) = buildCreatePayload(nm)
    extend += extendcc
    extend += r['identity']
    return (x, extend)
Exemplo n.º 3
0
def remoteKeyX (on):
    r = consensus.getRouter(on)
    x = numunpack(os.urandom(DH_SEC_LEN))
    X = pow(DH_G,x,DH_P)
    X = numpack(X,DH_LEN)
    router_descriptor = consensus.getRouterDescriptor(r['identityhash'])
    router_onion_key = consensus.getRouterOnionKey(router_descriptor)
    remoteKey = RSA.importKey(router_onion_key)
    payload = hybridEncrypt(remoteKey, X)
    return (x, payload)
Exemplo n.º 4
0
def buildExtendPayload(on):
    match = re.search(r'(\d{1,3}\.){3}\d{1,3}(:\d{1,5})?', on)
    # if on =="Goblin500":
    #     print "Goblin500"
    #     ip = [82,26,108,68]
    #     port = 9001
    #     extend = struct.pack("B" * len(ip), *ip)
    #     extend += struct.pack("H", port)

    #     x, pl_To_Next = remoteKeyX(on) 
    #     extend += pl_To_Next
    #     r = consensus.getRouter(on)

    #     print r['identity'].encode('hex')
    #     extend += r['identity']

    if match:
        ip, port,identity = on.split(":")
        print ip
        # print type(ip)
        d = consensus.get_data_by_ip(ip)

        ip = map(int,ip.split("."))
        port = int(port)

        extend = struct.pack("B" * len(ip), *ip)
        extend += struct.pack("H", port)
        d = consensus.get_data_by_ip(ip)

        x, pl_To_Next = remoteKeyX(d['identityhash'])

        extend += pl_To_Next
        extend += d['identity']

    else :
        r = consensus.getRouter(on)
        ip = map(int,r['ip'].split("."))
        port = int(r['orport'])
        extend = struct.pack("B" * len(ip), *ip)
        extend += struct.pack("H", port)

        x, pl_To_Next = remoteKeyX(on) #made into function much better than repeating code
           #creates the payload to the next hop
            #pl_To_Next = hybridEncrypt(remoteKey, X)
        extend += pl_To_Next
        extend += r['identity']

    return (x, extend)
Exemplo n.º 5
0
def buildCreatePayload(nm):
#get router rsa onion key
    r = consensus.getRouter(nm)
    rd = consensus.getRouterDescriptor(r['identity'])
    rdk = consensus.getRouterOnionKey(rd)
    rsa = RSA.importKey(rdk)

#generate diffie helman secret
    x = numunpack(os.urandom(DH_SEC_LEN))
#DH pub key X
    X = pow(DH_G, x, DH_P)
#encrypt X to remote
    createpayload = hybridEncrypt(rsa,numpack(X, DH_LEN))
#pack packet
    #pkt = struct.pack(">HB", circId, cellTypeToId("CREATE")) + createpayload + "\x00" * (509-len(createpayload))
    return (x, createpayload)
Exemplo n.º 6
0
def ip_port_for_on(on):
    test = consensus.getRouter(on)
    print test
Exemplo n.º 7
0
def recv_cell(io, cmd=None):
    while True:
        c = Cell()
        cell = c.unpack(io)
        print "Recv cell ", cell.__class__.__name__
        if cmd==None:
            return cell
        elif cell.__class__.__name__ == cmd:
            return cell
        print "Ignoring cell"

print "getting consensus"
consensus.fetchConsensus()

FIRST_HOP = "orion"
firstHopR = consensus.getRouter(FIRST_HOP)
print firstHopR

s = socket.socket()
ssl_sock = ssl.wrap_socket(s)
ssl_sock.connect((firstHopR['ip'], int(firstHopR['orport'])))
peerAddr= [int(x) for x in ssl_sock.getpeername()[0].split(".")]

# Send our versions cell to get started
cv = CellVersions()
cv.versions = [3]
ssl_sock.write(cv.pack())

# Wait for NetInfo, ignoring others and then send our netinfo
cnetinf = recv_cell(ssl_sock, 'CellNetInfo')
ssl_sock.send(cnetinf.pack())