Skip to content

Commit

Permalink
Add AID 32 for OmapiTest.testLongSelectResponse()
Browse files Browse the repository at this point in the history
AID 32 applet shall return a BER-TLV formatted response when selected.
  • Loading branch information
cheeriotb committed Nov 15, 2018
1 parent f8755a7 commit 15c0156
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -4,7 +4,8 @@ PACKAGE_AID = 0xA0:0x00:0x00:0x04:0x76:0x00
PACKAGE_NAME = com.github.cheeriotb.cts.cardlet
PACKAGE_VERSION = 1.63

APPLET_AID = 0xA0:0x00:0x00:0x04:0x76:0x41:0x6E:0x64:0x72:0x6F:0x69:0x64:0x43:0x54:0x53:0x31
APPLET_AID_31 = 0xA0:0x00:0x00:0x04:0x76:0x41:0x6E:0x64:0x72:0x6F:0x69:0x64:0x43:0x54:0x53:0x31
APPLET_AID_32 = 0xA0:0x00:0x00:0x04:0x76:0x41:0x6E:0x64:0x72:0x6F:0x69:0x64:0x43:0x54:0x53:0x32
APPLET_NAME = com.github.cheeriotb.cts.cardlet.OmapiApplet

SOURCES = ./src/com/github/cheeriotb/cts/cardlet/*.java
Expand Down Expand Up @@ -36,7 +37,8 @@ JC ?= javac
-d $(BUILD_JAVACARD_DIR) \
-classdir $(BUILD_CLASSES_DIR) \
-exportpath $(JAVACARD_EXPORT_DIR) \
-applet $(APPLET_AID) $(APPLET_NAME) \
-applet $(APPLET_AID_31) $(APPLET_NAME) \
-applet $(APPLET_AID_32) $(APPLET_NAME) \
$(PACKAGE_NAME) $(PACKAGE_AID) $(PACKAGE_VERSION)

default: classes
Expand Down
87 changes: 80 additions & 7 deletions src/com/github/cheeriotb/cts/cardlet/OmapiApplet.java
Expand Up @@ -18,6 +18,7 @@

package com.github.cheeriotb.cts.cardlet;

import javacard.framework.AID;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
Expand All @@ -26,16 +27,61 @@

public class OmapiApplet extends Applet {

final private static byte INS_BASIC_CLASS_1 = (byte) 0x06;
final private static byte INS_BASIC_CLASS_3 = (byte) 0x0A;
final private static byte INS_BASIC_CLASS_2 = (byte) 0x08;
final private static byte INS_BASIC_CLASS_4 = (byte) 0x0C;
private static final byte INS_BASIC_CLASS_1 = (byte) 0x06;
private static final byte INS_BASIC_CLASS_3 = (byte) 0x0A;
private static final byte INS_BASIC_CLASS_2 = (byte) 0x08;
private static final byte INS_BASIC_CLASS_4 = (byte) 0x0C;

final private static byte[] FCI_TEMPLATE = {
private static final byte[] SELECT_RESPONSE_FCP = {
(byte) 0x62, (byte) 0x1A, (byte) 0x82, (byte) 0x02, (byte) 0x38, (byte) 0x21,
(byte) 0x83, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x8A, (byte) 0x01,
(byte) 0x00, (byte) 0x8C, (byte) 0x02, (byte) 0x20, (byte) 0x00, (byte) 0xC6,
(byte) 0x09, (byte) 0x90, (byte) 0x01, (byte) 0x00, (byte) 0x83, (byte) 0x01,
(byte) 0x00, (byte) 0x83, (byte) 0x01, (byte) 0x00
};

private static final byte[] SELECT_RESPONSE_FMD = {
(byte) 0x64, (byte) 0x07, (byte) 0x53, (byte) 0x05, (byte) 0x01, (byte) 0x02,
(byte) 0x03, (byte) 0x04, (byte) 0x05
};

private static final byte[] SELECT_RESPONSE_FCI_LONG = {
(byte) 0x6F, (byte) 0x81, (byte) 0x87, (byte) 0x84, (byte) 0x10, (byte) 0x53,
(byte) 0x6C, (byte) 0x63, (byte) 0x74, (byte) 0x52, (byte) 0x65, (byte) 0x73,
(byte) 0x70, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20,
(byte) 0x31, (byte) 0x2E, (byte) 0x30, (byte) 0xA5, (byte) 0x73, (byte) 0x65,
(byte) 0x06, (byte) 0x07, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xFC, (byte) 0x6B, (byte) 0x01, (byte) 0x60, (byte) 0x0B, (byte) 0x06,
(byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xFC,
(byte) 0x6B, (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x63, (byte) 0x09,
(byte) 0x06, (byte) 0x07, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xFC, (byte) 0x6B, (byte) 0x03, (byte) 0x64, (byte) 0x0B, (byte) 0x06,
(byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xFC,
(byte) 0x6B, (byte) 0x04, (byte) 0x80, (byte) 0x00, (byte) 0x64, (byte) 0x0B,
(byte) 0x06, (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xFC, (byte) 0x6B, (byte) 0x04, (byte) 0x02, (byte) 0x55, (byte) 0x64,
(byte) 0x0B, (byte) 0x06, (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xFC, (byte) 0x6B, (byte) 0x04, (byte) 0x03, (byte) 0x70,
(byte) 0x65, (byte) 0x0D, (byte) 0x06, (byte) 0x0B, (byte) 0x2A, (byte) 0x86,
(byte) 0x48, (byte) 0x86, (byte) 0xFC, (byte) 0x6B, (byte) 0x05, (byte) 0x04,
(byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x66, (byte) 0x0C, (byte) 0x06,
(byte) 0x0A, (byte) 0x2B, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x01,
(byte) 0x2A, (byte) 0x02, (byte) 0x6E, (byte) 0x01, (byte) 0x03, (byte) 0x9F,
(byte) 0x6E, (byte) 0x06, (byte) 0x00, (byte) 0x77, (byte) 0x60, (byte) 0x22,
(byte) 0x01, (byte) 0x20, (byte) 0x9F, (byte) 0x65, (byte) 0x01, (byte) 0xFF
};

private static final byte[] SELECT_RESPONSE_FCI_SHORT = {
(byte) 0x6F, (byte) 0x0A, (byte) 0x64, (byte) 0x03, (byte) 0x53, (byte) 0x01,
(byte) 0x01, (byte) 0x62, (byte) 0x03, (byte) 0x85, (byte) 0x01, (byte) 0x01
};

private static final byte[] AID_LONG_RESPONSE = {
(byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x76, (byte) 0x41,
(byte) 0x6E, (byte) 0x64, (byte) 0x72, (byte) 0x6F, (byte) 0x69, (byte) 0x64,
(byte) 0x43, (byte) 0x54, (byte) 0x53, (byte) 0x32
};

private OmapiApplet() {
}

Expand All @@ -47,8 +93,35 @@ public static void install(byte[] bArray, short bOffset, byte bLength) {
public void process(APDU apdu) throws ISOException {
byte[] buffer = apdu.getBuffer();
if (selectingApplet()) {
Util.arrayCopy(FCI_TEMPLATE, (short) 0, buffer, (short) 0, (short) FCI_TEMPLATE.length);
apdu.setOutgoingAndSend((short) 0, (short) FCI_TEMPLATE.length);
byte[] response;
switch (buffer[ISO7816.OFFSET_P2] & 0x0C) {
// Return FCI template, optional use of FCI tag and length
case 0x00:
AID selected = new AID(buffer, ISO7816.OFFSET_CDATA, buffer[ISO7816.OFFSET_LC]);
if (selected.equals(AID_LONG_RESPONSE, (short) 0,
(byte) AID_LONG_RESPONSE.length)) {
response = SELECT_RESPONSE_FCI_LONG;
} else {
response = SELECT_RESPONSE_FCI_SHORT;
}
break;
// Return FCP template, mandatory use of FCP tag and length
case 0x04:
response = SELECT_RESPONSE_FCP;
break;
// Return FMD template, mandatory use of FMD tag and length
case 0x08:
response = SELECT_RESPONSE_FMD;
break;
// No response data if Le field absent, or proprietary if Le field present
case 0x0C:
return;
default:
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
return;
}
Util.arrayCopy(response, (short) 0, buffer, (short) 0, (short) response.length);
apdu.setOutgoingAndSend((short) 0, (short) response.length);
return;
}
byte[] output = null;
Expand Down

0 comments on commit 15c0156

Please sign in to comment.