chore(python): improve authentication errors
What changed, and why it matters
This commit improves error messages in the Trezor Python command-line library when a user tries to run device authentication on hardware models that do not support it, or when the installed library version lacks the needed root certificates for a model. It does not change cryptographic behavior; it only fails earlier with clearer messages instead of potentially confusing downstream failures.
No urgent action. Treat as routine hardening. Users and integrators may update trezorlib to benefit from clearer error diagnostics when using device authentication across different Trezor models.
Security signals we found
Defensive input validation added before authentication flow
Explicit unsupported-model denylist introduced
Missing root-certificate handling now fails fast with update guidance
No cryptographic code changes; no privilege escalation or memory safety issues evident
Evidence from the diff
In python/src/trezorlib/cli/device.py, the authenticate() CLI command now checks session.model against an explicit UNSUPPORTED_MODELS tuple (T1B1, T2T1, D001, D002, D003) and against authentication.roots_for_model(). If the model is unsupported or no roots are known, it raises click.ClickException with a descriptive message. Previously the command would proceed and likely fail later or with a less helpful error. The change is purely defensive UX hardening.
Changed components
python/src/trezorlib/cli/device.pytrezorlib CLI authenticate commandInspect captured patch +19 / −1
### python/src/trezorlib/cli/device.py
@@ -24,7 +24,7 @@
import click
import requests
-from .. import authentication, debuglink, device, exceptions, messages
+from .. import authentication, debuglink, device, exceptions, messages, models
from ..tools import format_path
from . import ChoiceType, ui, with_session
@@ -465,6 +465,24 @@ def authenticate(
Development devices are rejected unless the --devel option is given.
"""
+ # Models which do not support authentication.
+ UNSUPPORTED_MODELS = (
+ models.T1B1,
+ models.T2T1,
+ models.D001,
+ models.D002,
+ models.D003,
+ )
+ if session.model in UNSUPPORTED_MODELS:
+ raise click.ClickException(
+ f"Device authentication is not supported on Trezor {session.model.name}."
+ )
+ if not authentication.roots_for_model(session.model):
+ raise click.ClickException(
+ f"This version of trezorlib cannot authenticate Trezor {session.model.name}. "
+ "Please update trezorlib."
+ )
+
if hex_challenge is None:
hex_challenge = secrets.token_hex(32)
Why this scored 23/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.