From 31c3c5c89690d185502f721083c895a0c8490a14 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Sun, 20 Oct 2024 00:02:15 +0200 Subject: [PATCH] feat(core): remove even more logging [no changelog] --- core/src/trezor/wire/thp/alternating_bit_protocol.py | 4 ++-- core/src/trezor/wire/thp/channel.py | 2 +- core/src/trezor/wire/thp/crypto.py | 4 ++-- core/src/trezor/wire/thp/session_context.py | 8 ++------ core/src/trezor/wire/thp_main.py | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core/src/trezor/wire/thp/alternating_bit_protocol.py b/core/src/trezor/wire/thp/alternating_bit_protocol.py index 364ecdbca4..d8ba60c5b2 100644 --- a/core/src/trezor/wire/thp/alternating_bit_protocol.py +++ b/core/src/trezor/wire/thp/alternating_bit_protocol.py @@ -72,7 +72,7 @@ def set_expected_receive_seq_bit(cache: ChannelCache, seq_bit: int) -> None: Set the expected sequential number (bit) of the next message to be received in the provided channel """ - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: log.debug(__name__, "Set sync receive expected seq bit to %d", seq_bit) if seq_bit not in (0, 1): raise ThpError("Unexpected receive sync bit") @@ -86,7 +86,7 @@ def set_expected_receive_seq_bit(cache: ChannelCache, seq_bit: int) -> None: def _set_send_seq_bit(cache: ChannelCache, seq_bit: int) -> None: if seq_bit not in (0, 1): raise ThpError("Unexpected send seq bit") - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: log.debug(__name__, "setting sync send seq bit to %d", seq_bit) # set third bit to "seq_bit" value cache.sync &= 0xDF diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py index 529244e247..ef983bb2ae 100644 --- a/core/src/trezor/wire/thp/channel.py +++ b/core/src/trezor/wire/thp/channel.py @@ -44,7 +44,7 @@ if TYPE_CHECKING: class Channel: def __init__(self, channel_cache: ChannelCache) -> None: - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: log.debug(__name__, "channel initialization") self.iface: WireInterface = interface_manager.decode_iface(channel_cache.iface) self.channel_cache: ChannelCache = channel_cache diff --git a/core/src/trezor/wire/thp/crypto.py b/core/src/trezor/wire/thp/crypto.py index ba211490f6..8a50a03637 100644 --- a/core/src/trezor/wire/thp/crypto.py +++ b/core/src/trezor/wire/thp/crypto.py @@ -22,7 +22,7 @@ def enc(buffer: utils.BufferType, key: bytes, nonce: int, auth_data: bytes) -> b Encrypts the provided `buffer` with AES-GCM (in place). Returns a 16-byte long encryption tag. """ - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: log.debug(__name__, "enc (key: %s, nonce: %d)", hexlify(key), nonce) iv = _get_iv_from_nonce(nonce) aes_ctx = aesgcm(key, iv) @@ -39,7 +39,7 @@ def dec( the tag computed in decryption, otherwise it returns `False`. """ iv = _get_iv_from_nonce(nonce) - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: log.debug(__name__, "dec (key: %s, nonce: %d)", hexlify(key), nonce) aes_ctx = aesgcm(key, iv) aes_ctx.auth(auth_data) diff --git a/core/src/trezor/wire/thp/session_context.py b/core/src/trezor/wire/thp/session_context.py index ebe518b8b7..8999ed3cf6 100644 --- a/core/src/trezor/wire/thp/session_context.py +++ b/core/src/trezor/wire/thp/session_context.py @@ -36,7 +36,7 @@ class GenericSessionContext(Context): self.handler_finder: HandlerFinder = find_handler async def handle(self) -> None: - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: self._handle_debug() next_message: Message | None = None @@ -63,10 +63,6 @@ class GenericSessionContext(Context): get_bytes_as_str(self.channel_id), self.session_id, ) - # if is_debug_session: - # import apps.debug - - # apps.debug.DEBUG_CONTEXT = self async def _handle_message( self, @@ -124,7 +120,7 @@ class GenericSessionContext(Context): expected_types: Container[int], expected_type: type[protobuf.MessageType] | None = None, ) -> protobuf.MessageType: - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: exp_type: str = str(expected_type) if expected_type is not None: exp_type = expected_type.MESSAGE_NAME diff --git a/core/src/trezor/wire/thp_main.py b/core/src/trezor/wire/thp_main.py index d25fa1d8cd..b924d96b65 100644 --- a/core/src/trezor/wire/thp_main.py +++ b/core/src/trezor/wire/thp_main.py @@ -62,7 +62,7 @@ async def thp_main_loop(iface: WireInterface): while True: try: - if __debug__: + if __debug__ and utils.ALLOW_DEBUG_MESSAGES: log.debug(__name__, "thp_main_loop") packet = await read ctrl_byte, cid = ustruct.unpack(">BH", packet)