fix(core/python): fix encoding in authentication challenge
What changed, and why it matters
This commit fixes how the Trezor Python library builds an authentication challenge. Previously, the code encoded the length of a header and the length of the challenge as a single byte, which only works for values up to 255. The fix uses a variable-length 'compact size' encoding instead, which can handle larger values. If a challenge or header were ever 256 bytes or longer, the old code would produce an incorrect byte string, which could cause authentication to fail or behave unexpectedly. There is no direct evidence in the commit that this was exploitable as a security vulnerability, but it is a correctness fix in a security-sensitive authentication path.
Treat as a low-to-moderate correctness fix in a security-sensitive function. Review whether any deployed code passes challenges or headers longer than 255 bytes, and verify that compact_size matches the device's expected encoding. No urgent action is indicated absent evidence of active exploitation.
Security signals we found
Fix in authentication/verification code path
Change from fixed single-byte length prefix to variable-length compact_size encoding
Potential for incorrect serialization if challenge/header length exceeds 255 bytes
No changelog entry and minimal commit message
Evidence from the diff
In python/src/trezorlib/authentication.py, the construction of challenge_bytes for verify_authentication_response changed from using len(x).to_bytes(1, ‘big’) to compact_size(len(x)) for both CHALLENGE_HEADER and challenge. The old single-byte length prefix is only valid for lengths 0-255. compact_size is presumably a Bitcoin-style variable-length integer encoding that supports larger lengths. This is a defensive correctness fix in challenge serialization. The commit message and diff do not describe a specific vulnerability, attack scenario, or CVE.
Changed components
python/src/trezorlib/authentication.pyverify_authentication_response functionTrezor Python client library authentication challenge verificationInspect captured patch +3 / −3
diff --git a/python/src/trezorlib/authentication.py b/python/src/trezorlib/authentication.py
index a4b53530..3ea8aae8 100644
--- a/python/src/trezorlib/authentication.py
+++ b/python/src/trezorlib/authentication.py
@@ -28,7 +28,7 @@ from cryptography.x509.oid import NameOID, ObjectIdentifier, SignatureAlgorithmO
from . import _root_keys, device
from .client import Session
-from .tools import workflow
+from .tools import compact_size, workflow
LOG = logging.getLogger(__name__)
@@ -498,9 +498,9 @@ def verify_authentication_response(
as a `PublicKey` object or as a byte-string.
"""
challenge_bytes = (
- len(CHALLENGE_HEADER).to_bytes(1, "big")
+ compact_size(len(CHALLENGE_HEADER))
+ CHALLENGE_HEADER
- + len(challenge).to_bytes(1, "big")
+ + compact_size(len(challenge))
+ challenge
)
Why this scored 44/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.