Commit Graph

53 Commits

Author SHA1 Message Date
Philipp Maier 214e103407 sysmo_usimsjs1.py: do not print OP/OPc twice
The method that shows the OP/OPc prints the OP/OPc value twice. Lets
remove the redundant output

Change-Id: I0c890b977b3a9dc80b5c328b0c859f0bc9c7ef8b
2020-01-03 15:09:58 +01:00
Philipp Maier 925b20e927 utils.py: cosmetic: add missing new line
Change-Id: I69c335c5ac4fc209daa7fcd7e9f8d509eec289b4
2019-11-11 11:39:33 +01:00
Philipp Maier 9fa8e47b4c sysmo-usimsjs1.py: refactor functions into class
The module sysmo-usimsjs1.py contains a lot of functions that could also
be methods of a class. Lets refactor those functions into class. This is
also an intermediate step towords support for different card models in
the future.

Related: SYS#4466
Change-Id: I2230f50b9d3c85a0d23b29ba5ed0af2471d22e8c
2019-11-11 11:32:21 +01:00
Philipp Maier 594bdd8248 utils.py: cosmetic: add comment to int_to_list()
It may not be immediately obvious what int_to_list() does, lets add a
comment to clarify

elated: SYS#4466
Change-Id: I82639a7333c3d805f6242aa58a3d42800a804820
2019-11-11 11:32:10 +01:00
Philipp Maier 8e427d0b68 utils.py: use generic functions to lookup strings in a table
To find out which algorithm ID corresponds to which string and vice
versa we currently use tables and dictionaries. However, this way can be
generalized and other parts of the program can profit from that

Change-Id: I68388ae27d05fcd1bc9de100e040da0c2bb8e799
Related: SYS#4466
2019-11-11 11:29:37 +01:00
Philipp Maier 6fa296a800 sysmo_usimsjs1: simplfy encoding of ef_mlngc
ef_mlngc currently has no encoding method at the moment. Instead it
reads and writes the parameters directly using offsets. This is a bit
complicated, lets rather read and write the file in a single go and
encode/decode the contents using class methods (like we already do with
the other files)

Change-Id: Ia5c64710306b763804254cf9807e81627a699728
Related: SYS#4466
2019-11-07 13:33:08 +01:00
Philipp Maier b15d23459b tests: add a script to regenerate .out files for tests
Currently all the .out files need to be regenerated by hand. Lets add a
script for this to make things easier
2019-11-07 11:57:15 +01:00
Philipp Maier 70b7fcde40 sysmo_usimsjs1: check ADM1 length
The length of the ADM1 key is currently not checked. The key is 8
digits long for all sysmo-usim-sjs1 cards. Lets make sure that the
length is checked before trying to authenticate.

Change-Id: I10a89d8343c889f6c1b2cf3fc67d08dcf08790cf
2019-09-02 12:05:34 +02:00
Philipp Maier 83760e2c22 Support programming of the MNC length value (EF.AD)
The file EF.AD contains the length of the MNC, this allows to phone to
distinguish where MCC/MNC end and where the MSIN number of the IMSI
begins. All cards are shipped with an MNC length of 2, which is fine for
the most situations, but when a MNC with 3 digits is needed the MNC
length value has to be updated. Otherwise the phone will recognize the
third digit of the MNC as part of the MSIN.

Related: OS#3850
2019-03-21 17:05:42 +01:00
Philipp Maier 3bd5054d56 sysmo_usimsjs1: use correct parameter for 3G auth
when programming the 3G authentication (EF_AUTH), the parameter for 2G
is used.

- make sure that parameter algo_3g_str is used to select the 3g
  authentication algorithem, do not use algo_2g_str here.

Change-Id: I6aaf49062f6faf36455dc48639dc58f3da8e804d
2018-10-24 17:37:24 +02:00
Harald Welte b8845748f5 cosmetic typo: attemt -> attempt 2018-09-28 08:30:18 +02:00
Philipp Maier 48c0993312 tests/test-data: Update ADM1 key
Updated the test-data to the ADM1 key of the test card we currently have
in use. Developers must change this ADM1 key to match theur own
testcards.

Change-Id: I68e7a739fa093d255006bf427c0a332610935800
Related: OS#3376
2018-08-08 12:30:13 +02:00
Philipp Maier 75342b86d1 tests/run-tests: Prepare test card before executing the tests
All tests need a physical card to be inserted in a reader. This card may
have a different IMSI and/or ICCID id set than the one that is expected
by the tests. Since sysmo-usim-tool.sjs1.py unconditionally displays
IMSI and ICCID we find those parameters in every .out file.

In order to run the unit-tests without changing the .out files very often
or having to manually prepare a test card we should write the expected
IMSI and ICCID before each testsuite is executed.

- Add a script to the testsuite that prepares the testcard, run this
  script from run-tests before the actual tests are executed.

Change-Id: I470f4f7d5facab277b6e78252bac7cc4d1fbc6bb
Related: OS#3376
2018-08-08 12:30:13 +02:00
Philipp Maier 12f0d25693 tests/08_seq: Test resetting of SEQ/SQN
the resetting of the SEQ/SQN parameters is currently not tested, we
currently only read out the parameters. Lets test resetting as well.

Change-Id: Ie3e386a79f69cd5e35782f593c3a30e1d2b50afb
Related: OS#3376
2018-08-08 12:30:13 +02:00
Philipp Maier 050231d86c tests/05_milenage_par: Extend unit test
At the moment we only read the milenage parameters but we do not write
them. Lets extend the unit test so that we test writing as well.

Change-Id: I81dd27b3e65510db931188171093f0e909cde16f
Related: OS#3376
2018-08-08 12:30:13 +02:00
Philipp Maier 6868ea7c26 tests/08_seq: Update .out file
The log output for writing the SQN parameters has changed. Update the
.out file accordingly

Change-Id: I58e7c44d3ff0a1c4fea7b8edaa4ca7326a4fd88a
Related: OS#3376
2018-08-08 12:29:50 +02:00
Philipp Maier 01d60a1f03 tests/04_algo: Update .out file
The output for the Algo setting has changed. Update the .out file
accordingly.

Change-Id: Ia9d175e0a8dbd02fd518f1735e42aa56296ea24d
Related: OS#3376
2018-08-08 12:29:26 +02:00
Philipp Maier 8c31a63f31 tests/run-tests: Replace == by -eq when comparing rc
The use of == with test seems to cause problems when comparing the
return code in line 20. Lets use -eq instead.

Change-Id: I92905770f3a96a632a51858952a82180303d6c05
Related: OS#3376
2018-08-08 12:28:22 +02:00
Philipp Maier 0868212cc8 tests/04_algo.sh: Fix string concatenation.
The concatenation

ALGOS=+"MILENAGE:...

seems to cause problems. Lets replace it with:

ALGOS=$ALGOS"MILENAGE:...

Change-Id: I8d946c47502305be77595cd45a64708d03441dd5
Related OS#3376
2018-08-08 12:28:22 +02:00
Philipp Maier 061dddb94a sysmo_usimsjs1: Remove excess space in log output
The log prints an excess spaces when SQN params are changed. Lets
remove those

Change-Id: I224927a44ee623d27f2cf202cc3addb59251917f
Related: OS#3376
2018-08-08 12:28:22 +02:00
Philipp Maier 4cab3bb127 sysmo-usim-tool.sjs1: Add capability to write IMSI
We unconditionally display the IMSI but we still lack support for
writing it. Lets support writing the IMSI as well in order to be more
complete.

- Add support for writing the IMSI

Change-Id: I1b3d1e1aae953663c13e78217de2a8ec3282b969
Related: OS#3376
2018-08-08 12:28:12 +02:00
Philipp Maier 5144c904e6 sysmo-usim-tool.sjs1: Add option -I --set-iccid to help
The helptext lacks the option -I

Change-Id: I25958cedb7d084aedf68f1a56e473098f88ac754
Related: OS#3376
2018-08-08 12:23:45 +02:00
Philipp Maier a415a225cf sysmo_usimsjs1: Also recognize algo by its number
The test 04_algo.sh suggests that an algorithm should also be
identified by its number (this is the old way). Since we upgraded
the commandline interface to accept the names of the algorithms the
support for the old way that used numbers had been removed. However,
we should stay compatible with the old method to keep legacy scripts
of customers working.

- Check if the given parameter that references tha algorithem is
  a number. If yes, us it, otherwise lookup the number by the
  given string name.

Change-Id: Ib41e4870d05820b6967f648eeeba416113bbc120
Related: OS#3376
2018-08-08 12:23:33 +02:00
Philipp Maier ed0c9ab4dc ICC: recognize card by its ATR
When working in an environment with multiple card terminals, then it
might be helpful to make sure that only the intended target simcard
(sysmo-usim-sjs1) is accessed.

- Add atr parameter to the ICC, SIM and USIM classes. When no atr
  is given, then ICC will pick any card as it was before

- Make sure to pass the ATR when the sim object is created

Change-Id: I874aae92d29a7e1051e4cebefd85592c5fb78a2e
Related: OS#3376
2018-07-04 15:10:23 +02:00
Philipp Maier 5c2733a7e9 cosmetic: correct indentation in log output
When reading Milenage sequence parameters, the log output is not
correctly indented. Lets correct this.

- correct log output

Change-Id: I59c1df45d722d71a54cdfdab2b7cd7ac35554f70
2018-07-04 14:40:46 +02:00
Philipp Maier be9db88384 usage: correct misleading usage description
When using the -T option the user has to supply two authentication
alogorithms. One for 2G and one for 3G. The authentication algorithms
used to be symbolized by integer numbeers. This was later changed so
that the user could use the clear names of the algorithms. Unfortunately
the usage text was not changed.

- Update usage description

Change-Id: I6a47e4fc24f4b3f0664050032cc15d81703f30c5
2018-07-04 13:38:48 +02:00
Philipp Maier 75aa246987 remove unused uption -v --verbose
The verbose mode (APDU-Trace) is no longer implemented, so lets
remove the option as well.

Change-Id: Ic47864da886a3ab39384b0553fc326b8f3b4db96
2018-07-04 12:15:02 +02:00
Neels Hofmeyr b2f56ad3fc README: hint at pcscd dependency 2018-02-28 15:46:09 +01:00
Neels Hofmeyr 8a50c51e2d sysmo-usim-tool.sjs1.py: add '-T list' to show available algos 2017-12-14 05:25:28 +01:00
Neels Hofmeyr bb7e45f436 sysmo_usimsjs1.py: define algos as tuple, print numbers with the names
Collapse two functions of if-cascades into a data structure matching algo
numbers with string names. Use dicts produced from the initial tuple defining
the relation, to re-implement the functions.

When printing out algos, also print out the numbers set on the USIM.

This prepares for printing a list of available algos by commandline switch.
2017-12-14 05:22:51 +01:00
Neels Hofmeyr 9cf40ef497 readme: document dependency on python-pyscard 2017-12-14 01:33:12 +01:00
Harald Welte d7b90f8db7 implement resetting of SQN parameters 2017-08-17 14:38:10 +02:00
Harald Welte 5c15b238f5 Divide SQNms Offset by 6
The SQNms offset is a *byte* index into the SQNA file, let's divide
this by 6 before showing it to the user, so he can immediately
make the connection into the SQN array dumped below
2017-08-17 14:38:07 +02:00
Harald Welte 9b3c122329 Fix decoding of SQN values in SYSMO_USIMSJS1_FILE_EF_SQNC 2017-08-17 13:15:39 +02:00
Harald Welte d7da172cbf Add README.md file 2017-08-16 23:16:21 +02:00
Harald Welte 5140557f3b Add testsuite
The idea of the testsuite is to test all functions of the utility
against one known SIM card that is inserted at the time the test
is executed.

We could insert this card into a reader attached to a
permanently-running machine and then use that as a jenkins build
test slave.
2017-08-16 23:16:17 +02:00
Harald Welte 7660d07aa9 Proper string representation of OP / OPc mode
The output should be intuitive without the user having to look
at the manual side by side.
2017-08-16 23:16:17 +02:00
Harald Welte 3d7b74b3af Print/Parse string representation of Algorithm Identifiers
We don't want to force the user to always open the manual every time
he uses the tool.
2017-08-16 22:38:38 +02:00
Harald Welte 72cf09e620 Add support for reading misc. MILENAGE parameters
We now can read
* IDX, MAX_DELTA and AGE_LIMIT parameters
* whether or not SQN, age and max delta are enforced
* SEQ array
* Authentication Counter
2017-08-16 21:14:44 +02:00
Harald Welte b7ec495145 EF_OPC is actually specified in ADF_USIM, so let's select it there 2017-08-16 21:14:44 +02:00
Harald Welte dc45c05b15 Migration to python 'card' from Benoit Michau
There are quite complete python utilities already out there as part
of Benoit Micuhau's 'card' python library. They support plenty of
SIM, UICC and USIM related bits.  Let's use them rather than re-
inventing the wheel here.
2017-08-16 21:14:44 +02:00
Harald Welte 4086758393 Import slightly modified version of mitshell/card
the modifications can be found in https://github.com/mitshell/card/pull/2
and I wouuld hope that once Benoit has merged this we can remove the
local copy here and simply rely on pypi pulling it from the repo.
2017-08-16 21:14:44 +02:00
Harald Welte 5666cd6818 Unconditionally print ICCID and IMSI
This can help a lot in identifying the cards and in giving context in
case a user copy+pastes the output.  Let's always read those values.
2017-08-16 21:14:44 +02:00
Harald Welte 6d5127c89a add list_to_int() utility function to convert byte-lists to integers 2017-08-16 21:14:44 +02:00
Harald Welte e786eb1310 add .gitignore file 2017-08-16 21:13:37 +02:00
Harald Welte 78b18df47c remove unused 'adm1' argument from many functions
The main program performs ADM1 authentication before using any
of the sysmo_usim_{read,write}* functions, so passing adm1 as
argument to them is just an unused argument that we can remove
2017-08-16 10:04:39 +02:00
Philipp Maier 55bb02bc62 Add ICCID reading/programming feature
sysmo-usim-tool still can't read or program the ICCID. This patch
adds enables reading and writing EF.ICCID
2017-03-21 00:30:34 +01:00
Philipp Maier 14aaab262e auth: prevent unintential card lock down
If the user submints a wrong ADM1 key with the commandline, the
authentication will fail. However, by the output of the program
it mey not be clear to the user that the reason for the failure
was a wrong ADM1 key. The user might try the same command with
the same parameters a few time and lock down the card.

This commit fixes that by failing gracefully with a very clear
error message. Furthermore, if a decreased authentication counter
is detected, no further authentication attempts will be made
until the user supplies the option -f (--force).
2017-03-17 16:43:35 +01:00
Neels Hofmeyr a73acbc8e4 cosmetic fix: sysmo_usim_show_milenage_params() was defined twice 2017-03-05 01:01:34 +01:00
Neels Hofmeyr 4d144983c3 cosmetic: typo and slash to clarify OP or OPC 2017-03-05 01:01:03 +01:00