Skip to content

Commit

Permalink
Ledger: Test firmware version for trusted input requirement
Browse files Browse the repository at this point in the history
The last change broke Ledger Nano S/X on firmware versions < 1.4.0.

We now check the firmware version to see if we need to use trusted
inputs or not. The behaviour with firmware version < 1.4.0 is
the same as before.
  • Loading branch information
EchterAgo committed Sep 30, 2020
1 parent 27dcad1 commit 6929cd7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions plugins/ledger/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
BITCOIN_CASH_SUPPORT = (1, 1, 8)
CASHADDR_SUPPORT = (1, 2, 5)
MULTI_OUTPUT_SUPPORT = (1, 1, 4)
TRUSTED_INPUTS_REQUIRED = (1, 4, 0)

def test_pin_unlocked(func):
"""Function decorator to test the Ledger for being unlocked, and if not,
Expand Down Expand Up @@ -158,6 +159,9 @@ def supports_cashaddr(self):
def supports_multi_output(self):
return self.multiOutputSupported

def requires_trusted_inputs(self):
return self.trustedInputsRequired

def perform_hw1_preflight(self):
try:
firmwareInfo = self.dongleObject.getFirmwareVersion()
Expand All @@ -166,6 +170,7 @@ def perform_hw1_preflight(self):
self.is_hw1() and firmwareVersion >= BITCOIN_CASH_SUPPORT_HW1
self.cashaddrFWSupported = firmwareVersion >= CASHADDR_SUPPORT
self.multiOutputSupported = firmwareVersion >= MULTI_OUTPUT_SUPPORT
self.trustedInputsRequired = firmwareVersion >= TRUSTED_INPUTS_REQUIRED

if not checkFirmware(firmwareInfo) or not self.supports_bitcoin_cash():
self.dongleObject.dongle.close()
Expand Down Expand Up @@ -444,14 +449,14 @@ def sign_transaction(self, tx, password, *, use_cache=False):
# Get trusted inputs from the original transactions
for utxo in inputs:
sequence = int_to_hex(utxo[5], 4)
if self.get_client_electrum().is_hw1():
if not self.get_client_electrum().requires_trusted_inputs():
txtmp = bitcoinTransaction(bfh(utxo[0]))
tmp = bfh(utxo[3])[::-1]
tmp += bfh(int_to_hex(utxo[1], 4))
tmp += txtmp.outputs[utxo[1]].amount
chipInputs.append({'value' : tmp, 'witness' : True, 'sequence' : sequence})
redeemScripts.append(bfh(utxo[2]))
elif (not p2shTransaction) or self.get_client_electrum().supports_multi_output():
else:
txtmp = bitcoinTransaction(bfh(utxo[0]))
trustedInput = self.get_client().getTrustedInput(txtmp, utxo[1])
trustedInput['sequence'] = sequence
Expand All @@ -461,11 +466,6 @@ def sign_transaction(self, tx, password, *, use_cache=False):
redeemScripts.append(bfh(utxo[2]))
else:
redeemScripts.append(txtmp.outputs[utxo[1]].script)
else:
tmp = bfh(utxo[3])[::-1]
tmp += bfh(int_to_hex(utxo[1], 4))
chipInputs.append({'value' : tmp, 'witness': True, 'sequence' : sequence})
redeemScripts.append(bfh(utxo[2]))

# Sign all inputs
inputIndex = 0
Expand Down

0 comments on commit 6929cd7

Please sign in to comment.