1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 06:18:07 +00:00

python: ignore failures of EndSession call, so that end_session() does not raise

This commit is contained in:
matejcik 2020-08-28 12:46:13 +02:00 committed by matejcik
parent e0583dd5cb
commit ffe3b5487d
2 changed files with 15 additions and 10 deletions

View File

@ -216,11 +216,7 @@ def list_devices(no_resolve):
for transport in enumerate_devices():
client = TrezorClient(transport, ui=ui.ClickUI())
click.echo("{} - {}".format(transport, format_device_name(client.features)))
try:
# firmwares <2.3.4 do not recognize EndSession
client.end_session()
except Exception:
pass
client.end_session()
@cli.command()

View File

@ -352,7 +352,7 @@ class TrezorClient:
return self.features.device_id
@tools.session
def lock(self):
def lock(self, *, _refresh_features=True):
"""Lock the device.
If the device does not have a PIN configured, this will do nothing.
@ -365,8 +365,12 @@ class TrezorClient:
To invalidate passphrase cache, use `end_session()`. To lock _and_ invalidate
passphrase cache, use `clear_session()`.
"""
# Private argument _refresh_features can be used internally to avoid
# refreshing in cases where we will refresh soon anyway. This is used
# in TrezorClient.clear_session()
self.call(messages.LockDevice())
self.refresh_features()
if _refresh_features:
self.refresh_features()
@tools.session
def ensure_unlocked(self):
@ -391,7 +395,13 @@ class TrezorClient:
If passphrase is enabled, further actions will prompt for it again.
"""
# since: 2.3.4, 1.9.4
self.call(messages.EndSession())
try:
self.call(messages.EndSession())
except exceptions.TrezorFailure:
# A failure most likely means that the FW version does not support
# the EndSession call. We ignore the failure and clear the local session_id.
# The client-side end result is identical.
pass
self.session_id = None
@tools.session
@ -403,7 +413,6 @@ class TrezorClient:
Equivalent to calling `lock()`, `end_session()` and `init_device()`.
"""
# call LockDevice manually to save one refresh_features() call
self.call(messages.LockDevice())
self.lock(_refresh_features=False)
self.end_session()
self.init_device(new_session=True)