blob: 1072ee856f2fb9db140ed741810169729b998c08 [file] [log] [blame]
Harald Welte94e87352021-04-02 13:38:00 +02001pySim-shell
2===========
Harald Weltebe9516f2021-04-03 11:30:10 +02003
4pySim-shell is an interactive command line shell for all kind of interactions with SIM cards.
5
6The interactive shell provides command for
7
8* navigating the on-card filesystem hierarchy
9* authenticating with PINs such as ADM1
10* CHV/PIN management (VERIFY, ENABLE, DISABLE, UNBLOCK)
11* decoding of SELECT response (file control parameters)
12* reading and writing of files and records in raw, hex-encoded binary format
13* for some files where related support has been developed:
14
15 * decoded reading (display file data in JSON format)
16 * decoded writing (encode from JSON to binary format, then write)
17
18By means of using the python ``cmd2`` module, various useful features improve usability:
19
20* history of commands (persistent across restarts)
21* output re-direction to files on your computer
22* output piping through external tools like 'grep'
23* tab completion of commands and SELECT-able files/directories
24* interactive help for all commands
25
26
27cmd2 basics
28-----------
29
30FIXME
31
32
33
34ISO7816 commands
35----------------
36
37This category of commands relates to commands that originate in the ISO 7861-4 specifications,
38most of them have a 1:1 resemblance in the specification.
39
40select
41~~~~~~
42
43The ``select`` command is used to select a file, either by its FID, AID or by its symbolic name.
44
45Try ``select`` with tab-completion to get a list of all current selectable items:
46
47::
48
49 pySIM-shell (MF)> select
50 .. 2fe2 a0000000871004 EF.ARR MF
51 2f00 3f00 ADF.ISIM EF.DIR
52 2f05 7f10 ADF.USIM EF.ICCID
53 2f06 7f20 DF.GSM EF.PL
54 2f08 a0000000871002 DF.TELECOM EF.UMPC
55
56Use ``select`` with a specific FID or name to select the new file.
57
58This will
59
60* output the [JSON decoded, if possible] select response
61* change the prompt to the newly selected file
62* enable any commands specific to the newly-selected file
63
64::
65
66 pySIM-shell (MF)> select ADF.USIM
67 {
68 "file_descriptor": {
69 "shareable": true,
70 "file_type": "df",
71 "structure": "no_info_given"
72 },
73 "df_name": "A0000000871002FFFFFFFF8907090000",
74 "proprietary_info": {
75 "uicc_characteristics": "71",
76 "available_memory": 101640
77 },
78 "life_cycle_status_int": "operational_activated",
79 "security_attrib_compact": "00",
80 "pin_status_template_do": "90017083010183018183010A83010B"
81 }
82 pySIM-shell (MF/ADF.USIM)>
83
84
85
86change_chv
87~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +020088.. argparse::
89 :module: pySim-shell
90 :func: Iso7816Commands.change_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +020091
92
93disable_chv
94~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +020095.. argparse::
96 :module: pySim-shell
97 :func: Iso7816Commands.disable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +020098
Harald Weltebe9516f2021-04-03 11:30:10 +020099
100enable_chv
101~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200102.. argparse::
103 :module: pySim-shell
104 :func: Iso7816Commands.enable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200105
106
107unblock_chv
108~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200109.. argparse::
110 :module: pySim-shell
111 :func: Iso7816Commands.unblock_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200112
Harald Weltebe9516f2021-04-03 11:30:10 +0200113
114verify_chv
115~~~~~~~~~~
Harald Weltebe9516f2021-04-03 11:30:10 +0200116This command allows you to verify a CHV (PIN), which is how the specifications call
117it if you authenticate yourself with the said CHV/PIN.
118
Harald Welted36f6942021-04-04 14:37:55 +0200119.. argparse::
120 :module: pySim-shell
121 :func: Iso7816Commands.verify_chv_parser
122
Harald Weltebe9516f2021-04-03 11:30:10 +0200123
124
125pySim commands
126--------------
127
128Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816
129or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute
130a complex sequence of card-commands.
131
132desc
133~~~~
134
135Display human readable file description for the currently selected file.
136
137
138dir
139~~~
Harald Welted36f6942021-04-04 14:37:55 +0200140.. argparse::
141 :module: pySim-shell
142 :func: PySimCommands.dir_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200143
144
145export
146~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200147.. argparse::
148 :module: pySim-shell
149 :func: PySimCommands.export_parser
150
Harald Weltebe9516f2021-04-03 11:30:10 +0200151
152tree
153~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200154FIXME
155
Harald Weltebe9516f2021-04-03 11:30:10 +0200156
157verify_adm
158~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200159FIXME
Harald Weltebe9516f2021-04-03 11:30:10 +0200160
161
162Linear Fixed EF commands
163------------------------
164
165These commands become enabled only when your currently selected file is of *Linear Fixed EF* type.
166
167read_record
168~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200169.. argparse::
170 :module: pySim.filesystem
171 :func: LinFixedEF.ShellCommands.read_rec_parser
172
Harald Weltebe9516f2021-04-03 11:30:10 +0200173
174read_record_decoded
175~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200176.. argparse::
177 :module: pySim.filesystem
178 :func: LinFixedEF.ShellCommands.read_rec_dec_parser
179
Harald Weltebe9516f2021-04-03 11:30:10 +0200180
Harald Welte850b72a2021-04-07 09:33:03 +0200181read_records
182~~~~~~~~~~~~
183.. argparse::
184 :module: pySim.filesystem
185 :func: LinFixedEF.ShellCommands.read_recs_parser
186
187
188read_records_decoded
189~~~~~~~~~~~~~~~~~~~~
190.. argparse::
191 :module: pySim.filesystem
192 :func: LinFixedEF.ShellCommands.read_recs_dec_parser
193
194
Harald Weltebe9516f2021-04-03 11:30:10 +0200195update_record
196~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200197.. argparse::
198 :module: pySim.filesystem
199 :func: LinFixedEF.ShellCommands.upd_rec_parser
200
Harald Weltebe9516f2021-04-03 11:30:10 +0200201
202update_record_decoded
203~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200204.. argparse::
205 :module: pySim.filesystem
206 :func: LinFixedEF.ShellCommands.upd_rec_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200207
208
Harald Welte4145d3c2021-04-08 20:34:13 +0200209edit_record_decoded
210~~~~~~~~~~~~~~~~~~~
211.. argparse::
212 :module: pySim.filesystem
213 :func: LinFixedEF.ShellCommands.edit_rec_dec_parser
214
215This command will read the selected record, decode it to its JSON representation, save
216that JSON to a temporary file on your computer, and launch your configured text editor.
217
218You may then perform whatever modifications to the JSON representation, save + leave your
219text editor.
220
221Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
222back to the record on the SIM card.
223
224This allows for easy interactive modification of records.
225
226
Harald Weltebe9516f2021-04-03 11:30:10 +0200227
228Transparent EF commands
229-----------------------
230
231These commands become enabled only when your currently selected file is of *Transparent EF* type.
232
233
234read_binary
235~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200236.. argparse::
237 :module: pySim.filesystem
238 :func: TransparentEF.ShellCommands.read_bin_parser
239
Harald Weltebe9516f2021-04-03 11:30:10 +0200240
241read_binary_decoded
242~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200243.. argparse::
244 :module: pySim.filesystem
245 :func: TransparentEF.ShellCommands.read_bin_dec_parser
246
Harald Weltebe9516f2021-04-03 11:30:10 +0200247
248update_binary
249~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200250.. argparse::
251 :module: pySim.filesystem
252 :func: TransparentEF.ShellCommands.upd_bin_parser
253
Harald Weltebe9516f2021-04-03 11:30:10 +0200254
255update_binary_decoded
256~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200257.. argparse::
258 :module: pySim.filesystem
259 :func: TransparentEF.ShellCommands.upd_bin_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200260
Harald Welte0d4e98a2021-04-07 00:14:40 +0200261In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as
262input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific
263parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element
264inside the document as well as a new value for tat field:
265
266Th below example demonstrates this by modifying the ofm field within EF.AD:
267
268::
269
270 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
271 {
272 "ms_operation_mode": "normal",
273 "specific_facilities": {
274 "ofm": true
275 },
276 "len_of_mnc_in_imsi": 2
277 }
278 pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false
279 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
280 {
281 "ms_operation_mode": "normal",
282 "specific_facilities": {
283 "ofm": false
284 },
285 "len_of_mnc_in_imsi": 2
286 }
287
Harald Weltebe9516f2021-04-03 11:30:10 +0200288
Harald Welte4145d3c2021-04-08 20:34:13 +0200289edit_binary_decoded
290~~~~~~~~~~~~~~~~~~~
291This command will read the selected binary EF, decode it to its JSON representation, save
292that JSON to a temporary file on your computer, and launch your configured text editor.
293
294You may then perform whatever modifications to the JSON representation, save + leave your
295text editor.
296
297Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
298to the SIM card.
299
300This allows for easy interactive modification of file contents.
301
Harald Weltebe9516f2021-04-03 11:30:10 +0200302
Harald Welte15fae982021-04-10 10:22:27 +0200303USIM commands
304-------------
305
306authenticate
307~~~~~~~~~~~~
308.. argparse::
309 :module: pySim.ts_31_102
310 :func: ADF_USIM.AddlShellCommands.authenticate_parser
311
312
313
Harald Weltebe9516f2021-04-03 11:30:10 +0200314cmd2 settable parameters
315------------------------
316
317``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level
318shell: They can be read and set, and they will influence the behavior somehow.
319
320conserve_write
321~~~~~~~~~~~~~~
322
323If enabled, pySim will (when asked to write to a card) always first read the respective file/record and
324verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped.
325Writes will only be performed if the new value is different from the current on-card value.
326
327If disabled, pySim will always write irrespective of the current/new value.
328
Harald Welte1748b932021-04-06 21:12:25 +0200329json_pretty_print
330~~~~~~~~~~~~~~~~~
331
332This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line
333output with indent level of 4 spaces) or not.
334
335The default value of this parameter is 'true'.
336
Harald Weltebe9516f2021-04-03 11:30:10 +0200337debug
338~~~~~
339
340If enabled, full python back-traces will be displayed in case of exceptions
341
Harald Welte7829d8a2021-04-10 11:28:53 +0200342apdu_trace
343~~~~~~~~~~
344
345Boolean variable that determines if a hex-dump of the command + response APDU shall be printed.
346
Harald Weltebe9516f2021-04-03 11:30:10 +0200347numeric_path
348~~~~~~~~~~~~
349
350Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names.
351
352::
353
354 pySIM-shell (MF/EF.ICCID)> set numeric_path True
355 numeric_path - was: False
356 now: True
357 pySIM-shell (3f00/2fe2)> set numeric_path False
358 numeric_path - was: True
359 now: False
360 pySIM-shell (MF/EF.ICCID)> help set