IMSIPseudo.java: display menu
Add a menu with the following actions: IMSI Pseudonymization 1 Show LU counter 2 Show IMSI 3 Change IMSI Selecting "Change IMSI" opens a submenu: Change IMSI 1 Set 1 as last digit 2 Set 2 as last digit Except for "Show LU counter", the actions are not implemented yet.
This commit is contained in:
parent
234ab54bf7
commit
ca866fe7c5
|
@ -6,6 +6,7 @@ import javacard.framework.ISOException;
|
||||||
|
|
||||||
import sim.toolkit.EnvelopeHandler;
|
import sim.toolkit.EnvelopeHandler;
|
||||||
import sim.toolkit.ProactiveHandler;
|
import sim.toolkit.ProactiveHandler;
|
||||||
|
import sim.toolkit.ProactiveResponseHandler;
|
||||||
import sim.toolkit.ToolkitConstants;
|
import sim.toolkit.ToolkitConstants;
|
||||||
import sim.toolkit.ToolkitException;
|
import sim.toolkit.ToolkitException;
|
||||||
import sim.toolkit.ToolkitInterface;
|
import sim.toolkit.ToolkitInterface;
|
||||||
|
@ -14,48 +15,52 @@ import sim.toolkit.ToolkitRegistry;
|
||||||
public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants {
|
public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants {
|
||||||
// DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM,
|
// DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM,
|
||||||
// which has a limited number of write cycles.
|
// which has a limited number of write cycles.
|
||||||
private byte helloMenuItem;
|
|
||||||
|
|
||||||
|
private byte STKServicesMenuId;
|
||||||
static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' };
|
static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' };
|
||||||
|
|
||||||
|
/* Main menu */
|
||||||
static byte[] title = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm',
|
static byte[] title = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm',
|
||||||
'i', 'z', 'a', 't', 'i', 'o', 'n'};
|
'i', 'z', 'a', 't', 'i', 'o', 'n'};
|
||||||
|
static byte[] showLU = new byte[] {'S', 'h', 'o', 'w', ' ', 'L', 'U', ' ', 'c', 'o', 'u', 'n', 't', 'e', 'r'};
|
||||||
|
static byte[] showIMSI = new byte[] {'S', 'h', 'o', 'w', ' ', 'I', 'M', 'S', 'I'};
|
||||||
|
static byte[] changeIMSI = new byte[] {'C', 'h', 'a', 'n', 'g', 'e', ' ', 'I', 'M', 'S', 'I', ' '};
|
||||||
|
private Object[] itemListMain = {title, showLU, showIMSI, changeIMSI};
|
||||||
|
|
||||||
|
/* Change IMSI menu */
|
||||||
|
static byte[] setDigit1 = new byte[] {'S', 'e', 't', ' ', '1', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ',
|
||||||
|
'd', 'i', 'g', 'i', 't'};
|
||||||
|
static byte[] setDigit2 = new byte[] {'S', 'e', 't', ' ', '2', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ',
|
||||||
|
'd', 'i', 'g', 'i', 't'};
|
||||||
|
private Object[] itemListChangeIMSI = {changeIMSI, setDigit1, setDigit2};
|
||||||
|
|
||||||
private IMSIPseudo() {
|
private IMSIPseudo() {
|
||||||
// This is the interface to the STK applet registry (which is separate
|
/* Register menu and trigger on location updates */
|
||||||
// from the JavaCard applet registry!)
|
|
||||||
ToolkitRegistry reg = ToolkitRegistry.getEntry();
|
ToolkitRegistry reg = ToolkitRegistry.getEntry();
|
||||||
|
STKServicesMenuId = reg.initMenuEntry(title, (short)0, (short)title.length, PRO_CMD_SELECT_ITEM, false,
|
||||||
// Define the applet Menu Entry
|
(byte)0, (short)0);
|
||||||
helloMenuItem = reg.initMenuEntry(title, (short)0, (short)title.length,
|
|
||||||
PRO_CMD_SELECT_ITEM, false, (byte)0, (short)0);
|
|
||||||
reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS);
|
reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is called by the card when the applet is installed. You must
|
|
||||||
// instantiate your applet and register it here.
|
|
||||||
public static void install(byte[] bArray, short bOffset, byte bLength) {
|
public static void install(byte[] bArray, short bOffset, byte bLength) {
|
||||||
IMSIPseudo applet = new IMSIPseudo();
|
IMSIPseudo applet = new IMSIPseudo();
|
||||||
|
|
||||||
applet.register();
|
applet.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This processes APDUs sent directly to the applet. For STK applets, this
|
|
||||||
// interface isn't really used.
|
|
||||||
public void process(APDU arg0) throws ISOException {
|
public void process(APDU arg0) throws ISOException {
|
||||||
// ignore the applet select command dispached to the process
|
|
||||||
if (selectingApplet())
|
if (selectingApplet())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This processes STK events.
|
|
||||||
public void processToolkit(byte event) throws ToolkitException {
|
public void processToolkit(byte event) throws ToolkitException {
|
||||||
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
|
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
|
||||||
|
|
||||||
if (event == EVENT_MENU_SELECTION) {
|
if (event == EVENT_MENU_SELECTION) {
|
||||||
byte selectedItemId = envHdlr.getItemIdentifier();
|
byte selectedItemId = envHdlr.getItemIdentifier();
|
||||||
|
|
||||||
if (selectedItemId == helloMenuItem) {
|
if (selectedItemId == STKServicesMenuId) {
|
||||||
showMsg(LUCounter);
|
showMenu(itemListMain, (byte)4);
|
||||||
|
handleMenuResponseMain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,4 +76,44 @@ public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConst
|
||||||
proHdlr.send();
|
proHdlr.send();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showMenu(Object[] itemList, byte itemCount) {
|
||||||
|
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
|
||||||
|
proHdlr.init((byte) PRO_CMD_SELECT_ITEM,(byte)0,DEV_ID_ME);
|
||||||
|
|
||||||
|
for (byte i=(byte)0;i<itemCount;i++) {
|
||||||
|
if (i == 0) {
|
||||||
|
/* Title */
|
||||||
|
proHdlr.appendTLV((byte)(TAG_ALPHA_IDENTIFIER | TAG_SET_CR), (byte[])itemList[i],
|
||||||
|
(short)0, (short)((byte[])itemList[i]).length);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* Menu entry */
|
||||||
|
proHdlr.appendTLV((byte)(TAG_ITEM | TAG_SET_CR), (byte)i, (byte[])itemList[i], (short)0,
|
||||||
|
(short)((byte[])itemList[i]).length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proHdlr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleMenuResponseMain() {
|
||||||
|
ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler();
|
||||||
|
|
||||||
|
switch (rspHdlr.getItemIdentifier()) {
|
||||||
|
case 1: /* Show LU counter */
|
||||||
|
showMsg(LUCounter);
|
||||||
|
break;
|
||||||
|
case 2: /* Show IMSI */
|
||||||
|
/* TODO */
|
||||||
|
break;
|
||||||
|
case 3: /* Change IMSI */
|
||||||
|
showMenu(itemListChangeIMSI, (byte)3);
|
||||||
|
handleMenuResponseChangeIMSI();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleMenuResponseChangeIMSI() {
|
||||||
|
/* TODO */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue