Skip to content

Commit

Permalink
add factory reset
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgamma committed Jun 6, 2023
1 parent 0d27ac4 commit 9366028
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/src/main/java/im/status/keycard/applet/ApplicationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class ApplicationInfo {
static final byte CAPABILITY_KEY_MANAGEMENT = (byte) 0x02;
static final byte CAPABILITY_CREDENTIALS_MANAGEMENT = (byte) 0x04;
static final byte CAPABILITY_NDEF = (byte) 0x08;
static final byte CAPABILITY_FACTORY_RESET = (byte) 0x10;

static final byte CAPABILITIES_ALL = CAPABILITY_SECURE_CHANNEL | CAPABILITY_KEY_MANAGEMENT | CAPABILITY_CREDENTIALS_MANAGEMENT | CAPABILITY_NDEF;
static final byte CAPABILITIES_ALL = CAPABILITY_SECURE_CHANNEL | CAPABILITY_KEY_MANAGEMENT | CAPABILITY_CREDENTIALS_MANAGEMENT | CAPABILITY_NDEF | CAPABILITY_FACTORY_RESET;

/**
* Constructs an object by parsing the TLV data.
Expand Down Expand Up @@ -191,4 +192,13 @@ public boolean hasCredentialsManagementCapability() {
public boolean hasNDEFCapability() {
return (capabilities & CAPABILITY_NDEF) == CAPABILITY_NDEF;
}

/**
* Returns true if the device supports the Factory Reset capability.
*
* @return true or false
*/
public boolean hasFactoryResetCapability() {
return (capabilities & CAPABILITY_FACTORY_RESET) == CAPABILITY_FACTORY_RESET;
}
}
15 changes: 15 additions & 0 deletions lib/src/main/java/im/status/keycard/applet/KeycardCommandSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
public class KeycardCommandSet {
static final byte INS_INIT = (byte) 0xFE;
static final byte INS_FACTORY_RESET = (byte) 0xFD;
static final byte INS_GET_STATUS = (byte) 0xF2;
static final byte INS_SET_NDEF = (byte) 0xF3;
static final byte INS_IDENTIFY_CARD = (byte) 0x14;
Expand Down Expand Up @@ -81,6 +82,9 @@ public class KeycardCommandSet {
public static final byte EXPORT_KEY_P2_PUBLIC_ONLY = 0x01;
public static final byte EXPORT_KEY_P2_EXTENDED_PUBLIC = 0x02;

static final byte FACTORY_RESET_P1_MAGIC = (byte) 0xAA;
static final byte FACTORY_RESET_P2_MAGIC = 0x55;

static final byte TLV_APPLICATION_INFO_TEMPLATE = (byte) 0xA4;

private final CardChannel apduChannel;
Expand Down Expand Up @@ -887,4 +891,15 @@ public APDUResponse init(String pin, String altPin, String puk, byte[] sharedSec
APDUCommand init = new APDUCommand(0x80, INS_INIT, 0, 0, secureChannel.oneShotEncrypt(initData));
return apduChannel.send(init);
}

/**
* Sends the FACTORY RESET command to the card.
*
* @return the raw card response
* @throws IOException communication error
*/
public APDUResponse factoryReset() throws IOException {
APDUCommand factoryReset = new APDUCommand(0x80, INS_FACTORY_RESET, FACTORY_RESET_P1_MAGIC, FACTORY_RESET_P2_MAGIC, new byte[0]);
return apduChannel.send(factoryReset);
}
}

0 comments on commit 9366028

Please sign in to comment.