Commit Graph

794 Commits

Author SHA1 Message Date
Philipp Maier bc1485e06d pysim-testdata: add test data for sysmo-isim-sja5 2023-06-05 16:07:03 +02:00
Harald Welte 219a5f369c OTA: Fix padding of AES CMAC
When using AES CMAC for authentication of OTA messages, we must not pad
the user data before calling the CMAC function. This is unlike the DES
MAC, where padding to the DES block size is mandatory.

This bug was discovered when trying to talk OTA with AES to a
sysmoISIM-SJA5.  This patch makes the OTA AES interoperate with the
card.  Also, with this patch the cryptographic results of pySim/ota.py
are identical to those of the java code
org.opentelecoms.gsm0348.impl.crypto.CipheringManager

Change-Id: I4b40b5857f95ccb21c35795abe7a1995e368bac3
2023-06-03 12:45:35 +00:00
Harald Welte 03650582e0 SJA5: Proper encode/decode of TUAK data in EF.USIM_AUTH_KEY
Unfortunately, TUAK requires a number of additional (and
differently-sized) parameters, so the format of EF.USIM_AUTH_KEY
differs significantly depending on TUAK or non-TUAK case.

Change-Id: I0dcfe05777510fb34973dc2259b137133d8e199d
2023-06-03 12:45:35 +00:00
Harald Welte 557c13685e SJA5: Add TUAK + XOR-2G algorithm definitions for EF_[U]SIM_AUTH_KEY
Change-Id: I62a7255d991fa1ed09a7c9bcf8be4b68acfa61a7
2023-06-03 12:45:35 +00:00
Harald Welte 954ce95a16 SJA2: Implement DF.SYSTEM/EF.0348_KEY using construct
This implicitly adds support for JSON->binary encoding, not just
decoding (previous code predating construct support).

Change-Id: I0994d9f66a504dd3c60b43ed5cf6645515dcbc6a
2023-06-03 12:45:35 +00:00
Harald Welte ba6d6ab64f ts_31_102: EF_SUPI_NAI: Decode/Encode GLI+GCI as UTF-8 strings
According to TS 23.003 Section 28.15 and 28.16 both GLI and GCI
are NAI as defined in IETF RFC 7542, which in turn specifies they
are encoded in UTF-8.

Change-Id: I0a82bd0d0a2badd7bc4a1f8de2c3e3c144ee5b12
2023-06-03 12:45:35 +00:00
Harald Welte 455611c9a3 ts_31_102: Add decoder/encoder for DF.5GS/EF.Routing_Indicator
This file is rather important for 5G SA operation, so we should have
a proper encoder/decoder in place.

Change-Id: I1b37fdfc2807976880b2cafb61951f08eebeb344
2023-06-03 12:45:35 +00:00
Tobias Engel d70ac22618 modem_atcmd: raise ProtocolError instead of ReaderError on CME ERROR
Also accept ProtocolError in addition to SwMatchError in filesystem.py
when probing for applications

Change-Id: I82b50408328f8eaaee5c9e311c4620d20f930642
2023-06-02 15:35:43 +00:00
Vadim Yanitskiy bca01523df setup.py: fix syntax errors (missing commas)
Change-Id: Ia53a659ad9652d582e2bf4a039a3e18631435072
Fixes: 2b15e315 "setup: add missing pyyaml to setup.py and README.md"
Fixes: 93aac3ab "pySim-shell: fix compatibility problem with cmd2 >= 2.0.0 (Settable)"
2023-05-28 17:13:21 +07:00
Matan Perelman c296cb593e cards: Add support for Gialer SIM cards
Change-Id: Icd2021aec630ac018f66ab565e03112047389e17
2023-05-27 12:37:16 +02:00
Merlin Chlosta 69b69d4d84 docs: add SUPI/SUCI usage example
Change-Id: I2908ea9df7e78c596554731085902e2ab7278328
2023-05-27 12:37:12 +02:00
Harald Welte 0489ae67cf cards.py: support ATR-based detection of sysmoISIM-SJA5
The cards are 99% software-compatible to the SJA2, so let's just
derive the SJA5 class from the SJA2

Change-Id: I706631baaf447c49904277886bc9a3f6ba3f5532
2023-05-25 22:23:07 +02:00
Harald Welte 2bee70cbac ts_31_102: Add DF.SAIP support
DF.SAIP (SIMalliance Interoperable Profile) is not part of 31.102,
but something from the eSIM/eUICC universe of TCA (formerly known as
SIMalliance).  However, as 3GPP does not specify how/where the card
stores the information required for SUCI calculation, the
TCA/SIMalliance standard is the only standard there is.  Some CardOS
start to use this standard even for non-eSIM/eUICC use cases.

Change-Id: Iffb65af335dfdbd7791fca9a0a6ad4b79814a57c
2023-05-25 09:58:34 +02:00
Harald Welte 24e77a7758 ts_31_102: Fix FID + SFI of EF.MCHPPLMN
Change-Id: I7e24c904e47cc6f90e90b8634cbed478bd14231f
2023-05-25 07:55:44 +00:00
Harald Welte 5206429c0c ts_31_102: Fix FID of EF.OPL5G (it's 4F08 instead of 6F08)
Change-Id: I68c7ad93dabd768d80ae629498aee29d7bab5542
2023-05-25 07:55:44 +00:00
Harald Welte 04bd5140fd ts_31_102: Fix EF.NIA FID
The FID in ADF.USIM is different from the FID in DF.GSM.  So while
we can re-use the ts_51_011 EF_NIA class definition, we must pass in
a different fid to the constructor.

Change-Id: Ib414d5b476666e276824266e33b341175a2ee05a
2023-05-25 07:55:44 +00:00
Harald Welte 33eef850c0 ts_51_011: Fix EF.Phase FID (it's 6FAE, not 6FA3)
Change-Id: I11df83b17b8d6eaab309908cbee646c888abab0d
2023-05-25 07:55:44 +00:00
Harald Welte 10a1a0a22e ts_51_011: Fix FID of EF.BCCH
It's 6F74, not 6F7F! (see TS 51.011 Section 10.3.14)

Change-Id: I9d90fa05a0f926f99a5d4832341cc8a9449df7ae
2023-05-25 07:55:44 +00:00
Harald Welte fc67de2219 ts_31_102: Extend from Rel16 to Rel17
This adds definitions for a variety of files which were added in Release
17 of 3GPP TS 31.102.

Change-Id: I61badc1988b006a1065bdfdcc8a93b758e31f79b
2023-05-25 07:55:44 +00:00
Harald Welte c224b3b5f1 ts_51_011: Add sst_service_[de]{activate,allocate} shell commands
Just like the existing commands for UST/IST: Allow the user to
activate/deactivate individual services.  As EF.SST also contains
information about "allocation" of a service, let's have commands for
allocation and activation.

Change-Id: If959d06248cb1a9d2c0a21cdd40d438726cbc5f0
2023-05-25 07:55:44 +00:00
Vadim Yanitskiy ade366d2a9 setup.py: add missing packages for pySim-trace.py
pySim-trace.py is broken if pySim is installed using setup.py:

  fixeria@DELL:~$ pySim-trace.py
  Traceback (most recent call last):
    File "/usr/bin/pySim-trace.py", line 8, in <module>
      from pySim.apdu import *
  ModuleNotFoundError: No module named 'pySim.apdu'

Change-Id: I371143cb4009db46275ec7a020497b909dcc3b4e
2023-05-24 09:03:01 +00:00
Vadim Yanitskiy a793552b4f contrib/jenkins.sh: print pylint version before running it
Change-Id: Icc96ff16af482581dc97a387bcff1374fbb620f3
Related: OS#6034
2023-05-23 13:12:41 +02:00
Oliver Smith e47ea5f2e5 Fix pylint errors
In a previous patch the dependency on cmd2 was changed from cmd2==1.5 to
cmd2>=1.5. After this was merged, this lead to the docker images getting
rebuilt and now having a higher cmd2 version that gets used in the CI
checks. So while the patch was in review, pylint was actually running
with a lower cmd2 version and was taking different code paths.

Fix for:
pySim-shell.py:30:4: E0611: No name 'fg' in module 'cmd2' (no-name-in-module)
pySim-shell.py:30:4: E0611: No name 'bg' in module 'cmd2' (no-name-in-module)
pySim-shell.py:154:8: E1123: Unexpected keyword argument 'use_ipython' in method call (unexpected-keyword-arg)
pySim-shell.py:171:30: E1120: No value for argument 'settable_object' in constructor call (no-value-for-parameter)
pySim-shell.py:173:30: E1120: No value for argument 'settable_object' in constructor call (no-value-for-parameter)
pySim-shell.py:175:30: E1120: No value for argument 'settable_object' in constructor call (no-value-for-parameter)
pySim-shell.py:176:30: E1120: No value for argument 'settable_object' in constructor call (no-value-for-parameter)

Fixes: f8a3d2b3 ("requirements.txt: allow cmd2 versions greater than 1.5")
Fixes: OS#6034
Change-Id: I182d3a2b87e70ed551a70c88d3d531a36bf53f53
2023-05-23 13:12:33 +02:00
Philipp Maier 3bcc22f73d README.md: add missing pycryptodome to dependency list
Change-Id: Ib3cf13a1ad38749ac82d1b36fa32d9c5aba29e1a
2023-05-17 17:30:49 +02:00
Philipp Maier 2b15e315e2 setup: add missing pyyaml to setup.py and README.md
Change-Id: I1d35f38b17a315dd58e8dd91a27bfa6c2c85905d
2023-05-17 17:30:49 +02:00
Philipp Maier f8a3d2b3db requirements.txt: allow cmd2 versions greater than 1.5
Since we now have fixed the compatibility issues with recent cmd2
versions, we may allow also versions greater than 1.5 in the
requirements.txt

Change-Id: I87702c5250a3660c84458939167bffdca9c06059
2023-05-17 17:30:49 +02:00
Harald Welte 961b803ec4 pySim-shell: fix compatibility problem with cmd2 >= 2.3.0 (bg)
cmd2.fg and cmd2.bg have been deprecated in cmd2 2.3.0 and removed
in cmd2 2.4.0. Let's work around this by a version check.

Related upstream commits:
(See also: https://github.com/python-cmd2/cmd2)

Commit f57b08672af97f9d973148b6c30d74fe4e712d14
Author: Kevin Van Brunt <kmvanbrunt@gmail.com>
Date:   Mon Oct 11 15:20:46 2021 -0400

and

Commit f217861feae45a0a1abb56436e68c5dd859d64c0
Author: Kevin Van Brunt <kmvanbrunt@gmail.com>
Date:   Wed Feb 16 13:34:13 2022 -0500

Change-Id: I9fd32c0fd8f6d40e00a318602af97c288605e8e5
2023-05-17 17:30:49 +02:00
Harald Welte c85d4067fd pySim-shell: fix compatibility problem with cmd2 >= 2.0.0 (include_ipy)
In version 2.0.0, the use_ipython parameter in the Cmd constructor is
renamed to include_ipy. There are still plenty of older cmd2
installations around, so let's work around this using a version check.

See also: https://github.com/python-cmd2/cmd2

Commit: 2397280cad072a27a51f5ec1cc64908039d14bd1
Author: Kevin Van Brunt <kmvanbrunt@gmail.com>
Date: 2021-03-26 18:56:33

This commit is based on pySim gerrit changes:
Ifce40410587c85ae932774144b9548b154ee8ad0
I19d28276e73e7024f64ed693c3b5e37c1344c687

Change-Id: Ibc0e18b002a03ed17933be4d0b4f4e86ad99c26e
2023-05-17 17:30:49 +02:00
Harald Welte 93aac3abe6 pySim-shell: fix compatibility problem with cmd2 >= 2.0.0 (Settable)
In cmd2 relase 2.0.0 the constructor of Settable adds a settable_object
parameter, which apparantly was optional at first, but then became
mandatory. Older versions must not have the settable_object parameter
but versions from 2.0.0 on require it. Let's add a version check so that
we stay compatible to cmd2 versions below and above 2.0.0.

See also: https://github.com/python-cmd2/cmd2

Commit 486734e85988d0d0160147b0b44a37759c833e8a
Author: Eric Lin <anselor@gmail.com>
Date:   2020-08-19 20:01:50

and

Commit 8f981f37eddcccc919329245b85fd44d5975a6a7
Author: Eric Lin <anselor@gmail.com>
Date: 2021-03-16 17:25:34

This commit is based on pySim gerrit change:
Ifce40410587c85ae932774144b9548b154ee8ad0

Change-Id: I38efe4702277ee092a5542d7d659df08cb0adeff
2023-05-17 17:30:49 +02:00
Vadim Yanitskiy 87dd020d5f Add very basic profile for R-UIM (CDMA) cards
R-UIM (CDMA) cards are pretty much like the normal GSM SIM cards and
"speak" the same 2G APDU protocol, except that they have their own file
hierarchy under MF(3f00)/DF.CDMA(7f25).  They also have DF.TELECOM(7f10)
and even DF.GSM(7f20) with a limited subset of active EFs.  The content
of DF.CDMA is specified in 3GPP2 C.S0023-D.

This patch adds a very limited card profile for R-UIM, including auto-
detecion and a few EF definitions under DF.CDMA.  This may be useful
for people willing to explore or backup their R-UIMs.  To me this was
useful for playing with an R-UIM card from Skylink [1] - a Russian
MNO, which provided 450 MHz CDMA coverage until 2016.

[1] https://en.wikipedia.org/wiki/Sky_Link_(Russia)

Change-Id: Iacdebdbc514d1cd1910d173d81edd28578ec436a
2023-05-10 00:14:13 +00:00
Vadim Yanitskiy 6b19d80229 ts_51_011: fix EF_ServiceTable: use self for static method
Even though _bit_byte_offset_for_service() is a @staticmethod, it's
still available via self, just like any non-static method.

Change-Id: I3590dda341d534deb1b7f4743ea31ab16dbd6912
2023-05-10 00:14:13 +00:00
Vadim Yanitskiy e63cb2cc4d setup.py: add missing pySim-trace.py' to scripts[]
Change-Id: I44dfcf48ae22182bd7aaa908559f3d1e1e31acce
2023-05-05 15:12:17 +07:00
Vadim Yanitskiy b34f23448c filesystem: define more convenient codec for EF.ACC
This patch improves the output of the 'read_binary_decoded' command:

pySIM-shell (MF/DF.GSM/EF.ACC)> read_binary_decoded
{
    "ACC0": false,
    "ACC1": false,
    "ACC2": false,
    "ACC3": false,
    "ACC4": false,
    "ACC5": false,
    "ACC6": false,
    "ACC7": false,
    "ACC8": false,
    "ACC9": false,
    "ACC10": false,
    "ACC11": false,
    "ACC12": false,
    "ACC13": false,
    "ACC14": false,
    "ACC15": true
}

And allows to set/unset individual ACCs using 'update_binary_decoded':

pySIM-shell (MF/DF.GSM/EF.ACC)> update_binary_decoded --json-path 'ACC15' 0
"0000"
pySIM-shell (MF/DF.GSM/EF.ACC)> update_binary_decoded --json-path 'ACC8' 1
"0100"
pySIM-shell (MF/DF.GSM/EF.ACC)> update_binary_decoded --json-path 'ACC0' 1
"0101"

Change-Id: I805b3277410745815d3fdc44b9c0f8c5be8d7a10
Related: SYS#6425
2023-04-18 04:36:34 +07:00
Vadim Yanitskiy 0d80fa9150 pySim-prog.py: fix SyntaxWarning: using is with a literal
Change-Id: If9460bf827242a1dfc518213e3faa9137a21869a
2023-04-14 00:11:19 +07:00
Philipp Maier 7b9e24482d pySim-shell: add cardinfo command
It may sometimes be helpful to get a bit of general information about
the card. To sort out problems it sometimes helps to get an idea what
card type and ICCID pySim-shell has in memory.

Change-Id: If31ed17102dc0108e27a5eb0344aabaaf19b19f9
2023-03-27 10:37:28 +02:00
Harald Welte 61ef1571f9 pySim-shell.py: add a command for RUN GSM ALGORITHM
Change-Id: Id7876d83d018aca79253784411d3a9d54a249a0a
2023-03-22 09:57:32 +00:00
Vadim Yanitskiy 9970f59f4f SimCardCommands.run_gsm(): use send_apdu_checksw()
Change-Id: Ib713cf8154a3aba72bc5776a8d99ec47631ade28
2023-03-22 09:57:32 +00:00
Vadim Yanitskiy 1dd5cb540d fix SimCardCommands.run_gsm(): always use CLA=0xa0
Depending on the card type (SIM or USIM/ISUM), self.cla_byte may
be either 0xa0 or 0x00.  Sending RUN GSM ALGORITHM with CLA=0x00
fails with SW=6985 (Command not allowed), so let's make sure
that we always use CLA=0xa0 regardless of the card type.

Change-Id: Ia0abba136dbd4cdea8dbbc3c4d6abe12c2863680
2023-03-22 09:57:32 +00:00
Oliver Smith 41fbf12dba gitignore: add manuals related files
Change-Id: I93a63b33032f93f381b8ef451aecc97d3011ce8c
2023-03-20 13:30:38 +01:00
Oliver Smith 308d7cdf78 docs/Makefile: don't forward shrink to sphinx
Adjust the catch-all target at the end of the Makefile that is supposed
to route all unknown targets to sphinx, so it doesn't do this for the
shrink target. The shrink target has recently been added to
Makefile.common.inc in osmo-gsm-manuals, which gets included right above
the catch-all target. So it isn't an unknown target, but for some reason
the sphinx catch-all runs in addition to the shrink target (runs
shrink-pdfs.sh, see output below) and fails. As I did not add the
catch-all logic, preserve it but add an exception for the shrink rule.

Fix for:
  + make -C docs publish publish-html
  make: Entering directory '/build/docs'
  /opt/osmo-gsm-manuals/build/shrink-pdfs.sh _build/latex/osmopysim-usermanual.pdf
  * _build/latex/osmopysim-usermanual.pdf: 272K (shrunk from 336K)
  Running Sphinx v5.3.0

  Sphinx error:
  Builder name shrink not registered or available through entry point

Related: SYS#6380
Change-Id: If2802bb93909aba90debe5e03f3047cec73e2f54
2023-03-20 12:28:06 +01:00
Harald Welte 0707b80ad3 ts_102_222: Implement support for RESIZE FILE for an EF
This adds pySim-shell support for the RESIZE FILE command in order
to change the size of linear fixed or transparent EF.

Change-Id: I03fbb683e26231c75f345330ac5f914ac88bbe7a
2023-03-09 09:49:40 +00:00
Oliver Smith da1f562294 docs: change upload path for html docs
Upload it to pysim/master/html instead of latest/pysim.

Related: OS#5902
Change-Id: I0b338bd7d1fb2620d63e651eeb8e40c7d8e722e2
2023-03-07 12:44:14 +01:00
Harald Welte a07d509de6 docs: Document the file-specific commands for ADF.USIM/EF.EST
Change-Id: Iddba9f25ba957f03ca25628a7742fe40fd79c030
2023-02-23 10:02:49 +01:00
Harald Welte 18b7539925 31.102: EF.EST enables/disables services; name commands accordingly
EF.EST is the *enabled* services table.  Let's call the shell commands
enable and disable, rather than activate/deactivate.

Change-Id: Iacbdab42bc08e2be38ad7233d903fa7cda0d95b6
2023-02-23 10:00:51 +01:00
Harald Welte 577312a04e docs: Add reference for various commands
A number of more recently introduced commands were not yet listed in the
manual, let's fix that.

Change-Id: I39150f55eecb5d8ff48292dc5cc0f9e16dd4398c
2023-02-23 09:52:44 +01:00
Philipp Maier 8490240ce6 cards: sysmo-isim-sja2: make sure an ADF is present in EF.DIR before selecting it
sysmo-isim-sja2 may come in different configurations, so some may
intentionally lack ADF.USIM or ADF.ISIM. Since select_adf_by_aid() may
raise an exception when selecting a non existent file we should make
sure that the ADF we intend to select is indeed present. A reliable way
to do this is to check if the application is registered in EF.DIR.

Change-Id: Icf6f6b36f246398af408ec432d493fe3f22963dd
2023-02-10 18:28:39 +01:00
Harald Welte 865eea68c3 filesystem: add unit tests for encoder/decoder methods
Lets add test vectors for the per-record/per-file encode/decode of
our various classes for the Elementary Files.

We keep the test vectors as class variables of the respective EF-classes
to ensure implementation and test vectors are next to each other.

The test classes then iterate over all EF subclasses and execute the
decode/encode functions using the test vectors from the class variables.

Change-Id: I02d884547f4982e0b8ed7ef21b8cda75237942e2
Related: OS#4963
2023-02-01 10:52:23 +01:00
Harald Welte d2edd414a8 ts_51_011: Fix decoding/encoding of EF_LOCIGPRS
The P-TMSI signature is a 3-byte value, not a 1-byte value.

Change-Id: I06e8d3efe0b3cf3970159c913acfd2f72280302d
2023-01-31 17:26:09 +01:00
Harald Welte caa94b5a81 Assume first record number if caller specifies none
This fixes a regression introduced in Change-Id
I02d6942016dd0631b21d1fd301711c13cb27962b which added support for
different encoding/decoding of records by their record number.

Change-Id: I0c5fd21a96d2344bfd9551f31030eba0769636bf
2023-01-31 17:26:09 +01:00
Harald Welte 9b9efb6a7a ts_31_102: Fix several bugs in EF_ECC encoder
The encoder function apparently was never tested, it didn't match at all
the output of the decoder, not even in terms of the string keys of the
dict.

Change-Id: Id67bc39d52c4dfb39dc7756d8041cbd552ccbbc4
2023-01-31 17:26:09 +01:00