Osmopysim Usermanual
Osmopysim Usermanual
1 Introduction 1
1.1 pySim-shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Video Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.2 Running pySim-shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.3 Usage Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.4 Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1.5 cmd2 basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.1.6 pySim commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.1.7 ISO7816 commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.1.8 TS 102 221 commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.1.9 Linear Fixed EF commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.1.10 Transparent EF commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
1.1.11 BER-TLV EF commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.1.12 USIM commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.1.13 File-specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.1.14 UICC Administrative commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.1.15 ARA-M commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.1.16 GlobalPlatform commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.1.17 eUICC ISD-R commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.1.18 cmd2 settable parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.2 pySim-trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.2.1 Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.2.2 Running pySim-trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.2.3 pySim-trace command line reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.2.4 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.3 Legacy tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.3.1 pySim-prog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
1.3.2 pySim-read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
1.4 pySim-smpp2sim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.4.1 Running pySim-smpp2sim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.4.2 Example execution with sample output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
1.5 pySim library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
1.5.1 pySim filesystem abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
1.5.2 pySim commands abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
1.5.3 pySim Transport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
1.5.4 pySim utility functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
1.5.5 pySim exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
1.5.6 pySim card_handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
1.5.7 pySim card_key_provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
1.6 pySim eSIM libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
i
1.6.1 GSMA SGP.21/22 Remote SIM Provisioning (RSP) - High Level . . . . . . . . . . . . . . . 89
1.6.2 GSMA SGP.21/22 Remote SIM Provisioning (RSP) - Low Level . . . . . . . . . . . . . . . 91
1.6.3 SIMalliance / TCA Interoperable Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
1.7 osmo-smdpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
1.7.1 Running osmo-smdpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
1.8 sim-rest-server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
1.8.1 REST API Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
1.8.2 Concrete example using the included sysmoISIM-SJA2 . . . . . . . . . . . . . . . . . . . . 117
1.9 suci-keytool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
1.9.1 Generating keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.9.2 Dumping public keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.9.3 suci-keytool syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.10 saip-tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
1.10.1 Profile Package Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
1.10.2 JAVA card applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
1.10.3 saip-tool syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Index 131
ii
CHAPTER
ONE
INTRODUCTION
pySim is a python implementation of various software that helps you with managing subscriber identity cards for
cellular networks, so-called SIM cards.
Many Osmocom (Open Source Mobile Communications) projects relate to operating private / custom cellular networks,
and provisioning SIM cards for said networks is in many cases a requirement to operate such networks.
To make use of most of pySim’s features, you will need a programmable SIM card, i.e. a card where you are the
owner/operator and have sufficient credentials (such as the ADM PIN) in order to write to many if not most of the files
on the card.
Such cards are, for example, available from sysmocom, a major contributor to pySim. See https://www.sysmocom.de/
products/lab/sysmousim/ for more details.
pySim supports classic GSM SIM cards as well as ETSI UICC with 3GPP USIM and ISIM applications. It is easily
extensible, so support for additional files, card applications, etc. can be added easily by any python developer. We do
encourage you to submit your contributions to help this collaborative development project.
pySim consists of several parts:
• a python library containing plenty of objects and methods that can be used for writing custom programs inter-
facing with SIM cards.
• the [new] interactive pySim-shell command line program
• the [new] pySim-trace APDU trace decoder
• the [legacy] pySim-prog and pySim-read tools
1.1 pySim-shell
pySim-shell is an interactive command line shell for all kind of interactions with SIM cards, including classic GSM
SIM, GSM-R SIM, UICC, USIM, ISIM, HPSIM and recently even eUICC.
If you’re familiar with Unix/Linux shells: Think of it like the bash for SIM cards.
The pySim-shell interactive shell provides commands for
• navigating the on-card filesystem hierarchy
• authenticating with PINs such as ADM1
• CHV/PIN management (VERIFY, ENABLE, DISABLE, UNBLOCK)
• decoding of SELECT response (file control parameters)
• reading and writing of files and records in raw, hex-encoded binary format
• for most files (where related file-specific encoder/decoder classes have been developed):
1
osmopysim-usermanual
• decoded reading (display file data represented in human and machine readable JSON format)
• decoded writing (encode from JSON to binary format, then write)
• if your card supports it, and you have the related privileges: resizing, creating, enabling and disabling of files
• performing GlobalPlatform operations, including establishment of Secure Channel Protocol (SCP), Installing
applications, installing key material, etc.
• listing/enabling/disabling/deleting eSIM profiles on Consumer eUICC
By means of using the python cmd2 module, various useful features improve usability:
• history of commands (persistent across restarts)
• output re-direction to files on your computer
• output piping through external tools like grep
• tab completion of commands and SELECT-able files/directories
• interactive help for all commands
A typical interactive pySim workflow would look like this:
• starting the program, specifying which smart card interface to use to talk to the card
• verifying the PIN (if needed) or the ADM1 PIN in case you want to write/modify the card
• selecting on-card application dedicated files like ADF.USIM and navigating the tree of DFs
• reading and potentially modifying file contents, in raw binary (hex) or decoded JSON format
2 Chapter 1. Introduction
osmopysim-usermanual
Positional Arguments
command A pySim-shell command that would optionally be executed at startup
command_args Optional Arguments for command
Named Arguments
--apdu-trace Trace the command/response APDUs exchanged with the card
Default: False
-e, --execute-command A pySim-shell command that will be executed at startup
Default: []
Serial Reader
Use a simple/ultra-low-cost serial reader attached to a (physical or USB/virtual) RS232 port. This doesn’t work with
all RS232-attached smart card readers, only with the very primitive readers following the ancient Phoenix or Smart
Mouse design.
-d, --device Serial Device for SIM access
Default: “/dev/ttyUSB0”
-b, --baud Baud rate used for SIM access
Default: 9600
PC/SC Reader
Use a PC/SC card reader to talk to the SIM card. PC/SC is a standard API for how applications access smart card
readers, and is available on a variety of operating systems, such as Microsoft Windows, MacOS X and Linux. Most
vendors of smart card readers provide drivers that offer a PC/SC interface, if not even a generic USB CCID driver is
used. You can use a tool like pcsc_scan -r to obtain a list of readers available on your system.
--pcsc-shared Open PC/SC reaer in SHARED access (default: EXCLUSIVE)
Default: False
-p, --pcsc-device Number of PC/SC reader to use for SIM access
--pcsc-regex Regex matching PC/SC reader to use for SIM access
OsmocomBB Reader
Use an OsmocomBB compatible phone to access the SIM inserted to the phone SIM slot. This will require you to run
the OsmocomBB firmware inside the phone (can be ram-loaded). It also requires that you run the osmocon program,
which provides a unix domain socket to which this reader driver can attach.
--osmocon Socket path for Calypso (e.g. Motorola C1XX) based reader (via OsmocomBB)
1.1. pySim-shell 3
osmopysim-usermanual
General Options
--script script with pySim-shell commands to be executed automatically at start-up
--csv Read card data from CSV file
--csv-column-key per-CSV-column AES transport key
Default: []
--card_handler Use automatic card handling machine
--noprompt Run in non interactive mode
Default: False
--skip-card-init Skip all card/profile initialization
Default: False
-a, --pin-adm ADM PIN used for provisioning (overwrites default)
-A, --pin-adm-hex ADM PIN used for provisioning, as hex string (16 characters long)
Technical References
This guide covers the basic workflow of provisioning SIM cards with the 5G SUCI feature. For detailed information
on the SUCI feature and file contents, the following documents are helpful:
• USIM files and structure: 3GPP TS 31.102
• USIM tests (incl. file content examples): 3GPP TS 31.121
• Test keys for SUCI calculation: 3GPP TS 33.501
For specific information on sysmocom SIM cards, refer to
• the sysmoISIM-SJA5 User Manual for the curent sysmoISIM-SJA5 product
• the sysmoISIM-SJA2 User Manual for the older sysmoISIM-SJA2 product
4 Chapter 1. Introduction
osmopysim-usermanual
In short, you can enable SUCI calculation in the UE with these steps:
• activate USIM Service 124
• make sure USIM Service 125 is disabled
• store the public keys in EF.SUCI_Calc_Info
• set the Routing Indicator (required)
If you want to disable the feature, you can just disable USIM Service 124 (and 125) in EF.UST.
Admin PIN
The usual way to authenticate yourself to the card as the cellular operator is to validate the so-called ADM1 (admin)
PIN. This may differ from card model/vendor to card model/vendor.
Start pySIM-shell and enter the admin PIN for your card. If you bought the SIM card from your network operator and
don’t have the admin PIN, you cannot change SIM contents!
Launch pySIM:
$ ./pySim-shell.py -p 0
Otherwise, write commands will fail with SW Mismatch: Expected 9000 and got 6982.
Key Provisioning
˓→-> {}
The following JSON config defines the testfile from 3GPP TS 31.121, Section 4.9.4 with test keys from 3GPP TS
33.501, Annex C.4. Highest priority (0) has a Profile-B (identifier: 2) key in key slot 1, which means the key
with hnet_pubkey_identifier: 27.
1.1. pySim-shell 5
osmopysim-usermanual
{
"prot_scheme_id_list": [
{"priority": 0, "identifier": 2, "key_index": 1},
{"priority": 1, "identifier": 1, "key_index": 2},
{"priority": 2, "identifier": 0, "key_index": 0}],
"hnet_pubkey_list": [
{"hnet_pubkey_identifier": 27,
"hnet_pubkey":
˓→"0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C70
˓→"},
{"hnet_pubkey_identifier": 30,
"hnet_pubkey": "5A8D38864820197C3394B92613B20B91633CBD897119273BF8E4A6F4EEC0A650
˓→"}]
˓→"0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C70
˓→"5A8D38864820197C3394B92613B20B91633CBD897119273BF8E4A6F4EEC0A650"}]}'
WARNING: These are TEST KEYS with publicly known/specified private keys, and hence unsafe for live/secure de-
ployments! For use in production networks, you need to generate your own set[s] of keys.
Routing Indicator
The Routing Indicator must be present for the SUCI feature. By default, the contents of the file is invalid (ffffffff):
The Routing Indicator is a four-byte file but the actual Routing Indicator goes into bytes 0 and 1 (the other bytes are
reserved). To set the Routing Indicator to 0x71:
You can also set the routing indicator to 0x0, which is valid and means “routing indicator not specified”, leaving it to
the modem.
6 Chapter 1. Introduction
osmopysim-usermanual
˓→ 71, 73, 85, 86, 87, 89, 90, 93, 94, 95, 122, 123, 124, 126]
In this case, UST Service 124 is already enabled and you’re good to go. The sysmoISIM-SJA2 does not support on-SIM
calculation, so service 125 must be disabled.
sysmoISIM-SJA2 come 5GS-enabled. By default however, the configuration stored in the card file-system is not valid
for 5G networks: Service 124 is enabled, but EF.SUCI_Calc_Info and EF.Routing_Indicator are empty files (hence do
not contain valid data).
At least for Qualcomm’s X55 modem, this results in an USIM error and the whole modem shutting 5G down. If you
don’t need SUCI concealment but the smartphone refuses to connect to any 5G network, try to disable the UST service
124.
sysmoISIM-SJA5 are shipped with a more forgiving default, with valid EF.Routing_Indicator contents and disabled
Service 124
The SUCI calculation can also be performed by the USIM application on the UICC directly. The UE then uses the
GET IDENTITY command (see also 3GPP TS 31.102, section 7.5) to retrieve a SUCI value.
The sysmoISIM-SJA5-S17 supports SUCI calculation by the USIM. The configuration is not much different to the
above described configuration of SUCI calculation in the UE.
The main difference is how the key provisioning is done. When the SUCI calculation is done by the USIM, then the
key material is not accessed by the UE. The specification (see also 3GPP TS 31.102, section 7.5.1.1), also does not
specify any file or file format to store the key material. This means the exact way to perform the key provisioning is an
implementation detail of the USIM card application.
In the case of sysmoISIM-SJA5-S17, the key material for SUCI calculation by the USIM is stored in
ADF.USIM/DF.SAIP/EF.SUCI_Calc_Info (not in ADF.USIM/DF.5GS/EF.SUCI_Calc_Info!).
1.1. pySim-shell 7
osmopysim-usermanual
The file format is exactly the same as specified in 3GPP TS 31.102, section 4.4.11.8. This means the above described
key provisioning procedure can be applied without any changes, except that the file location is different.
To signal to the UE that the USIM is setup up for SUCI calculation, service 125 must be enabled in addition to service
124 (see also 3GPP TS 31.102, section 5.3.48)
To verify that the SUCI calculation works as expected, it is possible to issue a GET IDENTITY command using pySim-
shell:
select ADF.USIM
get_identity
The USIM should then return a SUCI TLV Data object that looks like this:
Preparation
In this example we will install the CAP file HelloSTK_09122024.cap [1] on an sysmoISIM-SJA2 card. Since the
interface is standardized, the exact card model does not matter.
The example applet makes use of the STK (Sim-Toolkit), so we must supply STK installation parame-
ters. Those parameters are supplied in the form of a hexstring and should be provided by the applet man-
ufacturer. The available parameters and their exact encoding is specified in ETSI TS 102 226, section
8.2.1.3.2.1. The installation of HelloSTK_09122024.cap [1], will require the following STK installation parameters:
“010001001505000000000000000000000000”
During the installation, we also have to set a memory quota for the volatile and for the non volatile card memory. Those
values also should be provided by the applet manufacturer. In this example, we will allow 255 bytes of volatile memory
and 255 bytes of non volatile memory to be consumed by the applet.
To install JAVA-card applets, one must be in the possession of the key material belonging to the card. The keys are
usually provided by the card manufacturer. The following example will use the following keyset:
Keyname Keyvalue
DEK/KIK 5524F4BECFE96FB63FC29D6BAAC6058B
ENC/KIC 542C37A6043679F2F9F71116418B1CD5
MAC/KID 34F11BAC8E5390B57F4E601372339E3C
8 Chapter 1. Introduction
osmopysim-usermanual
[1] https://osmocom.org/projects/cellular-infrastructure/wiki/HelloSTK
Applet Installation
To prepare the installation, a secure channel to the ISD must be established first:
˓→security-level 1
Warning
In case you get an “EXCEPTION of type ‘ValueError’ occurred with message: card cryptogram doesn’t match”
error message, it is very likely that there is a problem with the key material. The card may lock the ISD access after
a certain amount of failed tries. Carefully check the key material any try again.
When the secure channel is established, we are ready to install the applet. The installation normally is a multi step
procedure, where the loading of an executable load file is announced first, then loaded and then installed in a final step.
The pySim-shell command install_cap automatically takes care of those three steps.
The applet is now installed on the card. We can now quit pySim-shell and remove the card from the reader and test the
applet in a mobile phone. There should be a new STK application with one menu entry shown, that will greet the user
when pressed.
1.1. pySim-shell 9
osmopysim-usermanual
Applet Removal
To remove the applet, we must establish a secure channel to the ISD (see above). Then we can delete the applet using
the delete_card_content command.
The parameter “D07002CA44” is the load-file-AID of the applet. The load-file-AID is encoded in the .cap file and
also displayed during the installation process. It is also important to note that when the applet is installed, it cannot be
installed (under the same AID) again until it is removed.
The CardKeyProviderCsv
The CardKeyProviderCsv allows you to retrieve card-individual key material from a CSV (comma separated value) file
that is accessible to pySim.
The CSV file must have the expected column names, for example ICCID and ADM1 in case you would like to use that
CSV to obtain the card-specific ADM1 PIN when using the verify_adm command.
You can specify the CSV file to use via the –csv command-line option of pySim-shell. If you do not specify a CSV file,
pySim will attempt to open a CSV file from the default location at ~/.osmocom/pysim/card_data.csv, and use that, if it
exists.
pySim supports column-level CSV encryption. This feature will make sure that your key material is not stored in
plaintext in the CSV file.
The encryption mechanism uses AES in CBC mode. You can use any key length permitted by AES (128/192/256 bit).
Following GSMA FS.28, the encryption works on column level. This means different columns can be decrypted using
different key material. This means that leakage of a column encryption key for one column or set of columns (like a
specific security domain) does not compromise various other keys that might be stored in other columns.
You can specify column-level decryption keys using the –csv-column-key command line argument. The syntax is
FIELD:AES_KEY_HEX, for example:
pySim-shell.py –csv-column-key SCP03_ENC_ISDR:000102030405060708090a0b0c0d0e0f
10 Chapter 1. Introduction
osmopysim-usermanual
In order to avoid having to repeat the column key for each and every column of a group of keys within a keyset, there
are pre-defined column group aliases, which will make sure that the specified key will be used by all columns of the
set:
• UICC_SCP02 is a group alias for UICC_SCP02_KIC1, UICC_SCP02_KID1, UICC_SCP02_KIK1
• UICC_SCP03 is a group alias for UICC_SCP03_KIC1, UICC_SCP03_KID1, UICC_SCP03_KIK1
• SCP03_ECASD is a group alias for SCP03_ENC_ECASD, SCP03_MAC_ECASD, SCP03_DEK_ECASD
• SCP03_ISDA is a group alias for SCP03_ENC_ISDA, SCP03_MAC_ISDA, SCP03_DEK_ISDA
• SCP03_ISDR is a group alias for SCP03_ENC_ISDR, SCP03_MAC_ISDR, SCP03_DEK_ISDR
Field naming
• For look-up of UICC/SIM/USIM/ISIM or eSIM profile specific key material, pySim uses the ICCID field as
lookup key.
• For look-up of eUICC specific key material (like SCP03 keys for the ISD-R, ECASD), pySim uses the EID field
as lookup key.
As soon as the CardKeyProviderCsv finds a line (row) in your CSV where the ICCID or EID match, it looks for the
column containing the requested data.
ADM PIN
The verify_adm command will attempt to look up the ADM1 column indexed by the ICCID of the SIM/UICC.
SCP02 / SCP03
SCP02 and SCP03 each use key triplets consisting if ENC, MAC and DEK keys. For more details, see the applicable
GlobalPlatform specifications.
If you do not want to manually enter the key material for each specific card as arguments to the establish_scp02 or
establish_scp03 commands, you can make use of the –key-provider-suffix option. pySim uses this suffix to compose
the column names for the CardKeyProvider as follows.
• SCP02_ENC_ + suffix for the SCP02 ciphering key
• SCP02_MAC_ + suffix for the SCP02 MAC key
• SCP02_DEK_ + suffix for the SCP02 DEK key
• SCP03_ENC_ + suffix for the SCP03 ciphering key
• SCP03_MAC_ + suffix for the SCP03 MAC key
• SCP03_DEK_ + suffix for the SCP03 DEK key
So for example, if you are using a command like establish_scp03 –key-provider-suffix ISDR, then the column names
for the key material look-up are SCP03_ENC_ISDR, SCP03_MAC_ISDR and SCP03_DEK_ISDR, respectively.
The identifier used for look-up is determined by the definition of the Security Domain. For example, the eUICC ISD-R
and ECASD will use the EID of the eUICC. On the other hand, the ISD-P of an eSIM or the ISD of an UICC will use
the ICCID.
1.1. pySim-shell 11
osmopysim-usermanual
osmo-remsim
osmo-remsim is a suite of software programs enabling physical/geographic separation of a cellular phone (or modem)
on the one hand side and the UICC/eUICC card on the other side.
Using osmo-remsim, you can operate an entire fleet of modems/phones, as well as banks of SIM cards and dynamically
establish or remove the connections between modems/phones and cards.
To access remote cards with pySim-shell via osmo-remseim (RSPRO), the provided libifd_remsim_client would be
used to provide a virtual PC/SC reader on the local machine. pySim-shell can then access this reader like any other
PC/SC reader.
More information on osmo-remsim can be found under:
• https://osmocom.org/projects/osmo-remsim/wiki
• https://ftp.osmocom.org/docs/osmo-remsim/master/osmo-remsim-usermanual.pdf
Android APDU proxy is an Android app that provides a bridge between a host computer and the UICC/eUICC slot of
an Android smartphone.
The APDU proxy connects to VPCD server that runs on the remote host (in this case the local machine where pySim-
shell is running). The VPCD server then provides a virtual PC/SC reader, that pySim-shell can access like any other
PC/SC reader.
On the Android side the UICC/eUICC is accessed via OMAPI (Open Mobile API), which is available in Android since
API level Android 8 (API level 29).
More information Android APDU proxy can be found under:
• https://gitea.osmocom.org/sim-card/android-apdu-proxy
desc
Display human readable file description for the currently selected file.
dir
12 Chapter 1. Introduction
osmopysim-usermanual
Named Arguments
export
Named Arguments
˓→Invalid class'
To enable full traceback, run the following command: 'set debug true'
pySIM-shell (00:MF)>
1.1. pySim-shell 13
osmopysim-usermanual
The exception above is more or less expected. It just means that 50 files which are defined (most likely as optional files
in some later 3GPP release) were not found on the card, or were invalidated/disabled when trying to SELECT them.
fsdump
Export filesystem metadata and file contents of all files below current DF in machine-readable json format. This is
similar to “export”, but much easier to parse by downstream processing tools. You usually may want to call this from
the MF and verify the ADM1 PIN (if available) to maximize the amount of readable files.
Named Arguments
tree
Display a tree of the card filesystem. It is important to note that this displays a tree of files that might potentially exist
(based on the card profile). In order to determine if a given file really exists on a given card, you have to try to select
that file.
Example:
14 Chapter 1. Introduction
osmopysim-usermanual
verify_adm
Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order to get write/update
permissions to most of the files on SIM cards.
Positional Arguments
ADM ADM pin value. If none given, CSV file will be queried
Named Arguments
In the above case, the ADM was successfully verified. Please make always sure to use the correct ADM1 for the specific
card you have inserted! If you present a wrong ADM1 value several times consecutively, your card ADM1 will likely be
permanently locked, meaning you will never be able to reach ADM1 privilege level. For sysmoUSIM/ISIM products,
three consecutive wrong ADM1 values will lock the ADM1.
Example (erroneous):
To enable full traceback, run the following command: 'set debug true'
If you frequently work with the same set of cards that you need to modify using their ADM1, you can put a CSV file with
those cards ICCID + ADM1 values into a CSV (comma separated value) file at ~/.osmocom/pysim/card_data.csv.
In this case, you can use the verify_adm command without specifying an ADM1 value.
Example (successful):
In this case, the CSV file contained a record for the ICCID of the card (11111111) and that value was used to successfully
verify ADM1.
Example (erroneous):
1.1. pySim-shell 15
osmopysim-usermanual
To enable full traceback, run the following command: 'set debug true'
In this case there was no record for the ICCID of the card in the CSV file.
reset
Perform card reset and display the card ATR.
Example:
intro
[Re-]Display the introductory banner
Example:
equip
Equip pySim-shell with a card; particularly useful if the program was started before a card was present, or after a card
has been replaced by the user while pySim-shell was kept running.
bulk_script
Positional Arguments
Named Arguments
16 Chapter 1. Introduction
osmopysim-usermanual
echo
Positional Arguments
apdu
Send a raw APDU to the card, and print SW + Response. CAUTION: this command bypasses the logical channel
handling of pySim-shell and card state changes are not tracked. Dpending on the raw APDU sent, pySim-shell may not
continue to work as expected if you e.g. select a different file.
Positional Arguments
Named Arguments
In the above case the raw APDU hex-string 00a40400023f00 was sent to the card, to which it responded with status
word 6700. Keep in mind that pySim-shell has no idea what kind of raw commands you are sending to the card, and
it hence is unable to synchronize its internal state (such as the currently selected file) with the card. The use of this
command should hence be constrained to commands that do not have any high-level support in pySim-shell yet.
1.1. pySim-shell 17
osmopysim-usermanual
select
The select command is used to select a file, either by its FID, AID or by its symbolic name.
Try select with tab-completion to get a list of all current selectable items:
Use select with a specific FID or name to select the new file.
This will
• output the [JSON decoded, if possible] select response
• change the prompt to the newly selected file
• enable any commands specific to the newly-selected file
}
pySIM-shell (00:MF/ADF.USIM)>
status
The status command [re-]obtains the File Control Template of the currently-selected file and print its decoded output.
Example:
18 Chapter 1. Introduction
osmopysim-usermanual
change_chv
Positional Arguments
NEWPIN PIN code value. If none given, CSV file will be queried
PIN PIN code value. If none given, CSV file will be queried
Named Arguments
disable_chv
1.1. pySim-shell 19
osmopysim-usermanual
Positional Arguments
PIN PIN code value. If none given, CSV file will be queried
Named Arguments
enable_chv
Positional Arguments
PIN PIN code value. If none given, CSV file will be queried
Named Arguments
unblock_chv
Positional Arguments
PUK PUK code value. If none given, CSV file will be queried
NEWPIN PIN code value. If none given, CSV file will be queried
Named Arguments
verify_chv
Verify (authenticate) using specified CHV (PIN) code, which is how the specifications call it if you authenticate yourself
using the specified PIN. There usually is at least PIN1 and PIN2.
20 Chapter 1. Introduction
osmopysim-usermanual
Positional Arguments
PIN PIN code value. If none given, CSV file will be queried
Named Arguments
deactivate_file
Deactivate the currently selected file. A deactivated file can no longer be accessed for any further operation (such as
selecting and subsequently reading or writing).
Any access to a file that is deactivated will trigger the error SW 6283 ‘Selected file invalidated/disabled’
In order to re-access a deactivated file, you need to activate it again, see the activate_file command below. Note that for
deactivation the to-be-deactivated EF must be selected, but for activation, the DF above the to-be-activated EF must
be selected!
This command sends a DEACTIVATE FILE APDU to the card (used to be called INVALIDATE in TS 11.11 for classic
SIM).
activate_file
Activate the specified EF by sending an ACTIVATE FILE apdu command (used to be called REHABILITATE in TS
11.11 for classic SIM).
Positional Arguments
open_channel
Positional Arguments
close_channel
1.1. pySim-shell 21
osmopysim-usermanual
Positional Arguments
switch_channel
Positional Arguments
suspend_uicc
This command allows you to perform the SUSPEND UICC command on the card. This is a relatively recent power-
saving addition to the UICC specifications, allowing for suspend/resume while maintaining state, as opposed to a full
power-off (deactivate) and power-on (activate) of the card.
The pySim command just sends that SUSPEND UICC command and doesn’t perform the full related sequence including
the electrical power down.
Perform the SUSPEND UICC command. Only supported on some UICC (check EF.UMPC).
Named Arguments
22 Chapter 1. Introduction
osmopysim-usermanual
resume_uicc
This command allows you to perform the SUSPEND UICC command for the RESUME operation on the card.
Suspend/Resume is a relatively recent power-saving addition to the UICC specifications, allowing for suspend/resume
while maintaining state, as opposed to a full power-off (deactivate) and power-on (activate) of the card.
The pySim command just sends that SUSPEND UICC (RESUME) command and doesn’t perform the full related
sequence including the electrical power down.
Perform the REUSME UICC operation. Only supported on some UICC. Also: A power-cycle of the card is required
between SUSPEND and RESUME, and only very few non-RESUME commands are permitted between SUSPEND
and RESUME. See TS 102 221 Section 11.1.22.
Positional Arguments
terminal_capability
This command allows you to perform the TERMINAL CAPABILITY command towards the card.
TS 102 221 specifies the TERMINAL CAPABILITY command using which the terminal (Software + hardware talking
to the card) can expose their capabilities. This is also used in the eUICC universe to let the eUICC know which features
are supported.
Perform the TERMINAL CAPABILITY function. Used to inform the UICC about terminal capability.
[--actual-used-freq-100k ACTUAL_USED_FREQ_100K]
[--extended-logical-channel] [--uicc-clf] [--lui-d]
[--lpd-d] [--lds-d] [--lui-e-scws]
[--metadata-update-alerting]
[--enterprise-capable-device] [--lui-e-e4e] [--lpr]
1.1. pySim-shell 23
osmopysim-usermanual
read_record
Positional Arguments
Named Arguments
24 Chapter 1. Introduction
osmopysim-usermanual
read_record_decoded
Positional Arguments
Named Arguments
read_records
read_records_decoded
Named Arguments
update_record
1.1. pySim-shell 25
osmopysim-usermanual
Positional Arguments
update_record_decoded
Positional Arguments
Named Arguments
edit_record_decoded
Positional Arguments
26 Chapter 1. Introduction
osmopysim-usermanual
decode_hex
Positional Arguments
Named Arguments
read_binary
Named Arguments
read_binary_decoded
Named Arguments
1.1. pySim-shell 27
osmopysim-usermanual
update_binary
Positional Arguments
Named Arguments
update_binary_decoded
Positional Arguments
Named Arguments
{
"ms_operation_mode": "normal_and_specific_facilities",
"additional_info": {
"ciphering_indicator": false,
"csg_display_control": false,
"prose_services": false,
"extended_drx": true
},
"rfu": 0,
"mnc_len": 2,
"extensions": "ff"
}
pySIM-shell (00:MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path additional_info.
(continues on next page)
28 Chapter 1. Introduction
osmopysim-usermanual
If this command fails, it means that the file is not encodable; please check your input and/or use the raw update_binary
command.
edit_binary_decoded
This command will read the selected binary EF, decode it to its JSON representation, save that JSON to a temporary
file on your computer, and launch your configured text editor.
You may then perform whatever modifications to the JSON representation, save + leave your text editor.
Afterwards, the modified JSON will be re-encoded to the binary format, and the result written to the SIM card.
This allows for easy interactive modification of file contents.
If this command fails before the editor is spawned, it means that the current file contents is not decodable, and you
should use the update_binary_decoded or update_binary command.
If this command fails after making your modificatiosn in the editor, it means that the new file contents is not encodable;
please check your input and/or us the raw update_binary comamdn.
decode_hex
Positional Arguments
Named Arguments
1.1. pySim-shell 29
osmopysim-usermanual
retrieve_tags
Retrieve a list of all tags present in the currently selected file.
retrieve_data
Positional Arguments
set_data
Positional Arguments
del_data
Positional Arguments
30 Chapter 1. Introduction
osmopysim-usermanual
authenticate
Positional Arguments
terminal_profile
Send a TERMINAL PROFILE command to the card. This is used to inform the card about which optional features
the terminal (modem/phone) supports, particularly in the context of SIM Toolkit, Proactive SIM and OTA. You must
specify a hex-string with the encoded terminal profile you want to send to the card.
Positional Arguments
envelope
Send an ENVELOPE command to the card. This is how a variety of information is communicated from the terminal
(modem/phone) to the card, particularly in the context of SIM Toolkit, Proactive SIM and OTA.
Positional Arguments
envelope_sms
Send an ENVELOPE(SMS-PP-Download) command to the card. This emulates a terminal (modem/phone) having
received a SMS with a PID of ‘SMS for the SIM card’. You can use this command in the context of testing OTA related
features without a modem/phone or a cellular network.
Positional Arguments
1.1. pySim-shell 31
osmopysim-usermanual
get_identity
Send a GET IDENTITY command to the card. This is part of the procedure for “SUCI calculation performed on
USIM” supported by USIM with support for both EF.UST service 124 and 125.
Named Arguments
EF.ARR: read_arr_record
Read one EF.ARR record in flattened, human-friendly form.
EF.ARR: read_arr_records
Read + decode all EF.ARR records in flattened, human-friendly form.
DF.GSM/EF.SST: sst_service_allocate
Mark a given single service as allocated in EF.SST. Requires service number as argument.
DF.GSM/EF.SST: sst_service_activate
Mark a given single service as activated in EF.SST. Requires service number as argument.
DF.GSM/EF.SST: sst_service_deallocate
Mark a given single service as deallocated in EF.SST. Requires service number as argument.
DF.GSM/EF.SST: sst_service_deactivate
Mark a given single service as deactivated in EF.SST. Requires service number as argument.
ADF.USIM/EF.EST: est_service_enable
Enables a single service in EF.EST. Requires service number as argument.
ADF.USIM/EF.EST: est_service_disable
Disables a single service in EF.EST. Requires service number as argument.
EF.IMSI: update_imsi_plmn
Change the PLMN part (MCC+MNC) of the IMSI. Requires a single argument consisting of 5/6 digits of concatenated
MCC+MNC.
32 Chapter 1. Introduction
osmopysim-usermanual
ADF.USIM/EF.UST: ust_service_activate
Activates a single service in EF.UST. Requires service number as argument.
ADF.USIM/EF.UST: ust_service_deactivate
Deactivates a single service in EF.UST. Requires service number as argument.
ADF.USIM/EF.UST: ust_service_check
Check consistency between services of this file and files present/activated. Many services determine if one or multiple
files shall be present/activated or if they shall be absent/deactivated. This performs a consistency check to ensure that
no services are activated for files that are not - and vice-versa, no files are activated for services that are not. Error
messages are printed for every inconsistency found.
ADF.ISIM/EF.IST: ist_service_activate
Activates a single service in EF.IST. Requires service number as argument.
ADF.ISIM/EF.IST: ist_service_deactivate
Deactivates a single service in EF.UST. Requires service number as argument.
ADF.ISIM/EF.IST: ist_service_check
Check consistency between services of this file and files present/activated. Many services determine if one or multiple
files shall be present/activated or if they shall be absent/deactivated. This performs a consistency check to ensure that
no services are activated for files that are not - and vice-versa, no files are activated for services that are not. Error
messages are printed for every inconsistency found.
delete_file
Delete the specified file. DANGEROUS! See TS 102 222 Section 6.4. This will permanently delete the specified file
from the card. pySim has no support to re-create files yet, and even if it did, your card may not allow it!
Positional Arguments
Named Arguments
--force-delete I really want to permanently delete the file. I know pySim cannot re-create it yet!
Default: False
1.1. pySim-shell 33
osmopysim-usermanual
terminate_df
Terminate the specified DF. DANGEROUS! See TS 102 222 6.7. This is a permanent, one-way operation on the card.
There is no undo, you can not recover a terminated DF. The only permitted command for a terminated DF is the DLETE
FILE command.
Positional Arguments
Named Arguments
--force I really want to terminate the file. I know I can not recover from it!
Default: False
terminate_ef
Terminate the specified DF. DANGEROUS! See TS 102 222 6.7. This is a permanent, one-way operation on the card.
There is no undo, you can not recover a terminated DF. The only permitted command for a terminated DF is the DLETE
FILE command.
Positional Arguments
Named Arguments
--force I really want to terminate the file. I know I can not recover from it!
Default: False
terminate_card
Terminate the Card. SUPER DANGEROUS! See TS 102 222 Section 6.9. This will permanently brick the card and
can NOT be recovered from!
Named Arguments
--force-terminate-card I really want to permanently terminate the card. It will not be usable after-
wards!
Default: False
34 Chapter 1. Introduction
osmopysim-usermanual
create_ef
Create a new EF below the currently selected DF. Requires related privileges.
Positional Arguments
required arguments
Named Arguments
create_df
Create a new DF below the currently selected DF. Requires related privileges.
Positional Arguments
1.1. pySim-shell 35
osmopysim-usermanual
required arguments
Named Arguments
resize_ef
Resize an existing EF below the currently selected DF. Requires related privileges.
Positional Arguments
required arguments
aram_get_all
Obtain and decode all access rules from the ARA-M applet on the card.
NOTE: if the total size of the access rules exceeds 255 bytes, this command will fail, as it doesn’t yet implement
fragmentation/reassembly on rule retrieval. YMMV
[
(continues on next page)
36 Chapter 1. Introduction
osmopysim-usermanual
}
]
},
{
"ar_do": [
{
"apdu_ar_do": {
"generic_access_rule": "always"
}
},
{
"perm_ar_do": {
"permissions": "0000000000000001"
}
}
]
}
]
}
]
}
]
aram_get_config
Perform Config handshake with ARA-M applet: Tell it our version and retrieve its version.
NOTE: Not supported in all ARA-M implementations.
aram_store_ref_ar_do
1.1. pySim-shell 37
osmopysim-usermanual
Named Arguments
--device-app-id Identifies the specific device application that the rule appplies to. Hash of Certifi-
cate of Application Provider, or UUID. (20/32 hex bytes)
--aid Identifies the specific SE application for which rules are to be stored. Can be a
partial AID, containing for example only the RID. (5-16 or 0 hex bytes)
--aid-empty No specific SE application, applies to implicitly selected application (all channels)
Default: False
--pkg-ref Full Android Java package name (up to 127 chars ASCII)
--apdu-never APDU access is not allowed
Default: False
--apdu-always APDU access is allowed
Default: False
--apdu-filter APDU filter: multiple groups of 8 hex bytes (4 byte CLA/INS/P1/P2 followed by
4 byte mask)
--nfc-always NFC event access is allowed
Default: False
--nfc-never NFC event access is not allowed
Default: False
--android-permissions Android UICC Carrier Privilege Permissions (8 hex bytes)
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:
˓→always
aram_delete_all
This command will request deletion of all access rules stored within the ARA-M applet. Use it with caution, there is
no undo. Any rules later intended must be manually inserted again using aram_store_ref_ar_do
aram_lock
This command allows to lock the access to the STORE DATA command. This renders all access rules stored within
the ARA-M applet effectively read-only. The lock can only be removed via a secure channel to the security domain
and is therefore suitable to prevent unauthorized changes to ARA-M rules.
Removal of the lock:
NOTE: ARA-M Locking is a proprietary feature that is specific to sysmocom’s fork of Bertrand Martel’s ARA-M
implementation. ARA-M Locking is supported in newer (2025) applet versions from v0.1.0 onward.
38 Chapter 1. Introduction
osmopysim-usermanual
get_data
Perform the GlobalPlatform GET DATA command in order to obtain some card-specific data.
Positional Arguments
get_status
Perform GlobalPlatform GET STATUS command in order to retrieve status information on Issuer Security Domain,
Executable Load File, Executable Module or Applications.
Positional Arguments
Named Arguments
set_status
Perform GlobalPlatform SET STATUS command in order to change the life cycle state of the Issuer Security Domain,
Supplementary Security Domain or Application. This normally requires prior authentication with a Secure Channel
Protocol.
Positional Arguments
1.1. pySim-shell 39
osmopysim-usermanual
Named Arguments
store_data
Perform the GlobalPlatform GET DATA command in order to store some card-specific data. See GlobalPlatform
CardSpecification v2.3Section 11.11 for details.
Positional Arguments
DATA
Named Arguments
put_key
Perform the GlobalPlatform PUT KEY command in order to store a new key on the card. See GlobalPlatform Card-
Specification v2.3 Section 11.8 for details.
˓→rsa_chines_remainder_q,rsa_chines_remainder_pq,rsa_chines_remainder_dpi,rsa_chines_
˓→remainder_dqi,ecc_public_key,ecc_private_key,ecc_field_parameter_p,ecc_field_parameter_
˓→a,ecc_field_parameter_b,ecc_field_parameter_g,ecc_field_parameter_n,ecc_field_
˓→parameter_k,ecc_key_parameters_reference,not_available}
Named Arguments
40 Chapter 1. Introduction
osmopysim-usermanual
delete_key
Perform GlobalPlaform DELETE (Key) command. If both KID and KVN are specified, exactly one key is deleted. If
only either of the two is specified, multiple matching keys may be deleted.
Named Arguments
load
Perform a GlobalPlatform LOAD command. (We currently only support loading without DAP and without ciphering.)
Named Arguments
1.1. pySim-shell 41
osmopysim-usermanual
install_cap
Perform a .cap file installation using GlobalPlatform LOAD and INSTALL commands.
[--install-parameters-non-volatile-memory-quota INSTALL_PARAMETERS_
˓→NON_VOLATILE_MEMORY_QUOTA]
[--install-parameters-stk INSTALL_PARAMETERS_STK]
FILE
Positional Arguments
Named Arguments
install_for_personalization
Perform GlobalPlatform INSTALL [for personalization] command in order to inform a Security Domain that the fol-
lowing STORE DATA commands are meant for a specific AID (specified here).
Positional Arguments
install_for_install
˓→verification,trusted_path,authorized_management,token_management,global_delete,global_
˓→lock,global_registry,final_application,global_service,receipt_generation,ciphered_load_
˓→file_data_block,contactless_activation,contactless_self_activation}]
42 Chapter 1. Introduction
osmopysim-usermanual
Named Arguments
install_for_load
Perform GlobalPlatform INSTALL [for load] command in order to prepare to load an application.
Named Arguments
1.1. pySim-shell 43
osmopysim-usermanual
delete_card_content
Perform a GlobalPlatform DELETE [card content] command in order to delete an Executable Load File, an Application
or an Executable Load File and its related Applications.
Positional Arguments
Named Arguments
--delete-related-objects Delete not only the object but also its related objects
Default: False
establish_scp02
Establish a secure channel using the GlobalPlatform SCP02 protocol. It can be released again by using release_scp.
Named Arguments
44 Chapter 1. Introduction
osmopysim-usermanual
establish_scp03
Establish a secure channel using the GlobalPlatform SCP03 protocol. It can be released again by using release_scp.
Named Arguments
release_scp
Release any previously established SCP (Secure Channel Protocol)
1.1. pySim-shell 45
osmopysim-usermanual
Example:
Once you are at this stage, you can issue the various eUICC related commands against the ISD-R application
es10x_store_data
Perform a raw STORE DATA command as defined for the ES10x eUICC interface.
Positional Arguments
get_euicc_configured_addresses
Obtain the configured SM-DP+ and/or SM-DS addresses using the ES10a GetEuiccConfiguredAddresses() function.
Example:
set_default_dp_address
Positional Arguments
46 Chapter 1. Introduction
osmopysim-usermanual
get_euicc_challenge
Obtain an authentication challenge from the eUICC using the ES10b GetEUICCChallenge() function.
Example:
get_euicc_info1
Obtain EUICC Information (1) from the eUICC using the ES10b GetEUICCCInfo() function.
Example:
get_euicc_info2
Obtain EUICC Information (2) from the eUICC using the ES10b GetEUICCCInfo() function.
Example:
1.1. pySim-shell 47
osmopysim-usermanual
˓→"
}
}
48 Chapter 1. Introduction
osmopysim-usermanual
list_notification
Obtain the list of notifications from the eUICC using the ES10b ListNotification() function.
Example:
remove_notification_from_list
Positional Arguments
get_profiles_info
Obtain information about the profiles present on the eUICC using the ES10c GetProfilesInfo() function.
Example:
1.1. pySim-shell 49
osmopysim-usermanual
enable_profile
Named Arguments
50 Chapter 1. Introduction
osmopysim-usermanual
disable_profile
Named Arguments
delete_profile
Named Arguments
euicc_memory_reset
Perform an ES10c eUICCMemoryReset function. This will permanently delete the selected subset of profiles from the
eUICC.
1.1. pySim-shell 51
osmopysim-usermanual
Named Arguments
get_eid
Obtain the EID of the eUICC using the ES10c GetEID() function.
Example:
set_nickname
Positional Arguments
Named Arguments
get_certs
Obtain the certificates from an IoT eUICC using the ES10c GetCerts() function.
get_eim_configuration_data
Obtain the eIM configuration data from an IoT eUICC using the ES10b GetEimConfigurationData() function.
52 Chapter 1. Introduction
osmopysim-usermanual
conserve_write
If enabled, pySim will (when asked to write to a card) always first read the respective file/record and verify if the to-be-
written value differs from the current on-card value. If not, the write will be skipped. Writes will only be performed if
the new value is different from the current on-card value.
If disabled, pySim will always write irrespective of the current/new value.
json_pretty_print
This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line output with indent
level of 4 spaces) or not.
The default value of this parameter is ‘true’.
debug
If enabled, full python back-traces will be displayed in case of exceptions
apdu_trace
Boolean variable that determines if a hex-dump of the command + response APDU shall be printed.
numeric_path
Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names.
1.2 pySim-trace
pySim-trace is a utility for high-level decode of APDU protocol traces such as those obtained with Osmocom SIMtrace2
or osmo-qcdiag.
pySim-trace leverages the existing knowledge of pySim-shell on anything related to SIM cards, including the struc-
ture/encoding of the various files on SIM/USIM/ISIM/HPSIM cards, and applies this to decoding protocol traces. This
means that it shows not only the name of the command (like READ BINARY), but actually understands what the
currently selected file is, and how to decode the contents of that file.
pySim-trace also understands the parameters passed to commands and how to decode them, for example of the AU-
THENTICATE command within the USIM/ISIM/HPSIM application.
1.2. pySim-trace 53
osmopysim-usermanual
1.2.1 Demo
To get an idea how pySim-trace usage looks like, you can watch the relevant part of the 11/2022 SIMtrace2 tutorial
whose recording is freely accessible.
./pySim-trace.py gsmtap-udp
This binds to the default UDP port 4729 (GSMTAP) on localhost (127.0.0.1), and decodes any APDUs received there.
1.3.1 pySim-prog
pySim-prog was the first part of the pySim software suite. It started as a tool to write ICCID, IMSI, MSISDN and Ki
to very simplistic SIM cards, and was later extended to a variety of other cards. As the number of features supported
became no longer bearable to express with command-line arguments, pySim-shell was created.
Basic use cases can still use pySim-prog.
54 Chapter 1. Introduction
osmopysim-usermanual
not all parameters are supported by all card types. In particular, very simple programmable SIM cards will only
support a very basic set of parameters, such as MCC, MNC, IMSI and KI values.
• one where the parameters are generated from a minimal set:
It is also possible to leave the generation of certain parameters to pySim-prog. This is in particular helpful when
a large number of cards should be initialized with randomly generated key material.
pySim-prog.py -p <pcsc_reader> --mcc <mcc_value> --mnc <mnc_value> --secret
<random_secret> --num <card_number> --pin-adm <adm_pin>
The parameter --secret specifies a random seed that is used to generate the card individual parameters. (IMSI).
The secret should contain enough randomness to avoid conflicts. It is also recommended to store the secret safely,
in case cards have to be re-generated or the current card batch has to be extended later. For security reasons, the
key material, which is also card individual, will not be derived from the random seed. Instead a new random
set of Ki and OPc will be generated during each programming cycle. This means fresh keys are generated, even
when the --num remains unchanged.
The parameter --num specifies a card individual number. This number will be manged into the random seed so
that it serves as an identifier for a particular set of randomly generated parameters.
In the example above the parameters --mcc, and --mnc are specified as well, since they identify the GSM
network where the cards should operate in, it is absolutely required to keep them static. pySim-prog will use
those parameters to generate a valid IMSI that thas the specified MCC/MNC at the beginning and a random tail.
Specifying the card type:
pySim-prog usually autodetects the card type. In case auto detection does not work, it is possible to specify the
parameter --type. The following card types are supported:
• Fairwaves-SIM
• fakemagicsim
• gialersim
• grcardsim
• magicsim
• OpenCells-SIM
• supersim
• sysmoISIM-SJA2
• sysmoISIM-SJA5
• sysmosim-gr1
• sysmoSIM-GR2
• sysmoUSIM-SJS1
• Wavemobile-SIM
Specifying the card reader:
It is most common to use pySim-prog together whith a PCSC reader. The PCSC reader number is specified via the
--pcsc-device or -p option. However, other reader types (such as serial readers and modems) are supported. Use
the --help option of pySim-prog for more information.
56 Chapter 1. Introduction
osmopysim-usermanual
"imsi","iccid","acc","ki","opc","adm1"
"999700000053010","8988211000000530108","0001","51ACE8BD6313C230F0BFE1A458928DF0",
˓→"E5A00E8DE427E21B206526B5D1B902DF","65942330"
"999700000053011","8988211000000530116","0002","746AAFD7F13CFED3AE626B770E53E860",
˓→"38F7CE8322D2A7417E0BBD1D7B1190EC","13445792"
"999700123053012","8988211000000530124","0004","D0DA4B7B150026ADC966DC637B26429C",
˓→"144FD3AEAC208DFFF4E2140859BAE8EC","53540383"
"999700000053013","8988211000000530132","0008","52E59240ABAC6F53FF5778715C5CE70E",
˓→"D9C988550DC70B95F40342298EB84C5E","26151368"
"999700000053014","8988211000000530140","0010","3B4B83CB9C5F3A0B41EBD17E7D96F324",
˓→"D61DCC160E3B91F284979552CC5B4D9F","64088605"
"999700000053015","8988211000000530157","0020","D673DAB320D81039B025263610C2BBB3",
˓→"4BCE1458936B338067989A06E5327139","94108841"
"999700000053016","8988211000000530165","0040","89DE5ACB76E06D14B0F5D5CD3594E2B1",
˓→"411C4B8273FD7607E1885E59F0831906","55184287"
"999700000053017","8988211000000530173","0080","977852F7CEE83233F02E69E211626DE1",
˓→"2EC35D48DBF2A99C07D4361F19EF338F","70284674"
The following commandline will instruct pySim-prog to use the provided CSV file as parameter source and the ICCID
(read from the card before programming) as a key to identify the card. To use the IMSI as a key, the parameter
--read-imsi can be used instead of --read-iccid. However, this option is only recommended to be used in very
specific corner cases.
pySim-prog.py -p <pcsc_reader> --read-csv <path_to_csv_file> --source csv --read-iccid
It is also possible to pick a row from the CSV file by manually providing an ICCID (option --iccid) or an IMSI
(option --imsi) that is then used as a key to find the matching row in the CSV file.
pySim-prog.py -p <pcsc_reader> --read-csv <path_to_csv_file> --source csv --iccid
<iccid_value>
Batch programming
In case larger card batches need to be programmed, it is possible to use the --batch parameter to run pySim-prog in
batch mode.
The batch mode will prompt the user to insert a card. Once a card is detected in the reader, the programming is carried
out. The user may then remove the card again and the process starts over. This allows for a quick and efficient card
programming without permanent commandline interaction.
1.3.2 pySim-read
pySim-read allows to read some of the most important data items from a SIM card. This means it will only read some
files of the card, and will only read files accessible to a normal user (without any special authentication)
These days, it is recommended to use the export command of pySim-shell instead. It performs a much more
comprehensive export of all of the [standard] files that can be found on the card. To get a human-readable decode
instead of the raw hex export, you can use export --json.
Specifically, pySim-read will dump the following:
• MF
• EF.ICCID
• DF.GSM
• EF,IMSI
• EF.GID1
• EF.GID2
• EF.SMSP
• EF.SPN
• EF.PLMNsel
• EF.PLMNwAcT
• EF.OPLMNwAcT
• EF.HPLMNAcT
• EF.ACC
• EF.MSISDN
• EF.AD
• EF.SST
• ADF.USIM
• EF.EHPLMN
• EF.UST
• EF.ePDGId
• EF.ePDGSelection
• ADF.ISIM
• EF.PCSCF
• EF.DOMAIN
58 Chapter 1. Introduction
osmopysim-usermanual
• EF.IMPI
• EF.IMPU
• EF.UICCIARI
• EF.IST
pySim-read usage
Named Arguments
Serial Reader
Use a simple/ultra-low-cost serial reader attached to a (physical or USB/virtual) RS232 port. This doesn’t work with
all RS232-attached smart card readers, only with the very primitive readers following the ancient Phoenix or Smart
Mouse design.
-d, --device Serial Device for SIM access
Default: “/dev/ttyUSB0”
-b, --baud Baud rate used for SIM access
Default: 9600
PC/SC Reader
Use a PC/SC card reader to talk to the SIM card. PC/SC is a standard API for how applications access smart card
readers, and is available on a variety of operating systems, such as Microsoft Windows, MacOS X and Linux. Most
vendors of smart card readers provide drivers that offer a PC/SC interface, if not even a generic USB CCID driver is
used. You can use a tool like pcsc_scan -r to obtain a list of readers available on your system.
--pcsc-shared Open PC/SC reaer in SHARED access (default: EXCLUSIVE)
Default: False
-p, --pcsc-device Number of PC/SC reader to use for SIM access
--pcsc-regex Regex matching PC/SC reader to use for SIM access
Talk to a SIM Card inside a mobile phone or cellular modem which is attached to this computer and offers an AT
command interface including the AT+CSIM interface for Generic SIM access as specified in 3GPP TS 27.007.
--modem-device Serial port of modem for Generic SIM Access (3GPP TS 27.007)
OsmocomBB Reader
Use an OsmocomBB compatible phone to access the SIM inserted to the phone SIM slot. This will require you to run
the OsmocomBB firmware inside the phone (can be ram-loaded). It also requires that you run the osmocon program,
which provides a unix domain socket to which this reader driver can attach.
--osmocon Socket path for Calypso (e.g. Motorola C1XX) based reader (via OsmocomBB)
1.4 pySim-smpp2sim
This is a program to emulate the entire communication path SMSC-CN-RAN-ME that is usually between an OTA
backend and the SIM card. This allows to play with SIM OTA technology without using a mobile network or even a
mobile phone.
An external application can act as SMPP ESME and must encode (and encrypt/sign) the OTA SMS and submit them
via SMPP to this program, just like it would submit it normally to a SMSC (SMS Service Centre). The program then
re-formats the SMPP-SUBMIT into a SMS DELIVER TPDU and passes it via an ENVELOPE APDU to the SIM card
that is locally inserted into a smart card reader.
The path from SIM to external OTA application works the opposite way.
The default SMPP system_id is test. Likewise, the default SMPP password is test
Named Arguments
--apdu-trace Trace the command/response APDUs exchanged with the card
Default: False
Serial Reader
Use a simple/ultra-low-cost serial reader attached to a (physical or USB/virtual) RS232 port. This doesn’t work with
all RS232-attached smart card readers, only with the very primitive readers following the ancient Phoenix or Smart
Mouse design.
-d, --device Serial Device for SIM access
Default: “/dev/ttyUSB0”
-b, --baud Baud rate used for SIM access
Default: 9600
60 Chapter 1. Introduction
osmopysim-usermanual
PC/SC Reader
Use a PC/SC card reader to talk to the SIM card. PC/SC is a standard API for how applications access smart card
readers, and is available on a variety of operating systems, such as Microsoft Windows, MacOS X and Linux. Most
vendors of smart card readers provide drivers that offer a PC/SC interface, if not even a generic USB CCID driver is
used. You can use a tool like pcsc_scan -r to obtain a list of readers available on your system.
--pcsc-shared Open PC/SC reaer in SHARED access (default: EXCLUSIVE)
Default: False
-p, --pcsc-device Number of PC/SC reader to use for SIM access
--pcsc-regex Regex matching PC/SC reader to use for SIM access
OsmocomBB Reader
Use an OsmocomBB compatible phone to access the SIM inserted to the phone SIM slot. This will require you to run
the OsmocomBB firmware inside the phone (can be ram-loaded). It also requires that you run the osmocon program,
which provides a unix domain socket to which this reader driver can attach.
--osmocon Socket path for Calypso (e.g. Motorola C1XX) based reader (via OsmocomBB)
SMPP Options
--smpp-bind-port TCP Port to bind the SMPP socket to
Default: 2775
--smpp-bind-ip IPv4/IPv6 address to bind the SMPP socket to
Default: “::”
--smpp-system-id SMPP System-ID used by ESME to bind
Default: “test”
--smpp-password SMPP Password used by ESME to bind
Default: “test”
Using reader PCSC[HID Global OMNIKEY 3x21 Smart Card Reader [OMNIKEY 3x21 Smart Card␣
˓→Reader] 00 00]
The application has hence bound to local TCP port 2775 and expects your SMS-sending applications to send their SMS
there. Once you do, you will see log output like below:
1.4. pySim-smpp2sim 61
osmopysim-usermanual
And once your external program is sending SMS to the simulated SMSC, it will log something like
˓→xfa(\xa5\xba\xc6\x9d<^\x9d\xf2\xc7\x15]\xfd\xdeD\x9c\x82k#b\x15Ve0x{0\xe8\xbe]")
˓→'400290217ff6227052000000002d02700000281516191212b0000127fa28a5bac69d3c5e9df2c7155dfdde449c826b2362155
˓→'}))
62 Chapter 1. Introduction
osmopysim-usermanual
do_delete_all(opts)
Delete all data from a BER-TLV EF
do_delete_data(opts)
Delete data for a given tag in a BER-TLV EF
do_retrieve_data(opts)
Retrieve (Read) data from a BER-TLV EF
do_retrieve_tags(_opts)
List tags available in a given BER-TLV EF
do_set_data(opts)
Set (Write) data for a given tag in a BER-TLV EF
static export(as_json: bool, lchan)
Export the file contents of a BerTlvEF. This method returns a shell command string (See also ShellCom-
mand definition in this class) that can be used to write the file contents back.
class pySim.filesystem.CardADF(aid: str, has_fs: bool = False, **kwargs)
ADF (Application Dedicated File) in the smart card filesystem
Parameters
• fid – File Identifier (4 hex digits)
• sfid – Short File Identifier (2 hex digits, optional)
• name – Brief name of the file, like EF_ICCID
• desc – Description of the file
• parent – Parent CardFile object within filesystem hierarchy
• profile – Card profile that this file should be part of
• service – Service (SST/UST/IST) associated with the file
static export(as_json: bool, lchan)
Export application specific parameters that are not part of the UICC filesystem.
class pySim.filesystem.CardApplication(name, adf: CardADF | None = None, aid: str = None, sw: dict =
None)
A card application is represented by an ADF (with contained hierarchy) and optionally some SW definitions.
Parameters
• adf – ADF name
• sw – Dict of status word conversions
static export(as_json: bool, lchan)
Export application specific parameters, in the form of commandline script. (see also comment in the export
method of class “CardFile”)
interpret_sw(sw)
Interpret a given status word within the application.
Parameters
sw – Status word as string of 4 hex digits
Returns
Tuple of two strings
class pySim.filesystem.CardDF(**kwargs)
DF (Dedicated File) in the smart card filesystem. Those are basically sub-directories.
Parameters
• fid – File Identifier (4 hex digits)
• sfid – Short File Identifier (2 hex digits, optional)
• name – Brief name of the file, like EF_ICCID
• desc – Description of the file
• parent – Parent CardFile object within filesystem hierarchy
• profile – Card profile that this file should be part of
• service – Service (SST/UST/IST) associated with the file
class ShellCommands
64 Chapter 1. Introduction
osmopysim-usermanual
fully_qualified_path_fobj() → List[CardFile]
Return fully qualified path to file as list of CardFile instance references.
fully_qualified_path_str(prefer_name: bool = True) → str
Return fully qualified path to file as string.
Parameters
prefer_name – Preferably build path of names; fall-back to FIDs as required
get_mf() → CardMF | None
Return the MF (root) of the file system.
get_profile()
Get the profile associated with this file. If this file does not have any profile assigned, try to find a file above
(usually the MF) in the filesystem hirarchy that has a profile assigned
get_selectable_names(flags=[]) → List[str]
Return a dict of {‘identifier’: File} that is selectable from the current file.
Parameters
flags – Specify which selectables to return ‘FIDS’ and/or ‘NAMES’; If not specified, all
selectables will be returned.
Returns
list containing all selectable names.
get_selectables(flags=[]) → Dict[str, CardFile]
Return a dict of {‘identifier’: File} that is selectable from the current file.
Parameters
flags – Specify which selectables to return ‘FIDS’ and/or ‘NAMES’; If not specified, all
selectables will be returned.
Returns
dict containing all selectable items. Key is identifier (string), value a reference to a CardFile
(or derived class) instance.
should_exist_for_services(services: List[int])
Assuming the provided list of activated services, should this file exist and be activated?.
class pySim.filesystem.CardMF(**kwargs)
MF (Master File) in the smart card filesystem
Parameters
• fid – File Identifier (4 hex digits)
• sfid – Short File Identifier (2 hex digits, optional)
• name – Brief name of the file, like EF_ICCID
• desc – Description of the file
• parent – Parent CardFile object within filesystem hierarchy
• profile – Card profile that this file should be part of
• service – Service (SST/UST/IST) associated with the file
add_application_df(app: CardADF)
Add an Application to the MF
66 Chapter 1. Introduction
osmopysim-usermanual
68 Chapter 1. Introduction
osmopysim-usermanual
relative_to_mf() → Path
Return a path relative to MF, i.e. without initial explicit MF.
class pySim.filesystem.TransRecEF(fid: str, rec_len: int, sfid: str = None, name: str = None, desc: str =
None, parent: CardDF | None = None, size: Tuple[int, int | None] = (1,
None), **kwargs)
Transparent EF (Entry File) containing fixed-size records.
These are the real odd-balls and mostly look like mistakes in the specification: Specified as ‘transparent’ EF, but
actually containing several fixed-length records inside. We add a special class for those, so the user only has to
provide encoder/decoder functions for a record, while this class takes care of split / merge of records.
Parameters
• fid – File Identifier (4 hex digits)
• sfid – Short File Identifier (2 hex digits, optional)
• name – Brief name of the file, like EF_ICCID
• desc – Description of the file
• parent – Parent CardFile object within filesystem hierarchy
• rec_len – Length of the fixed-length records within transparent EF
• size – tuple of (minimum_size, recommended_size)
decode_record_bin(raw_bin_data: bytearray) → dict
Decode raw (binary) data into abstract representation.
A derived class would typically provide a _decode_record_bin() or _decode_record_hex() method for im-
plementing this specifically for the given file. This function checks which of the method exists, add calls
them (with conversion, as needed).
Parameters
raw_bin_data – binary encoded data
Returns
abstract_data; dict representing the decoded data
decode_record_hex(raw_hex_data: str) → dict
Decode raw (hex string) data into abstract representation.
A derived class would typically provide a _decode_record_bin() or _decode_record_hex() method for im-
plementing this specifically for the given file. This function checks which of the method exists, add calls
them (with conversion, as needed).
Parameters
raw_hex_data – hex-encoded data
Returns
abstract_data; dict representing the decoded data
encode_record_bin(abstract_data: dict, total_len: int | None = None) → bytearray
Encode abstract representation into raw (binary) data.
A derived class would typically provide an _encode_record_bin() or _encode_record_hex() method for
implementing this specifically for the given file. This function checks which of the method exists, add calls
them (with conversion, as needed).
Parameters
• abstract_data – dict representing the decoded data
70 Chapter 1. Introduction
osmopysim-usermanual
72 Chapter 1. Introduction
osmopysim-usermanual
74 Chapter 1. Introduction
osmopysim-usermanual
76 Chapter 1. Introduction
osmopysim-usermanual
78 Chapter 1. Introduction
osmopysim-usermanual
80 Chapter 1. Introduction
osmopysim-usermanual
PC/SC transport
PC/SC is the standard API for accessing smart card interfaces on all major operating systems, including the MS Win-
dows Family, OS X as well as Linux / Unix OSs.
class pySim.transport.pcsc.PcscSimLink(opts: Namespace = Namespace(pcsc_dev=0), **kwargs)
pySim: PCSC reader transport link.
connect()
Connect to a card immediately
disconnect()
Disconnect from card
get_atr() → Hexstr
Retrieve card ATR
Serial/UART transport
This transport implements interfacing smart cards via very simplistic UART readers. These readers basically wire
together the Rx+Tx pins of a RS232 UART, provide a fixed crystal oscillator for clock, and operate the UART at 9600
bps. These readers are sometimes called Phoenix.
class pySim.transport.serial.SerialSimLink(opts=Namespace(device='/dev/ttyUSB0', baudrate=9600),
rst: str = '-rts', debug: bool = False, **kwargs)
pySim: Transport Link for serial (RS232) based readers included with simcard
connect()
Connect to a card immediately
disconnect()
Disconnect from card
get_atr() → Hexstr
Retrieve card ATR
send_tpdu(tpdu: Hexstr) → Tuple[Hexstr, SwHexstr]
Implementation specific method for sending the resulting TPDU. This method must accept TPDUs as de-
fined in ETSI TS 102 221, section 7.3.1 and 7.3.2, depending on the protocol selected.
wait_for_card(timeout: int | None = None, newcardonly: bool = False)
Wait for a card and connect to it
Parameters
• timeout – Maximum wait time in seconds (None=no timeout)
• newcardonly – Should we wait for a new card, or an already inserted one ?
82 Chapter 1. Introduction
osmopysim-usermanual
class pySim.utils.DataObject(name: str, desc: str | None = None, tag: int | None = None)
A DataObject (DO) in the sense of ISO 7816-4. Contrary to ‘normal’ TLVs where one simply has any number
of different TLVs that may occur in any order at any point, ISO 7816 has the habit of specifying TLV data but
with very spcific ordering, or specific choices of tags at specific points in a stream. This class tries to represent
this.
Parameters
• name – A brief, all-lowercase, underscore separated string identifier
• desc – A human-readable description of what this DO represents
• tag – The tag associated with this DO
decode(binary: bytes) → Tuple[dict, bytes]
Decode a single DOs from the input data. :param binary: binary bytes of encoded data
Returns
tuple of (decoded_result, binary_remainder)
abstractmethod from_bytes(do: bytes)
Parse the value part of the DO into the internal state of this instance. :param do: binary encoded bytes
from_tlv(do: bytes) → bytes
Parse binary TLV representation into internal state. The resulting decoded representation is _not_ returned,
but just internalized in the object instance! :param do: input bytes containing TLV-encoded representation
Returns
bytes remaining at end of ‘do’ after parsing one TLV/DO.
abstractmethod to_bytes() → bytes
Encode the internal state of this instance into the TLV value part. :returns: binary bytes encoding the
internal state
to_dict() → dict
Return a dict in form “name: decoded_value”
to_tlv() → bytes
Encode internal representation to binary TLV. :returns: bytes encoded in TLV format.
class pySim.utils.DataObjectChoice(name: str, desc: str | None = None, members=None)
One Data Object from within a choice, identified by its tag. This means that exactly one member of the choice
must occur, and which one occurs depends on the tag.
decode(binary: bytes) → Tuple[dict, bytes]
Decode a single DOs from the choice based on the tag. :param binary: binary bytes of encoded data
Returns
tuple of (decoded_result, binary_remainder)
class pySim.utils.DataObjectCollection(name: str, desc: str | None = None, members=None)
A DataObjectCollection consits of multiple Data Objects identified by their tags. A given encoded DO may
contain any of them in any order, and may contain multiple instances of each DO.
decode(binary: bytes) → Tuple[List, bytes]
Decode any number of DOs from the collection until the end of the input data, or uninitialized memory
(0xFF) is found. :param binary: binary bytes of encoded data
Returns
tuple of (decoded_result, binary_remainder)
84 Chapter 1. Introduction
osmopysim-usermanual
Parameters
• hexstring – hexstring to expand
• length – desired length of the resulting hexstring.
Returns
expanded hexstring
pySim.utils.get_addr_type(addr)
Validates the given address and returns it’s type (FQDN or IPv4 or IPv6) Return: 0x00 (FQDN), 0x01 (IPv4),
0x02 (IPv6), None (Bad address argument given)
TODO: Handle IPv6
pySim.utils.mcc_from_imsi(imsi: str) → str | None
Derive the MCC (Mobile Country Code) from the first three digits of an IMSI
pySim.utils.mnc_from_imsi(imsi: str, long: bool = False) → str | None
Derive the MNC (Mobile Country Code) from the 4th to 6th digit of an IMSI
pySim.utils.parse_command_apdu(apdu: bytes) → int
Parse a given command APDU and return case (see also ISO/IEC 7816-3, Table 12 and Figure 26), lc, le and the
data field.
Parameters
apdu – hexstring that contains the command APDU
Returns
tuple containing case, lc and le values of the APDU (case, lc, le, data)
pySim.utils.sanitize_pin_adm(pin_adm, pin_adm_hex=None) → Hexstr
The ADM pin can be supplied either in its hexadecimal form or as ascii string. This function checks the supplied
opts parameter and returns the pin_adm as hex encoded string, regardless in which form it was originally supplied
by the user
pySim.utils.sw_match(sw: str, pattern: str) → bool
Match given SW against given pattern.
pySim.utils.tabulate_str_list(str_list, width: int = 79, hspace: int = 2, lspace: int = 1, align_left: bool =
True) → str
Pretty print a list of strings into a tabulated form.
Parameters
• width – total width in characters per line
• space – horizontal space between cells
• lspace – number of spaces before row
• align_lef – Align text to the left side
Returns
multi-line string containing formatted table
pySim.utils.verify_luhn(digits: str)
Verify the Luhn check digit; raises ValueError if it is incorrect.
86 Chapter 1. Introduction
osmopysim-usermanual
error()
Method called when pySim failed to program a card. Move card to ‘bad’ batch.
get(first: bool = False)
Method called when pySim needs a new card to be inserted.
Parameters
first – set to true when the get method is called the first time. This is required to prevent
blocking when a card is already inserted into the reader. The reader API would not recognize
that card as “new card” until it would be removed and re-inserted again.
88 Chapter 1. Introduction
osmopysim-usermanual
pySim.esim.es2p
GSMA eSIM RSP ES2+ interface according to SGP.22 v2.5
class pySim.esim.es2p.CancelOrder(url_prefix: str, func_req_id: str | None, session: Session)
pySim.esim.es8p
Implementation of GSMA eSIM RSP (Remote SIM Provisioning) ES8+ as per SGP22 v3.0 Section 5.5
class pySim.esim.es8p.BoundProfilePackage(metadata: ProfileMetadata | None = None)
Representing a bound profile package (BPP) as defined in SGP.22 Section 2.5.4
decode(euicc_ot, eid: str, bpp_bin: bytes)
Decode a BPP into the PPP and subsequently UPP. This is what happens inside an eUICC.
encode(ss: RspSessionState, dp_pb: CertAndPrivkey) → bytes
Generate a bound profile package (SGP.22 2.5.4).
class pySim.esim.es8p.ProfileMetadata(iccid_bin: bytes, spn: str, profile_name: str)
Representation of Profile metadata. Right now only the mandatory bits are supported, but in general this should
follow the StoreMetadataRequest of SGP.22 5.5.3
add_notification(event: str, address: str)
Add an ‘other’ notification to the notification configuration of the metadata
gen_store_metadata_request() → bytes
Generate encoded (but unsigned) StoreMetadataRequest DO (SGP.22 5.5.3)
set_icon(is_png: bool, icon_data: bytes)
Set the icon that is part of the metadata.
class pySim.esim.es8p.ProtectedProfilePackage(metadata: ProfileMetadata | None = None)
Representing a protected profile package (PPP) as defined in SGP.22 Section 2.5.3
90 Chapter 1. Introduction
osmopysim-usermanual
pySim.esim.es9p
GSMA eSIM RSP ES9+ interface according ot SGP.22 v2.5
class pySim.esim.es9p.AuthenticateClient(url_prefix: str, func_req_id: str | None, session: Session)
pySim.esim.http_json_api
GSMA eSIM RSP HTTP/REST/JSON interface according to SGP.22 v2.5
exception pySim.esim.http_json_api.ApiError(func_ex_status: dict)
Exception representing an error at the API level (status != Executed).
class pySim.esim.http_json_api.ApiParam
A class representing a single parameter in the API.
classmethod decode(data)
[Validate and] Decode the given value.
classmethod encode(data)
[Validate and] Encode the given value.
classmethod verify_decoded(data)
Verify the decoded representation of a value. Should raise an exception if something is odd.
classmethod verify_encoded(data)
Verify the encoded representation of a value. Should raise an exception if something is odd.
class pySim.esim.http_json_api.ApiParamBase64
class pySim.esim.http_json_api.ApiParamBoolean
Base class representing an API parameter of ‘boolean’ type.
92 Chapter 1. Introduction
osmopysim-usermanual
class pySim.esim.http_json_api.ApiParamFqdn
String, as a list of domain labels concatenated using the full stop (dot, period) character as separator between
labels. Labels are restricted to the Alphanumeric mode character set defined in table 5 of ISO/IEC 18004
classmethod verify_encoded(data)
Verify the encoded representation of a value. Should raise an exception if something is odd.
class pySim.esim.http_json_api.ApiParamInteger
Base class representing an API parameter of ‘integer’ type.
classmethod verify_decoded(data)
Verify the decoded representation of a value. Should raise an exception if something is odd.
classmethod verify_encoded(data)
Verify the encoded representation of a value. Should raise an exception if something is odd.
class pySim.esim.http_json_api.ApiParamString
Base class representing an API parameter of ‘string’ type.
exception pySim.esim.http_json_api.HttpHeaderError
exception pySim.esim.http_json_api.HttpStatusError
pySim.esim.x509_cert
Implementation of X.509 certificate handling in GSMA eSIM as per SGP22 v3.0
class pySim.esim.x509_cert.CertAndPrivkey(required_policy_oid: ObjectIdentifier | None = None, cert:
Certificate | None = None, priv_key=None)
A pair of certificate and private key, as used for ECDSA signing.
ecdsa_sign(plaintext: bytes) → bytes
Sign some input-data using an ECDSA signature compliant with SGP.22, which internally refers to Global
Platform 2.2 Annex E, which in turn points to BSI TS-03111 which states “concatenated raw R + S values”.
get_authority_key_identifier() → AuthorityKeyIdentifier
Return the AuthorityKeyIdentifier X.509 extension of the certificate.
get_cert_as_der() → bytes
Return certificate encoded as DER.
get_subject_alt_name() → SubjectAlternativeName
Return the SubjectAlternativeName X.509 extension of the certificate.
class pySim.esim.x509_cert.CertificateSet(root_cert: Certificate)
A set of certificates consisting of a trusted [self-signed] CA root certificate, and an optional number of interme-
diate certificates. Can be used to verify the certificate chain of any given other certificate.
add_intermediate_cert(cert: Certificate)
Add a potential intermediate certificate to the CertificateSet.
verify_cert_chain(cert: Certificate, max_depth: int = 100)
Verify if a given certificate’s signature chain can be traced back to the root CA of this CertificateSet.
exception pySim.esim.x509_cert.VerifyError
An error during certificate verification,
pySim.esim.x509_cert.cert_get_auth_key_id(cert: Certificate) → bytes
Obtain the authority key identifier of the given cert object (as raw bytes).
pySim.esim.x509_cert.cert_get_subject_key_id(cert: Certificate) → bytes
Obtain the subject key identifier of the given cert object (as raw bytes).
pySim.esim.x509_cert.cert_policy_has_oid(cert: Certificate, match_oid: ObjectIdentifier) → bool
Determine if given certificate has a certificatePolicy extension of matching OID.
pySim.esim.x509_cert.check_signed(signed: Certificate, signer: Certificate) → bool
Verify if ‘signed’ certificate was signed using ‘signer’.
pySim.esim.x509_cert.ecdsa_dss_to_tr03111(sig: bytes) → bytes
convert from DER format to BSI TR-03111; first get long integers; then convert those to bytes.
94 Chapter 1. Introduction
osmopysim-usermanual
expand_fill_pattern() → bytes
Expand the fill/repeat pattern as per TS 102 222 Section 6.3.2.2.2
file_content_from_tuples(l: List[Tuple]) → bytes | None
linearize a list of fillFileContent / fillFileOffset tuples into a stream of bytes.
property file_size: int | None
Return the size of the file in bytes.
from_fileDescriptor(fileDescriptor: dict)
Convert from ‘fileDescriptor’ as used by asn1tools for SAIP to internal representation
from_template(template: FileTemplate)
Determine defaults for file based on given FileTemplate.
from_tuples(l: List[Tuple])
Parse a list of fileDescriptor, fillFileContent, fillFileOffset tuples into this instance.
static get_tuplelist_item(l: List[Tuple], key: str)
get the [first] value matching given key from a list of (key, value) tuples.
static path_from_gfm(bin_path: bytes)
convert from byte-array of 16bit FIDs to list of integers
static path_to_gfm(path: List[int]) → bytes
convert from list of 16bit integers to byte-array
to_fileDescriptor() → dict
Convert from internal representation to ‘fileDescriptor’ as used by asn1tools for SAIP
to_gfm() → List[Tuple]
Generate a list of filePath, createFCP, fillFileContent, fillFileOffset tuples into this instance.
to_tuples() → List[Tuple]
Generate a list of fileDescriptor, fillFileContent, fillFileOffset tuples into this instance.
class pySim.esim.saip.FsNode(fid: int, parent: FsNode | None, file: File | None = None, name: str | None =
None)
A node in the filesystem hierarchy.
property fid_path: List[int]
Return the path of the node as list of integers.
property mf: FsNodeMF
Return the MF (root) of the hierarchy.
property name_path: List[str]
Return the path of the node as list of integers.
walk(fn, **kwargs)
call ‘fn(self, **kwargs) for the File.
class pySim.esim.saip.FsNodeADF(df_name: Hexstr, fid: int | None = None, parent: FsNodeDF | None =
None, file: File | None = None, name: str | None = None)
An ADF (Application Dedicated File) in the filesystem hierarchy.
class pySim.esim.saip.FsNodeDF(fid: int, parent: FsNodeDf , file: File | None = None, name: str | None =
None)
A DF (Dedicated File) in the filesystem hierarchy.
add_child(child: FsNode)
Add a child to the list of children of this DF.
add_file(file: File) → FsNodeDF
Create and link an appropriate FsNode for the given ‘file’ and insert it. Returns the new current DF (it
might have changed).
lookup_by_fidpath(path: List[int]) → FsNode
Look-up a FsNode based on the [fid baesd] given (absolute) path.
lookup_by_path(path: Path) → FsNode
Look-up a FsNode based on the [name based] given (absolute) path.
walk(fn, **kwargs)
call ‘fn(self, **kwargs) for the DF and recursively for all children.
class pySim.esim.saip.FsNodeEF(fid: int, parent: FsNode | None, file: File | None = None, name: str | None =
None)
An EF (Entry File) in the filesystem hierarchy.
class pySim.esim.saip.FsNodeMF(file: File | None = None)
The MF (Master File) in the filesystem hierarchy.
class pySim.esim.saip.FsProfileElement(decoded=None, mandated: bool = True, **kwargs)
A file-system bearing profile element, like MF, USIM, . . . .
We keep two major representations of the data: * The “decoded” member, as introduced by our parent class,
containing asn1tools syntax * the “files” dict, consisting of File values indexed by PE-name strings
The methods pe2files and files2pe convert between those two representations.
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
add_file(file: File)
Add a File to the ProfileElement.
create_file(pename: str) → File
Programatically create a file by its PE-Name.
file_template_for_path(path: Path, adf: str | None = None) → FileTemplate | None
Resolve the FileTemplate for given path, if we have any matching.
Parameters
• path – the path for which we would like to resolve the FileTemplate
• adf – string name of the ADF which might be used with this PE
96 Chapter 1. Introduction
osmopysim-usermanual
files2pe()
Update the “decoded” member with the contents of the “files” member.
pe2files()
Update the “files” member with the contents of the “decoded” member.
supports_file_for_path(path: Path, adf: str | None = None) → bool
Does this ProfileElement support a file of given path?
class pySim.esim.saip.Naa
A class defining a Network Access Application (NAA)
class pySim.esim.saip.NaaCsim
A class representing the CSIM (CDMA) Network Access Application (NAA)
class pySim.esim.saip.NaaIsim
A class representing the ISIM Network Access Application (NAA)
class pySim.esim.saip.NaaUsim
A class representing the USIM Network Access Application (NAA)
class pySim.esim.saip.ProfileElement(decoded=None, mandated: bool = True, pe_sequence:
ProfileElementSequence | None = None)
Generic Class representing a Profile Element (PE) within a SAIP Profile. This may be used directly, but ist
more likely sub-classed with a specific class for the specific profile element type, like e.g ProfileElementHeader,
ProfileElementMF, . . .
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
classmethod class_for_petype(pe_type: str) → ProfileElement | None
Return the subclass implementing the given pe-type string.
classmethod from_der(der: bytes, pe_sequence: ProfileElementSequence | None = None) →
ProfileElement
Construct an instance from given raw, DER encoded bytes.
Parameters
• der – raw, DER-encoded bytes of a single PE
• pe_sequence – back-reference to the PE-Sequence of which this PE is part of
property header
The decoded ProfileHeader.
property header_name: str
Return the name of the header field within the profile element.
property identification
An unique number for the PE within the PE-Sequence.
Type
The identification value
property templateID
Return the decoded templateID used by this profile element (if any).
to_der() → bytes
Build an encoded DER representation of the instance.
class pySim.esim.saip.ProfileElementAKA(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for Authentication and Key Agreement (AKA).
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
set_mapping(aid: bytes, options: int = 6)
Configure akaParametes for a mapping from another AID.
set_milenage(k: bytes, opc: bytes)
Configure akaParametes for MILENAGE.
set_tuak(k: bytes, topc: bytes, num_of_keccak: int = 1)
Configure akaParametes for TUAK.
set_xor3g(k: bytes)
Configure akaParametes for XOR-3G.
class pySim.esim.saip.ProfileElementApplication(decoded: dict | None = None, **kwargs)
Class representing an application ProfileElement.
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
add_instance(aid: Hexstr, class_aid: Hexstr, inst_aid: Hexstr, app_privileges: Hexstr, app_spec_pars:
Hexstr, uicc_toolkit_app_spec_pars: Hexstr = None, uicc_access_app_spec_pars: Hexstr =
None, uicc_adm_access_app_spec_pars: Hexstr = None, volatile_memory_quota: Hexstr =
None, non_volatile_memory_quota: Hexstr = None, process_data: list[Hexstr] = None)
Create a new instance and add it to the instanceList
98 Chapter 1. Introduction
osmopysim-usermanual
classmethod from_file(filename: str, aid: Hexstr, sd_aid: Hexstr = None, non_volatile_code_limit: int =
None, volatile_data_limit: int = None, non_volatile_data_limit: int = None,
hash_value: Hexstr = None) → ProfileElementApplication
Fill contents of application ProfileElement from a .cap file.
remove_instance(inst_aid: Hexstr)
Remove an instance from the instanceList
to_file(filename: str)
Write loadBlockObject contents of application ProfileElement to a .cap or .ijc file.
class pySim.esim.saip.ProfileElementCD(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for DF.CD
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class pySim.esim.saip.ProfileElementDf5GProSe(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for DF.5GProSe
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class pySim.esim.saip.ProfileElementDf5GS(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for ADF.USIM/DF.5GS
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class pySim.esim.saip.ProfileElementDfSAIP(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for DF.SAIP
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
files2pe()
Update the “decoded” member from the “files” member.
pe2files()
Update the “files” member with the contents of the “decoded” member.
supports_file_for_path(path: Path, adf: str | None = None) → bool
Does this ProfileElement support a file of given path?
class pySim.esim.saip.ProfileElementGsmAccess(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for ADF.USIM/DF.GSM-ACCESS
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class pySim.esim.saip.ProfileElementHeader(decoded: dict | None = None, ver_major: int | None = 2,
ver_minor: int | None = 3, iccid: Hexstr | None =
'00000000000000000000', profile_type: str | None = None,
**kwargs)
Class representing the ProfileElement for the Header of the PE-Sequence.
You would usually initialize an instance either with a “decoded” argument (as read from a DER-encoded SAIP
file via asn1tools), or [some of] the othe arguments in case you’re constructing a Profile Header from scratch.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• ver_major – Major SAIP version
• ver_minor – Minor SAIP version
• iccid – ICCID of the profile
• profile_type – operational, testing or bootstrap
class pySim.esim.saip.ProfileElementISIM(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for ADF.ISIM Mandatory Files
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
add_pin(key_ref: int, pin_value: bytes, max_attempts: int = 3, retries_left: int = 3, unblock_ref: int | None =
None, pin_attrib: int = 7)
Add a PIN to the pinCodes ProfileElement
class pySim.esim.saip.ProfileElementPuk(decoded: dict | None = None, **kwargs)
Class representing the ProfileElement for a PUK (PIN Unblocking Code)
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
add_puk(key_ref: int, puk_value: bytes, max_attempts: int = 10, retries_left: int = 10)
Add a PUK to the pukCodes ProfileElement
class pySim.esim.saip.ProfileElementRFM(decoded: dict | None = None, inst_aid: bytes | None = None,
sd_aid: bytes | None = None, adf_aid: bytes | None = None,
tar_list: List[bytes] | None = [], msl: int | None = 6, **kwargs)
Class representing the ProfileElement for RFM (Remote File Management).
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class pySim.esim.saip.ProfileElementSD(decoded: dict | None = None, **kwargs)
Class representing a securityDomain ProfileElement.
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class C9(**kwargs)
nested_collection_cls
alias of UiccSdInstallParams
add_key(key: SecurityDomainKey)
Add a given SecurityDomainKey to the keyList of the securityDomain.
add_scp(scp: int, i: int)
Add given SCP (and i parameter) to list of SCP of the Security Domain Install Params. Example:
add_scp(0x03, 0x70) for SCP03, or add_scp(0x02, 0x55) for SCP02.
find_key(key_version_number: int, key_id: int) → SecurityDomainKey | None
Find and return (if any) the SecurityDomainKey for given KVN + KID.
has_scp(scp: int) → bool
Determine if SD Installation parameters already specify given SCP.
remove_scp(scp: int)
Remove given SCP from list of SCP of the Security Domain Install Params.
class pySim.esim.saip.ProfileElementSSD(decoded: dict | None = None, **kwargs)
Class representing a securityDomain ProfileElement for a SSD.
Instantiate a new ProfileElement. This is usually either called with the ‘decoded’ argument after reading a SAIP-
DER-encoded PE. Alternatively, when constructing a PE from scratch, decoded is None, and a minimal PE-
Header is generated.
Parameters
• decoded – asn1tools-generated decoded structure for this PE
• mandated – Whether or not the PE-Header should contain the mandated attribute
• pe_sequence – back-reference to the PE-Sequence of which we’re part of
class pySim.esim.saip.ProfileElementSequence
A sequence of ProfileElement objects, which is the overall representation of an eSIM profile.
This primarily contains a list of PEs (pe_list member) as well as a number of convenience indexes like the
pe_by_type and pes_by_naa dicts that allow easier access to individual PEs within the sequence.
After calling the constructor, you have to further initialize the instance by either calling the parse_der() method,
or by manually adding individual PEs, including the header and end PEs.
add_file_at_path(path: Path, l: List)
Add a file at given path. This assumes that there’s only one instance of USIM/ISIM/CSIM inside the profile,
as otherwise the path name would not be globally unique.
add_hdr_and_end()
Initialize the PE Sequence with a header and end PE.
add_ssd(ssd: ProfileElementSSD)
Add a SSD (Supplementary Security Domain) After MNO-SD/ISD-P.
append(pe: ProfileElement)
Append a given PE to the end of the PE Sequence
cd(path: List[int])
Change the current directory to the [absolute] “path”.
pySim.esim.saip.oid
Implementation of SimAlliance/TCA Interoperable Profile OIDs
class pySim.esim.saip.oid.eOID(initializer)
OID helper for TCA eUICC prefix
pySim.esim.saip.personalization
Implementation of Personalization of eSIM profiles in SimAlliance/TCA Interoperable Profile.
class pySim.esim.saip.personalization.Adm1(input_value)
class pySim.esim.saip.personalization.Adm2(input_value)
class pySim.esim.saip.personalization.AlgoConfig(input_value)
Configurable Algorithm parameter.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.AlgorithmID(input_value)
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.AppPin(input_value)
Configurable PIN (Personal Identification Number). String of digits.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.ClassVarMeta(name, bases, namespace, **kwargs)
Metaclass that puts all additional keyword-args into the class. We use this to have one class definition for some-
thing like a PIN, and then have derived classes for PIN1, PIN2, . . .
class pySim.esim.saip.personalization.ConfigurableParameter(input_value)
Base class representing a part of the eSIM profile that is configurable during the personalization process (with
dynamic data from elsewhere).
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.Iccid(input_value)
Configurable ICCID. Expects the value to be a string of decimal digits. If the string of digits is only 18 digits
long, a Luhn check digit will be added.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.Imsi(input_value)
Configurable IMSI. Expects value to be a string of digits. Automatically sets the ACC to the last digit of the
IMSI.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.K(input_value)
class pySim.esim.saip.personalization.Opc(input_value)
class pySim.esim.saip.personalization.Pin(input_value)
Configurable PIN (Personal Identification Number). String of digits.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.Pin1(input_value)
class pySim.esim.saip.personalization.Pin2(input_value)
class pySim.esim.saip.personalization.Puk(input_value)
Configurable PUK (Pin Unblock Code). String ASCII-encoded digits.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.Puk1(input_value)
class pySim.esim.saip.personalization.Puk2(input_value)
class pySim.esim.saip.personalization.SdKey(input_value)
Configurable Security Domain (SD) Key. Value is presented as bytes.
validate()
Optional validation method. Can be used by derived classes to perform validation of the input value
(self.value). Will raise an exception if validation fails.
class pySim.esim.saip.personalization.SdKeyScp02_20(input_value)
class pySim.esim.saip.personalization.SdKeyScp02_20Dek(input_value)
class pySim.esim.saip.personalization.SdKeyScp02_20Enc(input_value)
class pySim.esim.saip.personalization.SdKeyScp02_20Mac(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_30(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_30Dek(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_30Enc(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_30Mac(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_31(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_31Dek(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_31Enc(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_31Mac(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_32(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_32Dek(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_32Enc(input_value)
class pySim.esim.saip.personalization.SdKeyScp03_32Mac(input_value)
class pySim.esim.saip.personalization.SdKeyScp80_01(input_value)
class pySim.esim.saip.personalization.SdKeyScp80_01Kic(input_value)
class pySim.esim.saip.personalization.SdKeyScp80_01Kid(input_value)
class pySim.esim.saip.personalization.SdKeyScp80_01Kik(input_value)
class pySim.esim.saip.personalization.SdKeyScp81_01(input_value)
class pySim.esim.saip.personalization.SdKeyScp81_01Dek(input_value)
class pySim.esim.saip.personalization.SdKeyScp81_01Psk(input_value)
pySim.esim.saip.templates
Implementation of SimAlliance/TCA Interoperable Profile Templates.
class pySim.esim.saip.templates.FileTemplate(fid: int, name: str, ftype, nb_rec: int | None, size: int |
None, arr: int, sfi: int | None = None, default_val: str |
None = None, content_rqd: bool = True, params: List |
None = None, ass_serv: List[int] | None = None,
high_update: bool = False, pe_name: str | None = None,
repeat: bool = False, ppath: List[int] = [])
Representation of a single file in a SimAlliance/TCA Profile Template. The argument order is done to match that
of the tables in Section 9 of the SAIP specification.
Parameters
• fid – The 16bit file-identifier of the file
• name – The name of the file in human-readable “EF.FOO”, “DF.BAR” notation
• ftype – The type of the file; can be ‘MF’, ‘ADF’, ‘DF’, ‘TR’, ‘LF’, ‘CY’, ‘BT’
• nb_rec – Then number of records (only valid for ‘LF’ and ‘CY’)
• size – The size of the file (‘TR’, ‘BT’); size of each record (‘LF, ‘CY’)
• arr – The record number of EF.ARR for referenced access rules
• sfi – The short file identifier, if any
• default_val – The default value [pattern] of the file
• content_rqd – Whether an instance of template must specify file contents
class pySim.esim.saip.templates.FilesTelecom
Files at DF.TELECOM as per Section 9.4 v2.3.1
class pySim.esim.saip.templates.FilesTelecomV2
Files at DF.TELECOM as per Section 9.4
class pySim.esim.saip.templates.FilesUsimDf5GS
DF.5GS Files at ADF.USIM as per Section 9.5.11 v2.3.1
parent
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimDf5GSv2
DF.5GS Files at ADF.USIM as per Section 9.5.11.2
parent
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimDf5GSv3
DF.5GS Files at ADF.USIM as per Section 9.5.11.3
parent
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimDf5GSv4
DF.5GS Files at ADF.USIM as per Section 9.5.11.4
parent
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimDfGsmAccess
DF.GSM-ACCESS Files at ADF.USIM as per Section 9.5.4
parent
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimDfPhonebook
DF.PHONEBOOK Files at ADF.USIM as per Section 9.5.3
class pySim.esim.saip.templates.FilesUsimDfSaip
DF.SAIP Files at ADF.USIM as per Section 9.5.12
parent
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimMandatory
Mandatory Files at ADF.USIM as per Section 9.5.1 v2.3.1
class pySim.esim.saip.templates.FilesUsimMandatoryV2
Mandatory Files at ADF.USIM as per Section 9.5.1
class pySim.esim.saip.templates.FilesUsimOptional
Optional Files at ADF.USIM as per Section 9.5.2 v2.3.1
extends
alias of FilesUsimMandatory
class pySim.esim.saip.templates.FilesUsimOptionalV2
Optional Files at ADF.USIM as per Section 9.5.2
extends
alias of FilesUsimMandatoryV2
class pySim.esim.saip.templates.FilesUsimOptionalV3
Optional Files at ADF.USIM as per Section 9.5.2.3 v3.3.1
extends
alias of FilesUsimMandatoryV2
class pySim.esim.saip.templates.ProfileTemplate
Representation of a SimAlliance/TCA Profile Template. Each Template is identified by its OID and consists of
a number of file definitions. We implement each profile template as a class derived from this base class. Each
such derived class is a singleton and has no instances.
classmethod base_df() → FileTemplate
Return the FileTemplate for the base DF of the given template. This may be a DF or ADF within this
template, or refer to another template (e.g. mandatory USIM if we are optional USIM.
class pySim.esim.saip.templates.ProfileTemplateRegistry
A registry of profile templates. Exists as a singleton class with no instances and only classmethods.
classmethod add(tpl: ProfileTemplate)
Add a ProfileTemplate to the registry. There can only be one Template per OID.
classmethod get_by_oid(oid: List[int] | str) → ProfileTemplate | None
Look-up the ProfileTemplate based on its OID. The OID can be given either in dotted-string format, or as
a list of integers.
class pySim.esim.saip.templates.SaipSpecVersion
Represents a specific version of the SIMalliance / TCA eUICC Profile Package: Interoperable Format Technical
Specification.
static for_version(req_version: str) → SaipSpecVersion | None
Return the subclass for the requested version number string.
classmethod suports_template_OID(OID: OID) → bool
Return if a given spec version supports a template of given OID.
classmethod version_match(ver: str) → bool
Check if the given version-string matches the classes version. trailing zeroes are ignored, so that for example
2.2.0 will be considered equal to 2.2
class pySim.esim.saip.templates.SaipSpecVersion101
class pySim.esim.saip.templates.SaipSpecVersion20
class pySim.esim.saip.templates.SaipSpecVersion21
class pySim.esim.saip.templates.SaipSpecVersion22
class pySim.esim.saip.templates.SaipSpecVersion23
class pySim.esim.saip.templates.SaipSpecVersion231
class pySim.esim.saip.templates.SaipSpecVersion31
class pySim.esim.saip.templates.SaipSpecVersion32
class pySim.esim.saip.templates.SaipSpecVersion331
pySim.esim.saip.validation
Implementation of SimAlliance/TCA Interoperable Profile validation.
class pySim.esim.saip.validation.CheckBasicStructure
ProfileConstraintChecker for the basic profile structure constraints.
check_identification_unique(pes: ProfileElementSequence)
Ensure that each PE has a unique identification value.
check_mandatory_services(pes: ProfileElementSequence)
Ensure that the PE for the mandatory services exist.
check_number_of_occurrence(pes: ProfileElementSequence)
Check The number of occurrence of various ProfileElements.
check_optional_ordering(pes: ProfileElementSequence)
Check the ordering of optional PEs following the respective mandatory ones.
check_start_and_end(pes: ProfileElementSequence)
Check for mandatory header and end ProfileElements at the right position.
class pySim.esim.saip.validation.FileCheckBasicStructure
Validator for the basic structure of a decoded file.
check_forbidden(l: List[Tuple])
Perform checks for forbidden parameters as described in Section 8.3.3.
check_seqence(l: List[Tuple])
Check the sequence/ordering.
exception pySim.esim.saip.validation.FileError
Raised when a FileConstraintChecker finds an error in a file [structure].
class pySim.esim.saip.validation.ProfileConstraintChecker
Base class of a constraint checker for a ProfileElementSequence.
check(pes: ProfileElementSequence)
Execute all the check_* methods of the ProfileConstraintChecker against the given ProfileElementSequence
exception pySim.esim.saip.validation.ProfileError
Raised when a ProfileConstraintChecker finds an error in a file [structure].
1.7 osmo-smdpp
osmo-smdpp is a proof-of-concept implementation of a minimal SM-DP+ as specified for the GSMA Consumer eSIM
Remote SIM provisioning.
At least at this point, it is intended to be used for research and development, and not as a production SM-DP+.
Unless you are a GSMA SAS-SM accredited SM-DP+ operator and have related DPtls, DPauth and DPpb certifi-
cates signed by the GSMA CI, you can not use osmo-smdpp with regular production eUICC. This is due to how
the GSMA eSIM security architecture works. You can, however, use osmo-smdpp with so-called test-eUICC, which
contain certificates/keys signed by GSMA test certificates as laid out in GSMA SGP.26.
At this point, osmo-smdpp does not support anything beyond the bare minimum required to download eSIM profiles
to an eUICC. Specifically, there is no ES2+ interface, and there is no built-in support for profile personalization yet.
osmo-smdpp currently
• [by default] uses test certificates copied from GSMA SGP.26 into ./smdpp-data/certs, assuming that your osmo-
smdpp would be running at the host name testsmdpplus1.example.com. You can of course replace those certifi-
cates with your own, whether SGP.26 derived or part of a private root CA setup with mathcing eUICCs.
• doesn’t understand profile state. Any profile can always be downloaded any number of times, irrespective of the
EID or whether it was donwloaded before. This is actually very useful for R&D and testing, as it doesn’t require
you to generate new profiles all the time. This logic of course is unsuitable for production usage.
• doesn’t perform any personalization, so the IMSI/ICCID etc. are always identical (the ones that are stored in the
respective UPP .der files)
• is absolutely insecure, as it
• does not perform all of the mandatory certificate verification (it checks the certificate chain, but not the expiration
dates nor any CRL)
• does not evaluate/consider any Confirmation Code
• stores the sessions in an unencrypted python shelve and is hence leaking one-time key materials used for profile
encryption and signing.
upstream smdpp {
server localhost:8000;
}
server {
listen 443 ssl;
server_name testsmdpplus1.example.com;
ssl_certificate /my/path/to/pysim/smdpp-data/certs/DPtls/CERT_S_SM_DP_TLS_NIST.
˓→pem;
ssl_certificate_key /my/path/to/pysim/smdpp-data/certs/DPtls/SK_S_SM_DP_TLS_NIST.
˓→pem;
location / {
proxy_read_timeout 600s;
proxy_hide_header X-Powered-By;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
(continues on next page)
proxy_pass http://smdpp/;
}
}
You can of course achieve a similar functionality with apache, lighttpd or many other web server software.
supplementary files
The smdpp-data/certs directory contains the DPtls, DPauth and DPpb as well as CI certificates used; they are copied
from GSMA SGP.26 v2. You can of course replace them with custom certificates if you’re operating eSIM with a
private root CA.
The smdpp-data/upp directory contains the UPP (Unprotected Profile Package) used. The file names (without .der
suffix) are looked up by the matchingID parameter from the activation code presented by the LPA.
commandline options
Typically, you just run it without any arguments, and it will bind its plain-HTTP ES9+ interface to localhost TCP port
8000.
osmo-smdpp currently doesn’t have any configuration file.
There are command line options for binding:
Bind the HTTP ES9+ to a port other than 8000:
./osmo-smdpp.py -p 8001
./osmo-smdpp.py -H 127.0.0.1
Supported eUICC
If you run osmo-smdpp with the included SGP.26 certificates, you must use an eUICC with matching SGP.26 certifi-
cates, i.e. the EUM certificate must be signed by a SGP.26 test root CA and the eUICC certificate in turn must be signed
by that SGP.26 EUM certificate.
sysmocom (sponsoring development and maintenance of pySim and osmo-smdpp) is selling SGP.26 test eUICC as
sysmoEUICC1-C2T. They are publicly sold in the sysmocom webshop.
In general you can use osmo-smdpp also with certificates signed by any other certificate authority. You just always
must ensure that the certificates of the SM-DP+ are signed by the same root CA as those of your eUICCs.
Hypothetically, osmo-smdpp could also be operated with GSMA production certificates, but it would require that
somebody brings the code in-line with all the GSMA security requirements (HSM support, . . . ) and operate it in a
GSMA SAS-SM accredited environment and pays for the related audits.
1.8 sim-rest-server
Sometimes there are use cases where a [remote] application will need access to a USIM for authentication purposes.
This is, for example, in case an IMS test client needs to perform USIM based authentication against an IMS core.
The pysim repository contains two programs: sim-rest-server.py and sim-rest-client.py that implement a simple ap-
proach to achieve the above:
sim-rest-server.py speaks to a [usually local] USIM via the PC/SC API and provides a high-level REST API towards
[local or remote] applications that wish to perform UMTS AKA using the USIM.
sim-rest-client.py implements a small example client program to illustrate how the REST API provided by sim-rest-
server.py can be used.
Request Body
{
"rand": "bb685a4b2fc4d697b9d6a129dd09a091",
"autn": "eea7906f8210000004faf4a7df279b56"
}
HTTP status codes are used to represent errors within the REST server and the SIM reader hardware. They are not
used to communicate protocol level errors reported by the SIM Card. An unsuccessful authentication will hence have
a 200 OK HTTP Status code and then encode the SIM specific error information in the Response Body.
Response Body
3. errors #. authentication error (incorrect MAC) #. authentication error (security context not supported) #. key
freshness failure #. unspecified card error
Example (succcess):
{
"successful_3g_authentication": {
"res": "b15379540ec93985",
"ck": "713fde72c28cbd282a4cd4565f3d6381",
"ik": "2e641727c95781f1020d319a0594f31a",
"kc": "771a2c995172ac42"
}
}
{
"synchronisation_failure": {
"auts": "dc2a591fe072c92d7c46ecfe97e5"
}
}
$ /usr/local/src/pysim/contrib/sim-rest-client.py -c 1 -n 0 -k␣
˓→841EAD87BC9D974ECA1C167409357601 -o 3211CACDD64F51C3FD3013ECD9A582A0
˓→'64d3f2a32f801214'}}
Slot 1
$ /usr/local/src/pysim/contrib/sim-rest-client.py -c 1 -n 1 -k␣
˓→5C2CE9633FF9B502B519A4EACD16D9DF -o 9834D619E71A02CD76F00CC7AA34FB32
˓→'d15ac5b0fff73ecc'}}
1.9 suci-keytool
Subscriber concealment is an important feature of the 5G SA architecture: It avoids the many privacy issues associated
with having a permanent identifier (SUPI, traditionally the IMSI) transmitted in plain text over the air interface. Using
SUCI solves this issue not just for the air interface; it even ensures the SUPI/IMSI is not known to the visited network
(VPLMN) at all.
In principle, the SUCI mechanism works by encrypting the SUPI by asymmetric (public key) cryptography: Only the
HPLMN is in possession of the private key and hence can decrypt the SUCI to the SUPI, while each subscriber has the
public key in order to encrypt their SUPI into the SUCI. In reality, the details are more complex, as there are ephemeral
keys and cryptographic MAC involved.
In any case, in order to operate a SUCI-enabled 5G SA network, you will have to
1. generate a ECC key pair of public + private key
2. deploy the public key on your USIMs
3. deploy the private key on your 5GC, specifically the UDM function
pysim contains (int its contrib directory) a small utility program that can make it easy to generate such keys: suci-
keytool.py
If you want the point-compressed representation, you can use the –compressed option:
Positional Arguments
command Possible choices: generate-key, dump-pub-key
The command to perform
Named Arguments
--key-file The key file to use
Sub-commands
generate-key
Named Arguments
dump-pub-key
Named Arguments
1.10 saip-tool
eSIM profiles are stored as a sequence of profile element (PE) objects in an ASN.1 DER encoded binary file. To inspect,
verify or make changes to those files, the saip-tool.py utility can be used.
NOTE: The file format, eSIM SAIP (SimAlliance Interoperable Profile) is specified in TCA eUICC Profile Package:
Interoperable Format Technical Specification
Inserting applications
An application is usually inserted in two steps. In the first step, the application PE is created and populated with the
executable code from a provided .cap or .ijc file. The user also has to pick a suitable load block AID.
The application instance, which exists inside the application PE, is created in a second step. Here the user must reference
the load block AID and pick, among other application related parameters, a suitable class and instance AID.
Example: Adding a JAVA-card applet to an existing profile package
# Step #1: Create the application PE and load the ijc contents from the .cap file:
$ ./contrib/saip-tool.py upp.der add-app --output-file upp_with_app.der --applet-file␣
˓→app.cap --aid '1122334455'
# Step #2: Create the application instance inside the application PE created in step #1:
$ ./contrib/saip-tool.py upp_with_app.der add-app-inst --output-file upp_with_app_and_
˓→instance.der \
--aid '1122334455' \
--class-aid '112233445501' \
--inst-aid '112233445501' \
--app-privileges '00' \
--app-spec-pars '00' \
--uicc-toolkit-app-spec-pars '01001505000000000000000000000000'
Read 29 PEs from file 'upp_with_app.der'
Found Load Package AID: 1122334455, adding new instance AID: 112233445501 to Application␣
˓→PE...
NOTE: The parameters of the sub-commands add-app and add-app-inst are application specific. It is up to the ap-
plication developer to pick parameters that suit the application correctly. For an exact command reference see section
saip-tool syntax. For parameter details see TCA eUICC Profile Package: Interoperable Format Technical Specification,
section 8.7 and ETSI TS 102 226, section 8.2.1.3.2
Inspecting applications
To inspect the application PE contents of an existing profile package, sub-command info with parameter ‘–apps’ can
be used. This command lists out all application and their parameters in detail. This allows an application developer to
check if the applet insertaion was carried out as expected.
Example: Listing applications and their parameters
instanceList[0]:
applicationLoadPackageAID: '1122334455' (5 bytes)
classAID: '112233445501' (8 bytes)
instanceAID: '112233445501' (8 bytes)
applicationPrivileges: '00' (1 bytes)
lifeCycleState: '07' (1 bytes)
applicationSpecificParametersC9: '00' (1 bytes)
applicationParameters:
uiccToolkitApplicationSpecificParametersField:
˓→'01001505000000000000000000000000' (16 bytes)
In case further analysis with external tools or transfer of applications from one profile package to another is necessary,
the executable code in the loadBlockObject field can be extracted to an .ijc or an .cap file.
Example: Extracting applications from a profile package
Removing applications
An application PE can be removed using sub-command remove-app. The user passes the load package AID as param-
eter. Then saip-tool.py will search for the related application PE and delete it from the PE sequence.
Example: Remove an application from a profile package
In some cases it is useful to remove only an instance from an existing application PE. This may be the case when the
an application developer wants to modify parameters of an application by removing and re-adding the instance. The
operation basically rolls the state back to step 1 explained in section Inserting applications
Example: Remove an application instance from an application PE
Utility program to work with eSIM SAIP (SimAlliance Interoperable Profile) files.
...
Positional Arguments
INPUT_UPP Unprotected Profile Package Input file
command Possible choices: split, dump, check, extract-pe, remove-pe, remove-naa, info,
extract-apps, add-app, remove-app, add-app-inst, remove-app-inst, edit-mand-
srv-list, tree
The command to perform
Named Arguments
--loglevel Possible choices: DEBUG, INFO, WARNING, ERROR, CRITICAL
Set the logging level
Default: “INFO”
--debug Enable DEBUG logging
Default: False
Sub-commands
split
Named Arguments
dump
Positional Arguments
Named Arguments
check
extract-pe
Named Arguments
remove-pe
Named Arguments
remove-naa
Named Arguments
info
Named Arguments
extract-apps
Named Arguments
add-app
Named Arguments
remove-app
Named Arguments
add-app-inst
[--uicc-access-app-spec-pars UICC_ACCESS_APP_SPEC_PARS]
[--uicc-adm-access-app-spec-pars UICC_ADM_ACCESS_APP_
˓→SPEC_PARS]
[--process-data PROCESS_DATA]
Named Arguments
remove-app-inst
Named Arguments
edit-mand-srv-list
˓→multiple-csim,tuak256,usim-test-algorithm,ber-tlv,dfLink,cat-tp,get-identity,profile-a-
˓→x25519,profile-b-p256,suciCalculatorApi,dns-resolution,scp11ac,scp11c-authorization-
˓→mechanism,s16mode,eaka}]
[--remove-flag {contactless,usim,isim,csim,
˓→milenage,tuak128,cave,gba-usim,gba-isim,mbms,eap,javacard,multos,multiple-usim,
˓→multiple-isim,multiple-csim,tuak256,usim-test-algorithm,ber-tlv,dfLink,cat-tp,get-
˓→identity,profile-a-x25519,profile-b-p256,suciCalculatorApi,dns-resolution,scp11ac,
˓→scp11c-authorization-mechanism,s16mode,eaka}]
Named Arguments
tree
TWO
• genindex
• modindex
• search
127
osmopysim-usermanual
p
pySim.card_handler, 86
pySim.card_key_provider, 87
pySim.commands, 73
pySim.esim, 88
pySim.esim.bsp, 91
pySim.esim.es2p, 89
pySim.esim.es8p, 90
pySim.esim.es9p, 91
pySim.esim.http_json_api, 92
pySim.esim.rsp, 89
pySim.esim.saip, 94
pySim.esim.saip.oid, 107
pySim.esim.saip.personalization, 107
pySim.esim.saip.templates, 109
pySim.esim.saip.validation, 113
pySim.esim.x509_cert, 93
pySim.exceptions, 86
pySim.filesystem, 62
pySim.transport, 79
pySim.transport.calypso, 80
pySim.transport.modem_atcmd, 81
pySim.transport.pcsc, 81
pySim.transport.serial, 82
pySim.utils, 82
129
osmopysim-usermanual
A 107
activate_file() (pySim.commands.SimCardCommands ApiError, 92
method), 73 ApiParam (class in pySim.esim.http_json_api), 92
ActivationCode (class in pySim.esim), 88 ApiParamBase64 (class in pySim.esim.http_json_api),
add() (pySim.esim.saip.templates.ProfileTemplateRegistry 92
class method), 112 ApiParamBoolean (class in pySim.esim.http_json_api),
add_application_df() (pySim.filesystem.CardMF 92
method), 66 ApiParamFqdn (class in pySim.esim.http_json_api), 92
add_child() (pySim.esim.saip.FsNodeDF method), 96 ApiParamInteger (class in pySim.esim.http_json_api),
add_file() (pySim.esim.saip.FsNodeDF method), 96 93
add_file() (pySim.esim.saip.FsProfileElement ApiParamString (class in pySim.esim.http_json_api),
method), 96 93
add_file() (pySim.filesystem.CardDF method), 64 append() (pySim.esim.saip.ProfileElementSequence
add_file_at_path() (pySim.esim.saip.ProfileElementSequence method), 104
method), 104 apply_matching_models()
add_files() (pySim.filesystem.CardDF method), 64 (pySim.filesystem.CardModel static method),
add_files() (pySim.filesystem.CardModel class 67
method), 67 AppPin (class in pySim.esim.saip.personalization), 107
add_hdr_and_end() (pySim.esim.saip.ProfileElementSequenceargparse_add_reader_args() (in module
method), 104 pySim.transport), 80
add_instance() (pySim.esim.saip.ProfileElementApplicationauthenticate() (pySim.commands.SimCardCommands
method), 98 method), 73
add_intermediate_cert() AuthenticateClient (class in pySim.esim.es9p), 91
(pySim.esim.x509_cert.CertificateSet method),
94 B
add_key() (pySim.esim.saip.ProfileElementSD method), base_df() (pySim.esim.saip.templates.ProfileTemplate
104 class method), 112
add_notification() (pySim.esim.es8p.ProfileMetadata bertlv_first_segment() (in module
method), 90 pySim.esim.saip), 106
add_pin() (pySim.esim.saip.ProfileElementPin BerTlvEF (class in pySim.filesystem), 62
method), 103 BerTlvEF.ShellCommands (class in pySim.filesystem),
add_puk() (pySim.esim.saip.ProfileElementPuk 62
method), 103 binary_size() (pySim.commands.SimCardCommands
add_scp() (pySim.esim.saip.ProfileElementSD method), method), 73
104 BoundProfilePackage (class in pySim.esim.es8p), 90
add_ssd() (pySim.esim.saip.ProfileElementSequence boxed_heading_str() (in module pySim.utils), 84
method), 104 bsp_key_derivation() (in module pySim.esim.bsp),
Adm1 (class in pySim.esim.saip.personalization), 107 92
Adm2 (class in pySim.esim.saip.personalization), 107 BspAlgo (class in pySim.esim.bsp), 91
AlgoConfig (class in pySim.esim.saip.personalization), BspAlgoCrypt (class in pySim.esim.bsp), 91
107 BspAlgoCryptAES128 (class in pySim.esim.bsp), 92
AlgorithmID (class in pySim.esim.saip.personalization), BspAlgoMac (class in pySim.esim.bsp), 92
131
osmopysim-usermanual
132 Index
osmopysim-usermanual
Index 133
osmopysim-usermanual
134 Index
osmopysim-usermanual
Index 135
osmopysim-usermanual
I
get_by_oid() (pySim.esim.saip.templates.ProfileTemplateRegistry
class method), 112 Iccid (class in pySim.esim.saip.personalization), 107
get_cert_as_der() (pySim.esim.x509_cert.CertAndPrivkey iccid (pySim.esim.saip.ProfileElementSequence prop-
method), 94 erty), 105
get_closest_prev_pe_for_templateID() identification (pySim.esim.saip.ProfileElement prop-
(pySim.esim.saip.ProfileElementSequence erty), 97
method), 105 Imsi (class in pySim.esim.saip.personalization), 107
get_field() (pySim.card_key_provider.CardKeyProvider init_reader() (in module pySim.transport), 80
method), 87 InitiateAuthentication (class in pySim.esim.es9p),
get_file_by_path() (pySim.esim.saip.templates.FileTemplate 91
method), 110 insert_after_pe() (pySim.esim.saip.ProfileElementSequence
get_index_by_pe() (pySim.esim.saip.ProfileElementSequence method), 105
method), 105 insert_at_index() (pySim.esim.saip.ProfileElementSequence
get_index_by_type() method), 105
(pySim.esim.saip.ProfileElementSequence interpret_sw() (in module pySim.filesystem), 72
method), 105 interpret_sw() (pySim.filesystem.CardApplication
get_mf() (pySim.filesystem.CardFile method), 66 method), 63
get_pe_for_type() (pySim.esim.saip.ProfileElementSequence
is_parent() (pySim.filesystem.Path method), 69
method), 105
get_pes_for_templateID() J
(pySim.esim.saip.ProfileElementSequence
JsonHttpApiFunction (class in
method), 105
pySim.esim.http_json_api), 93
get_pes_for_type() (pySim.esim.saip.ProfileElementSequence
JsonResponseHeader (class in
method), 105
pySim.esim.http_json_api), 93
get_profile() (pySim.filesystem.CardFile method), 66
get_selectable_names() (pySim.filesystem.CardFile
method), 66
K
get_selectables() (pySim.filesystem.CardDF K (class in pySim.esim.saip.personalization), 108
method), 64
get_selectables() (pySim.filesystem.CardEF L
method), 65 lchan_nr_to_cla() (in module pySim.commands), 78
get_selectables() (pySim.filesystem.CardFile LinFixedEF (class in pySim.filesystem), 67
method), 66 LinFixedEF.ShellCommands (class in
get_selectables() (pySim.filesystem.CardMF pySim.filesystem), 68
method), 67 LinkBase (class in pySim.transport), 79
get_subject_alt_name() LinkBaseTpdu (class in pySim.transport), 79
(pySim.esim.x509_cert.CertAndPrivkey lookup() (pySim.utils.CardCommandSet method), 82
method), 94 lookup_by_fidpath() (pySim.esim.saip.FsNodeDF
get_tuplelist_item() (pySim.esim.saip.File static method), 96
method), 95 lookup_by_path() (pySim.esim.saip.FsNodeDF
GetBoundProfilePackage (class in pySim.esim.es9p), method), 96
91 lookup_file_by_fid() (pySim.filesystem.CardDF
method), 64
H lookup_file_by_name() (pySim.filesystem.CardDF
HandleDownloadProgressInfo (class in method), 64
pySim.esim.es2p), 90 lookup_file_by_sfid() (pySim.filesystem.CardDF
HandleNotification (class in pySim.esim.es9p), 91 method), 64
has_scp() (pySim.esim.saip.ProfileElementSD method),
104 M
header (pySim.esim.saip.ProfileElement property), 97 mac_only_one() (pySim.esim.bsp.BspInstance method),
header_name (pySim.esim.saip.ProfileElement prop- 92
erty), 97 manage_channel() (pySim.commands.SimCardCommands
HttpHeaderError, 93 method), 74
HttpStatusError, 93 match() (pySim.filesystem.CardModel class method), 67
136 Index
osmopysim-usermanual
Index 137
osmopysim-usermanual
138 Index
osmopysim-usermanual
Index 139
osmopysim-usermanual
send_apdu_checksw() method), 77
(pySim.commands.SimCardCommands sw_match() (in module pySim.utils), 85
method), 76 SwMatchError, 86
send_apdu_checksw() (pySim.transport.LinkBase
method), 79 T
send_apdu_constr() (pySim.commands.SimCardCommands tabulate_str_list() (in module pySim.utils), 85
method), 76 templateID (pySim.esim.saip.ProfileElement property),
send_apdu_constr_checksw() 98
(pySim.commands.SimCardCommands terminal_profile() (pySim.commands.SimCardCommands
method), 76 method), 77
send_tpdu() (pySim.transport.calypso.CalypsoSimLink terminate_card_usage()
method), 80 (pySim.commands.SimCardCommands
send_tpdu() (pySim.transport.LinkBaseTpdu method), method), 77
80 terminate_df() (pySim.commands.SimCardCommands
send_tpdu() (pySim.transport.modem_atcmd.ModemATCommandLink method), 77
method), 81 terminate_ef() (pySim.commands.SimCardCommands
send_tpdu() (pySim.transport.pcsc.PcscSimLink method), 77
method), 81 TL0_DataObject (class in pySim.utils), 84
send_tpdu() (pySim.transport.serial.SerialSimLink to_bitstring() (pySim.esim.PMO method), 89
method), 82 to_bytes() (pySim.utils.DataObject method), 83
SerialSimLink (class in pySim.transport.serial), 82 to_bytes() (pySim.utils.TL0_DataObject method), 84
set_data() (pySim.commands.SimCardCommands to_der() (pySim.esim.es8p.UnprotectedProfilePackage
method), 77 method), 91
set_icon() (pySim.esim.es8p.ProfileMetadata method), to_der() (pySim.esim.saip.ProfileElement method), 98
90 to_der() (pySim.esim.saip.ProfileElementSequence
set_mapping() (pySim.esim.saip.ProfileElementAKA method), 106
method), 98 to_dict() (pySim.utils.DataObject method), 83
set_milenage() (pySim.esim.saip.ProfileElementAKA to_file() (pySim.esim.saip.ProfileElementApplication
method), 98 method), 99
set_sw_interpreter() (pySim.transport.LinkBase to_fileDescriptor() (pySim.esim.saip.File method),
method), 79 95
set_tpdu_format() (pySim.transport.LinkBaseTpdu to_gfm() (pySim.esim.saip.File method), 95
method), 80 to_qrcode() (pySim.esim.ActivationCode method), 89
set_tuak() (pySim.esim.saip.ProfileElementAKA to_saip_dict() (pySim.esim.saip.SecurityDomainKey
method), 98 method), 106
set_xor3g() (pySim.esim.saip.ProfileElementAKA to_saip_dict() (pySim.esim.saip.SecurityDomainKeyComponent
method), 98 method), 106
should_exist_for_services() to_string() (pySim.esim.ActivationCode method), 89
(pySim.filesystem.CardFile method), 66 to_tlv() (pySim.utils.DataObject method), 83
SimCardCommands (class in pySim.commands), 73 to_tuples() (pySim.esim.saip.File method), 95
SmdpAddress (class in pySim.esim.http_json_api), 93 TransparentEF (class in pySim.filesystem), 71
status() (pySim.commands.SimCardCommands TransparentEF.ShellCommands (class in
method), 77 pySim.filesystem), 71
StdoutApduTracer (class in pySim.transport), 80 TransRecEF (class in pySim.filesystem), 70
suports_template_OID() try_select_path() (pySim.commands.SimCardCommands
(pySim.esim.saip.templates.SaipSpecVersion method), 77
class method), 112
supports_file_for_path() U
(pySim.esim.saip.FsProfileElement method), unblock_chv() (pySim.commands.SimCardCommands
97 method), 77
supports_file_for_path() UnprotectedProfilePackage (class in
(pySim.esim.saip.ProfileElementGFM method), pySim.esim.es8p), 91
101 update_binary() (pySim.commands.SimCardCommands
suspend_uicc() (pySim.commands.SimCardCommands method), 78
140 Index
osmopysim-usermanual
W
wait_for_card() (pySim.transport.calypso.CalypsoSimLink
method), 80
wait_for_card() (pySim.transport.LinkBase method),
79
wait_for_card() (pySim.transport.modem_atcmd.ModemATCommandLink
method), 81
wait_for_card() (pySim.transport.pcsc.PcscSimLink
method), 82
Index 141