Skip to content

Commit

Permalink
Merge branch 'LedgerHQ-ledger-fixes-2.5.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWeigl committed Nov 2, 2015
2 parents fd156f0 + ac1ac34 commit e043fb6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions public/btchip/src/main/java/com/btchip/BTChipDongle.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ public BTChipOutput finalizeInput(byte[] outputScript, String outputAddress, Str
byte[] path = null;
if (changePath != null) {
path = BIP32Utils.splitPath(changePath);
resolvePath(changePath);
exchangeApdu(BTCHIP_CLA, BTCHIP_INS_HASH_INPUT_FINALIZE_FULL, (byte) 0xFF, (byte) 0x00, path, null);
oldAPI = ((lastSW == SW_INCORRECT_P1_P2) || (lastSW == SW_WRONG_P1_P2) || (lastSW == SW_CONDITIONS_NOT_SATISFIED));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,28 @@ private Transaction signInternal(UnsignedTransaction unsigned,
return null;
}
} catch (BTChipException e) {
if (e.getSW() == SW_CONDITIONS_NOT_SATISFIED) {
postErrorMessage("PIN is terminated");
return null;
}
if (e.getSW() == SW_HALTED) {
LedgerTransportTEEProxy proxy = (LedgerTransportTEEProxy) getTransport().getTransport();
try {
proxy.close();
proxy.init();
} catch (Exception ignore) {
int attempts = dongle.getVerifyPinRemainingAttempts();
if (attempts == 0) {
postErrorMessage("PIN is terminated");
return null;
}
}
catch (BTChipException e1) {
if (e1.getSW() == SW_CONDITIONS_NOT_SATISFIED) {
postErrorMessage("PIN is terminated");
return null;
}
}
catch (Exception ignore) {
}
}
}
Expand Down Expand Up @@ -300,7 +316,9 @@ private Transaction signInternal(UnsignedTransaction unsigned,
// Poor man counter
LedgerTransportTEEProxy proxy = (LedgerTransportTEEProxy) getTransport().getTransport();
try {
proxy.writeNVM(NVM_IMAGE, proxy.requestNVM().get());
byte[] updatedNvm = proxy.requestNVM().get();
proxy.writeNVM(NVM_IMAGE, updatedNvm);
proxy.setNVM(updatedNvm);
} catch (Exception ignore) {
}
}
Expand Down Expand Up @@ -455,15 +473,10 @@ public Optional<HdKeyNode> getAccountPubKeyNode(HdKeyPath keyPath) {
// is with leading "m/" -> replace the "m" away
String keyPathString = keyPath.toString().replace("m/", "");
if (isTEE) {
// Check if the PIN has been terminated - in this case, reinitialize
// Verify that the TEE is set up properly - PIN cannot be locked here
// as this is called directly after the account creation
try {
int attempts = dongle.getVerifyPinRemainingAttempts();
if (attempts == 0) {
context.deleteFile(NVM_IMAGE);
LedgerTransportTEEProxy proxy = (LedgerTransportTEEProxy) getTransport().getTransport();
proxy.setNVM(null);
proxy.init();
}
} catch (BTChipException e) {
if (e.getSW() == SW_HALTED) {
LedgerTransportTEEProxy proxy = (LedgerTransportTEEProxy) getTransport().getTransport();
Expand Down Expand Up @@ -491,7 +504,9 @@ public Optional<HdKeyNode> getAccountPubKeyNode(HdKeyPath keyPath) {
null,
null, null);
try {
proxy.writeNVM(NVM_IMAGE, proxy.requestNVM().get());
byte[] updatedNvm = proxy.requestNVM().get();
proxy.writeNVM(NVM_IMAGE, updatedNvm);
proxy.setNVM(updatedNvm);
} catch (Exception ignore) {
}
try {
Expand All @@ -503,7 +518,9 @@ public Optional<HdKeyNode> getAccountPubKeyNode(HdKeyPath keyPath) {
}
} finally {
try {
proxy.writeNVM(NVM_IMAGE, proxy.requestNVM().get());
byte[] updatedNvm = proxy.requestNVM().get();
proxy.writeNVM(NVM_IMAGE, updatedNvm);
proxy.setNVM(updatedNvm);
} catch (Exception ignore) {
}
}
Expand All @@ -523,7 +540,9 @@ public Optional<HdKeyNode> getAccountPubKeyNode(HdKeyPath keyPath) {
// Poor man counter
LedgerTransportTEEProxy proxy = (LedgerTransportTEEProxy) getTransport().getTransport();
try {
proxy.writeNVM(NVM_IMAGE, proxy.requestNVM().get());
byte[] updatedNvm = proxy.requestNVM().get();
proxy.writeNVM(NVM_IMAGE, updatedNvm);
proxy.setNVM(updatedNvm);
} catch (Exception ignore) {
}
}
Expand Down

0 comments on commit e043fb6

Please sign in to comment.