Project

General

Profile

Shadysimpy » History » Version 9

dexter, 09/06/2023 09:47 AM

1 1 zecke
Dieter Spaar has modified the shadysim.py to support the configured OTA mode on the sysmoUSIM-SJS1 (and by extension the SIM Cards issued at 31C3, the following camp and 32C3).
2
3
h2. What is it about
4
5
(U)SIM cards are Java capable and there is the Globalplatform that specifies standards API. SMS can be addressed directly to the SIM card, the SIM card will get events for network selection and others, it can modify call establishment attempts.
6
7
The following will show how to build the example applet and install it on your USIM. If you create plugins please make them available as Free Software and point us to them. If you find interesting Globalplatform APIs or hacks please talk about it.
8
9
h2. What you will need
10
11
* sysmoUSIM-SJS1 card
12
* KIC, KID private keys of the card
13
* PCSC, serial card reader or be able to send SMS to the SIM card
14
* JDK to create Java1.1 bytecode to create/customize SIM Toolkit applets.
15 3 osmith
* Dependency for sim-tools: python-pyscard
16 1 zecke
17
h2. What you can read
18
19
* JavaCard? API specification (​http://www.andresteder.com/static/api/simtoolkitapi/sim/toolkit/package-summary.html)
20
* 3GPP sim.toolkit API (​http://www.etsi.org/deliver/etsi_ts/101400_101499/101476/07.00.00_60/ts_101476v070000p.pdf). Specially setEvent is a good keyword to look at!
21 5 osmith
* 3GPP TS 31.102 Characteristics of the Universal Subscriber Identity Module (USIM) application, describes the file system in 4.7 https://www.etsi.org/deliver/etsi_ts/131100_131199/131102/15.08.00_60/ts_131102v150800p.pdf
22 1 zecke
23
h2. Building an example applet
24
25 9 dexter
* Install a JAVA compiler and ANT first:
26 1 zecke
<pre>
27 9 dexter
$ sudo apt-get install default-jdk ant
28 1 zecke
</pre>
29
30 9 dexter
* Clone hello-stk.git and prepare the build system:
31
<pre>
32
$ git clone https://gitea.osmocom.org/sim-card/hello-stk
33
$ cd hello-stk
34
$ git submodule update --init --recursive
35
</pre>
36
37
* Build example applets by running ANT:
38
<pre>
39
$ ant
40
Buildfile: /home/owner/work/git_master/hello-stk/build.xml
41
42
dist:
43
      [get] Getting: https://github.com/martinpaljak/ant-javacard/releases/latest/download/ant-javacard.jar
44
      [get] To: /home/owner/work/git_master/hello-stk/ant-javacard.jar
45
      [get] https://github.com/martinpaljak/ant-javacard/releases/latest/download/ant-javacard.jar moved to https://github.com/martinpaljak/ant-javacard/releases/download/v23.08.29/ant-javacard.jar
46
      [get] https://github.com/martinpaljak/ant-javacard/releases/download/v23.08.29/ant-javacard.jar moved to https://objects.githubusercontent.com/github-production-release-asset-2e65be/28853876/2cb87380-f21f-45e7-894e-54ca5a3513d0?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230906%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230906T085907Z&X-Amz-Expires=300&X-Amz-Signature=d16ac3b8e6a53831e85ec8315daa51b90f0ccfc09dcfd55d76bd8ff416a0651c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=28853876&response-content-disposition=attachment%3B%20filename%3Dant-javacard.jar&response-content-type=application%2Foctet-stream
47
      [cap] INFO: using JavaCard 3.0.5 SDK in /home/owner/work/git_master/hello-stk/oracle_javacard_sdks/jc305u3_kit with JDK 11
48
      [cap] INFO: targeting JavaCard 2.2.1 SDK in /home/owner/work/git_master/hello-stk/oracle_javacard_sdks/jc221_kit
49
      [cap] INFO: Setting package name to org.toorcamp.HelloSTK
50
      [cap] Building CAP with 1 applet from package org.toorcamp.HelloSTK (AID: D07002CA44)
51
      [cap] org.toorcamp.HelloSTK.HelloSTK D07002CA44900101
52
  [compile] Compiling files from /home/owner/work/git_master/hello-stk/hello-stk
53
  [compile] Compiling 1 source file to /home/owner/work/git_master/hello-stk/build/classes
54
  [compile] /home/owner/work/git_master/hello-stk/hello-stk/src/org/toorcamp/HelloSTK/HelloSTK.java
55
  [convert] [ INFO: ] Converter [v3.0.5]
56
  [convert] [ INFO: ]     Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
57
  [convert]     
58
  [convert]     
59
  [convert] [ INFO: ] conversion completed with 0 errors and 0 warnings.
60
   [verify] Verification passed
61
      [cap] CAP saved to /home/owner/work/git_master/hello-stk/build/HelloSTK.cap
62
      [cap] INFO: using JavaCard 3.0.5 SDK in /home/owner/work/git_master/hello-stk/oracle_javacard_sdks/jc305u3_kit with JDK 11
63
      [cap] INFO: targeting JavaCard 2.2.1 SDK in /home/owner/work/git_master/hello-stk/oracle_javacard_sdks/jc221_kit
64
      [cap] INFO: Setting package name to org.osmocom.IMSIChange
65
      [cap] Building CAP with 1 applet from package org.osmocom.IMSIChange (AID: D07002CA44)
66
      [cap] org.osmocom.IMSIChange.IMSIChange D07002CA44900102
67
  [compile] Compiling files from /home/owner/work/git_master/hello-stk/imsi-change
68
  [compile] Compiling 3 source files to /home/owner/work/git_master/hello-stk/build/classes
69
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/Bytes.java
70
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java
71
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/MobileIdentity.java
72
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java:83: warning: [cast] redundant cast to byte
73
  [compile] 			proHdlr.appendTLV((byte)(TAG_DEFAULT_TEXT), (byte)4, prefillVal, (short)0,
74
  [compile] 			                  ^
75
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java:134: warning: [cast] redundant cast to short
76
  [compile] 		gsmFile.select((short) SIMView.FID_DF_GSM);
77
  [compile] 		               ^
78
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java:135: warning: [cast] redundant cast to short
79
  [compile] 		gsmFile.select((short) SIMView.FID_EF_IMSI);
80
  [compile] 		               ^
81
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java:145: warning: [cast] redundant cast to short
82
  [compile] 		gsmFile.select((short) SIMView.FID_DF_GSM);
83
  [compile] 		               ^
84
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java:146: warning: [cast] redundant cast to short
85
  [compile] 		gsmFile.select((short) SIMView.FID_EF_IMSI);
86
  [compile] 		               ^
87
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/IMSIChange.java:173: warning: [cast] redundant cast to byte
88
  [compile] 		proHdlr.init((byte)PRO_CMD_REFRESH, SIM_REFRESH_SIM_INIT_FULL_FILE_CHANGE, DEV_ID_ME);
89
  [compile] 		             ^
90
  [compile] /home/owner/work/git_master/hello-stk/imsi-change/src/org/osmocom/IMSIChange/MobileIdentity.java:41: warning: [cast] redundant cast to byte
91
  [compile] 			byte nibble = bcd[(byte)nibble_i >> 1];
92
  [compile] 			                  ^
93
  [compile] 7 warnings
94
  [convert] [ INFO: ] Converter [v3.0.5]
95
  [convert] [ INFO: ]     Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
96
  [convert]     
97
  [convert]     
98
  [convert] [ INFO: ] conversion completed with 0 errors and 0 warnings.
99
   [verify] Verification passed
100
      [cap] CAP saved to /home/owner/work/git_master/hello-stk/build/ImsiChange.cap
101
102
BUILD SUCCESSFUL
103
Total time: 7 seconds
104
</pre>
105
106 1 zecke
107
h2. Working with a PC/SC reader
108
109
Make sure you have the KIC1, KIC2, KIC3 and KID1, KID2 and KID3 for your card. If you have a CCC Event card from 31C3 or later you should be set and for the sysmoUSIM-SJS1 be sure to buy the option that includes the ADM1 keys as otherwise no OTA keys will be provided to you (you will have to buy a new batch of cards then).
110
111
<pre>
112
#Clone if you have not done the above
113
git clone git://git.osmocom.org/sim/sim-tools/
114
cd sim-tools/shady-sim
115
116
# Load the applet
117
python shadysim.py --pcsc -l HelloSTK.cap -i HelloSTK.cap \
118
          --enable-sim-toolkit --module-aid d07002ca44900101 \
119
          --instance-aid d07002CA44900101 \
120 2 osmith
          --nonvolatile-memory-required 0100 \
121 1 zecke
          --volatile-memory-for-install 0100 \
122
          --max-menu-entry-text 15 \
123
          --max-menu-entries 05 --kic KIC1 \
124
          --kid KID1
125
126
# Delete it (it takes time)
127
python shadysim.py --pcsc -d d07002CA449001 \
128
          --kic KIC1 \
129
          --kid KID1
130
</pre>
131
132
h2. Working with a SMPP reader
133
134
Instead of directly interacting with the SIM through a PCSC reader the APDU is sent through SMPP. Replace the --pcsc call with --smpp and lines starting with SMPP are printed. These then need to be sent.
135 4 osmith
136
h2. Troubleshooting
137
138
h4. "SW match failed! Expected 9000 and got 6985."
139
140
You have probably tried to flash twice, without deleting the applet.
141 7 osmith
142
h4. "error: Source option 1.3 is no longer supported. Use 6 or later."
143
144
Your openjdk version is too new: support for building the source and target versions required for SIM applets has been dropped. Build with openjdk-8. On debian:
145
<pre>
146
$ export PATH=/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin:$PATH
147
</pre>
148
149
If you have upgraded your debian from 9 to 10, you might already have it installed (check if @/usr/lib/jvm/java-8-openjdk-amd64@ exists). Otherwise, you can add the debian 9 (stretch) related mirrors to your @/etc/apt/sources.list@ (copy the buster entries, but replace buster with stretch). After @apt update@, the openjdk-8 related packages are available for installation.
Add picture from clipboard (Maximum size: 48.8 MB)