blob: 4cdf9e02986943b54311c1ec12736c48fd8ba751 [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
Harald Weltef2e761c2021-04-11 11:56:44 +020026Running pySim-shell
27-------------------
28
29pySim-shell has a variety of command line arguments to control
30
31* which transport to use (how to use a reader to talk to the SIM card)
32* whether to automatically verify an ADM pin (and in which format)
33* whether to execute a start-up script
34
35.. argparse::
36 :module: pySim-shell
37 :func: option_parser
38
39
Harald Weltebe9516f2021-04-03 11:30:10 +020040
41cmd2 basics
42-----------
43
44FIXME
45
46
47
48ISO7816 commands
49----------------
50
51This category of commands relates to commands that originate in the ISO 7861-4 specifications,
52most of them have a 1:1 resemblance in the specification.
53
54select
55~~~~~~
56
57The ``select`` command is used to select a file, either by its FID, AID or by its symbolic name.
58
59Try ``select`` with tab-completion to get a list of all current selectable items:
60
61::
62
63 pySIM-shell (MF)> select
64 .. 2fe2 a0000000871004 EF.ARR MF
65 2f00 3f00 ADF.ISIM EF.DIR
66 2f05 7f10 ADF.USIM EF.ICCID
67 2f06 7f20 DF.GSM EF.PL
68 2f08 a0000000871002 DF.TELECOM EF.UMPC
69
70Use ``select`` with a specific FID or name to select the new file.
71
72This will
73
74* output the [JSON decoded, if possible] select response
75* change the prompt to the newly selected file
76* enable any commands specific to the newly-selected file
77
78::
79
80 pySIM-shell (MF)> select ADF.USIM
81 {
82 "file_descriptor": {
83 "shareable": true,
84 "file_type": "df",
85 "structure": "no_info_given"
86 },
87 "df_name": "A0000000871002FFFFFFFF8907090000",
88 "proprietary_info": {
89 "uicc_characteristics": "71",
90 "available_memory": 101640
91 },
92 "life_cycle_status_int": "operational_activated",
93 "security_attrib_compact": "00",
94 "pin_status_template_do": "90017083010183018183010A83010B"
95 }
96 pySIM-shell (MF/ADF.USIM)>
97
98
99
100change_chv
101~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200102.. argparse::
103 :module: pySim-shell
104 :func: Iso7816Commands.change_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200105
106
107disable_chv
108~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200109.. argparse::
110 :module: pySim-shell
111 :func: Iso7816Commands.disable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200112
Harald Weltebe9516f2021-04-03 11:30:10 +0200113
114enable_chv
115~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200116.. argparse::
117 :module: pySim-shell
118 :func: Iso7816Commands.enable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200119
120
121unblock_chv
122~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200123.. argparse::
124 :module: pySim-shell
125 :func: Iso7816Commands.unblock_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200126
Harald Weltebe9516f2021-04-03 11:30:10 +0200127
128verify_chv
129~~~~~~~~~~
Harald Weltebe9516f2021-04-03 11:30:10 +0200130This command allows you to verify a CHV (PIN), which is how the specifications call
131it if you authenticate yourself with the said CHV/PIN.
132
Harald Welted36f6942021-04-04 14:37:55 +0200133.. argparse::
134 :module: pySim-shell
135 :func: Iso7816Commands.verify_chv_parser
136
Harald Weltea4631612021-04-10 18:17:55 +0200137deactivate_file
138~~~~~~~~~~~~~~~
139Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11.
140
141
142activate_file
143~~~~~~~~~~~~~
144Activate the currently selected file. This used to be called REHABILITATE in TS 11.11.
Harald Weltebe9516f2021-04-03 11:30:10 +0200145
Harald Welte703f9332021-04-10 18:39:32 +0200146open_channel
147~~~~~~~~~~~~
148.. argparse::
149 :module: pySim-shell
150 :func: Iso7816Commands.open_chan_parser
151
152close_channel
153~~~~~~~~~~~~~
154.. argparse::
155 :module: pySim-shell
156 :func: Iso7816Commands.close_chan_parser
157
Harald Weltebe9516f2021-04-03 11:30:10 +0200158
159pySim commands
160--------------
161
162Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816
163or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute
164a complex sequence of card-commands.
165
166desc
167~~~~
168
169Display human readable file description for the currently selected file.
170
171
172dir
173~~~
Harald Welted36f6942021-04-04 14:37:55 +0200174.. argparse::
175 :module: pySim-shell
176 :func: PySimCommands.dir_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200177
178
179export
180~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200181.. argparse::
182 :module: pySim-shell
183 :func: PySimCommands.export_parser
184
Harald Weltebe9516f2021-04-03 11:30:10 +0200185
186tree
187~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200188FIXME
189
Harald Weltebe9516f2021-04-03 11:30:10 +0200190
191verify_adm
192~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200193FIXME
Harald Weltebe9516f2021-04-03 11:30:10 +0200194
195
196Linear Fixed EF commands
197------------------------
198
199These commands become enabled only when your currently selected file is of *Linear Fixed EF* type.
200
201read_record
202~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200203.. argparse::
204 :module: pySim.filesystem
205 :func: LinFixedEF.ShellCommands.read_rec_parser
206
Harald Weltebe9516f2021-04-03 11:30:10 +0200207
208read_record_decoded
209~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200210.. argparse::
211 :module: pySim.filesystem
212 :func: LinFixedEF.ShellCommands.read_rec_dec_parser
213
Harald Weltebe9516f2021-04-03 11:30:10 +0200214
Harald Welte850b72a2021-04-07 09:33:03 +0200215read_records
216~~~~~~~~~~~~
217.. argparse::
218 :module: pySim.filesystem
219 :func: LinFixedEF.ShellCommands.read_recs_parser
220
221
222read_records_decoded
223~~~~~~~~~~~~~~~~~~~~
224.. argparse::
225 :module: pySim.filesystem
226 :func: LinFixedEF.ShellCommands.read_recs_dec_parser
227
228
Harald Weltebe9516f2021-04-03 11:30:10 +0200229update_record
230~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200231.. argparse::
232 :module: pySim.filesystem
233 :func: LinFixedEF.ShellCommands.upd_rec_parser
234
Harald Weltebe9516f2021-04-03 11:30:10 +0200235
236update_record_decoded
237~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200238.. argparse::
239 :module: pySim.filesystem
240 :func: LinFixedEF.ShellCommands.upd_rec_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200241
242
Harald Welte4145d3c2021-04-08 20:34:13 +0200243edit_record_decoded
244~~~~~~~~~~~~~~~~~~~
245.. argparse::
246 :module: pySim.filesystem
247 :func: LinFixedEF.ShellCommands.edit_rec_dec_parser
248
249This command will read the selected record, decode it to its JSON representation, save
250that JSON to a temporary file on your computer, and launch your configured text editor.
251
252You may then perform whatever modifications to the JSON representation, save + leave your
253text editor.
254
255Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
256back to the record on the SIM card.
257
258This allows for easy interactive modification of records.
259
260
Harald Weltebe9516f2021-04-03 11:30:10 +0200261
262Transparent EF commands
263-----------------------
264
265These commands become enabled only when your currently selected file is of *Transparent EF* type.
266
267
268read_binary
269~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200270.. argparse::
271 :module: pySim.filesystem
272 :func: TransparentEF.ShellCommands.read_bin_parser
273
Harald Weltebe9516f2021-04-03 11:30:10 +0200274
275read_binary_decoded
276~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200277.. argparse::
278 :module: pySim.filesystem
279 :func: TransparentEF.ShellCommands.read_bin_dec_parser
280
Harald Weltebe9516f2021-04-03 11:30:10 +0200281
282update_binary
283~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200284.. argparse::
285 :module: pySim.filesystem
286 :func: TransparentEF.ShellCommands.upd_bin_parser
287
Harald Weltebe9516f2021-04-03 11:30:10 +0200288
289update_binary_decoded
290~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200291.. argparse::
292 :module: pySim.filesystem
293 :func: TransparentEF.ShellCommands.upd_bin_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200294
Harald Welte0d4e98a2021-04-07 00:14:40 +0200295In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as
296input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific
297parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element
298inside the document as well as a new value for tat field:
299
300Th below example demonstrates this by modifying the ofm field within EF.AD:
301
302::
303
304 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
305 {
306 "ms_operation_mode": "normal",
307 "specific_facilities": {
308 "ofm": true
309 },
310 "len_of_mnc_in_imsi": 2
311 }
312 pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false
313 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
314 {
315 "ms_operation_mode": "normal",
316 "specific_facilities": {
317 "ofm": false
318 },
319 "len_of_mnc_in_imsi": 2
320 }
321
Harald Weltebe9516f2021-04-03 11:30:10 +0200322
Harald Welte4145d3c2021-04-08 20:34:13 +0200323edit_binary_decoded
324~~~~~~~~~~~~~~~~~~~
325This command will read the selected binary EF, decode it to its JSON representation, save
326that JSON to a temporary file on your computer, and launch your configured text editor.
327
328You may then perform whatever modifications to the JSON representation, save + leave your
329text editor.
330
331Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
332to the SIM card.
333
334This allows for easy interactive modification of file contents.
335
Harald Weltebe9516f2021-04-03 11:30:10 +0200336
Harald Welte15fae982021-04-10 10:22:27 +0200337USIM commands
338-------------
339
340authenticate
341~~~~~~~~~~~~
342.. argparse::
343 :module: pySim.ts_31_102
344 :func: ADF_USIM.AddlShellCommands.authenticate_parser
345
346
347
Harald Weltebe9516f2021-04-03 11:30:10 +0200348cmd2 settable parameters
349------------------------
350
351``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level
352shell: They can be read and set, and they will influence the behavior somehow.
353
354conserve_write
355~~~~~~~~~~~~~~
356
357If enabled, pySim will (when asked to write to a card) always first read the respective file/record and
358verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped.
359Writes will only be performed if the new value is different from the current on-card value.
360
361If disabled, pySim will always write irrespective of the current/new value.
362
Harald Welte1748b932021-04-06 21:12:25 +0200363json_pretty_print
364~~~~~~~~~~~~~~~~~
365
366This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line
367output with indent level of 4 spaces) or not.
368
369The default value of this parameter is 'true'.
370
Harald Weltebe9516f2021-04-03 11:30:10 +0200371debug
372~~~~~
373
374If enabled, full python back-traces will be displayed in case of exceptions
375
Harald Welte7829d8a2021-04-10 11:28:53 +0200376apdu_trace
377~~~~~~~~~~
378
379Boolean variable that determines if a hex-dump of the command + response APDU shall be printed.
380
Harald Weltebe9516f2021-04-03 11:30:10 +0200381numeric_path
382~~~~~~~~~~~~
383
384Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names.
385
386::
387
388 pySIM-shell (MF/EF.ICCID)> set numeric_path True
389 numeric_path - was: False
390 now: True
391 pySIM-shell (3f00/2fe2)> set numeric_path False
392 numeric_path - was: True
393 now: False
394 pySIM-shell (MF/EF.ICCID)> help set