mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-20 18:16:05 +00:00
fix(python): bring back firmware version check
This commit is contained in:
parent
38d0b9ff64
commit
b4d3cb97c0
@ -324,8 +324,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)
|
||||
|
||||
|
||||
|
@ -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
|
||||
@ -62,7 +63,7 @@ class TrezorClient:
|
||||
_seedless_session: Session | None = None
|
||||
_features: messages.Features | None = None
|
||||
_protocol_version: int
|
||||
_setup_pin: str | None = None # Should by used only by conftest
|
||||
_setup_pin: str | None = None # Should be used only by conftest
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -170,6 +171,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
|
||||
|
||||
@ -203,12 +205,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,
|
||||
|
@ -66,6 +66,22 @@ class Session:
|
||||
self._write(messages.Cancel())
|
||||
|
||||
def ping(self, message: str, button_protection: bool | None = None) -> str:
|
||||
# We would like ping to work on any valid TrezorClient instance, but
|
||||
# due to the protection modes, we need to go through self.call, and that will
|
||||
# raise an exception if the firmware is too old.
|
||||
# So we short-circuit the simplest variant of ping with call_raw.
|
||||
if not button_protection:
|
||||
resp = self.call_raw(messages.Ping(message=message))
|
||||
if isinstance(resp, messages.ButtonRequest):
|
||||
# device is PIN-locked.
|
||||
# respond and hope for the best
|
||||
resp = (self.client.button_callback or default_button_callback)(
|
||||
self, resp
|
||||
)
|
||||
resp = messages.Success.ensure_isinstance(resp)
|
||||
assert resp.message is not None
|
||||
return resp.message
|
||||
|
||||
resp = self.call(
|
||||
messages.Ping(message=message, button_protection=button_protection),
|
||||
expect=messages.Success,
|
||||
|
Loading…
Reference in New Issue
Block a user