def test_invalid_harac_raises_raises_struct_error(self): # Check that in the case where an internal error caused bytestring (possible key material) to end up in hash # ratchet value, the system raises some error that prevents the output of packet. In this case the, error comes # from the unsuccessful encoding of hash ratchet counter. for l in range(1, 33): key_list = KeyList() key_list.keysets = [create_keyset('Alice', tx_key=SYMMETRIC_KEY_LENGTH * b'\x02', tx_harac=l * b'k')] with self.assertRaises(struct.error): send_packet(key_list, self.gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LENGTH), nick_to_pub_key("Alice"), True)
def test_valid_message_packet(self): # Setup gateway = Gateway(serial_error_correction=5) key_list = KeyList(master_key=bytes(SYMMETRIC_KEY_LENGTH)) key_list.keysets = [create_keyset('Alice', tx_key=SYMMETRIC_KEY_LENGTH * b'\x02', tx_harac=8)] # Test self.assertIsNone(send_packet(key_list, gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LENGTH), nick_to_pub_key("Alice"), True)) self.assertEqual(len(gateway.packets), 1) time.sleep(0.01) self.assertFalse(self.l_queue.empty())
def test_invalid_harac_raises_raises_struct_error(self): # Check that in case where internal error caused bytestring (possible key material) # to end up in hash ratchet value, system raises some error that prevents output of packet. # In this case the error comes from unsuccessful encoding of hash ratchet counter. for l in range(1, 33): key_list = KeyList() key_list.keysets = [ create_keyset(tx_key=KEY_LENGTH * b'\x02', tx_harac=l * b'k') ] with self.assertRaises(struct.error): send_packet(key_list, self.gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LEN), self.settings, '*****@*****.**', '*****@*****.**', True)
def test_valid_command_packet(self): """Test that commands are output as they should. Since command packets have no trailer, and since only user's Receiver Program has local decryption key, encryption with any key recipient is not already in possession of does not compromise plaintext. """ # Setup key_list = KeyList(master_key=bytes(SYMMETRIC_KEY_LENGTH)) key_list.keysets = [create_keyset(LOCAL_ID)] # Test self.assertIsNone(send_packet(key_list, self.gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LENGTH))) self.assertEqual(len(self.gateway.packets), 1) self.assertEqual(len(self.gateway.packets[0]), 345) self.assertEqual(self.l_queue.qsize(), 1)
def test_invalid_account_crashes(self): # Setup settings = Settings() gateway = Gateway() l_queue = Queue() key_list = KeyList() key_list.keysets = [create_keyset('Alice')] # Check that in case where internal error caused bytestring (possible key material) # to end up in account strings, System raises some error that prevents output of packet. # In this case the error comes from unsuccessful encoding of string (AttributeError) # or KeyList lookup error when bytes are used (StopIteration). These errors are not catched. with self.assertRaises(StopIteration): send_packet(bytes(256), key_list, settings, gateway, l_queue, b'*****@*****.**', '*****@*****.**', True) with self.assertRaises(AttributeError): send_packet(bytes(256), key_list, settings, gateway, l_queue, '*****@*****.**', b'*****@*****.**', True)
def test_valid_message_packet(self): # Setup settings = Settings(long_packet_rand_d=True) gateway = Gateway() l_queue = Queue() key_list = KeyList(master_key=bytes(32)) key_list.keysets = [ create_keyset(tx_hek=32 * b'\x01', tx_key=32 * b'\x02', tx_harac=8) ] # Test self.assertIsNone( send_packet(bytes(256), key_list, settings, gateway, l_queue, '*****@*****.**', '*****@*****.**', True)) self.assertEqual(len(gateway.packets), 1) self.assertEqual(len(gateway.packets[0]), 396) time.sleep(0.2) self.assertFalse(l_queue.empty())
def test_invalid_harac_crashes(self): # Setup settings = Settings() gateway = Gateway() l_queue = Queue() # Check that in case where internal error caused bytestring (possible key material) # to end up in hash ratchet value, system raises some error that prevents output of packet. # In this case the error comes from unsuccessful encoding of hash ratchet counter. for l in range(1, 32): key_list = KeyList() key_list.keysets = [ create_keyset(tx_hek=32 * b'\x01', tx_key=32 * b'\x02', tx_harac=l * b'k') ] with self.assertRaises(struct.error): send_packet(bytes(256), key_list, settings, gateway, l_queue, '*****@*****.**', '*****@*****.**', True)
def test_valid_message_packet(self): # Setup settings = Settings(multi_packet_random_delay=True) gateway = Gateway() key_list = KeyList(master_key=bytes(KEY_LENGTH)) key_list.keysets = [ create_keyset(tx_key=KEY_LENGTH * b'\x02', tx_harac=8) ] # Test self.assertIsNone( send_packet(key_list, gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LEN), settings, '*****@*****.**', '*****@*****.**', True)) self.assertEqual(len(gateway.packets), 1) self.assertEqual(len(gateway.packets[0]), 396) time.sleep(0.1) self.assertFalse(self.l_queue.empty())
def test_valid_command_packet(self): """\ Test that commands are output as they should Since command packets have no trailer, and since only user's RxM has local decryption key, encryption with any key recipient is not already in possession of does not compromise plaintext. """ # Setup settings = Settings() gateway = Gateway() l_queue = Queue() key_list = KeyList(master_key=bytes(32)) key_list.keysets = [create_keyset('local')] # Test self.assertIsNone( send_packet(bytes(256), key_list, settings, gateway, l_queue)) self.assertEqual(len(gateway.packets), 1) self.assertEqual(len(gateway.packets[0]), 365) time.sleep(0.2) self.assertTrue(l_queue.empty())