blob: 58588a2ccf595553dc5b3f6a6a4e361a2771d34c [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": {
Harald Welte747a9782022-02-13 17:52:28 +010083 "file_descriptor_byte": {
84 "shareable": true,
85 "file_type": "df",
86 "structure": "no_info_given"
87 }
Harald Weltebe9516f2021-04-03 11:30:10 +020088 },
89 "df_name": "A0000000871002FFFFFFFF8907090000",
90 "proprietary_info": {
91 "uicc_characteristics": "71",
92 "available_memory": 101640
93 },
94 "life_cycle_status_int": "operational_activated",
95 "security_attrib_compact": "00",
96 "pin_status_template_do": "90017083010183018183010A83010B"
97 }
98 pySIM-shell (MF/ADF.USIM)>
99
100
101
102change_chv
103~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200104.. argparse::
105 :module: pySim-shell
106 :func: Iso7816Commands.change_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200107
108
109disable_chv
110~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200111.. argparse::
112 :module: pySim-shell
113 :func: Iso7816Commands.disable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200114
Harald Weltebe9516f2021-04-03 11:30:10 +0200115
116enable_chv
117~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200118.. argparse::
119 :module: pySim-shell
120 :func: Iso7816Commands.enable_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200121
122
123unblock_chv
124~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200125.. argparse::
126 :module: pySim-shell
127 :func: Iso7816Commands.unblock_chv_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200128
Harald Weltebe9516f2021-04-03 11:30:10 +0200129
130verify_chv
131~~~~~~~~~~
Harald Weltebe9516f2021-04-03 11:30:10 +0200132This command allows you to verify a CHV (PIN), which is how the specifications call
133it if you authenticate yourself with the said CHV/PIN.
134
Harald Welted36f6942021-04-04 14:37:55 +0200135.. argparse::
136 :module: pySim-shell
137 :func: Iso7816Commands.verify_chv_parser
138
Harald Weltea4631612021-04-10 18:17:55 +0200139deactivate_file
140~~~~~~~~~~~~~~~
141Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11.
142
143
144activate_file
145~~~~~~~~~~~~~
146Activate the currently selected file. This used to be called REHABILITATE in TS 11.11.
Harald Weltebe9516f2021-04-03 11:30:10 +0200147
Harald Welte703f9332021-04-10 18:39:32 +0200148open_channel
149~~~~~~~~~~~~
150.. argparse::
151 :module: pySim-shell
152 :func: Iso7816Commands.open_chan_parser
153
154close_channel
155~~~~~~~~~~~~~
156.. argparse::
157 :module: pySim-shell
158 :func: Iso7816Commands.close_chan_parser
159
Harald Weltebe9516f2021-04-03 11:30:10 +0200160
Harald Welteec950532021-10-20 13:09:00 +0200161suspend_uicc
162~~~~~~~~~~~~
163This command allows you to perform the SUSPEND UICC command on the card. This is a relatively
164recent power-saving addition to the UICC specifications, allowing for suspend/resume while maintaining
165state, as opposed to a full power-off (deactivate) and power-on (activate) of the card.
166
167The pySim command just sends that SUSPEND UICC command and doesn't perform the full related sequence
168including the electrical power down.
169
170.. argparse::
171 :module: pySim-shell
172 :func: Iso7816Commands.suspend_uicc_parser
173
174
Harald Weltebe9516f2021-04-03 11:30:10 +0200175pySim commands
176--------------
177
178Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816
179or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute
180a complex sequence of card-commands.
181
182desc
183~~~~
184
185Display human readable file description for the currently selected file.
186
187
188dir
189~~~
Harald Welted36f6942021-04-04 14:37:55 +0200190.. argparse::
191 :module: pySim-shell
192 :func: PySimCommands.dir_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200193
194
195export
196~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200197.. argparse::
198 :module: pySim-shell
199 :func: PySimCommands.export_parser
200
Harald Weltebd02f842021-10-21 14:40:39 +0200201Please note that `export` works relative to the current working
202directory, so if you are in `MF`, then the export will contain all known
203files on the card. However, if you are in `ADF.ISIM`, only files below
204that ADF will be part of the export.
205
206Furthermore, it is strongly advised to first enter the ADM1 pin
207(`verify_adm`) to maximize the chance of having permission to read
208all/most files.
209
Harald Weltebe9516f2021-04-03 11:30:10 +0200210
211tree
212~~~~
Harald Welte7743c202021-05-03 23:30:11 +0200213
214Display a tree of the card filesystem. It is important to note that this displays a tree
215of files that might potentially exist (based on the card profile). In order to determine if
216a given file really exists on a given card, you have to try to select that file.
Harald Welted36f6942021-04-04 14:37:55 +0200217
Harald Weltebe9516f2021-04-03 11:30:10 +0200218
219verify_adm
220~~~~~~~~~~
Harald Welte7743c202021-05-03 23:30:11 +0200221
222Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order
223to get write/update permissions to most of the files on SIM cards.
224
225Currently only ADM1 is supported.
Harald Weltebe9516f2021-04-03 11:30:10 +0200226
227
Harald Weltedaf2b392021-05-03 23:17:29 +0200228reset
229~~~~~
Harald Weltedaf2b392021-05-03 23:17:29 +0200230Perform card reset and display the card ATR.
231
Harald Weltebd02f842021-10-21 14:40:39 +0200232intro
233~~~~~
234[Re-]Display the introductory banner
235
236
237equip
238~~~~~
239Equip pySim-shell with a card; particularly useful if the program was
240started before a card was present, or after a card has been replaced by
241the user while pySim-shell was kept running.
242
243bulk_script
244~~~~~~~~~~~
245.. argparse::
246 :module: pySim-shell
247 :func: PysimApp.bulk_script_parser
248
249Run a script for bulk-provisioning of multiple cards.
250
251
252echo
253~~~~
254.. argparse::
255 :module: pySim-shell
256 :func: PysimApp.echo_parser
257
258
Harald Weltedaf2b392021-05-03 23:17:29 +0200259
Harald Weltebe9516f2021-04-03 11:30:10 +0200260Linear Fixed EF commands
261------------------------
262
263These commands become enabled only when your currently selected file is of *Linear Fixed EF* type.
264
265read_record
266~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200267.. argparse::
268 :module: pySim.filesystem
269 :func: LinFixedEF.ShellCommands.read_rec_parser
270
Harald Weltebe9516f2021-04-03 11:30:10 +0200271
272read_record_decoded
273~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200274.. argparse::
275 :module: pySim.filesystem
276 :func: LinFixedEF.ShellCommands.read_rec_dec_parser
277
Harald Weltebe9516f2021-04-03 11:30:10 +0200278
Harald Welte850b72a2021-04-07 09:33:03 +0200279read_records
280~~~~~~~~~~~~
281.. argparse::
282 :module: pySim.filesystem
283 :func: LinFixedEF.ShellCommands.read_recs_parser
284
285
286read_records_decoded
287~~~~~~~~~~~~~~~~~~~~
288.. argparse::
289 :module: pySim.filesystem
290 :func: LinFixedEF.ShellCommands.read_recs_dec_parser
291
292
Harald Weltebe9516f2021-04-03 11:30:10 +0200293update_record
294~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200295.. argparse::
296 :module: pySim.filesystem
297 :func: LinFixedEF.ShellCommands.upd_rec_parser
298
Harald Weltebe9516f2021-04-03 11:30:10 +0200299
300update_record_decoded
301~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200302.. argparse::
303 :module: pySim.filesystem
304 :func: LinFixedEF.ShellCommands.upd_rec_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200305
306
Harald Welte4145d3c2021-04-08 20:34:13 +0200307edit_record_decoded
308~~~~~~~~~~~~~~~~~~~
309.. argparse::
310 :module: pySim.filesystem
311 :func: LinFixedEF.ShellCommands.edit_rec_dec_parser
312
313This command will read the selected record, decode it to its JSON representation, save
314that JSON to a temporary file on your computer, and launch your configured text editor.
315
316You may then perform whatever modifications to the JSON representation, save + leave your
317text editor.
318
319Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
320back to the record on the SIM card.
321
322This allows for easy interactive modification of records.
323
324
Harald Weltebe9516f2021-04-03 11:30:10 +0200325
326Transparent EF commands
327-----------------------
328
329These commands become enabled only when your currently selected file is of *Transparent EF* type.
330
331
332read_binary
333~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200334.. argparse::
335 :module: pySim.filesystem
336 :func: TransparentEF.ShellCommands.read_bin_parser
337
Harald Weltebe9516f2021-04-03 11:30:10 +0200338
339read_binary_decoded
340~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200341.. argparse::
342 :module: pySim.filesystem
343 :func: TransparentEF.ShellCommands.read_bin_dec_parser
344
Harald Weltebe9516f2021-04-03 11:30:10 +0200345
346update_binary
347~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200348.. argparse::
349 :module: pySim.filesystem
350 :func: TransparentEF.ShellCommands.upd_bin_parser
351
Harald Weltebe9516f2021-04-03 11:30:10 +0200352
353update_binary_decoded
354~~~~~~~~~~~~~~~~~~~~~
Harald Welted36f6942021-04-04 14:37:55 +0200355.. argparse::
356 :module: pySim.filesystem
357 :func: TransparentEF.ShellCommands.upd_bin_dec_parser
Harald Weltebe9516f2021-04-03 11:30:10 +0200358
Harald Welte0d4e98a2021-04-07 00:14:40 +0200359In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as
360input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific
361parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element
362inside the document as well as a new value for tat field:
363
364Th below example demonstrates this by modifying the ofm field within EF.AD:
365
366::
367
368 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
369 {
370 "ms_operation_mode": "normal",
371 "specific_facilities": {
372 "ofm": true
373 },
374 "len_of_mnc_in_imsi": 2
375 }
376 pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false
377 pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded
378 {
379 "ms_operation_mode": "normal",
380 "specific_facilities": {
381 "ofm": false
382 },
383 "len_of_mnc_in_imsi": 2
384 }
385
Harald Weltebe9516f2021-04-03 11:30:10 +0200386
Harald Welte4145d3c2021-04-08 20:34:13 +0200387edit_binary_decoded
388~~~~~~~~~~~~~~~~~~~
389This command will read the selected binary EF, decode it to its JSON representation, save
390that JSON to a temporary file on your computer, and launch your configured text editor.
391
392You may then perform whatever modifications to the JSON representation, save + leave your
393text editor.
394
395Afterwards, the modified JSON will be re-encoded to the binary format, and the result written
396to the SIM card.
397
398This allows for easy interactive modification of file contents.
399
Harald Weltebe9516f2021-04-03 11:30:10 +0200400
Harald Welte917d98c2021-04-21 11:51:25 +0200401
402BER-TLV EF commands
403-------------------
404
405BER-TLV EFs are files that contain BER-TLV structured data. Every file can contain any number
406of variable-length IEs (DOs). The tag within a BER-TLV EF must be unique within the file.
407
408The commands below become enabled only when your currently selected file is of *BER-TLV EF* type.
409
410retrieve_tags
411~~~~~~~~~~~~~
412
413Retrieve a list of all tags present in the currently selected file.
414
415
416retrieve_data
417~~~~~~~~~~~~~
418.. argparse::
419 :module: pySim.filesystem
420 :func: BerTlvEF.ShellCommands.retrieve_data_parser
421
422
423set_data
424~~~~~~~~
425.. argparse::
426 :module: pySim.filesystem
427 :func: BerTlvEF.ShellCommands.set_data_parser
428
429
430del_data
431~~~~~~~~
432.. argparse::
433 :module: pySim.filesystem
434 :func: BerTlvEF.ShellCommands.del_data_parser
435
436
437
Harald Welte15fae982021-04-10 10:22:27 +0200438USIM commands
439-------------
440
441authenticate
442~~~~~~~~~~~~
443.. argparse::
444 :module: pySim.ts_31_102
445 :func: ADF_USIM.AddlShellCommands.authenticate_parser
446
447
Harald Welte95ce6b12021-10-20 18:40:54 +0200448ARA-M commands
449--------------
450
451The ARA-M commands exist to manage the access rules stored in an ARA-M applet on the card.
452
453ARA-M in the context of SIM cards is primarily used to enable Android UICC Carrier Privileges,
454please see https://source.android.com/devices/tech/config/uicc for more details on the background.
455
456
457aram_get_all
458~~~~~~~~~~~~
459
460Obtain and decode all access rules from the ARA-M applet on the card.
461
462NOTE: if the total size of the access rules exceeds 255 bytes, this command will fail, as
463it doesn't yet implement fragmentation/reassembly on rule retrieval. YMMV
464
465::
466
467 pySIM-shell (MF/ADF.ARA-M)> aram_get_all
468 [
469 {
470 "ResponseAllRefArDO": [
471 {
472 "RefArDO": [
473 {
474 "RefDO": [
475 {
476 "AidRefDO": "ffffffffffff"
477 },
478 {
479 "DevAppIdRefDO": "e46872f28b350b7e1f140de535c2a8d5804f0be3"
480 }
481 ]
482 },
483 {
484 "ArDO": [
485 {
486 "ApduArDO": {
487 "generic_access_rule": "always"
488 }
489 },
490 {
491 "PermArDO": {
492 "permissions": "0000000000000001"
493 }
494 }
495 ]
496 }
497 ]
498 }
499 ]
500 }
501 ]
502
503aram_get_config
504~~~~~~~~~~~~~~~
505Perform Config handshake with ARA-M applet: Tell it our version and retrieve its version.
506
507NOTE: Not supported in all ARA-M implementations.
508
509.. argparse::
510 :module: pySim.ara_m
511 :func: ADF_ARAM.AddlShellCommands.get_config_parser
512
513
514aram_store_ref_ar_do
515~~~~~~~~~~~~~~~~~~~~
516Store a [new] access rule on the ARA-M applet.
517
518.. argparse::
519 :module: pySim.ara_m
520 :func: ADF_ARAM.AddlShellCommands.store_ref_ar_do_parse
521
522For example, to store an Android UICC carrier privilege rule for the SHA1 hash of the certificate used to sign the CoIMS android app of Supreeth Herle (https://github.com/herlesupreeth/CoIMS_Wiki) you can use the following command:
523
524::
525
526 pySIM-shell (MF/ADF.ARA-M)> aram_store_ref_ar_do --aid FFFFFFFFFFFF --device-app-id E46872F28B350B7E1F140DE535C2A8D5804F0BE3 --android-permissions 0000000000000001 --apdu-always
527
528
529aram_delete_all
530~~~~~~~~~~~~~~~
531This command will request deletion of all access rules stored within the
532ARA-M applet. Use it with caution, there is no undo. Any rules later
533intended must be manually inserted again using `aram_store_ref_ar_do`
534
535
Harald Welte15fae982021-04-10 10:22:27 +0200536
Harald Weltebe9516f2021-04-03 11:30:10 +0200537cmd2 settable parameters
538------------------------
539
540``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level
541shell: They can be read and set, and they will influence the behavior somehow.
542
543conserve_write
544~~~~~~~~~~~~~~
545
546If enabled, pySim will (when asked to write to a card) always first read the respective file/record and
547verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped.
548Writes will only be performed if the new value is different from the current on-card value.
549
550If disabled, pySim will always write irrespective of the current/new value.
551
Harald Welte1748b932021-04-06 21:12:25 +0200552json_pretty_print
553~~~~~~~~~~~~~~~~~
554
555This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line
556output with indent level of 4 spaces) or not.
557
558The default value of this parameter is 'true'.
559
Harald Weltebe9516f2021-04-03 11:30:10 +0200560debug
561~~~~~
562
563If enabled, full python back-traces will be displayed in case of exceptions
564
Harald Welte7829d8a2021-04-10 11:28:53 +0200565apdu_trace
566~~~~~~~~~~
567
568Boolean variable that determines if a hex-dump of the command + response APDU shall be printed.
569
Harald Weltebe9516f2021-04-03 11:30:10 +0200570numeric_path
571~~~~~~~~~~~~
572
573Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names.
574
575::
576
577 pySIM-shell (MF/EF.ICCID)> set numeric_path True
578 numeric_path - was: False
579 now: True
580 pySIM-shell (3f00/2fe2)> set numeric_path False
581 numeric_path - was: True
582 now: False
583 pySIM-shell (MF/EF.ICCID)> help set