Skip to content

Commit

Permalink
Fix showing IIN and platform type handling
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Aug 27, 2020
1 parent 2c1c951 commit 87aedd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
18 changes: 6 additions & 12 deletions library/src/main/java/com/fidesmo/fdsm/FidesmoCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class FidesmoCard {
private final static Logger logger = LoggerFactory.getLogger(FidesmoCard.class);

public enum ChipPlatform {

UNKNOWN(0),
JCOP242R1(1),
JCOP242R2(2),
JCOP3EMV(3),
Expand All @@ -54,12 +52,12 @@ public enum ChipPlatform {
this.v = v;
}

public static ChipPlatform valueOf(int v) {
public static Optional<ChipPlatform> valueOf(int v) {
for (ChipPlatform t : values()) {
if (t.v == v)
return t;
return Optional.of(t);
}
return UNKNOWN;
return Optional.empty();
}
}

Expand Down Expand Up @@ -103,12 +101,12 @@ public static ChipPlatform valueOf(int v) {
}

// Given CPLC, detect the platform from enumeration
public static ChipPlatform detectPlatform(byte[] cplc) {
public static Optional<ChipPlatform> detectPlatform(byte[] cplc) {
for (Map.Entry<byte[], ChipPlatform> e : CPLC_PLATFORMS.entrySet()) {
if (Arrays.equals(e.getKey(), Arrays.copyOf(cplc, e.getKey().length)))
return e.getValue();
return Optional.of(e.getValue());
}
return ChipPlatform.UNKNOWN;
return Optional.empty();
}

// Capabilities applet AID
Expand Down Expand Up @@ -184,10 +182,6 @@ public byte[] getBatchId() {
return batchId.clone();
}

public ChipPlatform getPlatform() {
return detectPlatform(cplc);
}

public static Optional<FidesmoCard> detectPlatformV2(APDUBIBO channel) {
// Select ISD
CommandAPDU selectISD = new CommandAPDU(0x00, 0xA4, 0x04, 0x00, 0x00);
Expand Down
8 changes: 4 additions & 4 deletions tool/src/main/java/com/fidesmo/fdsm/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import apdu4j.TerminalManager;
import apdu4j.terminals.LoggingCardTerminal;
import com.fasterxml.jackson.databind.JsonNode;
import com.fidesmo.fdsm.FidesmoCard.ChipPlatform;
import jnasmartcardio.Smartcardio;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.client.HttpResponseException;
Expand Down Expand Up @@ -276,11 +277,10 @@ public static void main(String[] argv) {
JsonNode capabilities = device.get("description").get("capabilities");
int platformVersion = capabilities.get("platformVersion").asInt();
int platformType = capabilities.get("osTypeVersion").asInt();

System.out.format("IIN: %s %n",
verbose ? String.format(" IIN: %s", HexUtils.bin2hex(iin)) : "");
if (verbose)
System.out.format("IIN: %s%n", HexUtils.bin2hex(iin));
// For platforms that are not yet supported by fdsm
String platform = FidesmoCard.ChipPlatform.valueOf(platformType).toString();
String platform = ChipPlatform.valueOf(platformType).map(ChipPlatform::toString).orElse("unknown");
System.out.format("OS type: %s (platform v%d)%n", platform, platformVersion);
}
} else {
Expand Down

0 comments on commit 87aedd7

Please sign in to comment.