Commit Graph

1506 Commits

Author SHA1 Message Date
Harald Welte
3a95fa12f6 pySim.esim.saip: Add some more docstring comments
Change-Id: I70cf2b4dff1952f581efa3b21211c542f43ce565
2024-08-18 19:38:44 +02:00
Harald Welte
b349149a88 pySim.esim.saip: Back-reference from ProfileElement to ProfileElementSequence
Store a back-reference to the PE-Sequence in the PE object; this is
neccessary for some upcoming patches, e.g. to determine the position in
the sequence, access the global filesystem hierarchy, etc.

Change-Id: I24b692e47e4dd0afb5a17b04d5e0251dded3d611
2024-08-18 19:38:44 +02:00
Harald Welte
3b30994ff0 pySim.esim.saip: pass up **kwargs from ProfileElement sub-class constructors
Change-Id: Ib2b7f6d7428d03e9a8c23af39a61f450096c12bc
2024-08-18 19:38:44 +02:00
Harald Welte
6a1e5eb4ee pySim.esim.saip: Move AKA specific post_dec + pre_enc to AKA subclass
Having AKA specific code in the generic ProfileElement base class dated
back to when we didn't have a ProfileElementAKA subclass.

Change-Id: Icd332183758b8ef20a77507b728f5e455698def0
2024-08-18 19:38:44 +02:00
Harald Welte
31c3c9a1e3 pySim.esim.saip: Refactor file size encoding into a method
Change-Id: I46b8cb81ef8cc1794c11b61e0adfb575f937b349
2024-08-18 19:38:44 +02:00
Harald Welte
6d495fb24d pySim.esim.saip: Improve File.from_template feature support
When populating a File from a FileTemplate, let's make sure we
* correctly treat the maximum file size for BER-TLV files
* respect the default value pattern / repeat pattern
* respect the high_update flag.

Change-Id: I3ba092e0893f53a18264dff5fa37b12ccd9bd47e
2024-08-18 19:38:44 +02:00
Harald Welte
01ddec2fdc contrib/saip-tool: Add command-line arguments to configure log level
Change-Id: I4257d7b76193cdaad8c8571ff49f29067e8ab8c8
2024-08-18 19:38:43 +02:00
Harald Welte
b2970d4bbe pySim.esim.saip.oid: Allow OID instance in prefix_match()
So far the prefix_match() required a string argument; let's also
permit another OID object to be passed; we internally convert that
to string.

Change-Id: I0feb7782d1813cc46ec78f170eb0fce804aebe3a
2024-08-16 18:06:12 +02:00
Harald Welte
1f477495ec saip-tool: Set default log level to INFO (instead of DEBUG)
most users don't want to debug the program.

Change-Id: I54ae558cf8d87bf64cc75431cc4edcc694fa9084
2024-08-16 17:46:41 +02:00
Harald Welte
97dfcaa9c7 pySim.filesystem: Permit Path object construction from FID integer list
we so far supported construction of the Path object from a string or
a list of strings.  Let's also add the option of constructing it from a
path consisting of a list of integer FID values.

Change-Id: Ia7e9375b3258d1fbfdc892cefba3e3bbe841c550
2024-08-16 17:46:41 +02:00
Harald Welte
022d562ae1 pySim.ts_102_221: Make sure FileDescriptor for BER-TLV contains file_type
before this change, structure == 'ber_tlv' was missing the
file_type == working_ef attribute.  So for linear_fixed, transparent
and cyclic, the file_type attribute was present, but for ber_tlv it was
missing. This is illogical from a user point of vie and makes downstream code
potentially more complex, as it cannot match on working_ef for all EF
types.

Change-Id: If0076cc6dd35a818c08309885f6ef1c1704052c6
2024-08-15 19:48:25 +02:00
Harald Welte
89dff98fb6 pySim.esim.saip.templates: Introduce dependency/hierarchy information
The SAIP specification is very weird in a way that it treats the DF and
EF descriptions as some kind of flat structure without describing the
hierarchy.  So when creating a DF, sometimes it should be created below
the current DF, and sometimes it should be adjacent next to the current
DF.

Let's introduce
* a 'ppath' property of FileTemplate to indicate if a file is anything
  but a direct sibling of the 'base DF' of the PE
* an 'extends' property of ProfileTemplate to indicate that a given
  template does not have its own 'base DF', but that its contents merely
  extends that of another ProfileTemplate
* a 'parent' property of ProfileTemplate to indicate a parent
  ProfileTemplate below whose 'base DF' our files should be placed.

Change-Id: Ieab4835cd21008b289713784c0eb7170af2ccfb9
2024-08-15 19:48:25 +02:00
Philipp Maier
526fdae6e5 pySim-shell: improve fsdump
In the previous patch we have improved the export command. Since
the implementation of the fsdump command is very similar to the
implementation of the export command we can now apply the same
improvements to the fsdump command as well.

Change-Id: I4d2ef7b383025a5bbf122f18ecd51b7d73aaba14
Related: OS#6092
2024-08-12 12:30:27 +02:00
Philipp Maier
c421645ba6 pySim-shell: improve export and enable exportation of DF and ADF files
Since we now have the ability to provide export methods for all file
types in the file system (this also includes DF and ADF files), we need
to support this at shell command level as well. Let's also renovate the
walk method and the action method that does the actual exporting.

Related: OS#6092
Change-Id: I3ee661dbae5c11fec23911775f352ac13bc2c6e5
2024-08-08 15:42:27 +02:00
Philipp Maier
12cc6821c4 runtime: add method to lookup a file by name without selecting it
In some cases it might come in handy to be able to lookup a random file
in the file system tree before actually selecting it. This would be
very useful in situations where we need to check the presence of the
file or if we need to check certain file attributes before performing
some task.

Related: OS#6092
Change-Id: I6b6121e749cea843163659e1a26bb3893c032e29
2024-08-08 15:37:35 +02:00
Philipp Maier
8597b64ee6 runtime: integrate escape route for applications without ADF support
the select_parent method in RuntimeLchan currently implements a way
to escape from an application that has no filesystem support. However,
this escape route can be integrated directly into the select_file
method. This will give us the benefit that it will work transparently
in all code locations.

(This also means we can get rid of the select_parent method again)

Related: OS#6120
Change-Id: Ie6f37d13af880d24a9c7a8a95cef436b603587c7
2024-08-08 15:37:35 +02:00
Philipp Maier
2d235f8143 filesystem: fix typo
Change-Id: I17f184bbcf494c5fe944602224cf72d6a22cbc9d
2024-08-08 15:37:35 +02:00
Philipp Maier
b92f4f52cc ara_m: add export support for the ARA-M application
This patch adds an export method to the CardApplicationARAM class.
This method reads the ARA-M configuration and transforms it into
executeable command lines, which can be executed as a script later
to restore an ARA-M configuration.

Related: OS#6092
Change-Id: I811cb9d25cb8ee194b4ead5fb2cabf1fdc0c1c43
2024-08-08 10:47:59 +02:00
Philipp Maier
03901cc9ce filesystem: add export method for ADF files
This patch adds an export method to CardADF, which calls the application
specific export method in CardApplication class

Related: OS#6092
Change-Id: I8129656096ecaf41b36e5f2afbbfbebcd0587886
2024-08-08 10:46:49 +02:00
Philipp Maier
b4530e71b7 filesystem: add placeholder export method in CardFile base class
We add export methods in subclasses of CardFile but the base class
itself lacks an export method. To make the code more readable and
to avoid unnecessary exceptions, les's add a default export method
that just returns a comment.

Related: OS#6092
Change-Id: Ife2a9bad14750db84a87fab907297028c33f1f7d
2024-08-08 10:46:39 +02:00
Harald Welte
7d9c6583ef pySim.cards: Make file_exists() check for activated/deactivated
The Card.file_exists() method is only called by legacy pySim-{read,prog}
when it wants to determine if it can read/write a file.  Therefore
it actually doesn't only want to know if the file exists, but also
if it's not deactivated.

Change-Id: I73bd1ab3780e475c96a10cd5dbdd45b829c67335
Closes: OS#6530
2024-08-07 14:10:21 +00:00
Philipp Maier
4515f1cf87 ara_m: fix --apdu-filter setting
The code for the --apdu-filter commandline option is not yet finished.
Let's finish it and make it work.

Related: OS#6092
Change-Id: Ib5fb388972fde0d50c3db0082ebf40bcca404681
2024-08-06 09:20:44 +02:00
Harald Welte
10e9e97724 pySim.esim.saip.templates: Add expand_default_value() method
This method can be used to expand the default value pattern of the
file system template for the file to the specified (record, file) length.

Change-Id: Id3eb16910c0bdfa572294e14ca1cd44ca95ca69f
2024-08-05 15:56:15 +00:00
Harald Welte
8f5fd37b4a pySim.esim.saip.templates: Fix '...' notation in default value
The default value must contain '...' to indicate a variable-length
default value section, not '..'

Change-Id: I8d78278065c145b86460acf8eb723babe777c4f6
2024-08-05 15:56:15 +00:00
Harald Welte
ca1b00f99e pySim.esim.saip.templates: Explicitly specifiy repeatable default value
Change-Id: I9ae2c36f5bffac392c1219bb6ea21c1c05dff4b9
2024-08-05 15:56:15 +00:00
Harald Welte
465d1a07e0 pySim.esim.saip.templates: Add SaipSpecVersion
The SAIP specification version implicitly determines which filesystem
templates (or versions thereof) are supported.  So if a given eUICC
states it implements SAIP version 2.3.0, then we have to translate
this into which template versions that means.  The new SaipSpecVersion
and its derived classes do exactly that.

Change-Id: I3a894c72c22e42bd2067e067be80a67197ad1bf2
2024-08-05 15:56:15 +00:00
Philipp Maier
44d51a7b16 pySim-shell: fix typo
Change-Id: I1bd995ae9eb59a44a48da62a7b0262faa84a4f2b
2024-08-05 15:20:15 +02:00
Harald Welte
5b513a543f pySim.esim.saip.oid: Fix OID defininitions for v3.3.1 IoT templates
Change-Id: Iac620362ae9336199f3b3b168a4bfeda3e2b7c35
2024-08-04 12:46:12 +02:00
Harald Welte
46bc37fa65 pySim.filesystem: Add __len__ method to Path object
This returns the length of the path.

Change-Id: I5e3ba726ed180405c4218ebeee240a3a40527f99
2024-08-04 12:46:12 +02:00
Harald Welte
19328e3bbd pySim.esim.saip.templates: Update to SAIP v3.3.1 (July 2023)
This new TCA SAIP version introduces a number of aditional templates

Change-Id: Ie8aeae3f5b36a3141a70f670c220932389d241a6
2024-08-04 12:46:12 +02:00
Harald Welte
d2254377b6 pySim.esim.saip.templates: Add a notion of the path of a file
The SAIP data format is inherently flat and doesn't intrinsically
have an idea of the tree-like structure of a filesystem.  However,
if we want to (for example) convert a physical USIM into an eSIM
profile, we need to find the template for a given file, where the file
is identified by its path.

Let's expose a path property of the FileTemplate object, and populate
that when creating the FileTemplate as part of a ProfileTemplate.

Change-Id: Ie145ba159081daf8fbfa544f6d4248f05b7eea96
2024-08-04 12:46:12 +02:00
Harald Welte
041a1b33fc pySim.esim.saip.template: Permit file-size for BER-TLV files
We previously only permitted this for transparent files (TR), but
file size can of course also be specified for BER-TLV files.

Change-Id: Ie007cf2ccde0a17d0fb853a96b833f064ae52c59
2024-08-04 12:46:12 +02:00
Harald Welte
d3a6bbc215 pySim.esim.saip: Add subcasses for EAP, DF.SNPN and DF.5G_ProSe
Change-Id: I8f29e72d387c66c99ceccffc9de23a68fd15dc46
2024-08-04 12:46:12 +02:00
Harald Welte
08d7c10211 pySim-shell: Support other ADMx values beyond ADM1 from 'verify_adm'
Change-Id: Icce6903c1e449889f8bc5003ccfe6af767a26d44
2024-08-04 12:46:02 +02:00
Harald Welte
fdae0ff90d pySim-shell: Support hexadecimal ADM pin in 'verify_adm'
Change-Id: I4191ed79ebe7869d8411d280a32ac2d4bbc210e3
Closes: OS#6480
2024-08-01 11:38:18 +02:00
Harald Welte
7c06bcdd57 Support EF.ICCID and EF.PL on classic TS 51.011 SIM
So far we only had the EF.ICCID and EF.PL within our UICC card profile.
However, a classic GSM SIM card is not an UICC, so the CardProfileSIM
also needs those files.

To avoid circular dependencies, move the definitions from ts_102_221.py
to ts_51_011.py

Change-Id: I6eaa5b579f02c7d75f443ee2b2cc8ae0ba13f2fe
Closes: OS#6485
2024-07-31 23:17:13 +02:00
Harald Welte
d81c2086c8 pySim.tlv: Fix from_dict of nested TLVs
The existing logic is wrong.  How we call from_dict() doesn't differ if
a member IE itself contains a nested collection: We always must pass a
single-entry dict with the snak-case name of the class to from_dict().

Change-Id: Ic1f9db45db75b887227c2e20785198814cbab0f5
Fixes: OS#6453
2024-07-31 23:17:13 +02:00
Harald Welte
d3fb38965b ara_m: Fix pySim.tlv.IE.from_dict() calls
Historically, to_dict and from_dict were not symmetric; this has been
fixed in I07e4feb3800b420d8be7aae8911f828f1da9dab8 in December 2023.

This however broke the ara_m legacy use of the from_dict() methods.
We've just introduced a from_val_dict() method in
I81654ea54aed9e598943f41a26a57dcc3a7f10c2, let's make use of it.

Change-Id: I3aaec40eb665d6254be7b103444c04ff48aac36d
2024-07-29 13:06:27 +02:00
Harald Welte
4fd3fa445c pySim.esim.saip: Add subclasses for gsm-access, phonebook, 5gs, saip
Those are all optional ProfileElements related to the USIM NAA.

Change-Id: I621cc3d2440babdc11b4b038f16acf418bbc88ad
2024-07-29 13:06:27 +02:00
Harald Welte
4f9ee0fa75 pySim.esim.saip: Refactor from_der() method to have class_for_petype()
Change-Id: I2e70dddb0b3adb41781e4db76de60bff2ae4fdb7
2024-07-29 13:06:27 +02:00
Harald Welte
6b1c6a986c pySim.esim.saip.templates: Build tree from template files
Change-Id: I13e80e9dbddbb145411378a0d9e01461aef75db4
2024-07-29 13:06:27 +02:00
Harald Welte
3d6a712e8c Fix missing AIDs in pySim.saip templates
Change-Id: Ie02e2d27ece0fbd9719468c8d31febd1937468f8
2024-07-29 13:06:27 +02:00
Harald Welte
8b1060a30e Reference pySim.filesystem derived classes from SAIP templates
Change-Id: Ia1c810262f1cfa48dae192c7de620c7f0fb69c25
2024-07-29 13:06:27 +02:00
Harald Welte
e354ef7d05 pySim.esim.saip: Initial support for parsing GenericFileManagement
Change-Id: I4a92f5849158a59f6acca05121d38adc0a495906
2024-07-29 13:06:16 +02:00
Harald Welte
e3e964589f pySim.ts_102_221: Add ProprietaryInformation sub-IEs of TS 102 222
We put those in ts_102_221 because that's where ProprietaryInformation
is defined, and we don't want to risk circular dependencies.

Change-Id: I526acfeacee9e4f7118f280b3549fd04fdb74336
2024-07-29 13:03:21 +02:00
Harald Welte
cf65d92039 pySim.ts_102_221: Fix FileDescriptor encoding for BER-TLV case
This fixes a long-standing bug in the FileDescriptor IE class which so
far only supported decoding, but not encoding of BER-TLV file
descriptors.

Change-Id: I598b0e1709ee004bcf01a53beb91f68470e1f3da
2024-07-29 13:03:21 +02:00
Harald Welte
f3b3ba15b8 pySim.filesystem: Add Path for abstraction/utility around file system paths
Change-Id: I202baa378988431a318850e3593ff1929d94d268
2024-07-29 13:01:51 +02:00
Harald Welte
bff8902ce1 pySim.commands: make use of status word interpreter for CHV
Related: OS#6398
Change-Id: I71efe9d6804c4845bb81f1b3b443215dad0ac301
2024-07-29 13:01:51 +02:00
Harald Welte
de5de0e9db pySim-shell: add "fsdump" command
This command exports the entire filesystem state as one JSON document,
which can be useful for storing it in a noSQL database, or for doing a
structured diff between different such dumps.

It's similar to "export", but then reasonably different to rectify a
separate command.

Change-Id: Ib179f57bc04d394efe11003ba191dca6098192d3
2024-07-29 10:48:22 +00:00
Harald Welte
d29f244aad pySim.tlv: Separate {to,from}_val_dict() from {to,from}_dict()
There are some situations where we want to work with a type-name-wrapped
dict that includes the type information, and others where we don't want
that.  The main reason is that nested IEs can only be reconstructed if
we can determine the type/class of the nested IE from the dict data.

Let's explicitly offer {to,from}_val_dict() methods that work with
the value-part only

Related: OS#6453
Change-Id: I81654ea54aed9e598943f41a26a57dcc3a7f10c2
2024-07-27 10:30:26 +02:00