Commit Graph

1630 Commits

Author SHA1 Message Date
Harald Welte
3442333760 esim.saip: New methods for inserting ProfileElement into sequence
ProfileElements.insert_after_pe() is a convenience method to insert
a new PE after an existing one in the sequence.  This is a frequent
task as there are strict ordering requirements in the SAIP format.

Change-Id: I4424926127b4867931c2157e9340bacd2682ff0c
2024-11-22 20:49:24 +01:00
Harald Welte
5354fc22d0 [cosmetic] esim: Fix various typos in comments/messages/docs
Change-Id: I806c7a37951e72027ab9346169a3f8fe241f2c46
2024-11-22 17:04:30 +01:00
Harald Welte
93237f4407 [cosmetic] esim.saip: Fix various typos in comments/docs/messages
Change-Id: I4fc603634a0f2b53e432a77f05e811a38ba065c2
2024-11-22 16:59:26 +01:00
Harald Welte
779092b0cd esim.saip: Fix computation of file content
When generating the file content (body), we need to proceed in the
following order:

1a) If FCP contains fillPattern/repeatPattern, compute file content from those

1b) If FCP doesn't contain fillPattern/repeatPattern but template
    exists, compute file content from template

2)  Apply any fillFileConten / fillFileOffset from the SAIP File on top
    of the above

Change-Id: I822bb5fbec11a3be35910a496af7168458fd949c
Closes: OS#6642
2024-11-22 16:03:58 +01:00
Harald Welte
6046102cbb esim.saip: Compute number of records from efFileSize and record_len
If we know the efFileSize and record_len, but Fcp doesn't contain
the number of records, we can simply compute it.

Change-Id: I0cc8e7241e37ee23df00c2622422904e7ccdca77
2024-11-22 16:01:58 +01:00
Harald Welte
118624d256 pySim.esim.saip: Treat "Readable and Updateable when deactivated" flag
There's a second flag hidden in the TS 102 222 "Special File
Information"; let's parse + re-encode it properly.

Change-Id: I7644d265f746c662b64f7156b3be08a01e3a97aa
Related: OS#6643
2024-11-22 16:01:58 +01:00
Harald Welte
599845394e esim.saip: Fix parsing/generating fillPattern + repeatPattern
So far we only thought of default filling coming from a template.
However, filling can happen from the Fcp, and we need to properly parse
and [re-]encode that information.

Change-Id: Iff339cbe841112a01c9c617f43b0e69df2521b51
Related: OS#6643
2024-11-22 16:01:25 +01:00
Philipp Maier
de8cc322f1 docs: add topic about remote UICC/eUICC access
With osmo-remsim and Android APDU proxy we have two powerful solutions to
allow remote acces to UICC/eUICC cards. Let's add a section where we give
a brief overview about those solutions, so that pySim-shell users get
awre of them.

Related: OS#6367
Change-Id: I73de4de2e5d4a01d6d91989ee684cbdb680de8ef
2024-11-19 10:56:26 +01:00
Philipp Maier
385d4407da pySim-shell_test: add new testcase for card initialization
The card initialization normally takes place automatically. Nearly all
testcases implicitly cover this code-path. However, it is also possible
to skip the card initialization and do it at some later point. This is
commonly the case for unprovisioned card that require some custom APDUs
in a basic initialization step. When this step is done one would use
the "equip" command to level up to the full featured mode. This patch
adds a testcase for this scenario

Related: OS#6367
Change-Id: I01a03fa07d8c62164453bd707c5943288ff1a972
2024-11-19 10:56:26 +01:00
Philipp Maier
852eff54df pySim/transport add support for T=1 protocol and fix APDU/TPDU layer conflicts
ETSI TS 102 221, section 7.3 specifies that UICCs (and eUICCs) may support two
different transport protocols: T=0 or T=1 or both. The spec also says that the
terminal must support both protocols.

This patch adds the necessary functionality to support the T=1 protocol
alongside the T=0 protocol. However, this also means that we have to sharpen
the lines between APDUs and TPDUs.

As this patch also touches the low level interface to readers it was also
manually tested with a classic serial reader. Calypso and AT command readers
were not tested.

Change-Id: I8b56d7804a2b4c392f43f8540e0b6e70001a8970
Related: OS#6367
2024-11-19 10:56:26 +01:00
Philipp Maier
f951c56449 global_platform/scp: refactor _wrap_cmd_apdu
The _wrap_cmd_apdu methods for SCP02 and SCP03 are a bit hard to read. Let's
refactor them so that it is easier to understand what happens. In particular
that one can not have encryption (cenc) without signing (cmac)

Related: OS#6367
Change-Id: I4c5650337779a4bd1f98673650c6c3cb526d518b
2024-11-19 09:55:48 +00:00
Philipp Maier
90881a2fff docs/osmo-smdpp: restructure subsection "osmo-smdpp"
Sphinx is complaining about a duplicate label "osmo-smdpp". Apparantly
because we use this label twices as section headline. The subsection
"osmo-smdpp" in "Running osmo-smdpp" talks about the commandline and the
supplementary files that osmo-smdpp needs to run. Let's split the two
topics into two different sections.

Change-Id: I8bc4979160a00d36a03b9cd10679562a08c2c55c
2024-11-18 10:49:25 +01:00
Philipp Maier
4aaccf8751 docs/legacy: remove unused '::' paragraph.
Change-Id: If51564665d3793d9108053ffeb97d81ae93ced51
2024-11-18 10:49:20 +01:00
Philipp Maier
3ef2c40951 docs/osmo-smdpp: fix typo
Change-Id: I9978c5e02c1affe95a3b72d63e88965d7af5303e
2024-11-18 10:49:02 +01:00
Philipp Maier
b845aab473 docs/osmo-smdpp: fix markup
Change-Id: I4a0ed6fb2eedf1892835c43d304a53c995f028c8
2024-11-18 10:48:50 +01:00
Philipp Maier
30c59fce42 pySim-shell_test/utils: treat cmd2 error "not a recognized command... as exception
When a pySim-shell command is not recognized, cmd2 prints "xyz is not a
recognized command, alias, or macro." This string is a normal print out
and not an exception, but during tests, it may point out a severe problem
and therefore it should be tread like an exception.

Related: OS#6367
Change-Id: I17be6af1547b31170622e17b9cfb9c492597670d
2024-11-04 15:01:16 +01:00
Philipp Maier
ec30022b1a pySim-shell: add new commandline option "--skip-card-init"
by default pySim-shell does all kinds of probing and file selection
on startup. This is to determine the card type and to find a suitable
card profile. However, in case the card is non yet provisioned this
probing may cause a error messages and even might upset the cards
internal state. So let's have a commandline option thrugh which we
can instruct pySim-shell to skip any initialization and to give us
a prompt immediately, so that we can enter custom APDUs

Related: OS#6367
Change-Id: I1d8a57de201fe7ad7cbcbc6f72969ea8521e821d
2024-11-04 14:54:33 +01:00
Philipp Maier
daa1c74047 pySim-shell: fix reset command for no-profile mode
There are situations where no card profile can be determined. In this case no
RuntimeState will be present. This is in particular the case when pySim-shell
is used on a card that is not provisioned/initialized yet. In those cases we
have to go the direct route and reset the card directly.

Related: OS#6367
Change-Id: I27bf9fdb131d8bdeba07f4dfd2b76b38f9bfdd17
2024-11-04 11:28:05 +01:00
Philipp Maier
5887fb70fb pySim-shell: allow checking of APDU responses
The "apdu" command allows us to send custom APDUs to a card. This command is
often used in low level initialization scripts or tests. To stop the script
execution in case of an error, the command allows us to specify a status word
that must match the status word of the response. But we have no such mechanism
for the response itself. Let's add another parameter where we can pass a regex
that the response must match.

Related: OS#6367
Change-Id: I97bbcdf37bdcf00ad50a875b96940c211de7073d
2024-11-04 11:28:05 +01:00
Philipp Maier
882e24677f pySim-shell_test/utils: print logfile on all types of errors
When pySim-shell has problems starting up, it exits with an error
code. This is detected by the testsuite, but it also causes an
early exit, so that the log file content are not printed.

Change-Id: Ic0f34eda32a7c557810abcb05a84e343741fdb8a
2024-11-04 11:28:05 +01:00
Philipp Maier
f4c156ae57 global_platform/scp: mapdu may be undeclared
when we sign and encrypt the APDU in _wrap_cmd_apdu (SCP03) we return an "mapdu"
at the end. However, in the (unlikely?) case where self.do_cencand
self.do_cmac are false, mapdu will be undeclared. In _wrap_cmd_apdu for SCP02
we just re-use the apdu variable and return it at the end, so when no
encryption and no signing is applied, the APDU falls just through without any
modifications. We should have the same mechanism for the SCP03 wrapping as
well.

Related: OS#6367

Change-Id: Ic7089a69dffd7313572c5b3e5953200be5925766
2024-11-04 11:28:05 +01:00
Philipp Maier
59593e0f28 pySim-shell-test: improve global platform tests
The tests that check the establishment of a secure channel currently only test
security level 3. Also the get_data command after it only tests data reception
from the card.

Let's extend the test coverage and test the SCP establishment for security
level 1 as well. Let's also add a get_status command to make sure sending data
to the card also works (without exceptions).

Related: OS#6367
Change-Id: Idff40b414a249e532df1bdce2a8deb9b0cb9718f
2024-11-04 11:28:05 +01:00
Philipp Maier
35b9b3c542 commands: fix apidoc (wrong order of parameters)
Change-Id: I4d17c71c7f992ecd795dd214d34f2e094c0a5b53
2024-11-01 10:29:27 +01:00
Philipp Maier
464d1ac2be commands: fix double space character in apidoc
Change-Id: Id0dbe4578fd212bc240aac80e1e416cb57e92cc7
2024-11-01 10:29:27 +01:00
Philipp Maier
909b8c1611 global_platform/scp: fix typo
Change-Id: Ib26d983c6a80419326de812af2781c5e710dbcfc
2024-11-01 10:29:27 +01:00
Philipp Maier
5d54f3b8d8 commands: fix typo
Change-Id: I4103b7474063a26f09666361aef72abcd35bc12d
2024-11-01 10:29:15 +01:00
Philipp Maier
98f4ea1447 pySim-shell_test/utils: display pySim-shell logfile content
When we configure the tests to display file content, we only display files that
we compare, let's also display log file contents from pySim-shell. This will
be useful in situations where we only have log output from the tests, but no
access to the file system of the test host.

Related: OS#6601
Change-Id: Ibf6f78d7e71c213c7ca1caaf21c4c890e892261e
2024-10-25 23:41:29 +00:00
Philipp Maier
32d6a9ab5f pySim-shell_test/utils: enumerate pySim-shell logs
When pySim-shell is called by a testcase, a logfile is createted. The logfile
filename contains the testcase name. However, a testcase may run pySim-shell
multiple times. In this case we overwrite the log from previous run. Let's use a
counter to generate unique file names for each run, so that we won't lose logs
from previous runs.

Related: OS#6601
Change-Id: Ib2195d9b2231f74d0a6c4fb28f4889b6c45efb1e
2024-10-25 23:41:29 +00:00
Philipp Maier
d8d52bdf77 pySim-shell_test/utils: delete log files in general
When we get rid of temporary files, we delete those using a wildcard,
but for the logs from pySim-shell we explicitly memorize the name
of the pySim-shell logfile and delete it later by this explicit
name. This is not necessary, let's just delete all log files present
using a wildcard.

Related: OS#6601
Change-Id: I09dc7e59d1a3dcb68f54e3a8dccb86a1bc6c9ee6
2024-10-25 23:41:29 +00:00
Harald Welte
12328c090d pySim.ts_31_102: Add support for EF.EARFCNList
This adds a construct + pyosmocore.tlv based declarative encoder/decoder
for the EF.EARFCNList file used in the context of NB-IoT in later
release USIMs.

Change-Id: I16797ca58c3ad6ebaf588d04fec011a0cbcfcef3
2024-10-25 18:09:19 +02:00
Philipp Maier
ba22e238f3 global_platform: ensure ArgumentParser gets a list for choices
When we use the argument parser with choices, we sometimes use a
list that we derive from a dictionary. However if we do that we
still must ensure that we really put a list and not a dict_values
or dict_keys class as parameter because this won't work any longer
with cmd2 version 2.5.0

Related: OS#6601
Change-Id: I165fefd8feb0d96cedc15d036fb32da381f711b3
2024-10-25 15:30:12 +02:00
Harald Welte
f9631fb361 pySim.esim.saip.templates: Fix DF_TELECOM FileID (7F10, not 7F11)
Change-Id: I4bc37f9d99c046cd6c6accaaf460a39eb79b660f
2024-10-20 10:14:34 +02:00
Harald Welte
f4dd9b5ceb docs/shell: Add missing :ref: when referencing other command
Change-Id: I18f110e6313932d82b19ecaa7e07ef00c2339513
2024-10-20 10:14:19 +02:00
Philipp Maier
82b0f1b39a pySim-shell_test: re-enable test_list_and_rm_notif
The problems with test_list_and_rm_notif (see also change id
I7d0b6a998499d84f0eb4e24592ad43210ac54806) are now resolved, so
we can re-enable the testcase now.

Closes: SYS#7094
Change-Id: I95eb3b9c02a69653797851197e882ea9316805fc
2024-10-11 16:13:07 +02:00
Harald Welte
3a905d637c pySim.euicc: Fix ASN.1 encoding of integer values
Change-Id: I26ee41705f5e95c5fa3a9997cbaebdacca3e89a7
Closes: SYS#7094
2024-10-11 16:13:07 +02:00
Oliver Smith
a8cfeb0111 docs/Makefile: make SPHINXBUILD work in venv
sphinx-build doesn't use the PYTHONPATH from the venv, unless it runs
as python3 -m sphinx.cmd.build. We need it to use the imports from
PYTHONPATH, so we can update the pyosmocom version in requirements.txt
in a patch, and this new version will be used in the jenkins job that
runs during gerrit review. Otherwise the previously installed version
(from the docker image) will be used.

Related: https://github.com/sphinx-doc/sphinx/issues/8910
Change-Id: I487e1af6a3493df5b806cc2d3d2b70bc5233b89f
2024-10-11 16:10:51 +02:00
Philipp Maier
7c62fc5ec4 jenkins: build docs in virtualenv as well
The build system uses a virtual environment, in which it installs
pysim and its dependencies. This is done for the integration tests,
but not when building the sphinx documentation. However, the
documentation build process also invokes pysim code to generate
documentation from the docstrings. This means we need pysim with
all its dependencies for the doc building as well.

Change-Id: I6381eeef7fa19873ca0cc330a0ab43b7ef5096e4
Related: SYS#7094
2024-10-11 15:59:58 +02:00
Philipp Maier
7429bc0ca0 tests: sanitize all cards before running tests
Even though our tests are written in a way that they shouldn't interfere
with each other, it may happen that one testrun writes content to a file
that upsets a different testrun. The resulting problems are often
difficult to diagnose.

To minimize the problem, let's add code that can reset the cards to a
defined state. This can be done using pySim-shell's export
feature. We can generate a backup from a known good state and then play
back the backup to reset files that have been changed. Files that didn't
change will not be written thanks to the conserve_write feature of
pySim-shell.

Related: OS#4384
Change-Id: I42eaf61280968518164f2280245136fd30a603ce
2024-10-05 08:44:20 +00:00
Philipp Maier
93c89856c8 utils: move enc_msisdn and dec_msisdn to legacy/utils.py
We now have a construct based encoder/decoder for the record content
of EF.MSISDN. This means that we do not need the functions enc_msisdn
and dec_msisdn in the non-legacy code anymore. We can now move both
to legacy/utils.py.

Related: OS#5714
Change-Id: I19ec8ba14551ec282fc0cc12ae2f6d528bdfc527
2024-09-27 18:17:19 +02:00
Philipp Maier
1f45799188 ts_102_221: se _test_de_encode instead of _test_decode in EF.DIR unittest
The unittest for EF.DIR only runs with _test_decode, but it also runs with
_test_de_encode without any problems

Related: OS#5714
Change-Id: If459073c6ff927c1cc1790d506e3979243b1fb4c
2024-09-27 18:17:19 +02:00
Philipp Maier
10ea4a0714 ts_51_011: use _test_de_encode instead of _test_decode in EF.CFIS unittest
The unittest for EF.CFIS only runs with _test_decode, but it also runs with
_test_de_encode without any problems

Related: OS#5714
Change-Id: Ib876fd799f871fe64ced2a7b64847ffd09e16ed9
2024-09-27 18:17:19 +02:00
Philipp Maier
dc2ca5d6be ts_51_011: fix unittest for EF.ADN
The unittest for EF.ADN can run with _test_de_encode. However, the original
test vectors seem to be from a card with a slightly larger record size, so
they need a bit of re-alignment

Related: OS#5714
Change-Id: I241792e66ee6167be6ddc076453344b6307d6265
2024-09-27 18:17:19 +02:00
Philipp Maier
39552464d8 ts_51_011: replace encoding of EF.MSISDN with construct model
The encoding of EF.MSISDN is currently done with enc_msisdn and
dec_msisdn from utils.py. Let's replace this with a construct
based model, similar to the one we already use with EF.ADN

Related: OS#5714
Change-Id: I647f5c63f7f87902a86c0c5d8e92fdc7f4350a5a
2024-09-27 18:17:19 +02:00
Philipp Maier
4045146f62 cosmetic: use **kwargs instead of **_kwargs
Some methods sometimes have a **_kwargs parameter, let's be consistent
and use **kwargs only.

Related: OS#5714
Change-Id: I98857cc774185e55a604eb4fbfbf62ed4bd6ded7
2024-09-27 18:17:19 +02:00
Philipp Maier
efddffe015 filesystem: pass total_len to construct of when encoding file contents
In our construct models we frequently use a context parameter "total_len",
we also pass this parameter to construct when we decode files, but we
do not pass it when we generate files. This is a problem, because when
total_len is used in the construct model, this parameter must be known
also when decoding the file.

Let's make sure that the total_len is properly determined and and passed
to construct (via pyosmocom).

Related: OS#5714
Change-Id: I1b7a51594fbc5d9fe01132c39354a2fa88d53f9b
2024-09-27 18:17:19 +02:00
Harald Welte
78c22a7d63 pySim-shell: New '-e' command line argument
Using '-e' it is possible to specify *multiple* pySim-shell commands
which shall be executed at startup.  This extends the current ability
to execute just a single command.

Example:
 ./pySim-shell.py -p0 -e 'select ADF.USIM/EF.IMSI' -e 'read_binary_decoded'

Change-Id: I74004f46105553f077c039ca0f86f75afccc7342
2024-09-23 16:13:16 +00:00
Philipp Maier
d96d04718e pySim-shell_test: disable test_list_and_rm_notif
The testcase euicc.test_list_and_rm_notif fails due to a problem
with the eUICC. The eUICC reports the following error when a
delete notification attempt is made:

"delete_notification_status": "undefinedError"

Let's temporarily disable this testcase until the problem is resolved.

Change-Id: I7d0b6a998499d84f0eb4e24592ad43210ac54806
2024-09-23 13:52:51 +02:00
Oliver Smith
7b95fac022 contrib/jenkins: add SKIP_CLEAN_WORKSPACE
In order to run this script from pyosmocom's contrib/jenkins.sh script,
we want to skip the clean workspace step. Add an environment variable to
do that.

Related: OS#6570
Change-Id: Ic8dc9b85da17719195f7374d37eccb4dedba6ce8
2024-09-23 08:38:55 +02:00
Oliver Smith
c09d4cc6b8 gitignore: add files generated with jenkins.sh
Change-Id: Iaffe04a3dfebd46efc479dc3665fd67f2c95f375
2024-09-23 08:38:55 +02:00
Philipp Maier
f87a00c04f Add testsuite for pySim-shell with real cards
This patch adds a comprehensive testsuite for pySim-shell. The testsuite
is based on python's unittest framework in combination with pySim-shell
scripts.

Related: OS#6531
Change-Id: Ieae1330767a6e55e62437f5f988a0d33b727b5de
2024-09-20 17:53:27 +02:00