From d2696cfadf6b09bfffe606334e4083250dd7e72d Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 22 Apr 2019 10:34:34 -0400 Subject: [PATCH] Add needs_passphrase_sent to enumerate output --- hwilib/devices/coldcard.py | 2 ++ hwilib/devices/digitalbitbox.py | 1 + hwilib/devices/keepkey.py | 4 ++++ hwilib/devices/ledger.py | 4 +--- hwilib/devices/trezor.py | 4 ++++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hwilib/devices/coldcard.py b/hwilib/devices/coldcard.py index 91689a4..bed73aa 100644 --- a/hwilib/devices/coldcard.py +++ b/hwilib/devices/coldcard.py @@ -225,6 +225,7 @@ def enumerate(password=''): path = d['path'].decode() d_data['type'] = 'coldcard' d_data['path'] = path + d_data['needs_passphrase'] = False client = None try: @@ -251,6 +252,7 @@ def enumerate(password=''): d_data['fingerprint'] = client._get_fingerprint_hex() d_data['type'] = 'coldcard' d_data['path'] = CC_SIMULATOR_SOCK + d_data['needs_passphrase_sent'] = False results.append(d_data) except RuntimeError as e: if str(e) == 'Cannot connect to simulator. Is it running?': diff --git a/hwilib/devices/digitalbitbox.py b/hwilib/devices/digitalbitbox.py index 1ef0dbb..d229005 100644 --- a/hwilib/devices/digitalbitbox.py +++ b/hwilib/devices/digitalbitbox.py @@ -603,6 +603,7 @@ def enumerate(password=''): else: master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) + d_data['needs_passphrase_sent'] = True except HWWError as e: d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() d_data['code'] = e.get_code() diff --git a/hwilib/devices/keepkey.py b/hwilib/devices/keepkey.py index 463fe95..15e7d8a 100644 --- a/hwilib/devices/keepkey.py +++ b/hwilib/devices/keepkey.py @@ -26,9 +26,13 @@ def enumerate(password=''): client.client.init_device() if not 'keepkey' in client.client.features.vendor: continue + d_data['needs_passphrase_sent'] = client.client.features.passphrase_protection and not client.client.features.passphrase_cached + if d_data['needs_passphrase_sent'] and not password: + raise DeviceNotReadyError("Passphrase needs to be specified before the fingerprint information can be retrieved") if client.client.features.initialized: master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) + d_data['needs_passphrase_sent'] = False # Passphrase is always needed for the above to have worked, so it's already sent else: d_data['error'] = 'Not initialized' except HWWError as e: diff --git a/hwilib/devices/ledger.py b/hwilib/devices/ledger.py index 8c2151f..1d6984e 100644 --- a/hwilib/devices/ledger.py +++ b/hwilib/devices/ledger.py @@ -350,9 +350,7 @@ def enumerate(password=''): client = LedgerClient(path, password) master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) - except HWWError as e: - d_data['error'] = "Could not open client or get fingerprint information: " + e.get_msg() - d_data['code'] = e.get_code() + d_data['needs_passphrase_sent'] = False except Exception as e: d_data['error'] = "Could not open client or get fingerprint information: " + str(e) d_data['code'] = UNKNOWN_ERROR diff --git a/hwilib/devices/trezor.py b/hwilib/devices/trezor.py index 025249f..05cea6d 100644 --- a/hwilib/devices/trezor.py +++ b/hwilib/devices/trezor.py @@ -421,9 +421,13 @@ def enumerate(password=''): client.client.init_device() if not 'trezor' in client.client.features.vendor: continue + d_data['needs_passphrase_sent'] = client.client.features.passphrase_protection and not client.client.features.passphrase_cached + if d_data['needs_passphrase_sent'] and not password: + raise DeviceNotReadyError("Passphrase needs to be specified before the fingerprint information can be retrieved") if client.client.features.initialized: master_xpub = client.get_pubkey_at_path('m/0h')['xpub'] d_data['fingerprint'] = get_xpub_fingerprint_hex(master_xpub) + d_data['needs_passphrase_sent'] = False # Passphrase is always needed for the above to have worked, so it's already sent else: d_data['error'] = 'Not initialized' except HWWError as e: