Browse Source

fix a bug with hw devices.

if a device is unplugged and then replugged before we notice (via scan_devices) then it will get into an unusable state, throwing all kinds of low level exceptions when we don't expect it. affects ledger, keepkey, dbb, but for some reason not trezor.
3.2.x
SomberNight 7 years ago
parent
commit
85b36e027f
  1. 2
      lib/plugins.py
  2. 7
      plugins/digitalbitbox/digitalbitbox.py
  3. 8
      plugins/keepkey/clientbase.py
  4. 14
      plugins/ledger/ledger.py
  5. 8
      plugins/trezor/clientbase.py

2
lib/plugins.py

@ -552,7 +552,7 @@ class DeviceMgr(ThreadJob, PrintError):
with self.lock:
connected = {}
for client, pair in self.clients.items():
if pair in pairs:
if pair in pairs and client.has_usable_connection_with_device():
connected[client] = pair
else:
disconnected_ids.append(pair[1])

7
plugins/digitalbitbox/digitalbitbox.py

@ -82,6 +82,13 @@ class DigitalBitbox_Client():
def is_paired(self):
return self.password is not None
def has_usable_connection_with_device(self):
try:
self.dbb_has_password()
except BaseException:
return False
return True
def _get_xpub(self, bip32_path):
if self.check_device_dialog():
return self.hid_send_encrypt(b'{"xpub": "%s"}' % bip32_path.encode('utf8'))

8
plugins/keepkey/clientbase.py

@ -113,6 +113,14 @@ class KeepKeyClientBase(GuiMixin, PrintError):
def is_pairable(self):
return not self.features.bootloader_mode
def has_usable_connection_with_device(self):
try:
res = self.ping("electrum pinging device")
assert res == "electrum pinging device"
except BaseException:
return False
return True
def used(self):
self.last_operation = time.time()

14
plugins/ledger/ledger.py

@ -57,6 +57,13 @@ class Ledger_Client():
def i4b(self, x):
return pack('>I', x)
def has_usable_connection_with_device(self):
try:
self.dongleObject.getFirmwareVersion()
except BaseException:
return False
return True
def test_pin_unlocked(func):
"""Function decorator to test the Ledger for being unlocked, and if not,
raise a human-readable exception.
@ -513,13 +520,6 @@ class LedgerPlugin(HW_PluginBase):
if self.libraries_available:
self.device_manager().register_devices(self.DEVICE_IDS)
def btchip_is_connected(self, keystore):
try:
self.get_client(keystore).getFirmwareVersion()
except Exception as e:
return False
return True
def get_btchip_device(self, device):
ledger = False
if (device.product_key[0] == 0x2581 and device.product_key[1] == 0x3b7c) or (device.product_key[0] == 0x2581 and device.product_key[1] == 0x4b7c) or (device.product_key[0] == 0x2c97):

8
plugins/trezor/clientbase.py

@ -119,6 +119,14 @@ class TrezorClientBase(GuiMixin, PrintError):
def is_pairable(self):
return not self.features.bootloader_mode
def has_usable_connection_with_device(self):
try:
res = self.ping("electrum pinging device")
assert res == "electrum pinging device"
except BaseException:
return False
return True
def used(self):
self.last_operation = time.time()

Loading…
Cancel
Save