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() except: s.close() print "Incorrect nonceB or Key!" sys.exit() # calculate session key A = int(strA) Cs = pow(A, b, m.PRIME2048) #print Cs ##### Key Establishment and Mutual Authentication ends ##### # start sending and receiving messages myAES = crypter.AESc( m.getMD5(Cs) ) m.loop_send(s, myAES, MBtitle)
# 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)) m.mSend(conn, responceA) # calculate session key B = int(strB) Ss = pow(B, a, m.PRIME2048) #print Ss ##### Key Establishment and Mutual Authentication ends ##### # start sending and receiving messages myAES = crypter.AESc( m.getMD5(Ss) ) m.loop_send(conn, myAES, MBtitle)