Skip to content

Commit 9366028

Browse files
committed
add factory reset
1 parent 0d27ac4 commit 9366028

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/src/main/java/im/status/keycard/applet/ApplicationInfo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public class ApplicationInfo {
2323
static final byte CAPABILITY_KEY_MANAGEMENT = (byte) 0x02;
2424
static final byte CAPABILITY_CREDENTIALS_MANAGEMENT = (byte) 0x04;
2525
static final byte CAPABILITY_NDEF = (byte) 0x08;
26+
static final byte CAPABILITY_FACTORY_RESET = (byte) 0x10;
2627

27-
static final byte CAPABILITIES_ALL = CAPABILITY_SECURE_CHANNEL | CAPABILITY_KEY_MANAGEMENT | CAPABILITY_CREDENTIALS_MANAGEMENT | CAPABILITY_NDEF;
28+
static final byte CAPABILITIES_ALL = CAPABILITY_SECURE_CHANNEL | CAPABILITY_KEY_MANAGEMENT | CAPABILITY_CREDENTIALS_MANAGEMENT | CAPABILITY_NDEF | CAPABILITY_FACTORY_RESET;
2829

2930
/**
3031
* Constructs an object by parsing the TLV data.
@@ -191,4 +192,13 @@ public boolean hasCredentialsManagementCapability() {
191192
public boolean hasNDEFCapability() {
192193
return (capabilities & CAPABILITY_NDEF) == CAPABILITY_NDEF;
193194
}
195+
196+
/**
197+
* Returns true if the device supports the Factory Reset capability.
198+
*
199+
* @return true or false
200+
*/
201+
public boolean hasFactoryResetCapability() {
202+
return (capabilities & CAPABILITY_FACTORY_RESET) == CAPABILITY_FACTORY_RESET;
203+
}
194204
}

lib/src/main/java/im/status/keycard/applet/KeycardCommandSet.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
public class KeycardCommandSet {
2020
static final byte INS_INIT = (byte) 0xFE;
21+
static final byte INS_FACTORY_RESET = (byte) 0xFD;
2122
static final byte INS_GET_STATUS = (byte) 0xF2;
2223
static final byte INS_SET_NDEF = (byte) 0xF3;
2324
static final byte INS_IDENTIFY_CARD = (byte) 0x14;
@@ -81,6 +82,9 @@ public class KeycardCommandSet {
8182
public static final byte EXPORT_KEY_P2_PUBLIC_ONLY = 0x01;
8283
public static final byte EXPORT_KEY_P2_EXTENDED_PUBLIC = 0x02;
8384

85+
static final byte FACTORY_RESET_P1_MAGIC = (byte) 0xAA;
86+
static final byte FACTORY_RESET_P2_MAGIC = 0x55;
87+
8488
static final byte TLV_APPLICATION_INFO_TEMPLATE = (byte) 0xA4;
8589

8690
private final CardChannel apduChannel;
@@ -887,4 +891,15 @@ public APDUResponse init(String pin, String altPin, String puk, byte[] sharedSec
887891
APDUCommand init = new APDUCommand(0x80, INS_INIT, 0, 0, secureChannel.oneShotEncrypt(initData));
888892
return apduChannel.send(init);
889893
}
894+
895+
/**
896+
* Sends the FACTORY RESET command to the card.
897+
*
898+
* @return the raw card response
899+
* @throws IOException communication error
900+
*/
901+
public APDUResponse factoryReset() throws IOException {
902+
APDUCommand factoryReset = new APDUCommand(0x80, INS_FACTORY_RESET, FACTORY_RESET_P1_MAGIC, FACTORY_RESET_P2_MAGIC, new byte[0]);
903+
return apduChannel.send(factoryReset);
904+
}
890905
}

0 commit comments

Comments
 (0)