pySim eSIM libraries

The pySim eSIM libraries implement a variety of functionality related to the GSMA eSIM universe, including the various interfaces of SGP.21 + SGP.22, as well as Interoperable Profile decioding, validation, personalization and encoding.

class pySim.esim.ActivationCode(hostname: str, token: str, oid: str | None = None, cc_required: bool | None = False)

SGP.22 section 4.1 Activation Code

static decode_str(ac: str) dict

decode an activation code from its string representation.

classmethod from_string(ac: str) ActivationCode

Create new instance from SGP.22 section 4.1 string representation.

to_qrcode()

Encode internal representation to QR code.

to_string(for_qrcode: bool = False) str

Convert from internal representation to SGP.22 section 4.1 string representation.

class pySim.esim.PMO(op: str)

Convenience conversion class for ProfileManagementOperation as used in ES9+ notifications.

classmethod from_bitstring(bstr: Tuple[bytes, int]) PMO

Parse a asn1tools BITSTRING representation.

classmethod from_int(i: int) PMO

Parse an integer representation.

to_bitstring() Tuple[bytes, int]

return value in a format as used by asn1tools for BITSTRING.

pySim.esim.compile_asn1_subdir(subdir_name: str, codec='der')

Helper function that compiles ASN.1 syntax from all files within given subdir

GSMA SGP.21/22 Remote SIM Provisioning (RSP) - High Level

pySim.esim.rsp

Implementation of GSMA eSIM RSP (Remote SIM Provisioning) as per SGP22 v3.0

class pySim.esim.rsp.RspSessionState(transactionId: str, serverChallenge: bytes, ci_cert_id: bytes)

Encapsulates the state of a RSP session. It is created during the initiateAuthentication and subsequently used by further API calls using the same transactionId. The session state is removed either after cancelSession or after notification. TODO: add some kind of time based expiration / garbage collection.

class pySim.esim.rsp.RspSessionStore(filename, flag='c', protocol=None, writeback=False)

A derived class as wrapper around the database-backed non-volatile storage ‘shelve’, in case we might need to extend it in the future. We use it to store RspSessionState objects indexed by transactionId.

pySim.esim.rsp.extract_euiccSigned1(authenticateServerResponse: bytes) bytes

Extract the raw, DER-encoded binary euiccSigned1 field from the given AuthenticateServerResponse. This is needed due to the very peculiar SGP.22 notion of signing sections of DER-encoded ASN.1 objects.

pySim.esim.rsp.extract_euiccSigned2(prepareDownloadResponse: bytes) bytes

Extract the raw, DER-encoded binary euiccSigned2 field from the given prepareDownloadrResponse. This is needed due to the very peculiar SGP.22 notion of signing sections of DER-encoded ASN.1 objects.

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)
class pySim.esim.es2p.ConfirmOrder(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es2p.DownloadOrder(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es2p.Es2PlusApiFunction(url_prefix: str, func_req_id: str | None, session: Session)

Base classs for representing an ES2+ API Function.

class pySim.esim.es2p.Es2pApiClient(url_prefix: str, func_req_id: str, server_cert_verify: str = None, client_cert: str = None)

Main class representing a full ES2+ API client. Has one method for each API function.

call_cancelOrder(data: dict) dict

Perform ES2+ CancelOrder function (SGP.22 section 5.3.3).

call_confirmOrder(data: dict) dict

Perform ES2+ ConfirmOrder function (SGP.22 section 5.3.2).

call_downloadOrder(data: dict) dict

Perform ES2+ DownloadOrder function (SGP.22 section 5.3.1).

call_handleDownloadProgressInfo(data: dict) dict

Perform ES2+ HandleDownloadProgressInfo function (SGP.22 section 5.3.5).

call_releaseProfile(data: dict) dict

Perform ES2+ CancelOrder function (SGP.22 section 5.3.4).

class pySim.esim.es2p.HandleDownloadProgressInfo(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es2p.ReleaseProfile(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

classmethod from_upp(upp: UnprotectedProfilePackage, bsp: BspInstance) ProtectedProfilePackage

Generate the PPP as a sequence of encrypted and MACed Command TLVs representing the UPP

class pySim.esim.es8p.UnprotectedProfilePackage(metadata: ProfileMetadata | None = None)

Representing an unprotected profile package (UPP) as defined in SGP.22 Section 2.5.2

classmethod from_der(der: bytes, metadata: ProfileMetadata | None = None) UnprotectedProfilePackage

Load an UPP from its DER representation.

to_der()

Return the DER representation of the UPP.

pySim.esim.es8p.gen_init_sec_chan_signed_part(iscsp: Dict) bytes

Generate the concatenated remoteOpId, transactionId, controlRefTemplate and smdpOtpk data objects without the outer SEQUENCE tag / length or the remainder of initialiseSecureChannel, as is required for signing purpose.

pySim.esim.es8p.gen_initialiseSecureChannel(transactionId: str, host_id: bytes, smdp_otpk: bytes, euicc_otpk: bytes, dp_pb)

Generate decoded representation of (signed) initialiseSecureChannel (SGP.22 5.5.2)

pySim.esim.es8p.gen_replace_session_keys(ppk_enc: bytes, ppk_cmac: bytes, initial_mcv: bytes) bytes

Generate encoded (but unsigned) ReplaceSessionKeysReqest DO (SGP.22 5.5.4)

pySim.esim.es8p.wrap_as_der_tlv(tag: int, val: bytes) bytes

Wrap the ‘value’ into a DER-encoded TLV.

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)
class pySim.esim.es9p.CancelSession(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es9p.Es9PlusApiFunction(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es9p.GetBoundProfilePackage(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es9p.HandleNotification(url_prefix: str, func_req_id: str | None, session: Session)
class pySim.esim.es9p.InitiateAuthentication(url_prefix: str, func_req_id: str | None, session: Session)

GSMA SGP.21/22 Remote SIM Provisioning (RSP) - Low Level

pySim.esim.bsp

Implementation of GSMA eSIM RSP (Remote SIM Provisioning BSP (BPP Protection Protocol), where BPP is the Bound Profile Package. So the full expansion is the “GSMA eSIM Remote SIM Provisioning Bound Profile Packate Protection Protocol”

Originally (SGP.22 v2.x) this was called SCP03t, but it has since been renamed to BSP.

class pySim.esim.bsp.BspAlgo

Base class representing a cryptographic algorithm within the BSP (BPP Security Protocol).

class pySim.esim.bsp.BspAlgoCrypt(s_enc: bytes)

Base class representing an encryption/decryption algorithm within the BSP (BPP Security Protocol).

decrypt(data: bytes) bytes

Decrypt given input bytes using the key material given in constructor.

encrypt(data: bytes) bytes

Encrypt given input bytes using the key material given in constructor.

class pySim.esim.bsp.BspAlgoCryptAES128(s_enc: bytes)

AES-CBC-128 implementation of the BPP Security Protocol for GSMA SGP.22 eSIM.

class pySim.esim.bsp.BspAlgoMac(s_mac: bytes, initial_mac_chaining_value: bytes)

Base class representing a message authentication code algorithm within the BSP (BPP Security Protocol).

class pySim.esim.bsp.BspAlgoMacAES128(s_mac: bytes, initial_mac_chaining_value: bytes)

AES-CMAC-128 implementation of the BPP Security Protocol for GSMA SGP.22 eSIM.

class pySim.esim.bsp.BspInstance(s_enc: bytes, s_mac: bytes, initial_mcv: bytes)

An instance of the BSP crypto. Initialized once with the key material via constructor, then the user can call any number of encrypt_and_mac cycles to protect plaintext and generate the respective ciphertext.

encrypt_and_mac_one(tag: int, plaintext: bytes) bytes

Encrypt + MAC a single plaintext TLV. Returns the protected ciphertext.

classmethod from_kdf(shared_secret: bytes, key_type: int, key_length: int, host_id: bytes, eid: bytes)

Convenience constructor for constructing an instance with keys from KDF.

mac_only_one(tag: int, plaintext: bytes) bytes

MAC a single plaintext TLV. Returns the protected ciphertext.

pySim.esim.bsp.bsp_key_derivation(shared_secret: bytes, key_type: int, key_length: int, host_id: bytes, eid, l: int = 16)

BSP protocol key derivation as per SGP.22 v3.0 Section 2.6.4.2

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.

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
class pySim.esim.http_json_api.JsonHttpApiFunction(url_prefix: str, func_req_id: str | None, session: Session)

Base classs for representing an HTTP[s] API Function.

call(data: dict, func_call_id: str | None = None, timeout=10) dict | None

Make an API call to the HTTP API endpoint represented by this object. Input data is passed in data as json-serializable dict. Output data is returned as json-deserialized dict.

decode(data: dict) dict

[further] Decode and validate the JSON-Dict of the response body.

encode(data: dict, func_call_id: str | None = None) dict

Validate an encode input dict into JSON-serializable dict for request body.

class pySim.esim.http_json_api.JsonResponseHeader

SGP.22 section 6.5.1.4.

classmethod verify_decoded(data)

Verify the decoded representation of a value. Should raise an exception if something is odd.

class pySim.esim.http_json_api.SmdpAddress

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 intermediate 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.

SIMalliance / TCA Interoperable Profile

pySim.esim.saip

Implementation of SimAlliance/TCA Interoperable Profile handling

class pySim.esim.saip.File(pename: str, l: List[Tuple] | None = None, template: FileTemplate | None = None, name: str | None = None)

Internal representation of a file in a profile filesystem.

Parameters:
  • pename – Name string of the profile element

  • l – List of tuples [fileDescriptor, fillFileContent, fillFileOffset profile elements]

  • template – Applicable FileTemplate describing defaults as per SAIP spec

  • name – Human-readable name like EF.IMSI, DF.TELECOM, ADF.USIM, …

check_template_modification_rules()

Check template modification rules as per SAIP section 8.3.3.

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

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

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:
  • 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.ProfileElementDfSNPN(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for DF.SNPN

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.ProfileElementEAP(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for DF.EAP

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.ProfileElementEnd(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for the End of the PE-Sequence.

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.ProfileElementGFM(decoded=None, mandated: bool = True, **kwargs)

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

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

class pySim.esim.saip.ProfileElementMF(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for the MF (Master File)

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.ProfileElementOptISIM(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for ADF.ISIM Optional 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

class pySim.esim.saip.ProfileElementOptUSIM(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for ADF.USIM Optional 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

class pySim.esim.saip.ProfileElementPhonebook(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for DF.PHONEBOOK

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.ProfileElementPin(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for a PIN (Personal Identification Number)

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_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”.

property cur_df: FsNodeDF | None

Current DF; this is where the next files are created.

classmethod from_der(der: bytes) ProfileElementSequence

Construct an instance from given raw, DER encoded bytes.

get_closest_prev_pe_for_templateID(cur: ProfileElement, tid: OID) ProfileElement | None

Return the PE of given templateID that is the closest PE prior to the given PE in the PE-Sequence.

get_index_by_pe(pe: ProfileElement) int

Return a list with the indicies of all instances of PEs of petype.

get_index_by_type(petype: str) List[int]

Return a list with the indicies of all instances of PEs of petype.

get_pe_for_type(tname: str) ProfileElement | None

Return a single profile element for given profile element type. Works only for types of which there is only a single instance in the PE Sequence!

get_pes_for_templateID(tid: OID) List[ProfileElement]

Return list of profile elements present for given profile element type.

get_pes_for_type(tname: str) List[ProfileElement]

Return list of profile elements present for given profile element type.

property iccid: str | None

The ICCID of the profile.

insert_after_pe(pe_before: ProfileElement, pe_new: ProfileElement) None

Insert a given [new] ProfileElement after a given [existing] PE in the PE Sequence.

insert_at_index(idx: int, pe: ProfileElement) None

Insert a given [new] ProfileElement at given index into the PE Sequence.

static naa_for_path(path: Path) Naa | None

determine the NAA for the given path

parse_der(der: bytes) None

Parse a sequence of PE from SAIP DER format and store the result in self.pe_list.

pe_for_path(path: Path) ProfileElement | None

Return the ProfileElement instance that can contain a file with matching path. This will either be an existing PE within the sequence, or it will be a newly-allocated PE that is inserted into the sequence.

static peclass_for_path(path: Path) ProfileElement | None

Return the ProfileElement class that can contain a file with given path.

rebuild_mandatory_gfstelist()

(Re-)build the eUICC Mandatory GFSTEList of the ProfileHeader based on what’s in the PE-Sequence. You would normally call this at the very end, before encoding a PE-Sequence to its DER format.

rebuild_mandatory_services()

(Re-)build the eUICC Mandatory services list of the ProfileHeader based on what’s in the PE-Sequence. You would normally call this at the very end, before encoding a PE-Sequence to its DER format.

remove_naas_of_type(naa: Naa) None

Remove all instances of NAAs of given type. This can be used, for example, to remove all CSIM NAAs from a profile. Will not just remove the PEs, but also any records in ‘eUICC-Mandatory-services’ or ‘eUICC-Mandatory-GFSTEList’.

renumber_identification()

Re-generate the ‘identification’ numbering of all PE headers.

to_der() bytes

Build an encoded DER representation of the instance.

class pySim.esim.saip.ProfileElementTelecom(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for DF.TELECOM

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.ProfileElementUSIM(decoded: dict | None = None, **kwargs)

Class representing the ProfileElement for ADF.USIM 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

class pySim.esim.saip.SecurityDomainKey(key_version_number: int, key_id: int, key_usage_qualifier: dict, key_components: List[SecurityDomainKeyComponent])

Representation of a key used for SCP access to a security domain.

classmethod from_saip_dict(saip: dict) SecurityDomainKey

Construct instance from the dict as generated by SAIP asn.1 decoder.

to_saip_dict() dict

Express instance in the dict format required by SAIP asn.1 encoder.

class pySim.esim.saip.SecurityDomainKeyComponent(key_type: str, key_data: bytes, mac_length: int = 8)

Representation of a key-component of a key for a security domain.

classmethod from_saip_dict(saip: dict) SecurityDomainKeyComponent

Construct instance from the dict as generated by SAIP asn.1 decoder.

to_saip_dict() dict

Express instance in the dict format required by SAIP asn.1 encoder.

pySim.esim.saip.bertlv_first_segment(binary: bytes) Tuple[bytes, bytes]

obtain the first segment of a binary concatenation of BER-TLV objects. Returns: tuple of first TLV and remainder.

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 something 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.personalization.file_replace_content(file: List[Tuple], new_content: bytes)

Completely replace all fillFileContent of a decoded ‘File’ with the new_content.

pySim.esim.saip.personalization.remove_unwanted_tuples_from_list(l: List[Tuple], unwanted_keys: List[str]) List[Tuple]

In a list of tuples, remove all tuples whose first part equals ‘unwanted_key’.

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

  • params – A list of parameters that an instance of the template must specify

  • ass_serv – The associated service[s] of the service table

  • high_update – Is this file of “high update frequency” type?

  • pe_name – The name of this file in the ASN.1 type of the PE. Auto-generated for most.

  • repeat – Whether the default_val pattern is a repeating pattern.

  • ppath – The intermediate path between the base_df of the ProfileTemplate and this file. If not specified, the file will be created immediately underneath the base_df.

expand_default_value_pattern(length: int | None = None) bytes | None

Expand the default value pattern to the specified length.

get_file_by_path(path: List[str]) FileTemplate | None

Return a FileTemplate matching the given path within this ProfileTemplate.

property path

Return the path of the given File within the hierarchy.

print_tree(indent: str = '')

recursive printing of FileTemplate tree structure.

class pySim.esim.saip.templates.FilesAtMF

Files at MF as per Section 9.2

class pySim.esim.saip.templates.FilesCD

Files at DF.CD as per Section 9.3

class pySim.esim.saip.templates.FilesDf5GProSe

DF.ProSe Files at ADF.USIM as per Section 9.5.14

parent

alias of FilesUsimMandatory

class pySim.esim.saip.templates.FilesDfSnpn

DF.SNPN Files at ADF.USIM as per Section 9.5.13

parent

alias of FilesUsimMandatory

class pySim.esim.saip.templates.FilesEap

Files at DF.EAP as per Section 9.8

class pySim.esim.saip.templates.FilesIsimMandatory

Mandatory Files at ADF.ISIM as per Section 9.6.1

class pySim.esim.saip.templates.FilesIsimOptional

Optional Files at ADF.ISIM as per Section 9.6.2 of v2.3.1

extends

alias of FilesIsimMandatory

class pySim.esim.saip.templates.FilesIsimOptionalv2

Optional Files at ADF.ISIM as per Section 9.6.2

extends

alias of FilesIsimMandatory

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].