def sk_exchange_robot(ip): print "Generating and exchanging session key..." #SK1 private_key, public_key = crypto.keypair() #SK2# port = 21567 client_public_key = socket_scripts.socket_host(port) #SK3# session_key = crypto.generate_session_key() #SK4# encrypted_session_key = crypto.session_key_encrypt(client_public_key, session_key) #SK5# #ip = "192.168.1.2" port = 21568 socket_scripts.socket_client(ip, port, encrypted_session_key) print "Login Session key = ", session_key return session_key
def sk_exchange_client(ip): print "Generating and exchanging session key..." #SK1# private_key, public_key = crypto.keypair() #SK2# #ip = "192.168.1.2" #time.sleep(10) port = 21567 socket_scripts.socket_client(ip, port, public_key) #SK5# port = 21568 #time.sleep(2) encrypted_session_key = socket_scripts.socket_host(port) #SK6# session_key = crypto.session_key_decrypt(private_key, encrypted_session_key) print "Login Session key = ", session_key return session_key
def authentication_client(ip, port): attempt_status = "" # Starts a while loop that terminates once the authentication server has failed # or succeded. while not (attempt_status == "success" or attempt_status == "failed"): # The user enters the string shown by the server and sends the value # via socket. The client then waits for a response as to whether the # entered code was correct user_attempt = raw_input( "Please enter the 5 digit authentication string displayed on the server terminal\n" ) socket_scripts.socket_client(ip, port, user_attempt) attempt_status = socket_scripts.socket_host(port) # Displays a message to the user informing them whether the authentication # was sucessful, failed or was wrong and needs to be attempted again if attempt_status == "success": print "Authentication Succeeded" elif attempt_status == "retry": print "Login Code Incorrect. Please try again" elif attempt_status == "failed": print "Authentication Failed!!!\nPlease restart the program and try again" print "\n" return attempt_status
def RSA_server(ip, port): print "Generating and exchanging session key..." #SK1 private_key, public_key = crypto.keypair() #SK2# #port = 21566 client_public_key = socket_scripts.socket_host(port) #SK3# session_key = crypto.generate_session_key() #SK4# encrypted_session_key = crypto.session_key_encrypt(client_public_key, session_key) #SK5# #ip = "192.168.1.2" #port = 21567 socket_scripts.socket_client(ip, port, encrypted_session_key) print "Session key = ", session_key return session_key
def authentication_server(ip, port): print "An authentication code will be displayed on this terminal." print "Within 30 seconds enter the same code on the client terminal to authenticate the client" raw_input("\nPress enter to display the authentication code...\n") # Calls the function dedicated to generating the authentication code, # saves the code to a variable and displays it on the terminal window # for the client to copy and input authentication_string = generate_authentication_string() print "The authentication string is:\n\n", authentication_string print "\n\nPlease enter this string on the client terminal within 30 seconds" # Defines the number of permitted login attempts allowed login_attempts = 3 attempt_status = "" # Starts a while loop which terminates when the client runs out of # login attempts and the recieved client authentication code does # not match the one stored by the server while (login_attempts > 0) and (not (attempt_status == "success")): # Sets up the socket ready to recieve the code from the client attempt_data = socket_scripts.socket_host(port) # Checks to see whether the client code inputted matches the # correct serverside value and stores this status in a variable. # If the attempt fails the login attempt value reduces by one. # If the inputted code is incorrect and the the amount of remaining # attempts are zero then the status fails whereas if there are # attempts remaining the status is set to retry if attempt_data == authentication_string: attempt_status = "success" print "Authentication Succeeded" # Sends the attempt status to the client via socket socket_scripts.socket_client(ip, port, attempt_status) else: login_attempts = login_attempts - 1 if login_attempts == 0: attempt_status = "failed" print "Authentication Failed!!!\nPlease restart the program and try again" else: attempt_status = "retry" print "Login Code Incorrect!\nAttempts Remaining = ", login_attempts # Sends the attempt status to the client via socket socket_scripts.socket_client(ip, port, attempt_status) print "\n" return attempt_status
def RSA_client(ip, port): print "Generating and exchanging session key..." #SK1# private_key, public_key = crypto.keypair() #SK2# #port = 21566 socket_scripts.socket_client(ip, port, public_key) #SK5# #port = 21567 encrypted_session_key = socket_scripts.socket_host(port) #SK6# session_key = crypto.session_key_decrypt(private_key, encrypted_session_key) print "Session key = ", session_key return session_key