Skip to content

Commit

Permalink
add change PUK and pairing password (#39)
Browse files Browse the repository at this point in the history
* add change PUK and pairing
  • Loading branch information
bitgamma authored Apr 9, 2021
1 parent d1098e9 commit b9f242a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 15 additions & 1 deletion android/src/main/java/im/status/ethereum/keycard/SmartCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
14 changes: 14 additions & 0 deletions ios/SmartCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions ios/StatusKeycard.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions ios/StatusKeycard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit b9f242a

Please sign in to comment.