def send(self, message): """ Send a message :param message: a message instance :type message: :class:`steam.core.msg.Msg`, :class:`steam.core.msg.MsgProto` """ if not isinstance(message, (Msg, MsgProto)): raise ValueError("Expected Msg or MsgProto, got %s" % message) if self.steam_id: message.steamID = self.steam_id if self.session_id: message.sessionID = self.session_id if self.verbose_debug: self._LOG.debug("Outgoing: %s\n%s" % (repr(message), str(message))) else: self._LOG.debug("Outgoing: %s", repr(message)) data = message.serialize() if self.channel_key: if self.channel_hmac: data = crypto.symmetric_encrypt_HMAC(data, self.channel_key, self.channel_hmac) else: data = crypto.symmetric_encrypt(data, self.channel_key) self.connection.put_message(data)
def send(self, message): """ Send a message :param message: a message instance :type message: :class:`steam.core.msg.Msg`, :class:`steam.core.msg.MsgProto` """ if not isinstance(message, (Msg, MsgProto)): raise ValueError("Expected Msg or MsgProto, got %s" % message) if self.steam_id: message.steamID = self.steam_id if self.session_id: message.sessionID = self.session_id if self.verbose_debug: self._LOG.debug("Outgoing: %s\n%s" % (repr(message), str(message))) else: self._LOG.debug("Outgoing: %s", repr(message)) data = message.serialize() if self.channel_key: if self.channel_hmac: data = crypto.symmetric_encrypt_HMAC(data, self.channel_key, self.channel_hmac) else: data = crypto.symmetric_encrypt(data, self.channel_key) self.connection.put_message(data)
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)