From a2a28c9c2302241f0c92e087716b25789a7733ae Mon Sep 17 00:00:00 2001 From: Tangem Date: Sun, 22 Jul 2018 15:26:06 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .idea/caches/build_file_checksums.ser | Bin 536 -> 536 bytes .../domain/cardReader/CardProtocol.java | 2 +- .../domain/wallet/BalanceValidator.java | 123 ++++++++---------- .../com/tangem/domain/wallet/TangemCard.java | 14 +- 4 files changed, 64 insertions(+), 75 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 1e0ce201553dda90f95705adfdf1eb773692f65a..64fede459930bf717abbbe75ed96f02705629f7f 100644 GIT binary patch delta 214 zcmbQiGJ|EpOy*yguT7leUoVhYP!N+;nwgWLmtK^Zl9O6m#K08owC1z;4>pdF2TTkM z6$K0o3<7V%%jK6|XE8kAaW=f7b)sSk1AlR9Nl9j2dNE96AwwMl8%XWEn+f}D?z89V zCg@3pI~`tF!l3SK6%$&VT2vfUl$mZ21Jx0eUNm_!qc$VY89) { return "Safe to accept. " + secondLine;} + else if (score>74) { return "Not fully safe to accept. " + secondLine;} + else if (score>30) { return "Not safe to accept. " + secondLine;} + else { return "Do not accept! " + secondLine;} } public int GetColor() { if (score>89) { return R.color.msg_okay;} @@ -46,7 +44,6 @@ public class BalanceValidator { return; } - // rule 2.c if(!CheckAttestationServiceResult(card) && CheckAttestationServiceAvailable(card)) { score = 0; @@ -55,17 +52,56 @@ public class BalanceValidator { return; } - // rule 3 - if(CheckOnlineBalance(card) && !NotConfirmTransaction(card)) + // rule 6 + if(NotConfirmTransaction(card)) { - if(card.isBalanceRecieved() && card.isBalanceEqual()) { - score = 100; - firstLine = "Verified balance"; - secondLine += "Confirmed balance and banknote identity. "; - if(card.getBalance() == 0) { - firstLine = "Zero balance"; - } + score = 0; + firstLine = "Unguaranted balance"; + secondLine = "Loading in progress. Wait for full confirmation in blockchain. "; + return; + } + + // rule 5 + if(IsLostSecondRead(card)) + { + score = 0; + secondLine = "Wallet and note keys were not verified. Tap again. "; + return; + } + + if(card.isBalanceRecieved() && card.isBalanceEqual()) { + score = 100; + firstLine = "Verified balance"; + secondLine = "Balance confirmed in blockchain. "; + if(card.getBalance() == 0) { + firstLine = ""; } + } + + // rule 4 TODO: need to check SignedHashed against number of outputs in blockchain + if(HasEverSigned(card)) + { + score = 80; + firstLine = "Unguaranteed balance"; + secondLine = "Potential unsent transaction. Redeem immediately if accept. "; + return; + } + // rule 7 + if(CheckOfflineBalance(card) && !CheckOnlineBalance(card)) + { + score = 80; + firstLine = "Verified offline balance"; + secondLine = "Can't obtain balance from blockchain. Restore internet connection to be more confident. "; + } + + // rule 2.b + if(CheckAttestationServiceAvailable(card)) + { + secondLine += "Verified note identity. "; + } else { + score = 80; + secondLine += "Card identity was not verified. Cannot reach Tangem attestation service. "; + } // if(card.getFailedBalanceRequestCounter()!=0) { // score -= 5 * card.getFailedBalanceRequestCounter(); @@ -74,62 +110,14 @@ public class BalanceValidator { // return; // } - // + // // if(card.isBalanceRecieved() && !card.isBalanceEqual()) { // score = 0; // firstLine = "Disputed balance"; // secondLine += " Cannot obtain trusted balance at the moment. Try to tap and check this banknote later."; // return; // } - } - // rule 7 - if(CheckOfflineBalance(card) && !CheckOnlineBalance(card)) - { - score = 90; - firstLine = "Verified offline balance"; - secondLine += "Restore internet connection to be more confident. "; - if(score <= 0) - return; - } - - // rule 2.b - if(!CheckAttestationServiceAvailable(card)) - { - score -= 15; - secondLine += "Card identity was not verified. Cannot reach attestation service. "; - if(score <= 0) - return; - } - - // rule 5 - if(IsLostSecondRead(card)) - { - score -= 30; - secondLine += "Wallet and banknote keys were not verified. Tap again. "; - if(score <= 0) - return; - } - - // rule 4 - if(!CheckSignHashes(card)) - { - score -= 50; - firstLine = "Unguaranteed balance"; - secondLine += "Potential unsent transaction at the moment. Check this banknote later. "; - if(score <= 0) - return; - } - - // rule 6 - if(NotConfirmTransaction(card)) - { - score -= 50; - String firstLine = "Unguaranted balance"; - secondLine += " Loading in progress. Wait for full confirmation in blockchain. "; - if(score <= 0) - return; - } } @@ -148,9 +136,10 @@ public class BalanceValidator { return card.isWalletPublicKeyValid(); } - boolean CheckSignHashes(TangemCard card) + boolean HasEverSigned(TangemCard card) { - return card.getSignHashes()==null; +// return card.getSignedHashes() != 0 || card.getRemainingSignatures() != card.getMaxSignatures(); + return card.getRemainingSignatures() != card.getMaxSignatures(); } boolean CheckAttestationServiceAvailable(TangemCard card) diff --git a/app/src/main/java/com/tangem/domain/wallet/TangemCard.java b/app/src/main/java/com/tangem/domain/wallet/TangemCard.java index 8a102554aa..e8833c4280 100644 --- a/app/src/main/java/com/tangem/domain/wallet/TangemCard.java +++ b/app/src/main/java/com/tangem/domain/wallet/TangemCard.java @@ -1214,13 +1214,13 @@ public class TangemCard { return Denomination; } - public byte[] SignHashes; - public void setSignHashes(byte[] SignHashes) { - this.SignHashes = SignHashes; + public int SignedHashes = -1; // Will remain -1 if tag was not found on card (= not safe to accept) + public void setSignedHashes(int SignedHashes) { + this.SignedHashes = SignedHashes; } - public byte[] getSignHashes() { - return SignHashes; + public int getSignedHashes() { + return SignedHashes; } @@ -1313,7 +1313,7 @@ public class TangemCard { if(failedBalanceRequestCounter != null) B.putInt("FailedBalance", failedBalanceRequestCounter.get()); - if(getSignHashes()!=null) B.putByteArray("SignHashes", getSignHashes()); + B.putInt("SignedHashes", getSignedHashes()); B.putString("Wallet", wallet); B.putString("Error", error); B.putBoolean("WalletPublicKeyValid", isWalletPublicKeyValid()); @@ -1434,7 +1434,7 @@ public class TangemCard { else encryptionMode = null; - if(B.containsKey("SignHashes")) setSignHashes(B.getByteArray("SignHashes")); + if(B.containsKey("SignedHashes")) setSignedHashes(B.getInt("SignedHashes")); if(B.containsKey("FailedBalance")) failedBalanceRequestCounter = new AtomicInteger(B.getInt("FailedBalance")); if (B.containsKey("Issuer")) issuer = Issuer.FindIssuer(B.getString("Issuer"));