def test_encryption_hmac(self): message = b'My secret message' key = b'9' * 32 hmac = b'3' * 16 cyphertext = crypto.symmetric_encrypt_HMAC(message, key, hmac) dmessage = crypto.symmetric_decrypt_HMAC(cyphertext, key, hmac) self.assertEqual(message, dmessage) # failing HMAC check with self.assertRaises(RuntimeError): crypto.symmetric_decrypt_HMAC(cyphertext, key, b'4'*16)
def test_encryption_hmac(self): message = b'My secret message' key = b'9' * 32 hmac = b'3' * 16 cyphertext = crypto.symmetric_encrypt_HMAC(message, key, hmac) dmessage = crypto.symmetric_decrypt_HMAC(cyphertext, key, hmac) self.assertEqual(message, dmessage) # failing HMAC check with self.assertRaises(RuntimeError): crypto.symmetric_decrypt_HMAC(cyphertext, key, b'4' * 16)
def _recv_messages(self): for message in self.connection: if not self.connected: break if self.channel_key: if self.channel_hmac: try: message = crypto.symmetric_decrypt_HMAC( message, self.channel_key, self.channel_hmac) except RuntimeError as e: self._LOG.exception(e) break else: message = crypto.symmetric_decrypt(message, self.channel_key) gevent.spawn(self._parse_message, message) self.idle() if not self._seen_logon and self.channel_secured: if self.wait_event('disconnected', timeout=5) is not None: return gevent.spawn(self.disconnect)
def _recv_messages(self): for message in self.connection: if not self.connected: break if self.channel_key: if self.channel_hmac: try: message = crypto.symmetric_decrypt_HMAC(message, self.channel_key, self.channel_hmac) except RuntimeError as e: self._LOG.exception(e) break else: message = crypto.symmetric_decrypt(message, self.channel_key) gevent.spawn(self._parse_message, message) gevent.idle() if not self._seen_logon and self.channel_secured: if self.wait_event('disconnected', timeout=5) is not None: return gevent.spawn(self.disconnect)