def Test_Verify_Hmac(): message = urandom(1212) sharedHkey = urandom(32) hmac_Calculated = common.get_HMAC(message,sharedHkey) print "hmac_Calculated = %s" % hmac_Calculated if common.Verify_HMAC(message, hmac_Calculated, sharedHkey): print "HMAC verification : success" else: print "HMAC verification : FAILURE"
def Ask_Server_For_List(username): nonceServer = common.Increment_Nonce(clientDataTable[1][6]) clearText = ''.join([nonceServer, username]) cipherText, iv = common.Symmetric_Encrypt(clearText, clientDataTable[1][4]) hmacInputData = ''.join([iv, cipherText]) hmac = common.get_HMAC(hmacInputData, clientDataTable[1][5]) sendData = ''.join([common.Get_Message_ID("client_to_server_list_update"), hmac, hmacInputData]) sockClient.send(sendData) clientDataTable[1][6] = nonceServer return
if recvdUsername != currentUserDataList[0]: print "Username doesn't match the client IP / Port combo" continue # HMAC, nonce and username is verified at this point, next we prepare the response response_nonce = common.Increment_Nonce(recvdNonce) userListMessage = "" for i in range(0, len(authed_users)): userListMessage = ''.join([userListMessage, chr(len(authed_users[i][0])), authed_users[i][0]]) # using chr(0) as a delimiter between user list and number of users userListMessageWithLength = ''.join([userListMessage, chr(0), str(len(authed_users))]) # print userListMessage response_plaintext = ''.join([response_nonce, userListMessageWithLength]) # print response_plaintext response_ciphertext, response_iv = common.Symmetric_Encrypt(response_plaintext, shared_aes) response_hmacInput = ''.join([response_iv, response_ciphertext]) response_hmac = common.get_HMAC(response_hmacInput, shared_hkey) response_message_id = common.Get_Message_ID("server_to_client_user_list") sendData = ''.join([response_message_id, response_hmac, response_hmacInput]) sock.send(sendData) # updating Nonce to response_Nonce in authed_users authed_users[authdUsersListIndex][6] = response_nonce print "sent user list to username = %s" % recvdUsername continue ##################### Handles the support for client to client communication ################## # Handles the Client1 request to server to initiate communication with client2 and sends a headsup to Client2 if client_message_id_name == "client1_request_to_server_for_client2": A1UserDataList, A1userFound, A1authdUsersListIndex = Get_User_Data_with_ip_port(client_ip, client_port) if A1userFound == False: print "Could not find source client IP or Port in the authd users list" continue