chore(core): less confusing log message when decoding protobuf
What changed, and why it matters
This commit only changes debug log messages and error text when decoding protobuf data. It adds a parameter so internal credential decoding can say 'protobuf' instead of 'message' in logs/errors, making diagnostics less confusing. There is no security fix or behavior change visible in the diff.
No security action required; this is a cosmetic logging/diagnostics change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds an is_message: bool = True parameter to wrap_protobuf_load() in core/src/trezor/wire/message_handler.py. When False, log and DataError strings use ‘protobuf’ instead of ‘message’. Two callers in core/src/apps/thp/credential_manager.py pass is_message=False when decoding Noise handshake and pairing credential payloads. The actual decode path (protobuf.decode) and exception handling are unchanged.
Changed components
core/src/trezor/wire/message_handler.pycore/src/apps/thp/credential_manager.pyInspect captured patch +13 / −9
diff --git a/core/src/apps/thp/credential_manager.py b/core/src/apps/thp/credential_manager.py
index 233529bc..cfcdc625 100644
--- a/core/src/apps/thp/credential_manager.py
+++ b/core/src/apps/thp/credential_manager.py
@@ -87,7 +87,7 @@ def issue_credential(
def unwrap_credential(encoded_noise_payload: AnyBytes) -> AnyBytes | None:
expected_type = protobuf.type_for_name("ThpHandshakeCompletionReqNoisePayload")
- msg = wrap_protobuf_load(encoded_noise_payload, expected_type)
+ msg = wrap_protobuf_load(encoded_noise_payload, expected_type, is_message=False)
if not ThpHandshakeCompletionReqNoisePayload.is_type_of(msg):
raise TypeError
return msg.host_pairing_credential
@@ -100,7 +100,9 @@ def decode_credential(
Decode a protobuf encoded pairing credential.
"""
expected_type = protobuf.type_for_name("ThpPairingCredential")
- credential = wrap_protobuf_load(encoded_pairing_credential_message, expected_type)
+ credential = wrap_protobuf_load(
+ encoded_pairing_credential_message, expected_type, is_message=False
+ )
if not ThpPairingCredential.is_type_of(credential):
raise TypeError
return credential
diff --git a/core/src/trezor/wire/message_handler.py b/core/src/trezor/wire/message_handler.py
index 97e8e88c..e0f8cc1e 100644
--- a/core/src/trezor/wire/message_handler.py
+++ b/core/src/trezor/wire/message_handler.py
@@ -25,6 +25,7 @@ EXPERIMENTAL_ENABLED = False
def wrap_protobuf_load(
buffer: AnyBytes,
expected_type: type[LoadedMessageType],
+ is_message: bool = True,
) -> LoadedMessageType:
try:
if __debug__ and utils.EMULATOR and utils.USE_THP:
@@ -35,17 +36,18 @@ def wrap_protobuf_load(
)
msg = protobuf.decode(buffer, expected_type, EXPERIMENTAL_ENABLED)
if __debug__ and utils.EMULATOR:
- log.debug(
- __name__, "received message contents:\n%s", utils.dump_protobuf(msg)
- )
+ what = "received message contents" if is_message else "decoded protobuf"
+ log.debug(__name__, "%s:\n%s", what, utils.dump_protobuf(msg))
return msg
except Exception as e:
+ what = "message" if is_message else "protobuf"
if __debug__:
log.exception(__name__, e)
- if e.args:
- raise DataError("Failed to decode message: " + " ".join(e.args))
- else:
- raise DataError("Failed to decode message")
+ if e.args:
+ raise DataError(
+ f"Failed to decode {what}: " + " ".join(str(arg) for arg in e.args)
+ )
+ raise DataError(f"Failed to decode {what}")
async def handle_single_message(ctx: Context, msg: Message) -> bool:
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.