refactor(tests): use `get_challenge_message()`
What changed, and why it matters
This is a minor code cleanup in the test suite. It replaces a manually constructed challenge message with a helper function that does the same thing. There is no change to the actual Trezor firmware or to how device authentication works in production.
No action needed. This is a non-security test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors tests/device_tests/test_authenticate_device.py to use trezorlib.authentication.get_challenge_message(challenge) instead of inline construction b”\x13AuthenticateDevice:” + compact_size(len(challenge)) + challenge. The helper produces the same byte string, so this is a pure test-code refactor with no functional change to the authentication protocol or firmware behavior.
Changed components
tests/device_tests/test_authenticate_device.pyInspect captured patch +10 / −7
diff --git a/tests/device_tests/test_authenticate_device.py b/tests/device_tests/test_authenticate_device.py
index 6815f284..054bd83d 100644
--- a/tests/device_tests/test_authenticate_device.py
+++ b/tests/device_tests/test_authenticate_device.py
@@ -2,8 +2,8 @@ import pytest
from cryptography import x509
from trezorlib import device, exceptions, messages
+from trezorlib.authentication import get_challenge_message
from trezorlib.debuglink import DebugSession as Session
-from trezorlib.tools import compact_size
from .certificate import (
check_signature_mcu,
@@ -53,9 +53,11 @@ def test_authenticate_device_optiga(
assert proof.mcu_signature is None
assert proof.mcu_certificates == []
- data = b"\x13AuthenticateDevice:" + compact_size(len(challenge)) + challenge
check_signature_optiga(
- proof.optiga_signature, proof.optiga_certificates, session.model, data
+ proof.optiga_signature,
+ proof.optiga_certificates,
+ session.model,
+ get_challenge_message(challenge),
)
@@ -76,9 +78,11 @@ def test_authenticate_device_mcu(
assert proof.mcu_signature is not None
assert len(proof.mcu_certificates) >= 1
- data = b"\x13AuthenticateDevice:" + compact_size(len(challenge)) + challenge
check_signature_mcu(
- proof.mcu_signature, proof.mcu_certificates, session.model, data
+ proof.mcu_signature,
+ proof.mcu_certificates,
+ session.model,
+ get_challenge_message(challenge),
)
@@ -98,12 +102,11 @@ def test_authenticate_device_tropic(
assert proof.mcu_signature is None
assert proof.mcu_certificates == []
- data = b"\x13AuthenticateDevice:" + compact_size(len(challenge)) + challenge
check_signature_tropic(
proof.tropic_signature,
proof.tropic_certificates,
session.model,
- data,
+ get_challenge_message(challenge),
)
Why this scored 15/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.