def exchange_keys_with_client(the_connection):
        '''
        Prompts as to whether to send keys or not
        If keys are not sent, program terminates because it is
        impossible to encrypt and decrypt messages
        '''
        try:
            
            # wait to receive client's public key
            key = the_connection.recv(8192)
            key = key.split(',')
            public_key_tuple = (key[0], key[1])
            print '[+] Secure Chat Partner\'s Public Key Received\n'

            secure_utils.display_processing_cursor("Generating And Exchanging Your Keys")
            (n, e, d) = secure_utils.generate_my_keys(MODULUS_N, EXPONENT, MULTIPLICATIVE_INVERSE)
        
            print "[+] Your TRUNCATED Public Key is (****{0},****{1})".format(str(n)[0:5], str(e)[0:5])
            print "[+] Your Private Key is hidden"
            
            public_key = str(n) + ',' + str(e)
            the_connection.send(public_key)
            print '[+] Your Public Key Has Been Sent To The Other Party'
        
            private_key_tuple = (n, d)
        
            return ((public_key_tuple), (private_key_tuple))
        except Exception, e:
                secure_utils.clear_screen()
                print "\n\033[1;41m[+] Error connecting to server or exchanging keys\033[1;m"
                raw_input("\nPress [ENTER] To Return To The Main Menu...\n")
                return
                pass
Пример #2
0
def exchange_keys_with_server(the_connection):
        '''
        Prompts as to whether to send keys or not
        If keys are not sent, program terminates because it is
        impossible to encrypt and decrypt messages
        '''
        try:
            
            # wait to receive client's public public_key
        
            secure_utils.display_processing_cursor("Generating And Exchanging Keys")
            (n, e, d) = secure_utils.generate_my_keys(MODULUS_N, EXPONENT, MULTIPLICATIVE_INVERSE)
        
            print "[+] Your TRUNCATED Public Key is (****{0},****{1})".format(str(n)[0:5], str(e)[0:5])
            print "[+] Your Private Key is hidden"
            
            generated_public_key = str(n) + ',' + str(e)
            the_connection.send(generated_public_key)
            print "[+] Sent Your Public Key To Your Secure Chat Partner"
        
            message_received = the_connection.recv(8192)
        
            if(message_received == "Send Keys"):
            
                message_received = the_connection.recv(8192)
                servers_public_key = message_received.split(",")
                servers_public_key_tuple = (servers_public_key[0], servers_public_key[1])
                print '[+] Server\'s Public Key Received\n'
                client_private_key_tuple = (n, d)        
                return ((servers_public_key_tuple), (client_private_key_tuple))
            else:
                
                print "\n\033[1;41m[+] Message Received from server : {0}\033[1;m".format(message_received)
                secure_utils.display_processing_cursor("Returning to main menu")
                return ((None, None), (None, None))    
        except Exception, e:
                secure_utils.clear_screen()
                print "\n\033[1;41m[+] Error connecting to server or exchanging keys\033[1;m"
                pass