Compare commits

..
Author SHA1 Message Date
Michele Balistreri af191dbdf8 bump version 2021-04-30 15:43:10 +03:00
Michele Balistreri 3d4ae98342 fix compilation 2021-04-29 16:21:41 +03:00
Michele Balistreri 58a544f8da add factory reset on iOS 2021-04-29 15:55:07 +03:00
Michele Balistreri 728f59d793 add missing import 2021-04-28 13:06:59 +03:00
Michele Balistreri 012d228079 add factory reset method (Android) 2021-04-28 12:41:26 +03:00
5 changed files with 27 additions and 72 deletions
@@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.support.annotation.Nullable;
import android.util.EventLog;
import android.util.Log;
@@ -206,22 +207,6 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
log("seed loaded to card");
}
public boolean tryDefaultPairing(KeycardCommandSet cmdSet, String instanceUID, WritableMap cardInfo) throws IOException {
try {
cmdSet.autoPair("KeycardDefaultPairing");
Pairing pairing = cmdSet.getPairing();
pairings.put(instanceUID, pairing.toBase64());
cardInfo.putString("new-pairing", pairing.toBase64());
openSecureChannel(cmdSet);
return true;
} catch(APDUException e) {
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
return false;
}
}
public WritableMap getApplicationInfo() throws IOException, APDUException {
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
ApplicationInfo info = new ApplicationInfo(cmdSet.select().checkOK().getData());
@@ -242,25 +227,23 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
Boolean isPaired = false;
if (!pairings.containsKey(instanceUID)) {
isPaired = tryDefaultPairing(cmdSet, instanceUID, cardInfo);
} else {
if (pairings.containsKey(instanceUID)) {
try {
openSecureChannel(cmdSet);
isPaired = true;
} catch(APDUException e) {
isPaired = tryDefaultPairing(cmdSet, instanceUID, cardInfo);
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
}
}
if (isPaired) {
ApplicationStatus status = new ApplicationStatus(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_APPLICATION).checkOK().getData());
if (isPaired) {
ApplicationStatus status = new ApplicationStatus(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_APPLICATION).checkOK().getData());
Log.i(TAG, "PIN retry counter: " + status.getPINRetryCount());
Log.i(TAG, "PUK retry counter: " + status.getPUKRetryCount());
Log.i(TAG, "PIN retry counter: " + status.getPINRetryCount());
Log.i(TAG, "PUK retry counter: " + status.getPUKRetryCount());
cardInfo.putInt("pin-retry-counter", status.getPINRetryCount());
cardInfo.putInt("puk-retry-counter", status.getPUKRetryCount());
cardInfo.putInt("pin-retry-counter", status.getPINRetryCount());
cardInfo.putInt("puk-retry-counter", status.getPUKRetryCount());
}
}
cardInfo.putBoolean("has-master-key?", info.hasMasterKey());
@@ -1,5 +1,6 @@
package im.status.ethereum.keycard;
import android.support.annotation.NonNull;
import android.util.Base64;
import static android.util.Base64.NO_PADDING;
@@ -28,8 +29,9 @@ public class SmartCardSecrets {
this.pairingPassword = pairingPassword;
}
@NonNull
public static SmartCardSecrets generate(final String userPin) throws NoSuchAlgorithmException, InvalidKeySpecException {
String pairingPassword = "KeycardDefaultPairing";
String pairingPassword = randomToken(5);
long pinNumber = randomLong(PIN_BOUND);
long pukNumber = randomLong(PUK_BOUND);
+11 -31
View File
@@ -20,11 +20,11 @@ class SmartCard {
func initialize(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
let puk = self.randomPUK()
let pairingPassword = "KeycardDefaultPairing"
let pairingPassword = self.randomPairingPassword();
let cmdSet = KeycardCommandSet(cardChannel: channel)
try cmdSet.select().checkOK()
try cmdSet.initialize(pin: pin, puk: puk, pairingPassword: pairingPassword).checkOK()
try cmdSet.initialize(pin: pin, puk: puk, pairingPassword: pairingPassword).checkOK();
resolve(["pin": pin, "puk": puk, "password": pairingPassword])
}
@@ -129,21 +129,19 @@ class SmartCard {
try openSecureChannel(cmdSet: cmdSet)
isPaired = true
} catch let error as CardError {
isPaired = try tryDefaultPairing(cmdSet: cmdSet, cardInfo: &cardInfo)
os_log("autoOpenSecureChannel failed: %@", String(describing: error));
} catch let error as StatusWord {
isPaired = try tryDefaultPairing(cmdSet: cmdSet, cardInfo: &cardInfo)
os_log("autoOpenSecureChannel failed: %@", String(describing: error));
}
} else {
isPaired = try tryDefaultPairing(cmdSet: cmdSet, cardInfo: &cardInfo)
}
if (isPaired) {
let status = try ApplicationStatus(cmdSet.getStatus(info: GetStatusP1.application.rawValue).checkOK().data);
os_log("PIN retry counter: %d", status.pinRetryCount)
os_log("PUK retry counter: %d", status.pukRetryCount)
if (isPaired) {
let status = try ApplicationStatus(cmdSet.getStatus(info: GetStatusP1.application.rawValue).checkOK().data);
os_log("PIN retry counter: %d", status.pinRetryCount)
os_log("PUK retry counter: %d", status.pukRetryCount)
cardInfo["pin-retry-counter"] = status.pinRetryCount
cardInfo["puk-retry-counter"] = status.pukRetryCount
cardInfo["pin-retry-counter"] = status.pinRetryCount
cardInfo["puk-retry-counter"] = status.pukRetryCount
}
}
cardInfo["paired?"] = isPaired
@@ -371,24 +369,6 @@ class SmartCard {
return cmdSet
}
func tryDefaultPairing(cmdSet: KeycardCommandSet, cardInfo: inout [String: Any]) throws -> Bool {
do {
try cmdSet.autoPair(password: "KeycardDefaultPairing")
let pairing = Data(cmdSet.pairing!.bytes).base64EncodedString()
self.pairings[bytesToHex(cmdSet.info!.instanceUID)] = pairing
cardInfo["new-pairing"] = pairing
try openSecureChannel(cmdSet: cmdSet)
return true
} catch let error as CardError {
os_log("autoOpenSecureChannel failed: %@", String(describing: error));
} catch let error as StatusWord {
os_log("autoOpenSecureChannel failed: %@", String(describing: error));
}
return false
}
func openSecureChannel(cmdSet: KeycardCommandSet) throws -> Void {
if let pairingBase64 = self.pairings[bytesToHex(cmdSet.info!.instanceUID)] {
cmdSet.pairing = try base64ToPairing(pairingBase64)
+2 -12
View File
@@ -9,18 +9,8 @@ class StatusKeycard: RCTEventEmitter {
var cardChannel: CardChannel? = nil
var nfcStartPrompt: String = "Hold your iPhone near a Status Keycard."
private var _keycardController: Any? = nil
@available(iOS 13.0, *)
private var keycardController: KeycardController? {
get {
return _keycardController as? KeycardController
}
set(kc) {
_keycardController = kc
}
}
private(set) lazy var keycardController: KeycardController? = nil
@objc
func nfcIsSupported(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
@@ -209,7 +199,7 @@ class StatusKeycard: RCTEventEmitter {
let nsError = error as NSError
if nsError.code == 200 && nsError.domain == "NFCError" {
self.sendEvent(withName: "keyCardOnNFCUserCancelled", body: nil)
} else if (nsError.code == 201 || nsError.code == 203) && (nsError.domain == "NFCError") {
} else if nsError.code == 201 && nsError.domain == "NFCError" {
self.sendEvent(withName: "keyCardOnNFCTimeout", body: nil)
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "react-native-status-keycard",
"homepage": "https://keycard.status.im/",
"version": "2.5.38",
"version": "2.5.35",
"description": "React Native library to interact with Status Keycard using NFC connection",
"main": "index.js",
"scripts": {