예제 #1
0
파일: client.py 프로젝트: kenken28/vpn
    sys.exit(1)
print "Connected to", s.getsockname()
MBtitle = "SERVER"

# Set up variables for Diffie-Hellman protocol
nonceB = str( m.randI(2**256,2**257) )
cID = str( m.randI(2**64,2**65) )
tmpAES = crypter.AESc( m.getMD5(Tkey) )
Tkey = "two hashes walked into a bar, one was a salted" # Erase key

#### Key Establishment and Mutual Authentication starts ####
b = m.randI(2**256,2**257)
B = pow(m.P_ROOT, b, m.PRIME2048)

# recieve ["I'm Alice", Ra]
hello1 = m.mRecv(s)
sID, nonceA = hello1.split(m.sp)

# send [Rb, E("Bob", Ra, gb mod p, Kab)]
hello2 = tmpAES.enc(cID + m.sp + nonceA + m.sp + str(B))
m.mSend(s, nonceB + m.sp + hello2)

# revieve [E("Alice", Rb, ga mod p, Kab)], and varify Rb and Kab
responceA = m.mRecv(s)
hello3raw = tmpAES.dec(responceA)
try:
    sID2, nonceBecho, strA = hello3raw.split(m.sp)
    if nonceBecho != nonceB or sID != sID2:
        s.close()
        print "Incorrect nonceB or sID or Key!"
        sys.exit()
예제 #2
0
파일: server.py 프로젝트: kenken28/vpn
# Set up variables for Diffie-Hellman protocol
nonceA = str( m.randI(2**256,2**257) )
sID = str( m.randI(2**64,2**65) )
tmpAES = crypter.AESc( m.getMD5(Tkey) )
Tkey = "two hashes walked into a bar, one was a salted" # Erase key

#### Key Establishment and Mutual Authentication starts ####
a = m.randI(2**256,2**257)
A = pow(m.P_ROOT, a, m.PRIME2048)

# send ["I'm Alice", Ra]
m.mSend(conn, sID + m.sp + nonceA)

# revieve [Rb, E("Bob", Ra, gb mod p, Kab)], and varify Ra and Kab
responceB = m.mRecv(conn)
nonceB, hello2 = responceB.split(m.sp)
hello2raw = tmpAES.dec(hello2)
try:
    cID, nonceAecho, strB = hello2raw.split(m.sp)
    if nonceAecho != nonceA:
        conn.close()
        print "Incorrect nonceA or Key!"
        sys.exit()
except:
    conn.close()
    print "Incorrect nonceA or Key!"
    sys.exit()

# send [E("Alice", Rb, ga mod p, Kab)]
responceA = tmpAES.enc(sID + m.sp + nonceB + m.sp + str(A))