From e3ff324c8b08d16913ddc878db4329ce8a500c88 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Thu, 27 Feb 2025 17:07:28 +0100 Subject: [PATCH] fix(python): bring back firmware version check --- python/src/trezorlib/cli/trezorctl.py | 2 -- python/src/trezorlib/client.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python/src/trezorlib/cli/trezorctl.py b/python/src/trezorlib/cli/trezorctl.py index d3f3be940f..6deea97a2e 100755 --- a/python/src/trezorlib/cli/trezorctl.py +++ b/python/src/trezorlib/cli/trezorctl.py @@ -325,8 +325,6 @@ def version() -> str: @with_session(empty_passphrase=True) def ping(session: "Session", message: str, button_protection: bool) -> str: """Send ping message.""" - - # TODO return short-circuit from old client for old Trezors return session.ping(message, button_protection) diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index e4707ff1aa..a470ce992b 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -18,6 +18,7 @@ from __future__ import annotations import logging import os import typing as t +import warnings from enum import IntEnum from . import exceptions, mapping, messages, models @@ -135,6 +136,7 @@ class TrezorClient: def features(self) -> messages.Features: if self._features is None: self._features = self.protocol.get_features() + self.check_firmware_version(warn_only=True) assert self._features is not None return self._features @@ -168,12 +170,25 @@ class TrezorClient: def refresh_features(self) -> messages.Features: self.protocol.update_features() self._features = self.protocol.get_features() + self.check_firmware_version(warn_only=True) return self._features def _get_protocol(self) -> Channel: protocol = ProtocolV1Channel(self.transport, mapping.DEFAULT_MAPPING) return protocol + def is_outdated(self) -> bool: + if self.features.bootloader_mode: + return False + return self.version < self.model.minimum_version + + def check_firmware_version(self, warn_only: bool = False) -> None: + if self.is_outdated(): + if warn_only: + warnings.warn("Firmware is out of date", stacklevel=2) + else: + raise exceptions.OutdatedFirmwareError(OUTDATED_FIRMWARE_ERROR) + def get_default_client( path: t.Optional[str] = None,