def tx_loop( settings: 'Settings', queues: Dict[bytes, 'Queue'], gateway: 'Gateway', contact_list: 'ContactList', group_list: 'GroupList', master_key: 'MasterKey', file_no: int # stdin input file descriptor ) -> None: """Get input from user and process it accordingly. Tx side of TFC runs two processes -- input and output loop -- separate from one another. This approach allows queueing assembly packets and their output based on priority of different packets. tx_loop handles TxM-side functions excluding message encryption, output and hash ratchet key/counter updates in key_list database and log file writes. """ sys.stdin = os.fdopen(file_no) window = Window(contact_list, group_list) while True: try: readline.set_completer( get_tab_completer(contact_list, group_list, settings)) readline.parse_and_bind('tab: complete') window.update_group_win_members(group_list) while not contact_list.has_local_contact(): new_local_key(contact_list, settings, queues, gateway) while not contact_list.has_contacts(): add_new_contact(contact_list, group_list, settings, queues, gateway) while not window.is_selected(): window.select_tx_window(settings, queues) user_input = UserInput(window, settings) if user_input.type == 'message': queue_message(user_input, window, settings, queues[MESSAGE_PACKET_QUEUE]) elif user_input.type == 'file': queue_file(window, settings, queues[FILE_PACKET_QUEUE], gateway) elif user_input.type == 'command': process_command(user_input, window, settings, queues, contact_list, group_list, gateway, master_key) except (EOFError, FunctionReturn, KeyboardInterrupt): pass
def test_standard_nick_psk_kex(self): # Setup o_getpass = getpass.getpass getpass.getpass = lambda x: 'test_password' input_list = [ '*****@*****.**', '*****@*****.**', 'Alice_', 'psk', '.' ] gen = iter(input_list) def mock_input(_): return str(next(gen)) builtins.input = mock_input contact_list = ContactList() group_list = GroupList() gateway = Gateway() settings = Settings(disable_gui_dialog=True) queues = {COMMAND_PACKET_QUEUE: Queue(), KEY_MANAGEMENT_QUEUE: Queue()} # Test self.assertIsNone( add_new_contact(contact_list, group_list, settings, queues, gateway)) contact = contact_list.get_contact('*****@*****.**') self.assertEqual(contact.nick, 'Alice_') self.assertEqual(contact.tx_fingerprint, bytes(32)) # Indicates that PSK function was called # Teardown getpass.getpass = o_getpass os.remove('[email protected] - Give to [email protected]')
def test_autonick_ecdhe_kex(self): # Setup input_list = [ '*****@*****.**', '*****@*****.**', '', '', '2QJL5gVSPEjMTaxWPfYkzG9UJxzZDNSx6PPeVWdzS5CFN7knZy', 'Yes' ] gen = iter(input_list) def mock_input(_): return str(next(gen)) builtins.input = mock_input contact_list = ContactList() group_list = GroupList() gateway = Gateway() settings = Settings() queues = {COMMAND_PACKET_QUEUE: Queue(), KEY_MANAGEMENT_QUEUE: Queue()} # Test self.assertIsNone( add_new_contact(contact_list, group_list, settings, queues, gateway)) contact = contact_list.get_contact('*****@*****.**') self.assertEqual(contact.nick, 'Alice') self.assertNotEqual( contact.tx_fingerprint, bytes(32)) # Indicates that PSK function was not called
def input_loop(queues: Dict[bytes, 'Queue'], settings: 'Settings', gateway: 'Gateway', contact_list: 'ContactList', group_list: 'GroupList', master_key: 'MasterKey', stdin_fd: int) -> None: """Get input from user and process it accordingly. Tx side of TFC runs two processes -- input and sender loop -- separate from one another. This allows prioritized output of queued assembly packets. input_loop handles Tx-side functions excluding assembly packet encryption, output and logging, and hash ratchet key/counter updates in key_list database. """ sys.stdin = os.fdopen(stdin_fd) window = TxWindow(contact_list, group_list) while True: with ignored(EOFError, FunctionReturn, KeyboardInterrupt): readline.set_completer(get_tab_completer(contact_list, group_list, settings)) readline.parse_and_bind('tab: complete') window.update_group_win_members(group_list) while not contact_list.has_local_contact(): new_local_key(contact_list, settings, queues) while not contact_list.has_contacts(): add_new_contact(contact_list, group_list, settings, queues) while not window.is_selected(): window.select_tx_window(settings, queues) user_input = get_input(window, settings) if user_input.type == MESSAGE: queue_message(user_input, window, settings, queues[MESSAGE_PACKET_QUEUE]) elif user_input.type == FILE: queue_file(window, settings, queues[FILE_PACKET_QUEUE], gateway) elif user_input.type == COMMAND: process_command(user_input, window, settings, queues, contact_list, group_list, master_key)
def test_standard_nick_psk_kex(self): # Setup getpass.getpass = lambda _: 'test_password' input_list = [ '*****@*****.**', '*****@*****.**', 'Alice_', 'psk', '.' ] gen = iter(input_list) builtins.input = lambda _: str(next(gen)) # Test self.assertIsNone( add_new_contact(self.contact_list, self.group_list, self.settings, self.queues)) contact = self.contact_list.get_contact('*****@*****.**') self.assertEqual(contact.nick, 'Alice_') self.assertEqual( contact.tx_fingerprint, bytes(FINGERPRINT_LEN)) # Indicates that PSK function was called
def test_default_nick_x25519_kex(self): # Setup input_list = [ '*****@*****.**', '*****@*****.**', '', '', '5JJwZE46Eic9B8sKJ8Qocyxa8ytUJSfcqRo7Hr5ES7YgFGeJjCJ', 'Yes' ] gen = iter(input_list) builtins.input = lambda _: str(next(gen)) # Test self.assertIsNone( add_new_contact(self.contact_list, self.group_list, self.settings, self.queues)) contact = self.contact_list.get_contact('*****@*****.**') self.assertEqual(contact.nick, 'Alice') self.assertNotEqual(contact.tx_fingerprint, bytes( FINGERPRINT_LEN)) # Indicates that PSK function was not called