Skip to content

Commit

Permalink
reverse bip44 patch, fixed in ledger app
Browse files Browse the repository at this point in the history
  • Loading branch information
smogm committed Oct 12, 2020
1 parent 3b53465 commit f9602f3
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions electrum/plugins/ledger/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from typing import Optional, Tuple
from binascii import hexlify, unhexlify # for btchip overwrites

from electrum import ecc, constants
from electrum import ecc
from electrum import bip32
from electrum.crypto import hash_160
from electrum.bitcoin import int_to_hex, var_int, is_segwit_script_type
from electrum.bip32 import BIP32Node, convert_bip32_intpath_to_strpath
from electrum.i18n import _
from electrum.keystore import Hardware_KeyStore, Xpub
from electrum.keystore import Hardware_KeyStore
from electrum.transaction import Transaction, PartialTransaction, PartialTxInput, PartialTxOutput
from electrum.wallet import Standard_Wallet
from electrum.util import bfh, bh2u, versiontuple, UserFacingException
Expand Down Expand Up @@ -269,24 +269,6 @@ def has_usable_connection_with_device(self):
return False
return True

def get_password_for_storage_encryption(self) -> str:
# since ledger firware 1.6.1 we need to provide the full derivation path
# see https://support.ledger.com/hc/en-us/articles/360015738179-Derivation-path-vulnerability-in-Bitcoin-derivatives
derivation = ("m/44'"
"/" + str(constants.net.BIP44_COIN_TYPE) + "'"
"/4541509'" # ascii 'ELE' as decimal ("BIP43 purpose")
"/1112098098'") # ascii 'BIE2' as decimal
# note: using a different password based on hw device type is highly undesirable! see #5993
xpub = self.get_xpub(derivation, "standard")
password = Xpub.get_pubkey_from_xpub(xpub, ()).hex()
return password

def request_root_fingerprint_from_device(self) -> str:
# since ledger firware 1.6.1 we need to provide the full derivation path
# see https://support.ledger.com/hc/en-us/articles/360015738179-Derivation-path-vulnerability-in-Bitcoin-derivatives
child_of_root_xpub = self.get_xpub("m/44'/" + str(constants.net.BIP44_COIN_TYPE) + "'", xtype='standard')
root_fingerprint = BIP32Node.from_xkey(child_of_root_xpub).fingerprint.hex().lower()
return root_fingerprint

@test_pin_unlocked
def get_xpub(self, bip32_path, xtype):
Expand All @@ -305,7 +287,7 @@ def get_xpub(self, bip32_path, xtype):
bip32_intpath = bip32.convert_bip32_path_to_list_of_uint32(bip32_path)
bip32_path = bip32_path[2:] # cut off "m/"
if len(bip32_intpath) >= 1:
prevPath = bip32.convert_bip32_intpath_to_strpath(bip32_intpath)[2:]
prevPath = bip32.convert_bip32_intpath_to_strpath(bip32_intpath[:-1])[2:]
nodeData = self.dongleObject.getWalletPublicKey(prevPath)
publicKey = compress_public_key(nodeData['publicKey'])
fingerprint_bytes = hash_160(publicKey)[0:4]
Expand Down Expand Up @@ -822,7 +804,7 @@ def setup_device(self, device_info, wizard, purpose):
device_id = device_info.device.id_
client = self.scan_and_create_client_for_device(device_id=device_id, wizard=wizard)
wizard.run_task_without_blocking_gui(
task=lambda: client.get_xpub("m/44'/" + str(constants.net.BIP44_COIN_TYPE) + "'", 'standard')) # TODO replace by direct derivation once Nano S > 1.1
task=lambda: client.get_xpub("m/44'/0'", 'standard')) # TODO replace by direct derivation once Nano S > 1.1
return client

def get_xpub(self, device_id, derivation, xtype, wizard):
Expand Down

0 comments on commit f9602f3

Please sign in to comment.