aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
2024-01-10WIP: osmo-smdpp ES9+ support for ASN.1 endpointlaforge/smdp_asn1Harald Welte1-29/+149
2024-01-09euicc: Fix decoding of SubjectKeyIdentifier.Harald Welte1-5/+3
There's actually no additional TLV structure inside the Tag 0x04. Change-Id: Ic922355308747a888083c5b26765d272b6b20bd0
2024-01-09pySim.saip.*: Support for parsing / operating on eSIM profilesHarald Welte5-0/+1668
This commit introduces the capability to parse and encode SimAlliance/TCA "Interoperable Profiles" and apply personalization operations on them. Change-Id: I71c252a214a634e1bd6f73472107efe2688ee6d2
2024-01-09Initial proof-of-concept SM-DP+ for GSMA consumer eSIM RSPHarald Welte84-0/+3163
This commit introduces * the osmo-smdpp.py program implementing the main procedures and the HTTP/REST based ES9+ * python modules for ES8+ and non-volatile RSP Session State storage * the ASN.1 source files required to parse/encode RSP * 3GPP test certificates from SGP.26 * an unsigned profile package (UPP) of a SAIP v2.3 TS48 test profile As I couldn't get the 'Klein' tls support to work, the SM-DP+ code currently does not support HTTPS/TLS but plan HTTP, so you either have to modify your LPA to use HTTP instead of HTTPS, or put a TLS proxy in front. I have successfully installed an eSIM profile on a test eUICC that contains certificate/key data within the test CI defined in GSMA SGP.26 Change-Id: I6232847432dc6920cd2bd08c84d7099c29ca1c11
2024-01-08pySim-shell: Update manual with examples for using with eUICC ISD-RHarald Welte1-1/+206
Change-Id: I4a0acdad5c7478ee76f92c7610c0e2a5331dea46
2024-01-08euicc: Fix eUICC list_notifications commandHarald Welte1-3/+4
Prior to this patch, the command would always raise exceptions. Change-Id: I75a7840c3f4b68bfc164a43908b100dd6e41e575
2024-01-08euicc: Fix delete_profile commandHarald Welte1-3/+3
Contrary to {enable,disable}_profile, the delete_profile does not use the ProfileIdentifier TLV, but directly the Iccid / IsdpAid. Change-Id: I43e298524048703264e16cbdd0b76d82ba976985
2024-01-08Allow logger to do lazy evaluation of format stringsHarald Welte3-7/+7
Change-Id: I39d26cdd5b85a61a06fd8c7a9d0a046e398819bd
2024-01-08add contrib/unber.py utilityHarald Welte1-0/+39
This tool is a replacement for asn1c 'unber' program with a much more useful/readable output: * contains hexadecimal raw tag values * contains hexdump of value, rather than HTML entities in pseudo-XML Change-Id: I22c1a461ccba04c2c8caaab7ca29ea6ae76e2ea3
2024-01-07Add pySim.esim.bsp module implementing BSP (BPP Protection Protocol)Harald Welte4-0/+370
This is the protocol used for the ES8+ interface between SM-DP+ and the eUICC in the GSMA eSIM system. Change-Id: Ic461936f2e68e1e6f7faab33d06acf3063e261e7
2024-01-04ts_102_310: Add file definitions resembling ETSI TS 102 310 (EAP)Harald Welte1-0/+114
The definitions are not used yet, as one would have to add that dynamically based on which EF.DIR entries contain the 0x73 discretionary template. As I don't have any cards implementing this so far, I'll skip that part. Change-Id: I532ff2c94021ab1b4520fe2b6988c8960319d208
2024-01-04ts_31_103: Add TLV + construct for EF_NAFKCAHarald Welte1-2/+9
Change-Id: I124064994eb695790e9a3aff40be8139b3a2f2cf
2024-01-04ts_31_103: Add construct for EF.GBABP and EF.GBANLHarald Welte2-1/+13
Change-Id: Ife06f54c2443f3e048bd36f706f309843703403a
2024-01-04construct: avoid StreamError exceptions due to files containing all-ffHarald Welte1-1/+10
In smart cards, files/records containing all-ff means they are simply not used/initialized. Let's avoid raising exceptions when interpreting 0xff as length value and reading less bytes as value. Change-Id: I09c3cb82063fc094eb047749996a6eceff757ea2
2024-01-04ts_31_102: Start to use construct for EF.SUCI_Calc_InfoHarald Welte2-63/+31
We cannot fully switch to construct for all of it easily due to the priority value and the ordering/sorting by priority implemented in the hand-coded version. But we can at least migrate the encode/decode of the hnet_pubkey_list via construct. Change-Id: I4ad5ea57bab37c2dc218e7752d538aa4cdc36ee3
2024-01-02fileystem/tlv: remove unused importsHarald Welte2-2/+1
Change-Id: I519c7792c7fbe18be63ddc77d211f0d034afcd1f
2023-12-29move SUCI sub-classes to EF_SUCI_CalcInfoHarald Welte1-27/+25
Change-Id: Iea6b176327881ff9414f4fe624e94811f9782927
2023-12-29global_platform: Add support for more GET DATA TLVsHarald Welte1-1/+61
Example: pySIM-shell (00:MF/ADF.ISD)> get_data extended_card_resources_info { "extended_card_resources_info": [ { "number_of_installed_app": 8 }, { "free_non_volatile_memory": 354504 }, { "free_volatile_memory": 10760 } ] } Change-Id: I129e43c377b62dae1b9a88a0a2dc9663ac2a97da
2023-12-29commands: Ignore exceptions during READ while UPDATEHarald Welte1-7/+21
If we are reading a file to check if we can skip the write to conserve writes, don't treat exceptions as fatal. The file may well have the access mode in a way that permits us to UPDATE but not to READ. Simply fall-back to unconditional UPDATE in this case. Change-Id: I7bffdaa7596e63c8f0ab04a3cb3ebe12f137d3a8
2023-12-29sysmocom_sja2: Implement EF_CHV files using constructHarald Welte1-20/+24
this has the advantage of getting the encoder for free (so far we only had the decoder). While at it, also add some tests data for the unit tests. Change-Id: Ifb8caf5cd96706d7fb6b452d6552b115c0828797
2023-12-29test_files: Test decoder also with ff-padded inputHarald Welte5-7/+53
It's customary in the SIM card universe to right-pad data with ff bytes. So far we only test decoders without such padding, which is unrealistic. Let's also tests the decoders with extra 'ff' padding present. For some files this doesn't make sense, so we add a _test_no_pad class attribute that can be spcified to prevent this new "test with ff-padding" from being executed for the test data of the class. Change-Id: I7f5cbb4a6f91040fe9adef9da0a1f30f9f156dae
2023-12-29tests_files.py: Reduce code duplicationHarald Welte1-24/+17
Change-Id: Ib84a0ae35262a19fce3e688afe8e1678a4c59eba
2023-12-29Fix TLV_IE_Collection.from_tlv in certain situationsHarald Welte1-1/+1
The existing code used to produce an empty output in situations where a TLV_IE_Collection would be parsed from a single TLV only with some additional trailing padding: >>> from pySim.utils import h2b >>> from pySim.ts_31_102 import EF_CSGT >>> t = EF_CSGT.Csgt_TLV_Collection() >>> t.from_tlv(h2b('8906810300666f6fff')) [TextCsgType(foo)] >>> t.to_dict() [] This was caused by an early return (actually returning the decoded result) but *without updating self.children*. Change-Id: I1c84ccf698c6ff7e7f14242f9aaf7d15ac2239f4
2023-12-29ts_31_102: Implement decoders/encoders for EFs below DF.HNBHarald Welte1-6/+83
These files are mostly related to CSG (Closed Subscriber Group) in the context of HomeNodeB (HNB), aka femtocells. Change-Id: Ie57963381e928e2c1da408ad46549a780056242a
2023-12-29support UCS-2 characters in EF.MMSUP, EF.ADN, EF.SPN, EF.PNN, EF.ECCHarald Welte3-4/+41
Now that we have support for the UCS-2 encoding as per TS 102 221 Annex A, we can start to make use of it from various file constructs. As some specs say "Either 7-bit GSM or UCS-2" we also introduce a related automatic GsmOrUcs2Adapter and GsmOrUcs2String class. Change-Id: I4eb8aea0a13260a143e2c60fca73c3c4312fd3b2
2023-12-29Implement convoluted encoding of UCS-2 as per TS 102 221 Annex AHarald Welte2-0/+202
TS 102 221 Annex A defines three variants of encoding UCS-2 characters into byte streams in files on UICC cards: One rather simplistic one, and two variants for optimizing memory utilization on the card. Let's impelement a construct "Ucs2Adapter" class for this. Change-Id: Ic8bc8f71079faec1bf0e538dc0dfa21403869c6d
2023-12-28add PlmnAdapter for decoding PLMN bcd-strings like 262f01 to 262-01Harald Welte6-17/+34
The human representation of a PLMN is usually MCC-MNC like 262-01 or 262-001. Let's add a PlmnAdapter for use within construct, so we can properly decode that. Change-Id: I96f276e6dcdb54a5a3d2bcde5ee6dbaf981ed789
2023-12-27Fix enumeration of GlobbalPlatformISDR during card_init()Harald Welte2-4/+4
We used __subclasses__(), but this only returns the immediate subclasses and not all further/nested subclasses. Instead, we must use the pySim.utils.all_subclasses() function to really get all of them. The hack to use the method signature of the constructor to determine if it's an intermediate class didn't work, as even GlobbalPlatformISDR has a optional argument for non-default AIDs. So let's introduce an explicit class attribute for that purpose. Change-Id: I7fb1637f8f7a149b536c4d77dac92736c526aa6c
2023-12-27global_platform: Add support for key types of v2.3.1 (including AES)Harald Welte1-1/+15
Change-Id: Iae30f18435c2b0a349bfd9240b9c7cca06674534
2023-12-27global_platform: Add TLV test data for Key Information DataHarald Welte2-14/+14
Change-Id: Ib7b73cb28abea98986a66264a0779263873d7fb2
2023-12-27global_platform: Correctly decode Key Information DataHarald Welte1-1/+2
The list contains tuples of (key_type, key_length). Let's fix that. Change-Id: Icf367827d62ed67afa27ee3d0ba9d5cd5bc65c99
2023-12-27Add TLV decoder test dataHarald Welte1-2/+19
This adds some first test data for the new unitdata driven test cases for the TLV encoder/decoder. It also fixes a bug in the ts_102_221.FileDescriptor decoder for BER-TLV structured files which was found and fixed while introducing the test data. Related: OS#6317 Change-Id: Ief156b7e466a772c78fb632b2fa00cba2eb1eba5
2023-12-27data-driven TLV unit data test supportHarald Welte1-0/+122
While we do have the _test_de_encode data driven tests for file definitions, we don't yet have something similar for derived classes of BER_TLV_IE. This means that TLVs used outside of the filesystem context (for example, decoding the SELECT/STATUS response, but also eUICC and other stuff) do not yet have test coverage. This commit just adds the related test code, but no test data yet. Related: OS#6317 Change-Id: Ied85f292bb57fde11dc188be84e3384dc3ff1601
2023-12-27tlv: Fix from_dict() symmetryHarald Welte1-4/+4
the to_dict() method generates a {class_name: value} dictionary, for both the nested and non-nested case. However, before this patch, the from_dict() method expects a plain list of child IE dicts in the nested case. This is illogical. Let's make sure from_dict always expectes a {class_name: value} dict for both nested and non-nested situations. Change-Id: I07e4feb3800b420d8be7aae8911f828f1da9dab8
2023-12-23filesystem: use pySim.utils.build_construct()Harald Welte2-9/+9
We recently introduced a pySim.utils.build_construct() wrapper around the raw call of the construct.build() method. So far, this wrapper was only used from pySim.tlv, but let's also use it from pySim.filesystem. Basically, whenever we use parse_construct(), we should use build_construct() as the inverse operation. Change-Id: Ibfd61cd87edc72882aa66d6ff17861a3e918affb
2023-12-23pySim-trace_test.sh: Force termcolor to suppress color generationHarald Welte1-0/+2
on some systems, the output would otherwise contain colored status words, which in turn mean the test otuput no longer matches the expected output. Change-Id: Icb700f6e85a285748e00367a398975aa5e75dec5
2023-12-23construct/tlv: Pass optional 'context' into construct decoder/encoderHarald Welte2-31/+36
The context is some opaque dictionary that can be used by the constructs; let's allow the caller of parse_construct, from_bytes, from_tlv to specify it. Also, when decoding a TLV_IE_Collection, pass the decode results of existing siblings via the construct. Change-Id: I021016aaa09cddf9d36521c1a54b468ec49ff54d
2023-12-23docs/shell: extend the introduction part; link to video presentationHarald Welte1-2/+21
Change-Id: I77c30921f2b8c002c9dda244656c348c96b41f06
2023-12-23additional encode/decode test data for various filesHarald Welte4-1/+33
Change-Id: Ib563a2204922d2013b5f7c5abde0773051e17938
2023-12-2331.102 + 51.011: Fix encode/decode of EF.CFISHarald Welte2-4/+24
The EF.CFIS definition is not identical to EF.ADN, so we cannot recycle the EF.ADN class to decode EF.CFIS. Change-Id: Idcab35cbe28332e3c8612bcb90226335b48ea973
2023-12-23fix encode/decode of xPLMNwAcTHarald Welte8-38/+42
There are some pretty intricate rules about how GSM and E-UTRAN are encoded, let's make sure we fully support both as per 3GPP TS 31.102 Release 17. As part of this, switch to a sorted list of access technologies, in order to have a defined order. This makes comparing in unit tests much easier. However, it also means that we need to sort the set when printing the list of AcT in pySim-read to generate deterministic output. Change-Id: I398ac2a2527bd11e9c652e49fa46d6ca8d334b88
2023-12-22test/test_files: set maxDiff attributeHarald Welte1-0/+4
Without this the diff between expected and actual output is truncated and one instead reads the following output: Diff is 844 characters long. Set self.maxDiff to None to see it. We actually want to see the full diff to see what's not matching. Change-Id: I6e89705061454191b6db1255de7fe549ad720800
2023-12-22tests: use case-insensitive compare of hex stringsHarald Welte1-4/+4
Change-Id: I080f6e173fec40c27dd3ebbf252eaddf5a0e15ba
2023-12-21transport: Extend the documentation for each transport driverHarald Welte4-4/+16
This driver description we add to the code is automatically added to the respective user manual sections. Change-Id: I8807bfb11f43b167f1321d556e09ec5234fff629
2023-12-21transport: Move printing of reader number/name to generic codeHarald Welte5-19/+11
Let's avoid copy+pasting print statements everywhere. The instances do already have a __str__ method for the purpose of printing their name in a generic way. Change-Id: I663a9ea69bf7e7aaa6502896b6a71ef692f8d844
2023-12-21transport/pcsc: Allow opening PC/SC readers by a regex of their nameHarald Welte2-13/+31
Opening PC/SC readers by index/number is very error-prone as the order is never deterministic in any system with multiple (hot-plugged, USB) readers. Instead, let's offer the alternative of specifying a regular expression to match the reader name (similar to remsim-bankd). Change-Id: I983f19c6741904c1adf27749c9801b44a03a5d78
2023-12-21transport: Pass argparse.Namespace directly into transport classesHarald Welte6-21/+23
It's odd that the individual transport driver specifies their argparse options but then the core transport part evaluates them individually. This means we cannot add new options within a transport. Let's pass the Namespace instance into the constructor of the specific transport to improve this. Change-Id: Ib977007dd605ec9a9c09a3d143d2c2308991a12c
2023-12-17move {enc,dec}_addr_tlv functions from pySim.util to pySim.legacy.utilHarald Welte3-123/+122
In the previous commit we've stopped using those functions from modern pySim-shell code. Hence, the only remaining user is the legacy tools, so we can move the code to the legacy module. Change-Id: I6f18ccb36fc33bc204c01f9ece135676510e67ec
2023-12-17isim: Replace legacy imperative address TLV encoder/decoder with constructHarald Welte2-18/+17
We've recently introduced IPv{4,6}Adapter construct classes and can switch to this instead of using the old imperative encoder/decoder functions {enc,dec}_addr_tlv(). Aside from code cleanup, this also means we now support the IPv6 address type in EF.PCSCF. Change-Id: I4d01ccfe473a8a80fbee33fdcbd8a19b39da85ac
2023-12-17bertlv_parse_len: Fix input data is smaller than num length octetsHarald Welte1-0/+2
This can happen if there's a file with invalid encoding on the card, such as a tag followed by all-ff. Let's gracefully ignore it and return zero bytes as response. Change-Id: Ic44557368a6034dbf4bb021ab23a57927c22def0