示例#1
0
文件: client.py 项目: kenken28/vpn
# Socket connection
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Connecting to SERVER..."
try:
    s.connect((HOST, PORT))
except socket.error as msg:
    s.close()
    s = None
    print 'Could not open socket.'
    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)
示例#2
0
文件: server.py 项目: kenken28/vpn
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    s.bind((HOST, PORT))
    print "Server IP address and Port:", s.getsockname()
    print "\nListening for incoming connection requests..."
    s.listen(1)
except socket.error as msg:
    s.close()
    print 'could not open socket'
    sys.exit(1)
conn, addr = s.accept()
print 'Connected by', addr
MBtitle = "CLIENT"

# 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)