From e3c826c6912dc84564b28b87a991f7ea179abc67 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Thu, 4 Apr 2024 09:40:46 +0200 Subject: [PATCH] Require noise tag with encrypted messages, improve debug logging --- core/src/trezor/wire/thp/channel.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py index f755386fd..2df9cd222 100644 --- a/core/src/trezor/wire/thp/channel.py +++ b/core/src/trezor/wire/thp/channel.py @@ -44,7 +44,8 @@ MAX_PAYLOAD_LEN = const(60000) class Channel(Context): def __init__(self, channel_cache: ChannelCache) -> None: - print("channel.__init__") + if __debug__: + log.debug(__name__, "channel initialization") iface = _decode_iface(channel_cache.iface) super().__init__(iface, channel_cache.channel_id) self.channel_cache = channel_cache @@ -279,7 +280,9 @@ class Channel(Context): self.sessions[session_id].incoming_message.publish( MessageWithType( message_type, - self.buffer[INIT_DATA_OFFSET + 3 : message_length - CHECKSUM_LENGTH], + self.buffer[ + INIT_DATA_OFFSET + 3 : message_length - CHECKSUM_LENGTH - TAG_LENGTH + ], ) ) @@ -379,7 +382,7 @@ class Channel(Context): # CALLED BY WORKFLOW / SESSION CONTEXT async def write(self, msg: protobuf.MessageType, session_id: int = 0) -> None: - print("channel.write") + print("channel.write:" + msg.MESSAGE_NAME) noise_payload_len = self._encode_into_buffer(msg, session_id) await self.write_and_encrypt(self.buffer[:noise_payload_len])