Harald Welte | 94e8735 | 2021-04-02 13:38:00 +0200 | [diff] [blame] | 1 | pySim-shell |
| 2 | =========== |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 3 | |
| 4 | pySim-shell is an interactive command line shell for all kind of interactions with SIM cards. |
| 5 | |
| 6 | The 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 | |
| 18 | By 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 Welte | f2e761c | 2021-04-11 11:56:44 +0200 | [diff] [blame] | 26 | Running pySim-shell |
| 27 | ------------------- |
| 28 | |
| 29 | pySim-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 |
Harald Welte | f422eb1 | 2023-06-09 11:15:09 +0200 | [diff] [blame^] | 38 | :prog: pySim-shell.py |
Harald Welte | f2e761c | 2021-04-11 11:56:44 +0200 | [diff] [blame] | 39 | |
Merlin Chlosta | 69b69d4 | 2023-05-11 12:59:01 +0200 | [diff] [blame] | 40 | Usage Examples |
| 41 | -------------- |
| 42 | .. toctree:: |
| 43 | :maxdepth: 1 |
| 44 | :caption: Tutorials for pySIM-shell: |
| 45 | |
| 46 | suci-tutorial |
Harald Welte | f2e761c | 2021-04-11 11:56:44 +0200 | [diff] [blame] | 47 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 48 | |
| 49 | cmd2 basics |
| 50 | ----------- |
| 51 | |
| 52 | FIXME |
| 53 | |
| 54 | |
| 55 | |
| 56 | ISO7816 commands |
| 57 | ---------------- |
| 58 | |
| 59 | This category of commands relates to commands that originate in the ISO 7861-4 specifications, |
| 60 | most of them have a 1:1 resemblance in the specification. |
| 61 | |
| 62 | select |
| 63 | ~~~~~~ |
| 64 | |
| 65 | The ``select`` command is used to select a file, either by its FID, AID or by its symbolic name. |
| 66 | |
| 67 | Try ``select`` with tab-completion to get a list of all current selectable items: |
| 68 | |
| 69 | :: |
| 70 | |
| 71 | pySIM-shell (MF)> select |
| 72 | .. 2fe2 a0000000871004 EF.ARR MF |
| 73 | 2f00 3f00 ADF.ISIM EF.DIR |
| 74 | 2f05 7f10 ADF.USIM EF.ICCID |
| 75 | 2f06 7f20 DF.GSM EF.PL |
| 76 | 2f08 a0000000871002 DF.TELECOM EF.UMPC |
| 77 | |
| 78 | Use ``select`` with a specific FID or name to select the new file. |
| 79 | |
| 80 | This will |
| 81 | |
| 82 | * output the [JSON decoded, if possible] select response |
| 83 | * change the prompt to the newly selected file |
| 84 | * enable any commands specific to the newly-selected file |
| 85 | |
| 86 | :: |
| 87 | |
| 88 | pySIM-shell (MF)> select ADF.USIM |
| 89 | { |
| 90 | "file_descriptor": { |
Harald Welte | 747a978 | 2022-02-13 17:52:28 +0100 | [diff] [blame] | 91 | "file_descriptor_byte": { |
| 92 | "shareable": true, |
| 93 | "file_type": "df", |
| 94 | "structure": "no_info_given" |
| 95 | } |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 96 | }, |
| 97 | "df_name": "A0000000871002FFFFFFFF8907090000", |
| 98 | "proprietary_info": { |
| 99 | "uicc_characteristics": "71", |
| 100 | "available_memory": 101640 |
| 101 | }, |
| 102 | "life_cycle_status_int": "operational_activated", |
| 103 | "security_attrib_compact": "00", |
| 104 | "pin_status_template_do": "90017083010183018183010A83010B" |
| 105 | } |
| 106 | pySIM-shell (MF/ADF.USIM)> |
| 107 | |
| 108 | |
Harald Welte | d01bd36 | 2022-02-15 15:56:48 +0100 | [diff] [blame] | 109 | status |
| 110 | ~~~~~~ |
| 111 | |
| 112 | The ``status`` command [re-]obtains the File Control Template of the |
| 113 | currently-selected file and print its decoded output. |
| 114 | |
| 115 | Example: |
| 116 | |
| 117 | :: |
| 118 | |
| 119 | pySIM-shell (MF/ADF.ISIM)> status |
| 120 | { |
| 121 | "file_descriptor": { |
| 122 | "file_descriptor_byte": { |
| 123 | "shareable": true, |
| 124 | "file_type": "df", |
| 125 | "structure": "no_info_given" |
| 126 | }, |
| 127 | "record_len": null, |
| 128 | "num_of_rec": null |
| 129 | }, |
| 130 | "file_identifier": "ff01", |
| 131 | "df_name": "a0000000871004ffffffff8907090000", |
| 132 | "proprietary_information": { |
| 133 | "uicc_characteristics": "71", |
| 134 | "available_memory": 101640 |
| 135 | }, |
| 136 | "life_cycle_status_integer": "operational_activated", |
| 137 | "security_attrib_compact": "00", |
| 138 | "pin_status_template_do": { |
| 139 | "ps_do": "70", |
| 140 | "key_reference": 11 |
| 141 | } |
| 142 | } |
| 143 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 144 | |
| 145 | change_chv |
| 146 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 147 | .. argparse:: |
| 148 | :module: pySim-shell |
| 149 | :func: Iso7816Commands.change_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 150 | |
| 151 | |
| 152 | disable_chv |
| 153 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 154 | .. argparse:: |
| 155 | :module: pySim-shell |
| 156 | :func: Iso7816Commands.disable_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 157 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 158 | |
| 159 | enable_chv |
| 160 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 161 | .. argparse:: |
| 162 | :module: pySim-shell |
| 163 | :func: Iso7816Commands.enable_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 164 | |
| 165 | |
| 166 | unblock_chv |
| 167 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 168 | .. argparse:: |
| 169 | :module: pySim-shell |
| 170 | :func: Iso7816Commands.unblock_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 171 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 172 | |
| 173 | verify_chv |
| 174 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 175 | .. argparse:: |
| 176 | :module: pySim-shell |
| 177 | :func: Iso7816Commands.verify_chv_parser |
| 178 | |
Harald Welte | a463161 | 2021-04-10 18:17:55 +0200 | [diff] [blame] | 179 | deactivate_file |
| 180 | ~~~~~~~~~~~~~~~ |
| 181 | Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11. |
| 182 | |
| 183 | |
| 184 | activate_file |
| 185 | ~~~~~~~~~~~~~ |
Harald Welte | 799c354 | 2022-02-15 15:56:28 +0100 | [diff] [blame] | 186 | .. argparse:: |
| 187 | :module: pySim-shell |
| 188 | :func: Iso7816Commands.activate_file_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 189 | |
Harald Welte | 703f933 | 2021-04-10 18:39:32 +0200 | [diff] [blame] | 190 | open_channel |
| 191 | ~~~~~~~~~~~~ |
| 192 | .. argparse:: |
| 193 | :module: pySim-shell |
| 194 | :func: Iso7816Commands.open_chan_parser |
| 195 | |
| 196 | close_channel |
| 197 | ~~~~~~~~~~~~~ |
| 198 | .. argparse:: |
| 199 | :module: pySim-shell |
| 200 | :func: Iso7816Commands.close_chan_parser |
| 201 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 202 | |
Harald Welte | 659781c | 2023-06-06 17:00:51 +0200 | [diff] [blame] | 203 | TS 102 221 commands |
| 204 | ------------------- |
| 205 | |
| 206 | These are commands as specified in ETSI TS 102 221, the core UICC specification. |
| 207 | |
Harald Welte | ec95053 | 2021-10-20 13:09:00 +0200 | [diff] [blame] | 208 | suspend_uicc |
| 209 | ~~~~~~~~~~~~ |
| 210 | This command allows you to perform the SUSPEND UICC command on the card. This is a relatively |
| 211 | recent power-saving addition to the UICC specifications, allowing for suspend/resume while maintaining |
| 212 | state, as opposed to a full power-off (deactivate) and power-on (activate) of the card. |
| 213 | |
| 214 | The pySim command just sends that SUSPEND UICC command and doesn't perform the full related sequence |
| 215 | including the electrical power down. |
| 216 | |
| 217 | .. argparse:: |
Harald Welte | 659781c | 2023-06-06 17:00:51 +0200 | [diff] [blame] | 218 | :module: pySim.ts_102_221 |
| 219 | :func: CardProfileUICC.AddlShellCommands.suspend_uicc_parser |
Harald Welte | ec95053 | 2021-10-20 13:09:00 +0200 | [diff] [blame] | 220 | |
Harald Welte | b0e0dce | 2023-06-06 17:21:13 +0200 | [diff] [blame] | 221 | resume_uicc |
| 222 | ~~~~~~~~~~~ |
| 223 | This command allows you to perform the SUSPEND UICC command for the RESUME operation on the card. |
| 224 | |
| 225 | Suspend/Resume is a relatively recent power-saving addition to the UICC specifications, allowing for |
| 226 | suspend/resume while maintaining state, as opposed to a full power-off (deactivate) and power-on |
| 227 | (activate) of the card. |
| 228 | |
| 229 | The pySim command just sends that SUSPEND UICC (RESUME) command and doesn't perform the full related |
| 230 | sequence including the electrical power down. |
| 231 | |
| 232 | .. argparse:: |
| 233 | :module: pySim.ts_102_221 |
| 234 | :func: CardProfileUICC.AddlShellCommands.resume_uicc_parser |
Harald Welte | ec95053 | 2021-10-20 13:09:00 +0200 | [diff] [blame] | 235 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 236 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 237 | pySim commands |
| 238 | -------------- |
| 239 | |
| 240 | Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816 |
| 241 | or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute |
| 242 | a complex sequence of card-commands. |
| 243 | |
| 244 | desc |
| 245 | ~~~~ |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 246 | Display human readable file description for the currently selected file. |
| 247 | |
| 248 | |
| 249 | dir |
| 250 | ~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 251 | .. argparse:: |
| 252 | :module: pySim-shell |
| 253 | :func: PySimCommands.dir_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 254 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 255 | Example: |
| 256 | :: |
| 257 | |
| 258 | pySIM-shell (MF)> dir |
| 259 | MF |
| 260 | 3f00 |
| 261 | .. ADF.USIM DF.SYSTEM EF.DIR EF.UMPC |
| 262 | ADF.ARA-M DF.EIRENE DF.TELECOM EF.ICCID MF |
| 263 | ADF.ISIM DF.GSM EF.ARR EF.PL |
| 264 | 14 files |
| 265 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 266 | |
| 267 | export |
| 268 | ~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 269 | .. argparse:: |
| 270 | :module: pySim-shell |
| 271 | :func: PySimCommands.export_parser |
| 272 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 273 | Please note that `export` works relative to the current working |
| 274 | directory, so if you are in `MF`, then the export will contain all known |
| 275 | files on the card. However, if you are in `ADF.ISIM`, only files below |
| 276 | that ADF will be part of the export. |
| 277 | |
| 278 | Furthermore, it is strongly advised to first enter the ADM1 pin |
| 279 | (`verify_adm`) to maximize the chance of having permission to read |
| 280 | all/most files. |
| 281 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 282 | |
| 283 | tree |
| 284 | ~~~~ |
Harald Welte | 7743c20 | 2021-05-03 23:30:11 +0200 | [diff] [blame] | 285 | Display a tree of the card filesystem. It is important to note that this displays a tree |
| 286 | of files that might potentially exist (based on the card profile). In order to determine if |
| 287 | a given file really exists on a given card, you have to try to select that file. |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 288 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 289 | Example: |
| 290 | :: |
| 291 | |
| 292 | pySIM-shell (MF)> tree --help |
| 293 | EF.DIR 2f00 Application Directory |
| 294 | EF.ICCID 2fe2 ICC Identification |
| 295 | EF.PL 2f05 Preferred Languages |
| 296 | EF.ARR 2f06 Access Rule Reference |
| 297 | EF.UMPC 2f08 UICC Maximum Power Consumption |
| 298 | DF.TELECOM 7f10 None |
| 299 | EF.ADN 6f3a Abbreviated Dialing Numbers |
| 300 | ... |
| 301 | |
| 302 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 303 | |
| 304 | verify_adm |
| 305 | ~~~~~~~~~~ |
Harald Welte | 7743c20 | 2021-05-03 23:30:11 +0200 | [diff] [blame] | 306 | Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order |
| 307 | to get write/update permissions to most of the files on SIM cards. |
| 308 | |
| 309 | Currently only ADM1 is supported. |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 310 | |
| 311 | |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 312 | reset |
| 313 | ~~~~~ |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 314 | Perform card reset and display the card ATR. |
| 315 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 316 | intro |
| 317 | ~~~~~ |
| 318 | [Re-]Display the introductory banner |
| 319 | |
| 320 | |
| 321 | equip |
| 322 | ~~~~~ |
| 323 | Equip pySim-shell with a card; particularly useful if the program was |
| 324 | started before a card was present, or after a card has been replaced by |
| 325 | the user while pySim-shell was kept running. |
| 326 | |
| 327 | bulk_script |
| 328 | ~~~~~~~~~~~ |
| 329 | .. argparse:: |
| 330 | :module: pySim-shell |
| 331 | :func: PysimApp.bulk_script_parser |
| 332 | |
Harald Welte | bd02f84 | 2021-10-21 14:40:39 +0200 | [diff] [blame] | 333 | |
| 334 | echo |
| 335 | ~~~~ |
| 336 | .. argparse:: |
| 337 | :module: pySim-shell |
| 338 | :func: PysimApp.echo_parser |
| 339 | |
| 340 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 341 | apdu |
| 342 | ~~~~ |
| 343 | .. argparse:: |
| 344 | :module: pySim-shell |
| 345 | :func: PySimCommands.apdu_cmd_parser |
| 346 | |
| 347 | |
Harald Welte | daf2b39 | 2021-05-03 23:17:29 +0200 | [diff] [blame] | 348 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 349 | Linear Fixed EF commands |
| 350 | ------------------------ |
| 351 | |
| 352 | These commands become enabled only when your currently selected file is of *Linear Fixed EF* type. |
| 353 | |
| 354 | read_record |
| 355 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 356 | .. argparse:: |
| 357 | :module: pySim.filesystem |
| 358 | :func: LinFixedEF.ShellCommands.read_rec_parser |
| 359 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 360 | |
| 361 | read_record_decoded |
| 362 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 363 | .. argparse:: |
| 364 | :module: pySim.filesystem |
| 365 | :func: LinFixedEF.ShellCommands.read_rec_dec_parser |
| 366 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 367 | |
Harald Welte | 850b72a | 2021-04-07 09:33:03 +0200 | [diff] [blame] | 368 | read_records |
| 369 | ~~~~~~~~~~~~ |
| 370 | .. argparse:: |
| 371 | :module: pySim.filesystem |
| 372 | :func: LinFixedEF.ShellCommands.read_recs_parser |
| 373 | |
| 374 | |
| 375 | read_records_decoded |
| 376 | ~~~~~~~~~~~~~~~~~~~~ |
| 377 | .. argparse:: |
| 378 | :module: pySim.filesystem |
| 379 | :func: LinFixedEF.ShellCommands.read_recs_dec_parser |
| 380 | |
| 381 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 382 | update_record |
| 383 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 384 | .. argparse:: |
| 385 | :module: pySim.filesystem |
| 386 | :func: LinFixedEF.ShellCommands.upd_rec_parser |
| 387 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 388 | |
| 389 | update_record_decoded |
| 390 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 391 | .. argparse:: |
| 392 | :module: pySim.filesystem |
| 393 | :func: LinFixedEF.ShellCommands.upd_rec_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 394 | |
| 395 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 396 | edit_record_decoded |
| 397 | ~~~~~~~~~~~~~~~~~~~ |
| 398 | .. argparse:: |
| 399 | :module: pySim.filesystem |
| 400 | :func: LinFixedEF.ShellCommands.edit_rec_dec_parser |
| 401 | |
| 402 | This command will read the selected record, decode it to its JSON representation, save |
| 403 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 404 | |
| 405 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 406 | text editor. |
| 407 | |
| 408 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 409 | back to the record on the SIM card. |
| 410 | |
| 411 | This allows for easy interactive modification of records. |
| 412 | |
| 413 | |
Harald Welte | aefd064 | 2022-02-25 15:26:37 +0100 | [diff] [blame] | 414 | decode_hex |
| 415 | ~~~~~~~~~~ |
| 416 | .. argparse:: |
| 417 | :module: pySim.filesystem |
| 418 | :func: LinFixedEF.ShellCommands.dec_hex_parser |
| 419 | |
| 420 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 421 | |
| 422 | Transparent EF commands |
| 423 | ----------------------- |
| 424 | |
| 425 | These commands become enabled only when your currently selected file is of *Transparent EF* type. |
| 426 | |
| 427 | |
| 428 | read_binary |
| 429 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 430 | .. argparse:: |
| 431 | :module: pySim.filesystem |
| 432 | :func: TransparentEF.ShellCommands.read_bin_parser |
| 433 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 434 | |
| 435 | read_binary_decoded |
| 436 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 437 | .. argparse:: |
| 438 | :module: pySim.filesystem |
| 439 | :func: TransparentEF.ShellCommands.read_bin_dec_parser |
| 440 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 441 | |
| 442 | update_binary |
| 443 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 444 | .. argparse:: |
| 445 | :module: pySim.filesystem |
| 446 | :func: TransparentEF.ShellCommands.upd_bin_parser |
| 447 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 448 | |
| 449 | update_binary_decoded |
| 450 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 451 | .. argparse:: |
| 452 | :module: pySim.filesystem |
| 453 | :func: TransparentEF.ShellCommands.upd_bin_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 454 | |
Harald Welte | 0d4e98a | 2021-04-07 00:14:40 +0200 | [diff] [blame] | 455 | In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as |
| 456 | input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific |
| 457 | parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element |
| 458 | inside the document as well as a new value for tat field: |
| 459 | |
| 460 | Th below example demonstrates this by modifying the ofm field within EF.AD: |
| 461 | |
| 462 | :: |
| 463 | |
| 464 | pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded |
| 465 | { |
| 466 | "ms_operation_mode": "normal", |
| 467 | "specific_facilities": { |
| 468 | "ofm": true |
| 469 | }, |
| 470 | "len_of_mnc_in_imsi": 2 |
| 471 | } |
| 472 | pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false |
| 473 | pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded |
| 474 | { |
| 475 | "ms_operation_mode": "normal", |
| 476 | "specific_facilities": { |
| 477 | "ofm": false |
| 478 | }, |
| 479 | "len_of_mnc_in_imsi": 2 |
| 480 | } |
| 481 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 482 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 483 | edit_binary_decoded |
| 484 | ~~~~~~~~~~~~~~~~~~~ |
| 485 | This command will read the selected binary EF, decode it to its JSON representation, save |
| 486 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 487 | |
| 488 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 489 | text editor. |
| 490 | |
| 491 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 492 | to the SIM card. |
| 493 | |
| 494 | This allows for easy interactive modification of file contents. |
| 495 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 496 | |
Harald Welte | aefd064 | 2022-02-25 15:26:37 +0100 | [diff] [blame] | 497 | decode_hex |
| 498 | ~~~~~~~~~~ |
| 499 | .. argparse:: |
| 500 | :module: pySim.filesystem |
| 501 | :func: TransparentEF.ShellCommands.dec_hex_parser |
| 502 | |
| 503 | |
Harald Welte | 917d98c | 2021-04-21 11:51:25 +0200 | [diff] [blame] | 504 | |
| 505 | BER-TLV EF commands |
| 506 | ------------------- |
| 507 | |
| 508 | BER-TLV EFs are files that contain BER-TLV structured data. Every file can contain any number |
| 509 | of variable-length IEs (DOs). The tag within a BER-TLV EF must be unique within the file. |
| 510 | |
| 511 | The commands below become enabled only when your currently selected file is of *BER-TLV EF* type. |
| 512 | |
| 513 | retrieve_tags |
| 514 | ~~~~~~~~~~~~~ |
| 515 | |
| 516 | Retrieve a list of all tags present in the currently selected file. |
| 517 | |
| 518 | |
| 519 | retrieve_data |
| 520 | ~~~~~~~~~~~~~ |
| 521 | .. argparse:: |
| 522 | :module: pySim.filesystem |
| 523 | :func: BerTlvEF.ShellCommands.retrieve_data_parser |
| 524 | |
| 525 | |
| 526 | set_data |
| 527 | ~~~~~~~~ |
| 528 | .. argparse:: |
| 529 | :module: pySim.filesystem |
| 530 | :func: BerTlvEF.ShellCommands.set_data_parser |
| 531 | |
| 532 | |
| 533 | del_data |
| 534 | ~~~~~~~~ |
| 535 | .. argparse:: |
| 536 | :module: pySim.filesystem |
| 537 | :func: BerTlvEF.ShellCommands.del_data_parser |
| 538 | |
| 539 | |
| 540 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 541 | USIM commands |
| 542 | ------------- |
| 543 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 544 | These commands are available only while ADF.USIM (or ADF.ISIM, respectively) is selected. |
| 545 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 546 | authenticate |
| 547 | ~~~~~~~~~~~~ |
| 548 | .. argparse:: |
| 549 | :module: pySim.ts_31_102 |
| 550 | :func: ADF_USIM.AddlShellCommands.authenticate_parser |
| 551 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 552 | terminal_profile |
| 553 | ~~~~~~~~~~~~~~~~ |
| 554 | .. argparse:: |
| 555 | :module: pySim.ts_31_102 |
| 556 | :func: ADF_USIM.AddlShellCommands.term_prof_parser |
| 557 | |
| 558 | envelope |
| 559 | ~~~~~~~~ |
| 560 | .. argparse:: |
| 561 | :module: pySim.ts_31_102 |
| 562 | :func: ADF_USIM.AddlShellCommands.envelope_parser |
| 563 | |
| 564 | envelope_sms |
| 565 | ~~~~~~~~~~~~ |
| 566 | .. argparse:: |
| 567 | :module: pySim.ts_31_102 |
| 568 | :func: ADF_USIM.AddlShellCommands.envelope_sms_parser |
| 569 | |
Harald Welte | 7ec8223 | 2023-06-06 18:15:52 +0200 | [diff] [blame] | 570 | get_identity |
| 571 | ~~~~~~~~~~~~ |
| 572 | .. argparse:: |
| 573 | :module: pySim.ts_31_102 |
| 574 | :func: ADF_USIM.AddlShellCommands.get_id_parser |
| 575 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 576 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 577 | File-specific commands |
| 578 | ---------------------- |
| 579 | |
| 580 | These commands are valid only if the respective file is currently selected. They perform some |
| 581 | operation that's specific to this file only. |
| 582 | |
| 583 | EF.ARR: read_arr_record |
| 584 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 585 | Read one EF.ARR record in flattened, human-friendly form. |
| 586 | |
| 587 | EF.ARR: read_arr_records |
| 588 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 589 | Read + decode all EF.ARR records in flattened, human-friendly form. |
| 590 | |
Harald Welte | c224b3b | 2023-05-23 18:44:44 +0200 | [diff] [blame] | 591 | DF.GSM/EF.SST: sst_service_allocate |
| 592 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 593 | Mark a given single service as allocated in EF.SST. Requires service number as argument. |
| 594 | |
| 595 | DF.GSM/EF.SST: sst_service_activate |
| 596 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 597 | Mark a given single service as activated in EF.SST. Requires service number as argument. |
| 598 | |
| 599 | DF.GSM/EF.SST: sst_service_deallocate |
| 600 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 601 | Mark a given single service as deallocated in EF.SST. Requires service number as argument. |
| 602 | |
| 603 | DF.GSM/EF.SST: sst_service_deactivate |
| 604 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 605 | Mark a given single service as deactivated in EF.SST. Requires service number as argument. |
| 606 | |
Harald Welte | a07d509 | 2023-02-23 10:02:49 +0100 | [diff] [blame] | 607 | ADF.USIM/EF.EST: est_service_enable |
| 608 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 609 | Enables a single service in EF.EST. Requires service number as argument. |
| 610 | |
| 611 | ADF.USIM/EF.EST: est_service_disable |
| 612 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 613 | Disables a single service in EF.EST. Requires service number as argument. |
| 614 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 615 | EF.IMSI: update_imsi_plmn |
| 616 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 617 | Change the PLMN part (MCC+MNC) of the IMSI. Requires a single argument consisting of 5/6 digits of |
| 618 | concatenated MCC+MNC. |
| 619 | |
| 620 | ADF.USIM/EF.UST: ust_service_activate |
| 621 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 622 | Activates a single service in EF.UST. Requires service number as argument. |
| 623 | |
| 624 | ADF.USIM/EF.UST: ust_service_deactivate |
| 625 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 626 | Deactivates a single service in EF.UST. Requires service number as argument. |
| 627 | |
| 628 | ADF.USIM/EF.UST: ust_service_check |
| 629 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 630 | Check consistency between services of this file and files present/activated. |
| 631 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 632 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 633 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 634 | messages are printed for every inconsistency found. |
| 635 | |
| 636 | ADF.ISIM/EF.IST: ist_service_activate |
| 637 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 638 | Activates a single service in EF.IST. Requires service number as argument. |
| 639 | |
| 640 | ADF.ISIM/EF.IST: ist_service_deactivate |
| 641 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 642 | Deactivates a single service in EF.UST. Requires service number as argument. |
| 643 | |
| 644 | ADF.ISIM/EF.IST: ist_service_check |
| 645 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 646 | Check consistency between services of this file and files present/activated. |
| 647 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 648 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 649 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 650 | messages are printed for every inconsistency found. |
| 651 | |
| 652 | |
| 653 | UICC Administrative commands |
| 654 | ---------------------------- |
| 655 | |
| 656 | ETSI TS 102 222 specifies a set of *Administrative Commands*, which can |
| 657 | be used by the card issuer / operator to modify the file system structure |
| 658 | (delete files, create files) or even to terminate individual files or the |
| 659 | entire card. |
| 660 | |
| 661 | pySim-shell supports those commands, but **use extreme caution**. |
| 662 | Unless you know exactly what you're doing, it's very easy to render your |
| 663 | card unusable. You've been warned! |
| 664 | |
| 665 | delete_file |
| 666 | ~~~~~~~~~~~ |
| 667 | .. argparse:: |
| 668 | :module: pySim.ts_102_222 |
| 669 | :func: Ts102222Commands.delfile_parser |
| 670 | |
| 671 | |
| 672 | terminate_df |
| 673 | ~~~~~~~~~~~~ |
| 674 | .. argparse:: |
| 675 | :module: pySim.ts_102_222 |
| 676 | :func: Ts102222Commands.termdf_parser |
| 677 | |
| 678 | terminate_ef |
| 679 | ~~~~~~~~~~~~ |
| 680 | .. argparse:: |
| 681 | :module: pySim.ts_102_222 |
| 682 | :func: Ts102222Commands.termdf_parser |
| 683 | |
| 684 | terminate_card |
| 685 | ~~~~~~~~~~~~~~ |
| 686 | .. argparse:: |
| 687 | :module: pySim.ts_102_222 |
| 688 | :func: Ts102222Commands.tcard_parser |
| 689 | |
| 690 | create_ef |
| 691 | ~~~~~~~~~ |
| 692 | .. argparse:: |
| 693 | :module: pySim.ts_102_222 |
| 694 | :func: Ts102222Commands.create_parser |
| 695 | |
| 696 | create_df |
| 697 | ~~~~~~~~~ |
| 698 | .. argparse:: |
| 699 | :module: pySim.ts_102_222 |
| 700 | :func: Ts102222Commands.createdf_parser |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 701 | |
Harald Welte | 0707b80 | 2023-03-07 11:43:37 +0100 | [diff] [blame] | 702 | resize_ef |
| 703 | ~~~~~~~~~ |
| 704 | .. argparse:: |
| 705 | :module: pySim.ts_102_222 |
| 706 | :func: Ts102222Commands.resize_ef_parser |
| 707 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 708 | |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 709 | ARA-M commands |
| 710 | -------------- |
| 711 | |
| 712 | The ARA-M commands exist to manage the access rules stored in an ARA-M applet on the card. |
| 713 | |
| 714 | ARA-M in the context of SIM cards is primarily used to enable Android UICC Carrier Privileges, |
| 715 | please see https://source.android.com/devices/tech/config/uicc for more details on the background. |
| 716 | |
| 717 | |
| 718 | aram_get_all |
| 719 | ~~~~~~~~~~~~ |
| 720 | |
| 721 | Obtain and decode all access rules from the ARA-M applet on the card. |
| 722 | |
| 723 | NOTE: if the total size of the access rules exceeds 255 bytes, this command will fail, as |
| 724 | it doesn't yet implement fragmentation/reassembly on rule retrieval. YMMV |
| 725 | |
| 726 | :: |
| 727 | |
| 728 | pySIM-shell (MF/ADF.ARA-M)> aram_get_all |
| 729 | [ |
| 730 | { |
| 731 | "ResponseAllRefArDO": [ |
| 732 | { |
| 733 | "RefArDO": [ |
| 734 | { |
| 735 | "RefDO": [ |
| 736 | { |
| 737 | "AidRefDO": "ffffffffffff" |
| 738 | }, |
| 739 | { |
| 740 | "DevAppIdRefDO": "e46872f28b350b7e1f140de535c2a8d5804f0be3" |
| 741 | } |
| 742 | ] |
| 743 | }, |
| 744 | { |
| 745 | "ArDO": [ |
| 746 | { |
| 747 | "ApduArDO": { |
| 748 | "generic_access_rule": "always" |
| 749 | } |
| 750 | }, |
| 751 | { |
| 752 | "PermArDO": { |
| 753 | "permissions": "0000000000000001" |
| 754 | } |
| 755 | } |
| 756 | ] |
| 757 | } |
| 758 | ] |
| 759 | } |
| 760 | ] |
| 761 | } |
| 762 | ] |
| 763 | |
| 764 | aram_get_config |
| 765 | ~~~~~~~~~~~~~~~ |
| 766 | Perform Config handshake with ARA-M applet: Tell it our version and retrieve its version. |
| 767 | |
| 768 | NOTE: Not supported in all ARA-M implementations. |
| 769 | |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 770 | |
| 771 | aram_store_ref_ar_do |
| 772 | ~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 773 | .. argparse:: |
| 774 | :module: pySim.ara_m |
| 775 | :func: ADF_ARAM.AddlShellCommands.store_ref_ar_do_parse |
| 776 | |
| 777 | For 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: |
Harald Welte | 95ce6b1 | 2021-10-20 18:40:54 +0200 | [diff] [blame] | 778 | :: |
| 779 | |
| 780 | pySIM-shell (MF/ADF.ARA-M)> aram_store_ref_ar_do --aid FFFFFFFFFFFF --device-app-id E46872F28B350B7E1F140DE535C2A8D5804F0BE3 --android-permissions 0000000000000001 --apdu-always |
| 781 | |
| 782 | |
| 783 | aram_delete_all |
| 784 | ~~~~~~~~~~~~~~~ |
| 785 | This command will request deletion of all access rules stored within the |
| 786 | ARA-M applet. Use it with caution, there is no undo. Any rules later |
| 787 | intended must be manually inserted again using `aram_store_ref_ar_do` |
| 788 | |
| 789 | |
Harald Welte | 577312a | 2023-02-23 09:51:30 +0100 | [diff] [blame] | 790 | GlobalPlatform commands |
| 791 | ----------------------- |
| 792 | |
| 793 | pySim-shell has only the mots rudimentary support for GlobalPlatform at this point. Please use dedicated |
| 794 | projects like GlobalPlatformPro meanwhile. |
| 795 | |
| 796 | get_data |
| 797 | ~~~~~~~~ |
| 798 | Performs the GET DATA command as specified by GlobalPlatform. |
| 799 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 800 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 801 | cmd2 settable parameters |
| 802 | ------------------------ |
| 803 | |
| 804 | ``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level |
| 805 | shell: They can be read and set, and they will influence the behavior somehow. |
| 806 | |
| 807 | conserve_write |
| 808 | ~~~~~~~~~~~~~~ |
| 809 | |
| 810 | If enabled, pySim will (when asked to write to a card) always first read the respective file/record and |
| 811 | verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped. |
| 812 | Writes will only be performed if the new value is different from the current on-card value. |
| 813 | |
| 814 | If disabled, pySim will always write irrespective of the current/new value. |
| 815 | |
Harald Welte | 1748b93 | 2021-04-06 21:12:25 +0200 | [diff] [blame] | 816 | json_pretty_print |
| 817 | ~~~~~~~~~~~~~~~~~ |
| 818 | |
| 819 | This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line |
| 820 | output with indent level of 4 spaces) or not. |
| 821 | |
| 822 | The default value of this parameter is 'true'. |
| 823 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 824 | debug |
| 825 | ~~~~~ |
| 826 | |
| 827 | If enabled, full python back-traces will be displayed in case of exceptions |
| 828 | |
Harald Welte | 7829d8a | 2021-04-10 11:28:53 +0200 | [diff] [blame] | 829 | apdu_trace |
| 830 | ~~~~~~~~~~ |
| 831 | |
| 832 | Boolean variable that determines if a hex-dump of the command + response APDU shall be printed. |
| 833 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 834 | numeric_path |
| 835 | ~~~~~~~~~~~~ |
| 836 | |
| 837 | Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names. |
| 838 | |
| 839 | :: |
| 840 | |
| 841 | pySIM-shell (MF/EF.ICCID)> set numeric_path True |
| 842 | numeric_path - was: False |
| 843 | now: True |
| 844 | pySIM-shell (3f00/2fe2)> set numeric_path False |
| 845 | numeric_path - was: True |
| 846 | now: False |
| 847 | pySIM-shell (MF/EF.ICCID)> help set |