1
0

hw: allow bypassing "too old firmware" error when using hw wallets

The framework here is generic enough that it can be used for any hw plugin,
however atm only Trezor is implemented.

closes #5391
This commit is contained in:
SomberNight
2019-05-31 04:09:03 +02:00
parent 7cba46c317
commit 371e1a6ebf
7 changed files with 71 additions and 17 deletions

View File

@@ -7,6 +7,7 @@ from electrum.util import UserCancelled, UserFacingException
from electrum.keystore import bip39_normalize_passphrase
from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32 as parse_path
from electrum.logging import Logger
from electrum.plugins.hw_wallet.plugin import OutdatedHwFirmwareException
from trezorlib.client import TrezorClient
from trezorlib.exceptions import TrezorFailure, Cancelled, OutdatedFirmwareError
@@ -29,6 +30,8 @@ MESSAGES = {
class TrezorClientBase(Logger):
def __init__(self, transport, handler, plugin):
if plugin.is_outdated_fw_ignored():
TrezorClient.is_outdated = lambda *args, **kwargs: False
self.client = TrezorClient(transport, ui=self)
self.plugin = plugin
self.device = plugin.device
@@ -62,15 +65,15 @@ class TrezorClientBase(Logger):
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
def __exit__(self, exc_type, e, traceback):
self.end_flow()
if exc_value is not None:
if issubclass(exc_type, Cancelled):
raise UserCancelled from exc_value
elif issubclass(exc_type, TrezorFailure):
raise RuntimeError(str(exc_value)) from exc_value
elif issubclass(exc_type, OutdatedFirmwareError):
raise UserFacingException(exc_value) from exc_value
if e is not None:
if isinstance(e, Cancelled):
raise UserCancelled from e
elif isinstance(e, TrezorFailure):
raise RuntimeError(str(e)) from e
elif isinstance(e, OutdatedFirmwareError):
raise OutdatedHwFirmwareException(e) from e
else:
return False
return True

View File

@@ -15,7 +15,7 @@ from electrum.logging import get_logger
from ..hw_wallet import HW_PluginBase
from ..hw_wallet.plugin import (is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data,
LibraryFoundButUnusable)
LibraryFoundButUnusable, OutdatedHwFirmwareException)
_logger = get_logger(__name__)
@@ -275,7 +275,7 @@ class TrezorPlugin(HW_PluginBase):
msg = (_('Outdated {} firmware for device labelled {}. Please '
'download the updated firmware from {}')
.format(self.device, client.label(), self.firmware_URL))
raise UserFacingException(msg)
raise OutdatedHwFirmwareException(msg)
# fixme: we should use: client.handler = wizard
client.handler = self.create_handler(wizard)