From b9f242aa11afbb6a79c269459c48e32a6091176c Mon Sep 17 00:00:00 2001 From: Bitgamma Date: Fri, 9 Apr 2021 12:21:36 +0300 Subject: [PATCH] add change PUK and pairing password (#39) * add change PUK and pairing --- .../keycard/RNStatusKeycardModule.java | 30 +++++++++++++++++++ .../im/status/ethereum/keycard/SmartCard.java | 16 +++++++++- ios/SmartCard.swift | 14 +++++++++ ios/StatusKeycard.m | 2 ++ ios/StatusKeycard.swift | 10 +++++++ package.json | 2 +- 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java b/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java index 062b187..6b317ae 100644 --- a/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java +++ b/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java @@ -341,6 +341,36 @@ public void run() { }).start(); } + @ReactMethod + public void changePairingPassword(final String pin, final String pairingPassword, final Promise promise) { + new Thread(new Runnable() { + public void run() { + try { + smartCard.changePairingPassword(pin, pairingPassword); + promise.resolve(true); + } catch (IOException | APDUException e) { + Log.d(TAG, e.getMessage()); + promise.reject(e); + } + } + }).start(); + } + + @ReactMethod + public void changePUK(final String pin, final String puk, final Promise promise) { + new Thread(new Runnable() { + public void run() { + try { + smartCard.changePUK(pin, puk); + promise.resolve(true); + } catch (IOException | APDUException e) { + Log.d(TAG, e.getMessage()); + promise.reject(e); + } + } + }).start(); + } + @ReactMethod public void changePin(final String currentPin, final String newPin, final Promise promise) { new Thread(new Runnable() { diff --git a/android/src/main/java/im/status/ethereum/keycard/SmartCard.java b/android/src/main/java/im/status/ethereum/keycard/SmartCard.java index 47289a3..6f4d167 100644 --- a/android/src/main/java/im/status/ethereum/keycard/SmartCard.java +++ b/android/src/main/java/im/status/ethereum/keycard/SmartCard.java @@ -405,10 +405,24 @@ public int verifyPin(final String pin) throws IOException, APDUException { return 3; } + public void changePairingPassword(final String pin, final String pairingPassword) throws IOException, APDUException { + KeycardCommandSet cmdSet = authenticatedCommandSet(pin); + + cmdSet.changePairingPassword(pairingPassword); + Log.i(TAG, "pairing password changed"); + } + + public void changePUK(final String pin, final String puk) throws IOException, APDUException { + KeycardCommandSet cmdSet = authenticatedCommandSet(pin); + + cmdSet.changePUK(puk); + Log.i(TAG, "puk changed"); + } + public void changePin(final String currentPin, final String newPin) throws IOException, APDUException { KeycardCommandSet cmdSet = authenticatedCommandSet(currentPin); - cmdSet.changePIN(0, newPin); + cmdSet.changePIN(newPin); Log.i(TAG, "pin changed"); } diff --git a/ios/SmartCard.swift b/ios/SmartCard.swift index 63ed595..aa65c0a 100644 --- a/ios/SmartCard.swift +++ b/ios/SmartCard.swift @@ -243,6 +243,20 @@ class SmartCard { resolve(3) } + func changePairingPassword(channel: CardChannel, pin: String, pairingPassword: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void { + let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin) + try cmdSet.changePairingPassword(pairingPassword: pairingPassword).checkOK() + os_log("pairing password changed") + resolve(true) + } + + func changePUK(channel: CardChannel, pin: String, puk: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void { + let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin) + try cmdSet.changePUK(puk: puk).checkOK() + os_log("puk changed") + resolve(true) + } + func changePin(channel: CardChannel, currentPin: String, newPin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void { let cmdSet = try authenticatedCommandSet(channel: channel, pin: currentPin) try cmdSet.changePIN(pin: newPin).checkOK() diff --git a/ios/StatusKeycard.m b/ios/StatusKeycard.m index bef9f7b..218d404 100644 --- a/ios/StatusKeycard.m +++ b/ios/StatusKeycard.m @@ -23,6 +23,8 @@ @interface RCT_EXTERN_REMAP_MODULE(RNStatusKeycard, StatusKeycard, RCTEventEmitt RCT_EXTERN_METHOD(installApplet:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(installAppletAndInitCard:(String *)pin resolve: (RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(verifyPin:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(changePairingPassword:(NSString *)pin pairingPassword:(NSString *)pairingPassword resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(changePUK:(NSString *)pin puk:(NSString *)puk resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(changePin:(NSString *)currentPin newPin:(NSString *)newPin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(unblockPin:(NSString *)puk newPin:(NSString *)newPin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(unpair:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) diff --git a/ios/StatusKeycard.swift b/ios/StatusKeycard.swift index c636f44..5921c4c 100644 --- a/ios/StatusKeycard.swift +++ b/ios/StatusKeycard.swift @@ -118,6 +118,16 @@ class StatusKeycard: RCTEventEmitter { keycardInvokation(reject) { [unowned self] channel in try self.smartCard.verifyPin(channel: channel, pin: pin, resolve: resolve, reject: reject) } } + @objc + func changePairingPassword(_ pin: String, pairingPassword: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + keycardInvokation(reject) { [unowned self] channel in try self.smartCard.changePairingPassword(channel: channel, pin: pin, pairingPassword: pairingPassword, resolve: resolve, reject: reject) } + } + + @objc + func changePUK(_ pin: String, puk: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + keycardInvokation(reject) { [unowned self] channel in try self.smartCard.changePUK(channel: channel, pin: pin, puk: puk, resolve: resolve, reject: reject) } + } + @objc func changePin(_ currentPin: String, newPin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { keycardInvokation(reject) { [unowned self] channel in try self.smartCard.changePin(channel: channel, currentPin: currentPin, newPin: newPin, resolve: resolve, reject: reject) } diff --git a/package.json b/package.json index a75fc28..c93c700 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-status-keycard", "homepage": "https://keycard.status.im/", - "version": "2.5.33", + "version": "2.5.34", "description": "React Native library to interact with Status Keycard using NFC connection (Android only)", "main": "index.js", "scripts": {