Commit Graph

1129 Commits

Author SHA1 Message Date
Harald Welte 8a39d00cc3 osmo-smdpp: Support multiple different profiles
Let's simply use the matchingId for filesystem lookup of the UPP file.

This way we can have any number of profiles by simply creating the
respeective files.

Change-Id: I0bc3a14b9fdfcc6322917dd0c69d8295de486950
2024-01-30 21:33:41 +01:00
Harald Welte 3f3fd1a841 add SAIP template handling + v3.1 definitions
This adds classes for describing profile templates as well
as derived classes defining the profile templates of the
"Profile Interoperability Technical Specification", specifically
it's "ANNEX A (Normative): File Structure Templates Definition"

We need a machine-readable definition of those templates, so
we can fully interpret an unprotected profile package (UPP),
as the UPP usually only contains the increment/difference to
a given teplate.

Change-Id: I79bc0a480450ca2de4b687ba6f11d0a4ea4f14c8
2024-01-29 09:23:36 +01:00
Harald Welte 263e3094ba requirements.txt: Switch to osmocom fork of asn1tools
This is sadly required as the Interoperable Profile format must process
elements of an ASN.1 sequence in order, which doesn't work if the parser
puts the elements in a python dict.

The osmocom fork of asn1tools hence uses OrderedDict to work around
this problem.

Change-Id: Id28fcf060f491bb3d76aa6d8026aa76058edb675
2024-01-29 09:21:57 +01:00
Harald Welte e815e79db9 esim.saip: More type annotations
Change-Id: Ib549817ee137bab610aea9c89a5ab86c2a7592ea
2024-01-29 09:21:53 +01:00
Harald Welte 9f55da998f esim.saip: Move OID to separate sub-module
This helps us to prevent circular imports in follow-up code.

Change-Id: I94f85f2257d4702376f4ba5eb995a544a2e53fd3
2024-01-29 08:06:12 +01:00
Harald Welte 488427993d saip.personalization: Fix ICCID fillFileContent replacement
Change-Id: Ic267fdde3b648b376ea6814783df1e90ea9bb9ad
2024-01-28 22:03:11 +01:00
Harald Welte 0bce94996f saip.personalization: Also drop any fillFileOffset
When replacing a file's contents, we must not just remove any
fillFileContent tuples, but also the fillFileOffset.

Change-Id: I3e4d97ae9de8a78f7bc0165ece5954481568b800
2024-01-28 22:03:11 +01:00
Harald Welte 3d6df6ce13 [cosmetic] ara_m: Give a spec reference for the PERM-AR-DO
PERM-AR-DO actually originates in a different spec than all other parts
of the ara_m.py, so let's explicitly mention that.

Change-Id: I6e0014c323f605860d0f70cd0c04d7e461e8a9de
2024-01-27 20:50:12 +00:00
Harald Welte 7f2263b4a0 runtime: Reset selected_file_fcp[_hex] if SELECT returns no data
In case SELECT doesn't return any response data, we must reset
the lchan.selected_file_fcp* members to None to prevent pySim-shell
preventing stale data from the previously selected file.

Change-Id: Ia04b8634e328e604e8df7e8d59b7fd532242d2ca
2024-01-27 21:47:13 +01:00
Harald Welte 9b1a9d9b2e ara_m: Use GlobalPlatform SELECT decoding
As the ARA-M applet is a GlobalPlatform applet, its SELECT response
decoding should be used, not the ETSI EUICC TS 102 221 fall-back.

Change-Id: I1a30b88a385f6de663aa837483dd32c0d104856f
2024-01-27 21:47:13 +01:00
Harald Welte 5e0439f881 ara_m: Permit encoding of empty AID (--aid '') in ARA-M rules
Encoding an empty AID-REF-DO (4F) is neccessary to achieve the meaning
described in "Secure Element Access Control - Public Release v1.0"
Table 6-1: "Empty: Indicates that the rules to be stored or retrieved
are associated with all SE applications not covered by a specific rule".

Change-Id: Iac6c3d78bc9ce36bac47589e5f7a0cc78e2efc38
2024-01-27 21:47:13 +01:00
Harald Welte 9fd4bbe42e osmo-smdpp: Constrain selection of CI certificate
We can only choose a CI certificate which is supported both by the eUICC
as well as which has signed our own SM-DP+ certificates.

Change-Id: I0b9130f06d501ca7d484063d56d606cfdd2544f4
2024-01-25 19:16:57 +01:00
Harald Welte 18d0a7de96 global_platform: Add shell command for PUT KEY
This command is used for installation of GlobalPlatform keys.  We only
implement the command without secure messaging at this point, as it is
used during card personalization.  Authentication will later be handled
by generic implementations of SCP02 and/or SCP03.

Change-Id: Icffe9e7743266d7262fbf440dd361b21eed7c5cf
2024-01-25 19:16:57 +01:00
Harald Welte 280a9a3408 docs: Add missing global_platform store_data command docs
In If30c5d31b4e7dd60d3a5cfb1d1cbdcf61741a50e we introduced a store_data
comamnd, but forgot to add it to the pySim-shell manual.

Change-Id: I6039818c2c0c5373b4a4ef1e33e152de7fbbd01a
2024-01-25 19:16:57 +01:00
Harald Welte e6124b0aba add contrib/eidtool.py: Tool for checking + computing EID checksum
Change-Id: If6c560a2de51718948fb99b816e080f2aff4d0ed
2024-01-25 19:16:57 +01:00
Harald Welte 6dadb6c215 docs: Update osmo-smdpp with pointer to sysmoEUICC1-C2T and SGP.26
Change-Id: Id031ca48549a3c2ac21c93a169262570843d8e2d
2024-01-25 19:16:57 +01:00
Harald Welte af87cd544f osmo-smdpp: Implement eUICC + EUM certificate signature chain validation
Change-Id: I961827c50ed5e34c6507bfdf853952ece5b0d121
2024-01-22 19:08:09 +01:00
Harald Welte 45b7dc9466 Move X.509 related code from osmo-smdpp to pySim.esim.x509_cert
Change-Id: I230ba0537b702b0bf6e9da9a430908ed2a21ca61
2024-01-22 17:57:55 +01:00
Harald Welte c83a963877 New pySim.esim.x509_cert module for X.509 certificate handling
Change-Id: Ia8cc2dac02fcd96624dc6d9348f103373eeeb614
2024-01-22 17:57:55 +01:00
Harald Welte 667d589f20 pySim.utils: Support datetime.datetime in JsonEncoder
Change-Id: I6223475cec8eb45c6fc4278109ad9dd1cb557800
2024-01-18 16:58:48 +01:00
Harald Welte ebb6f7f938 osmo-smdpp: Actually dump Rx/Tx JSON in JSON format and not as python dict
Change-Id: Ieea3fd2d0f0239acfa6a5c4cfdbfd558d1a3e0ea
2024-01-18 16:58:48 +01:00
Harald Welte 0311c92e96 Fix encoding of decoded/json data in update_{record_binary}_decoded
The patch introducing the is_hexstr type into the argparser was
accidentially also introduce in two locations where we actually don't
expect a hex-string.

This is a partial revert of I6426ea864bec82be60554dd125961a48d7751904

Change-Id: I3c3d2a2753aa7a2566a3b1add7ba70c86499d293
Closes: #6331
2024-01-18 16:58:48 +01:00
Harald Welte 66b337079a pySim-shell: Permit 'reset' command also in unqeuipped stage
If we are not 'equipped' as we could not detect any known applications
on the card, we used to only permit the 'apdu' command. However, we
should also permit the 'reset' command, as it also is something that's
possible with ever card, even of unknown types.

Change-Id: I23199da727973d7095ac18031f49e1e8423aa287
2024-01-16 18:48:52 +00:00
Harald Welte 4f3d11b378 euicc: Implement EID checksum verification + computation
Change-Id: I2cb342783137ee7e4b1be3b14e9c3747316f1995
2024-01-16 19:04:19 +01:00
Harald Welte cd18ed0a82 ts_102_221: Better explain 'selected file invalidated'
Some specs call it 'invalidated', others call it 'deactivated'.  If the
user is unfamiliar with this, the error message about "invalidated"
might not be obvious enough; let's also mention 'deactivated' in the
message and explicitly mention that it needs to be activated before use.

Change-Id: I91488b0e7dc25a8970022b09e575485a4165eefa
2024-01-16 19:04:10 +01:00
Harald Welte ecfb09037e global_platform: More definitions to support key loading
With the definitions from this commit, we can build key loading
TLVs, which is used to load ECC keys into eUICCs.

Change-Id: I853c94d37939ef3dd795f893232b0276a5a4af81
2024-01-14 18:21:57 +01:00
Harald Welte 1f7a9bd5b4 TLV: Add DGI encoding of "GP Scripting Language Annex B"
The DGI encoding is specified in Annex B of the
"GlobalPlatform Systems Scripting Language Specification v1.1.0"

which is an "archived" specification that is no longer published
by GlobalPlatform, despite it being referenced from the GlobalPlatform
Card Specification v2.3, which is the basis of the GSMA eSIM
specifications.

For some reason it was the belief of the specification authors that
yet another format of TLV encoding is needed, in addition to the BER-TLV
and COMPREHENSION-TLV used by the very same specifications.

The encoding of the tag is not really specified anywhere, but I've only
seen 16-bit examples.  The encoding of the length is specified and
implemented here accordingly.

Change-Id: Ie29ab7eb39f3165f3d695fcc1f02051338095697
2024-01-14 17:42:01 +01:00
Harald Welte d5be46ae7e global_platform: Implement generic store_data command
Change-Id: If30c5d31b4e7dd60d3a5cfb1d1cbdcf61741a50e
2024-01-14 17:32:53 +01:00
Harald Welte 7ba09f9392 euicc: Migrate ECASD + ISD-R over to global_platform.CardApplicationSD
Actually, the GSMA eUICC is a kind of derivative of a GlobalPlatform
card, and the ECASD and ISD-R are security domains.  As such, we
should make them derived classes of global_platform.CardApplicationSD
which means they inherit some of the shared shell_commands etc.

Change-Id: I660e874d9bcbb8c28a64e4ef82dc53bee97aacfc
2024-01-12 10:02:54 +01:00
Harald Welte 91842b471d Constrain user input to hex-string in argparse
We do have an is_hexstr function which we should use anywhere
where we expect the user to input a string of hex digits.  This way
we validate the input before running in some random exception.

Change-Id: I6426ea864bec82be60554dd125961a48d7751904
2024-01-12 10:02:54 +01:00
Harald Welte d1cc8d0c1d euicc: Fix decoding of SubjectKeyIdentifier.
There's actually no additional TLV structure inside the Tag 0x04.

Change-Id: Ic922355308747a888083c5b26765d272b6b20bd0
2024-01-09 23:35:10 +01:00
Harald Welte f2bcb44ccc pySim.saip.*: Support for parsing / operating on eSIM profiles
This commit introduces the capability to parse and encode
SimAlliance/TCA "Interoperable Profiles" and apply personalization
operations on them.

Change-Id: I71c252a214a634e1bd6f73472107efe2688ee6d2
2024-01-09 21:37:12 +00:00
Harald Welte 5bbb144a31 Initial proof-of-concept SM-DP+ for GSMA consumer eSIM RSP
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-09 21:37:12 +00:00
Harald Welte e76fae9c4c pySim-shell: Update manual with examples for using with eUICC ISD-R
Change-Id: I4a0acdad5c7478ee76f92c7610c0e2a5331dea46
2024-01-08 20:56:32 +00:00
Harald Welte c499dc79a8 euicc: Fix eUICC list_notifications command
Prior to this patch, the command would always raise exceptions.

Change-Id: I75a7840c3f4b68bfc164a43908b100dd6e41e575
2024-01-08 12:10:22 +00:00
Harald Welte 0002789a88 euicc: Fix delete_profile command
Contrary to {enable,disable}_profile, the delete_profile does not use
the ProfileIdentifier TLV, but directly the Iccid / IsdpAid.

Change-Id: I43e298524048703264e16cbdd0b76d82ba976985
2024-01-08 12:10:17 +00:00
Harald Welte cfa62cb95b Allow logger to do lazy evaluation of format strings
Change-Id: I39d26cdd5b85a61a06fd8c7a9d0a046e398819bd
2024-01-08 12:10:11 +00:00
Harald Welte d657708df2 add contrib/unber.py utility
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-08 11:18:49 +00:00
Harald Welte 242197b53d Add pySim.esim.bsp module implementing BSP (BPP Protection Protocol)
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-07 10:22:04 +01:00
Harald Welte 5b623a1247 ts_102_310: Add file definitions resembling ETSI TS 102 310 (EAP)
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-04 21:50:38 +01:00
Harald Welte 62e570b620 ts_31_103: Add TLV + construct for EF_NAFKCA
Change-Id: I124064994eb695790e9a3aff40be8139b3a2f2cf
2024-01-04 21:27:39 +01:00
Harald Welte 4fe7de8568 ts_31_103: Add construct for EF.GBABP and EF.GBANL
Change-Id: Ife06f54c2443f3e048bd36f706f309843703403a
2024-01-04 21:27:39 +01:00
Harald Welte b0c9ccba66 construct: avoid StreamError exceptions due to files containing all-ff
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-04 21:20:19 +01:00
Harald Welte e13403b206 ts_31_102: Start to use construct for EF.SUCI_Calc_Info
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-04 20:13:06 +01:00
Harald Welte 9a48aea263 fileystem/tlv: remove unused imports
Change-Id: I519c7792c7fbe18be63ddc77d211f0d034afcd1f
2024-01-02 21:13:30 +01:00
Harald Welte 19d2b93d7e move SUCI sub-classes to EF_SUCI_CalcInfo
Change-Id: Iea6b176327881ff9414f4fe624e94811f9782927
2023-12-29 18:51:25 +01:00
Harald Welte 9d607978fa global_platform: Add support for more GET DATA TLVs
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-29 18:51:25 +01:00
Harald Welte 1c0a249131 commands: Ignore exceptions during READ while UPDATE
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-29 18:51:25 +01:00
Harald Welte db1684df04 sysmocom_sja2: Implement EF_CHV files using construct
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-29 18:51:25 +01:00
Harald Welte ce01f48b00 test_files: Test decoder also with ff-padded input
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-29 18:51:25 +01:00