166 Commits

Author SHA1 Message Date
Harald Welte
d25ea35e7e pySim.esim.saip: Decode each 'File' element in ProfileElement
When loading a ProfileElement from its DER-ecoded format, populate
a dict with a pySim.esim.saip.File object for each file.

Change-Id: Ie2791c10289eb28daed2904467b0c5e5b11c94c2
2024-07-27 10:30:26 +02:00
Harald Welte
6d2e385acf pySim.esim.saip: Add OID comparison functions
Change-Id: Iab642e0cc6597f667ea126827ea888652f0f2689
2024-07-27 10:30:26 +02:00
Harald Welte
92bae20b49 osmo-smdpp + es9p_client: HTTP status 204 is used for handleNotification
As SGP.22 states, the handleNotification endpoint uses HTTP status 204,
not 200 (due to its empty body).

Change-Id: I890bdbd3e1c4578d2d5f0367958fdce26e338cac
2024-07-17 18:37:02 +02:00
Harald Welte
03194c0877 pySim.esim.es8p: Add support for encoding icon in ProfileMetadata
Change-Id: I8c6a0c628f07c2a9608174457d20b8955114731a
2024-07-17 18:05:57 +02:00
Harald Welte
84077f239f osmo-smdpp: Request enable/disable/delete notifications in metadata
this way, the eUICC will send us notifications whenever our profiles are
enabled/disabled/deleted.

Change-Id: I2861290864522b691b30b079c7c2e1466904df2d
2024-07-17 18:05:57 +02:00
Harald Welte
3ad3da8995 contrib/es9p_client: Add support for reporting notifications to SM-DP+
The ES9+ interface is not only used for downloading eSIM profiles, but
it is also used to report back the installation result as well as
profile management operations like enable/disable/delete.

Change-Id: Iefba7fa0471b34eae30700ed43531a515af0eb93
2024-07-17 18:05:57 +02:00
Harald Welte
96e2a521e9 pySim.esim.http_json_api: 'header' is not always present in response
For example, the ES9+ handleNotification function is defined with an
empty response body, so we cannot unconditionally assume that every HTTP
response will contain a JSON "header" value.

Change-Id: Ia3c5703b746c1eba91f85f8545f849a3f2d56e0b
2024-07-16 16:58:55 +00:00
Harald Welte
b5679386d7 pySim.esim.saip: Add methods to rebuild "mandatory" lists in ProfileHeader
The ProfileHeader PE contain lists of template-oids and services that
are mandatory in this profile.  Let's add methods that can be used to
(re-) compute those lists based on the actual PE contents of the
sequence.

The idea is that during programmatic construction of a profile, those methods
would be called after appending all PEs, just before encoding the
profile as DER.

Change-Id: Ib43db8695c6eb63965756364fda7546d82df0beb
2024-07-10 06:51:23 +00:00
Harald Welte
03aebf5b43 pySim.esim.saip: ProfileElement{Header,End} classes
Change-Id: I88e18c1ee4907eeac3ae5d04d7bc30d6765f91fa
2024-07-10 06:51:23 +00:00
Harald Welte
5f9b8a8fc1 pySim.esim.saip: Move initialization of PE header to base class
Let's avoid the copy+paste in the subclass constructors and initialize the profile
element header in the base class constructor.

Change-Id: I6e69ae1f0d33d963247fc506db33b3840c10c19a
2024-07-10 06:51:23 +00:00
Harald Welte
3b7e2ae2c1 pySim.saip: Add ProfileElementRFM class
Change-Id: I547e02c12345932deafa4b914fcaeaa183b69798
2024-07-10 06:51:23 +00:00
Harald Welte
2668eb6148 pySim.esim.saip: Add ProfileElementOpt{USIM,ISIM} classes
Change-Id: Iebff2e767baa19f272eeddc62d7d5b3a8f665db5
2024-07-10 06:51:23 +00:00
Harald Welte
3c530c3c1a pySim.saip.oid: Properly differentiate optional from non-optional templates
There are e.g. templates for usim and for opt-usim, and they should not
be confused with each other.  Let's reflect that in the naming.

Change-Id: Ic6d04ce3172dc969c6b8c018b8d305eb6fd3f550
2024-07-10 06:51:23 +00:00
Harald Welte
292191d67a pySim.esim.saip: Add ProfileElementAKA constructor + methods
This helps us to construct an akaParameter PE from scratch.

Change-Id: I4cc42c98bf82aec085ab7f48aea4ff7efa0eae9e
2024-07-10 06:51:23 +00:00
Harald Welte
c0ea149555 pySim.esim: Allow calling compile_asn1_subdir() with non-DER coddec
this isn't needed for the on-wire format, but can be useful for debug
output in GSER or JER.

Change-Id: I1de4b9506a92d60f582c328a180760332584f9e4
2024-07-10 06:51:23 +00:00
Harald Welte
200bf6eb8b pySim.esim.saip: Meaningful defaults in PE Constructor + test
Let's make sure the constructor of ProfileElement subclasses set
meaningful defaults to the self.decoded member, so that the to_der()
method can actually encode it.   This is required when constructing
a profile from scratch, as opposed to loading an existing one from DER.

Also, add a test to verify that the encoder passes without exception;
doesn't test the generated binary data.

Change-Id: I401bca16e58461333733877ec79102a5ae7fe410
2024-07-10 06:51:23 +00:00
Harald Welte
b6532b56d2 saip-tool: Add 'extract-apps' to dump all applications from eSIM profile
This new action can be used to dump all java applications as either raw
IJC file or converted to CAP format (the usual format generated by
JavaCard toolchains).

Change-Id: I51cffa5ba3ddbea491341d678ec9249d7cf470a5
2024-06-11 08:45:27 +02:00
Harald Welte
3d70f659f3 saip-tool: Add new 'info' action to print general information
It will print something like this:

SAIP Profile Version: 2.1
Profile Type: 'GSMA Generic eUICC Test Profile'
ICCID: 8949449999999990023f
Mandatory Services: usim, isim, csim, javacard, usim-test-algorithm

NAAs: mf[1], usim[1], csim[1], isim[1]
NAA mf
NAA usim (a0000000871002ff49ff0589)
        IMSI: 001010123456063
NAA csim
NAA isim (a0000000871004ff49ff0589)

Number of applications: 0

Change-Id: I107d457c3313a766229b569453c18a8d69134bec
2024-06-10 13:39:40 +02:00
Harald Welte
ecb65bc2f2 esim.saip: Remove debug print()
Change-Id: I8dfe29302225d951e656d1321bbd249bfe242602
2024-06-10 13:39:40 +02:00
Harald Welte
4680503acc esim.saip: Add ProfileElementSequence.remove_naas_of_type
This method allows the caller to remove all NAAs of a certain type,
for example to remove all CSIM instances from a given profile.

Change-Id: I64438bf0be58bad7a561c3744b7e9b1338a7857c
2024-06-09 12:18:16 +02:00
Harald Welte
0cb0e02c5c esim.saip: Introduce ProfileElement.identification property
Change-Id: I6525bb78619e574296488843e021d505e0632d99
2024-06-09 12:18:16 +02:00
Harald Welte
50d9e2a6d8 esim.es9p: Suppress sending requestHeader on ES9+
SGP.22 states that ES9+ should not include a requestHeader

Change-Id: Ic9aa874a82241d7b26e2bcb0423961173e103020
2024-06-09 12:18:16 +02:00
Harald Welte
888c6e5647 add contrib/es9p_client: Perform ES9+ client functions like LPA+eUICC
This tool can be used to test the SM-DP+. It implements the full dance
of all HTTPs API operations to get to the downloadProfile, and will
decrypt the BPP to the UPP, which is then subsequently stored as file on
disk.

Needless to say, this will only work if you have an eUICC certificate +
private key that is compatible with the CI of your SM-DP+.

Change-Id: Idf8881e82f9835f5221c58b78ced9937cf5fb520
2024-06-09 12:18:16 +02:00
Harald Welte
f07161d396 http_json_api / es9p: Add User-Agent header
ES9+ (And ES11) require the use of User-Agent, while ES2+ not.

Change-Id: Iffe64d82087940a82fbfa73bf5d2b7e864ae5d67
2024-06-09 12:18:16 +02:00
Harald Welte
0d1dea01df add pySim.esim.es9p with definitions of the ES9+ HTTP Interface
Let's use the infrastructure of pySim.esim.http_json_api to define
the ES9+ API Functions.  This can in turn be used by clients or even
osmo-smdpp can be ported over to using this infratructure rather than
open-coding a lot of the encoding/decoding of API request/response
parameters.

Change-Id: I194ef1d186391f36245c099cc70a4813185ecf9c
2024-06-09 12:18:16 +02:00
Harald Welte
f1495c1e4e esim.es2p: Split generic part of HTTP/REST API from ES2+
This way we can reuse it for other eSIM RSP HTTP interfaces like
ES9+, ES11, ...

Change-Id: I468041da40a88875e8df15b04d3ad508e06f16f7
2024-06-09 12:18:16 +02:00
Harald Welte
0251367ddb pySim.esim.saip: Meaningful constructors for [I]SD + SSD
So far the main use case was to read a ProfileElement-SD from
a DER file.  But when we want to construct one from scratch,
we need to have the constructor put some meaningful [default]
values into the class members.

Change-Id: I69e104f1d78165c12291317326dbab05977a1574
2024-06-04 23:18:37 +02:00
Harald Welte
bc949649da esim.saip: Implement ProfileElement.header_name for more PE types
We now cover all PE types as of PE_Definitions-3.3.1.asn

Change-Id: I37951a0441fe53fce7a329066aebd973389cb743
2024-06-04 23:00:46 +02:00
Harald Welte
4d5d2f5849 pySim.esim.saip.validation: Ensure unique PE identification value
Change-Id: I37b9eb4cfb74de79b0493986d976c8a5f8ccd8ea
2024-06-04 20:51:57 +00:00
Harald Welte
77256d0c48 esim.saip: Implement SecurityDomainSD.{add,has,remove}_key() methods
This way it's possible to programmatically inspect and modify the
high-level decoded key material inside a securityDomain profile element.

Change-Id: I18b1444303de80eaddd840a7e0061ea0098a8ba1
2024-06-04 20:51:57 +00:00
Harald Welte
80976b65e5 esim.saip: Introduce ProfileElement derived classes
It's rather useful to have derived classes implementing specific
functions related to that SAIP profile type.  Let's introruce that
concept and a first example for securityDomain, where methods allow
checking/adding/removing support for SCPs.

Change-Id: I0929cc704b2aabddbc2ddee79ab8b674b1ed4691
2024-06-04 20:51:57 +00:00
Harald Welte
fe28a1d87d esim.bsp: Fix a bug in demac_only_one()
When de-MAC-ing at the recipient side, we must increment the cipher(!)
block number even if no ciphering is done at all.

We did this correctly for MAC (sender) case, but not on the de-MAC
(receiver) case.

Change-Id: I97993f9e8357b36401d435aaa15558d1c7e411eb
2024-06-03 16:07:57 +00:00
Harald Welte
ee7be44528 utils: Introduce BER-TLV parsers that return raw tag or even raw TLV
In the eSIM RSP univers there are some rather ugly layering violatoins
where ASN.1 cannot be parsed but we have to mess with raw TLVs and the
details of DER encoding.  Let's add two funtions that make it more
convenient to work with this: They return the raw tag as integer, or
even the entire encoded TLV rather than the value part only.

Change-Id: I1e68a4003b833e86e9282c77325afa86ce144b98
2024-06-03 16:07:57 +00:00
Harald Welte
2755b54ded [cosmetic] fix typos in comments
Change-Id: I549ef7002e6ebef3f13af620cad8d03c7f4d891a
2024-06-02 18:23:31 +00:00
Harald Welte
56912caac7 osmo-smdpp: Don't re-encode euiccSigned1/euiccSigned2
We used to re-encode those parts of a decoded ASN.1 struct that is
cryptographically signed in the GSMA SGP.22 specification.  However, if
the received data follows a later spec and contains new/unknown records,
then our poor-man's attempt at re-encoding will render a different
binary, which in turn means the signature check will fail.

Let's instead do a manual step-by-step raw decode of the DER TLV
structure to extract the actual binary information of parts of ASN.1
objects.

Change-Id: I4e31fd4b23ec3be15b9d07c2c30a3e31e22bdda1
Closes: OS#6473
2024-05-30 20:06:59 +02:00
Harald Welte
1d1ba8e4cc esim.esp2: Allow HTTP methods other than POST
While all official/standardized ES2+ API functions use POST, there
are some vendor-specific extensions using different HTTP methods.  Be
flexible enough to allow derived classes to easily specify other methods.

Change-Id: I4b1a0dc7e6662485397c7708933bf16e5ed56e10
2024-04-03 00:49:33 +02:00
Harald Welte
b2b29cfed1 esim.es2p: Permit ApiParamInteger to be an actual integer
Usually, the specifications say that the integer type is actually
transmitted as a JSON string type.  However, it seems some
implementations do return a native JSON integer type.  Let's be
tolerant in that regard.

Change-Id: I5b47f8bba01225d53eff2ca086e53a2133abed7f
2024-04-03 00:49:31 +02:00
Harald Welte
b18c7d9be0 saip.personalization: Fix encoding of ICCID in ProfileHeader
To make things exciting, they decided that the ICCID in the profile
header is encoded different from the ICCID contained in EF.ICCID...

Change-Id: I5eacdcdc6bd0ada431eb047bfae930d79d6e3af8
2024-02-21 09:23:58 +01:00
Harald Welte
6d63712b51 saip.personalization: automatically compute class 'name' attribute
We can use the metaclass to set a proper non-camel-case name attribute.

Change-Id: If02df436c8f5ce01d21e9ee077ad3736e669d103
2024-02-21 09:23:58 +01:00
Harald Welte
2de552e712 saip.personalization: differentiate input_value from value
When personalizing e.g. the ICCID, the input_value is the raw
incrementing counter.  From that, we calculate the Luhn check digit,
and that "output" value is what we'll put in to the EF.ICCID specific
encoder.

However, we also store that output value in the instance in order
to generate the output CSV file containig the card-specific
personalization data.

Change-Id: Idfcd26c8ca9d73a9c2955f7c97e711dd59a27c4e
2024-02-21 09:23:55 +01:00
Harald Welte
19fa98e7d0 saip.personalization: Add support for SCP80/81/02/03 keys
Those keys are normally per-card unique, and hence the personalization
must be able to modify them in the profile.

Change-Id: Ibe4806366f1cce8edb09d52613b1dd56250fa5ae
2024-02-21 09:22:40 +01:00
Harald Welte
318faef583 saip.personalization: include encode/decode of value; add validation method
Change-Id: Ia9fa39c25817448afb191061acd4be894300eeef
2024-02-21 09:22:40 +01:00
Harald Welte
922b8a279c saip: improve docstrings
Change-Id: I0ca82a434e0bde3dc1b304dfc179d568588631c6
2024-02-18 22:30:08 +01:00
Harald Welte
7d88b076ad pylint: esim/saip/validation.py
pySim/esim/saip/validation.py:95:42: C0117: Consider changing "not not ('usim' in m_svcs or 'isim' in m_svcs)" to "'usim' in m_svcs or 'isim' in m_svcs" (unnecessary-negation)
pySim/esim/saip/validation.py:129:0: C0305: Trailing newlines (trailing-newlines)

Change-Id: Idcc9871d6a7068e8aedbd8cd81f4156918af5e50
2024-02-18 22:30:08 +01:00
Harald Welte
5ff0bafcda pylint: esim/saip/__init__.py
pySim/esim/saip/__init__.py:28:0: R0402: Use 'from pySim.esim.saip import templates' instead (consider-using-from-import)
pySim/esim/saip/__init__.py:166:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
pySim/esim/saip/__init__.py:206:4: W0612: Unused variable 'tagdict' (unused-variable)
pySim/esim/saip/__init__.py:273:23: C1802: Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty (use-implicit-booleaness-not-len)

Change-Id: I12ef46c847d197fb0c01e624818aeac14eb99e31
2024-02-18 22:30:08 +01:00
Harald Welte
d16a20ccc3 saip: profile processing; merging with templates
Introduce code that makes use of the information from
pySim.esim.saip.templates to build a complete representation of a file
by merging the template with the ProfileElement decribing the file.

This happens within the class pySim.esim.saip.File, whose instances are
created from ProfileElement + Template.

Change-Id: Ib1674920e488ade9597cb039e4e2047dcbc7864e
2024-02-18 22:30:08 +01:00
Harald Welte
54b4f0ccbd asn1/saip: Fix typo in original ASN.1: Compontents -> Components
Change-Id: I6bec5625579873a9ec267d896584608c9d5e3a2f
2024-02-18 22:30:08 +01:00
Harald Welte
95873a964e Introduce code for ES2+ API client functionality
Change-Id: Id652bb4c2df8893a824b8bb44beeafdfbb91de3f
2024-02-09 21:41:51 +01:00
Harald Welte
530bf73cbc pylint: esim/saip/oid.py
pySim/esim/saip/oid.py:30:11: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck)
pySim/esim/saip/oid.py:46:11: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck)

Change-Id: I65c9cd1bb2b6a1747a7fbb25052adc75605bc870
2024-02-05 09:53:50 +01:00
Harald Welte
5f6b64dc25 pylint: esim/saip/templates.py
pySim/esim/saip/templates.py:106:0: R1707: Disallow trailing comma tuple (trailing-comma-tuple)
pySim/esim/saip/templates.py:56:37: C0121: Comparison 'self.fid != None' should be 'self.fid is not None' (singleton-comparison)
pySim/esim/saip/templates.py:57:28: C0121: Comparison 'self.arr != None' should be 'self.arr is not None' (singleton-comparison)
pySim/esim/saip/templates.py:58:37: C0121: Comparison 'self.sfi != None' should be 'self.sfi is not None' (singleton-comparison)
pySim/esim/saip/templates.py:96:11: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck)
pySim/esim/saip/templates.py:591:0: W1404: Implicit string concatenation found in list (implicit-str-concat)

Change-Id: I181578ba630c8bdb558297e990411b59593652a0
2024-02-05 09:53:45 +01:00