Skip to content

Example: using GET_MASTER_FINGERPRINT for Legacy Client to get the master public key fingerprint#10603

Merged
SomberNight merged 2 commits into
spesmilo:masterfrom
iartemov-ledger:ledger_hardening
Apr 24, 2026
Merged

Example: using GET_MASTER_FINGERPRINT for Legacy Client to get the master public key fingerprint#10603
SomberNight merged 2 commits into
spesmilo:masterfrom
iartemov-ledger:ledger_hardening

Conversation

@iartemov-ledger
Copy link
Copy Markdown
Contributor

This PR provides an example of how new GET_MASTER_FINGERPRINT instruction of Ledger app-bitcoin can be adopted in a software wallet.
It overrides #10582 one.

Scope

Since the hardening introduced in LedgerHQ/app-bitcoin-legacy#297 (and in LedgerHQ/app-bitcoin-legacy#299 for bitcoin_testnet_legacy), it is no longer possible to get the public key at the master level. Therefore, the new GET_MASTER_FINGERPRINT instruction was introduced to replace it.

The changes in this PR apply only to the legacy app-bitcoin starting from version 2.4.11 (and the Ledger_Client_Legacy part). Specifically for Electrum, this only affects the bitcoin_testnet_legacy app variant (Bitcoin Test Legacy), as there is no hardening applied to the bitcoin_legacy variant (Bitcoin Legacy).
For app-bitcoin-new and the corresponding Ledger_Client_New, everything is already handled well through the get_master_fingerprint() call.

The new behavior is to first try the new instruction. If an error is returned (meaning the instruction does not exist in the app), it falls back to getWalletPublicKey(). This ensures backward compatibility with app versions older than v2.4.11.

Tests

This has been successfully tested as follows:

  1. Wallet creation with the previous unhardened version of app-bitcoin (using the m/84h/1h/0h path corresponding to testnet), and connecting to it with the hardened version of the app.
  2. Wallet creation and connection using the already hardened version.

In the corresponding traces, it was observed that INS_GET_WALLET_PUBLIC_KEY commands with bip32Path.length = 0 were effectively replaced by INS_GET_MASTER_FINGERPRINT calls.

Comment on lines +402 to +405
try:
return self.dongleObject.getMasterFingerprint()
except BTChipException as e:
if e.sw in (0x6d00, 0x6a80): # INS not supported / bad data
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you assume a newer version of ledger_bitcoin, you need to declare it and bump the minimum:
at runtime:

minimum_library = (0, 2, 0)

at build time (for binaries):
# device plugin: ledger
ledger-bitcoin>=0.2.0,<1.0
hidapi

(the pinned hashes, I will bump correspondingly)

  6.35 | E | plugin.DeviceMgr | failed to create client for ledger at b'1-5:1.0': AttributeError("'btchip' object has no attribute 'getMasterFingerprint'")
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/plugin.py", line 1267, in list_pairable_device_infos
    soft_device_id = client.get_soft_device_id()
  File "/home/user/wspace/electrum/electrum/plugin.py", line 1000, in wrapper
    return run_in_hwd_thread(partial(func, *args, **kwargs))
  File "/home/user/wspace/electrum/electrum/plugin.py", line 993, in run_in_hwd_thread
    return fut.result()
           ~~~~~~~~~~^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/user/wspace/electrum/electrum/plugins/ledger/ledger.py", line 453, in get_soft_device_id
    self._soft_device_id = self._get_master_fingerprint().hex()
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/user/wspace/electrum/electrum/plugins/ledger/ledger.py", line 403, in _get_master_fingerprint
    return self.dongleObject.getMasterFingerprint()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'btchip' object has no attribute 'getMasterFingerprint'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SomberNight , thank you for your feedback.
Sorry about that! The new ledger_bitcoin@v0.4.1 is indeed required, and I've just bumped the build-time and runtime versions in the lines you indicated.
Also tested with a venv from scratch locally.

SomberNight added a commit that referenced this pull request Apr 24, 2026
adapt Ledger_Client_Legacy to work with newer ledger bitcoin app

manual merge of #10603
@SomberNight SomberNight merged commit 44570bf into spesmilo:master Apr 24, 2026
15 of 17 checks passed
@SomberNight
Copy link
Copy Markdown
Member

merged in 5af40f4

Thanks for the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants