Revision ca866fe7
Added by osmith over 4 years ago
sim-applet/src/org/osmocom/IMSIPseudo/IMSIPseudo.java | ||
---|---|---|
6 | 6 |
|
7 | 7 |
import sim.toolkit.EnvelopeHandler; |
8 | 8 |
import sim.toolkit.ProactiveHandler; |
9 |
import sim.toolkit.ProactiveResponseHandler; |
|
9 | 10 |
import sim.toolkit.ToolkitConstants; |
10 | 11 |
import sim.toolkit.ToolkitException; |
11 | 12 |
import sim.toolkit.ToolkitInterface; |
... | ... | |
14 | 15 |
public class IMSIPseudo extends Applet implements ToolkitInterface, ToolkitConstants { |
15 | 16 |
// DON'T DECLARE USELESS INSTANCE VARIABLES! They get saved to the EEPROM, |
16 | 17 |
// which has a limited number of write cycles. |
17 |
private byte helloMenuItem; |
|
18 | 18 |
|
19 |
private byte STKServicesMenuId; |
|
19 | 20 |
static byte[] LUCounter = new byte[] { '0', 'x', ' ', 'L', 'U' }; |
21 |
|
|
22 |
/* Main menu */ |
|
20 | 23 |
static byte[] title = new byte[] { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm', |
21 | 24 |
'i', 'z', 'a', 't', 'i', 'o', 'n'}; |
25 |
static byte[] showLU = new byte[] {'S', 'h', 'o', 'w', ' ', 'L', 'U', ' ', 'c', 'o', 'u', 'n', 't', 'e', 'r'}; |
|
26 |
static byte[] showIMSI = new byte[] {'S', 'h', 'o', 'w', ' ', 'I', 'M', 'S', 'I'}; |
|
27 |
static byte[] changeIMSI = new byte[] {'C', 'h', 'a', 'n', 'g', 'e', ' ', 'I', 'M', 'S', 'I', ' '}; |
|
28 |
private Object[] itemListMain = {title, showLU, showIMSI, changeIMSI}; |
|
29 |
|
|
30 |
/* Change IMSI menu */ |
|
31 |
static byte[] setDigit1 = new byte[] {'S', 'e', 't', ' ', '1', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ', |
|
32 |
'd', 'i', 'g', 'i', 't'}; |
|
33 |
static byte[] setDigit2 = new byte[] {'S', 'e', 't', ' ', '2', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ', |
|
34 |
'd', 'i', 'g', 'i', 't'}; |
|
35 |
private Object[] itemListChangeIMSI = {changeIMSI, setDigit1, setDigit2}; |
|
22 | 36 |
|
23 | 37 |
private IMSIPseudo() { |
24 |
// This is the interface to the STK applet registry (which is separate |
|
25 |
// from the JavaCard applet registry!) |
|
38 |
/* Register menu and trigger on location updates */ |
|
26 | 39 |
ToolkitRegistry reg = ToolkitRegistry.getEntry(); |
27 |
|
|
28 |
// Define the applet Menu Entry |
|
29 |
helloMenuItem = reg.initMenuEntry(title, (short)0, (short)title.length, |
|
30 |
PRO_CMD_SELECT_ITEM, false, (byte)0, (short)0); |
|
40 |
STKServicesMenuId = reg.initMenuEntry(title, (short)0, (short)title.length, PRO_CMD_SELECT_ITEM, false, |
|
41 |
(byte)0, (short)0); |
|
31 | 42 |
reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS); |
32 | 43 |
} |
33 | 44 |
|
34 |
// This method is called by the card when the applet is installed. You must |
|
35 |
// instantiate your applet and register it here. |
|
36 | 45 |
public static void install(byte[] bArray, short bOffset, byte bLength) { |
37 | 46 |
IMSIPseudo applet = new IMSIPseudo(); |
38 |
|
|
39 | 47 |
applet.register(); |
40 | 48 |
} |
41 | 49 |
|
42 |
// This processes APDUs sent directly to the applet. For STK applets, this |
|
43 |
// interface isn't really used. |
|
44 | 50 |
public void process(APDU arg0) throws ISOException { |
45 |
// ignore the applet select command dispached to the process |
|
46 | 51 |
if (selectingApplet()) |
47 | 52 |
return; |
48 | 53 |
} |
49 | 54 |
|
50 |
// This processes STK events. |
|
51 | 55 |
public void processToolkit(byte event) throws ToolkitException { |
52 | 56 |
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler(); |
53 | 57 |
|
54 | 58 |
if (event == EVENT_MENU_SELECTION) { |
55 | 59 |
byte selectedItemId = envHdlr.getItemIdentifier(); |
56 | 60 |
|
57 |
if (selectedItemId == helloMenuItem) { |
|
58 |
showMsg(LUCounter); |
|
61 |
if (selectedItemId == STKServicesMenuId) { |
|
62 |
showMenu(itemListMain, (byte)4); |
|
63 |
handleMenuResponseMain(); |
|
59 | 64 |
} |
60 | 65 |
} |
61 | 66 |
|
... | ... | |
71 | 76 |
proHdlr.send(); |
72 | 77 |
return; |
73 | 78 |
} |
79 |
|
|
80 |
private void showMenu(Object[] itemList, byte itemCount) { |
|
81 |
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); |
|
82 |
proHdlr.init((byte) PRO_CMD_SELECT_ITEM,(byte)0,DEV_ID_ME); |
|
83 |
|
|
84 |
for (byte i=(byte)0;i<itemCount;i++) { |
|
85 |
if (i == 0) { |
|
86 |
/* Title */ |
|
87 |
proHdlr.appendTLV((byte)(TAG_ALPHA_IDENTIFIER | TAG_SET_CR), (byte[])itemList[i], |
|
88 |
(short)0, (short)((byte[])itemList[i]).length); |
|
89 |
|
|
90 |
} else { |
|
91 |
/* Menu entry */ |
|
92 |
proHdlr.appendTLV((byte)(TAG_ITEM | TAG_SET_CR), (byte)i, (byte[])itemList[i], (short)0, |
|
93 |
(short)((byte[])itemList[i]).length); |
|
94 |
} |
|
95 |
} |
|
96 |
proHdlr.send(); |
|
97 |
} |
|
98 |
|
|
99 |
private void handleMenuResponseMain() { |
|
100 |
ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler(); |
|
101 |
|
|
102 |
switch (rspHdlr.getItemIdentifier()) { |
|
103 |
case 1: /* Show LU counter */ |
|
104 |
showMsg(LUCounter); |
|
105 |
break; |
|
106 |
case 2: /* Show IMSI */ |
|
107 |
/* TODO */ |
|
108 |
break; |
|
109 |
case 3: /* Change IMSI */ |
|
110 |
showMenu(itemListChangeIMSI, (byte)3); |
|
111 |
handleMenuResponseChangeIMSI(); |
|
112 |
break; |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
private void handleMenuResponseChangeIMSI() { |
|
117 |
/* TODO */ |
|
118 |
} |
|
74 | 119 |
} |
Also available in: Unified diff
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.