Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f431c7d6cb | ||
|
|
c19d58bb5d | ||
|
|
ff570d4720 | ||
|
|
c0d09e3a49 | ||
|
|
d5feacb4ee | ||
|
|
eeeaa26819 | ||
|
|
29b3a3c578 | ||
|
|
b7fe831dd7 | ||
|
|
26db8dfd25 | ||
|
|
59052a36d7 |
@@ -46,5 +46,5 @@ dependencies {
|
||||
implementation 'com.facebook.react:react-native:+'
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.60'
|
||||
implementation 'org.apache.commons:commons-lang3:3.9'
|
||||
implementation 'com.github.status-im.status-keycard-java:android:3.0.1'
|
||||
implementation 'com.github.status-im.status-keycard-java:android:3.0.2'
|
||||
}
|
||||
|
||||
@@ -41,9 +41,10 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
if (this.smartCard == null) {
|
||||
this.smartCard = new SmartCard(getCurrentActivity(), reactContext);
|
||||
smartCard.start();
|
||||
this.smartCard = new SmartCard(reactContext);
|
||||
}
|
||||
|
||||
smartCard.start(getCurrentActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,13 +53,12 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
|
||||
@Override
|
||||
public void onHostDestroy() {
|
||||
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void nfcIsSupported(final Promise promise) {
|
||||
if (smartCard != null) {
|
||||
promise.resolve(smartCard.isNfcSupported());
|
||||
promise.resolve(smartCard.isNfcSupported(getCurrentActivity()));
|
||||
} else {
|
||||
promise.resolve(false);
|
||||
}
|
||||
|
||||
@@ -41,8 +41,6 @@ import org.bouncycastle.util.encoders.Hex;
|
||||
|
||||
public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
private NFCCardManager cardManager;
|
||||
private Activity activity;
|
||||
private ReactContext reactContext;
|
||||
private NfcAdapter nfcAdapter;
|
||||
private CardChannel cardChannel;
|
||||
private EventEmitter eventEmitter;
|
||||
@@ -56,12 +54,9 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
private static final String ENCRYPTION_PATH = "m/43'/60'/1581'/1'/0";
|
||||
private static final int WORDS_LIST_SIZE = 2048;
|
||||
|
||||
public SmartCard(Activity activity, ReactContext reactContext) {
|
||||
public SmartCard(ReactContext reactContext) {
|
||||
this.cardManager = new NFCCardManager();
|
||||
this.cardManager.setCardListener(this);
|
||||
this.activity = activity;
|
||||
this.reactContext = reactContext;
|
||||
this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity.getBaseContext());
|
||||
this.eventEmitter = new EventEmitter(reactContext);
|
||||
}
|
||||
|
||||
@@ -73,23 +68,31 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
Log.d(TAG, s);
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
if (!started) {
|
||||
public boolean start(Activity activity) {
|
||||
if(activity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity.getBaseContext());
|
||||
this.cardManager.start();
|
||||
started = true;
|
||||
}
|
||||
|
||||
if (this.nfcAdapter != null) {
|
||||
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
|
||||
activity.registerReceiver(this, filter);
|
||||
nfcAdapter.enableReaderMode(activity, this.cardManager, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
|
||||
return true;
|
||||
} else {
|
||||
log("not support in this device");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.nfcAdapter != null) {
|
||||
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
|
||||
activity.registerReceiver(this, filter);
|
||||
nfcAdapter.enableReaderMode(activity, this.cardManager, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
|
||||
return true;
|
||||
} else {
|
||||
log("not support in this device");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(Activity activity) {
|
||||
if (activity != null && nfcAdapter != null) {
|
||||
nfcAdapter.disableReaderMode(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +125,8 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNfcSupported() {
|
||||
return activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);
|
||||
public boolean isNfcSupported(Activity activity) {
|
||||
return activity != null && activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);
|
||||
}
|
||||
|
||||
public boolean isNfcEnabled() {
|
||||
@@ -233,14 +236,18 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
Boolean isPaired = false;
|
||||
|
||||
if (pairingBase64.length() > 0) {
|
||||
try {
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
|
||||
try {
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
isPaired = true;
|
||||
} catch(APDUException e) {
|
||||
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (isPaired) {
|
||||
ApplicationStatus status = new ApplicationStatus(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_APPLICATION).checkOK().getData());
|
||||
|
||||
Log.i(TAG, "PIN retry counter: " + status.getPINRetryCount());
|
||||
@@ -248,8 +255,6 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
|
||||
cardInfo.putInt("pin-retry-counter", status.getPINRetryCount());
|
||||
cardInfo.putInt("puk-retry-counter", status.getPUKRetryCount());
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,7 +592,18 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
Log.i(TAG, "pin verified");
|
||||
|
||||
byte[] hash = Hex.decode(message);
|
||||
RecoverableSignature signature = new RecoverableSignature(hash, cmdSet.signWithPath(hash, path, false).checkOK().getData());
|
||||
|
||||
RecoverableSignature signature;
|
||||
|
||||
if (cmdSet.getApplicationInfo().getAppVersion() < 0x0202) {
|
||||
String actualPath = new KeyPath(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_KEY_PATH).checkOK().getData()).toString();
|
||||
if (!actualPath.equals(path)) {
|
||||
cmdSet.deriveKey(path).checkOK();
|
||||
}
|
||||
signature = new RecoverableSignature(hash, cmdSet.sign(hash).checkOK().getData());
|
||||
} else {
|
||||
signature = new RecoverableSignature(hash, cmdSet.signWithPath(hash, path, false).checkOK().getData());
|
||||
}
|
||||
|
||||
Log.i(TAG, "Signed hash: " + Hex.toHexString(hash));
|
||||
Log.i(TAG, "Recovery ID: " + signature.getRecId());
|
||||
|
||||
Reference in New Issue
Block a user