def test_connect_from_client_for_valid_input_5th_section_can_be_decrypted_using_server_key_to_4_element_array(self): server_key = 563 self.worker = ServerWorker(server_id='server_id_123', server_key=server_key, trusted_server=None) encrypted = self.worker.process_message_from_client_and_generate_message_to_trusted( (312421, 'client_id', 'server_id_123', 'nested')) self.assertNotEqual(encrypted, self.worker.error_signal) decrypted = decrypt(encrypted[4], server_key).split(':') self.assertEqual(len(decrypted), 4)
def __init__(self, config): super().__init__(config) self.client = paramiko.SSHClient() self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.cmd = 'ls' self.timeout = 5 self.username = config.params['username'] self.password = decrypt(config.params['password'])
def __init__(self, config): self.smtp_host = config['smtp_host'] self.smtp_port = config['smtp_port'] self.from_addr = config['from_addr'] self.to_addr = config['to_addr'] self.ssl = config['ssl'] self.username = config['username'] self.password = decrypt(config['password']) self.alert_interval = config['alert_interval']
def test_connect_from_client_for_valid_input_5th_section_contains_server_id_client_id_nonce_and_message(self): server_key = 563 self.worker = ServerWorker(server_id='server_id_123', server_key=server_key, trusted_server=None) encrypted = self.worker.process_message_from_client_and_generate_message_to_trusted( (self.random_value, 'client_id', 'server_id_123', 'nested')) self.assertNotEqual(encrypted, self.worker.error_signal) decrypted = decrypt(encrypted[4], server_key).split(':') self.assertEqual(int(decrypted[1]), self.random_value) self.assertEqual(decrypted[2], 'client_id') self.assertEqual(decrypted[3], 'server_id_123')
def test_encrypted_message_can_be_encrypted(self): original_message = 'original message' key = generate_random_key() encrypted_message = encrypt(original_message, key) decrypted_message = decrypt(encrypted_message, key) self.assertEquals(original_message, decrypted_message)
def test_decrypted_message_is_different_for_different_keys(self): encrypted = 'encrypted' decrypted_first = decrypt(encrypted, 123) decrypted_second = decrypt(encrypted, 321) self.assertNotEqual(decrypted_first, decrypted_second)
def test_produces_a_decrypted_message(self): decrypted_message = decrypt('encrypted', 123) self.assertIsNotNone(decrypted_message)
def __init__(self, config): self.webhook = decrypt(config['webhook']) self.headers = {"Content-type": "application/json"} self.alert_interval = config['alert_interval']
def unpack_nested_message_from_trusted(self, encrypted_message): decrypted = decrypt(encrypted_message, self.client_key).split(':') self.validate_message_length(decrypted, 2) self.trusted_nonce = decrypted[0] self.session_key = decrypted[1]
def decrypt_and_split(self, key, message): return decrypt(message, key).split(':')
def test_connect_sends_encrypted_random_server_id_at_last_position(self): sid = 'server_id' client = Client(client_id=None, client_key=self.client_key, server=None, server_id=sid) encrypted = client.prepare_message_for_server()[3] decrypted = decrypt(encrypted, self.client_key).split(':') self.assertEqual(decrypted[3], '%s' % sid)
def test_connect_sends_encrypted_random_value_at_third_position(self): cid = 'client_id' client = Client(client_id=cid, client_key=self.client_key, server=None, server_id=None) encrypted = client.prepare_message_for_server()[3] decrypted = decrypt(encrypted, self.client_key).split(':') self.assertEqual(decrypted[2], '%s' % cid)
def test_connect_sends_encrypted_random_value_at_second_position(self): encrypted = self.client.prepare_message_for_server()[3] random = self.client.random_value decrypted = decrypt(encrypted, self.client_key).split(':') self.assertEqual(int(decrypted[1]), random)
def test_connect_sends_encrypted_own_nonce_at_first_position(self): encrypted = self.client.prepare_message_for_server()[3] nonce = self.client.nonce decrypted = decrypt(encrypted, self.client_key).split(':') self.assertEqual(decrypted[0], nonce)
def test_connect_sends_encrypted_with_own_key_element_that_contains_4_elements_separated_by_colons(self): encrypted = self.client.prepare_message_for_server()[3] decrypted = decrypt(encrypted, self.client_key).split(':') self.assertEqual(len(decrypted), 4)
def decrypt_with_id_and_split(self, message, id_key, separator): return decrypt(message, self.keys[id_key]).split(separator)