When updating files and records there are sometimes huge portions that
are just 0xff. Mostly this is at the end of a file or record that is not
completely used. Lets add a notation to tell PySim-shell how to fill
those sections.
Change-Id: Iedd7887bf7d706878f4a3beca8dbea456404610b
This adds support for creating/deleting and terminating files,
as well as support for permanent card termination.
Change-Id: I5b1ffb1334afa18d62beb642268066a30deb7ea6
We had a mixture of tab and 4space based indenting, which is a bad
idea. 4space is the standard in python, so convert all our code to
that. The result unfortuantely still shoed even more inconsistencies,
so I've decided to run autopep8 on the entire code base.
Change-Id: I4a4b1b444a2f43fab05fc5d2c8a7dd6ddecb5f07
At the moment the non checking send_apdu() method is used when records
are read. Lets use read_record_checksw so that we get an exception in
case there is a problem to read the specified record.
Change-Id: I9fc411e1b12e8d9fd89b9964209808c0706011bd
The computed length of the file may be negative, when the offset exceeds
the file length. When this is the case, return none
Change-Id: I2c017c620254fae188022851ef3b670730aab503
The transport layer provides a method send_apdu_checksw to send APDUs
and to be sure the SW is the expected one. Given that, there is no need
to verify the SW manually. The exception of send_apdu_checksw will catch
the problem and also display the SW in a human readable form.
Change-Id: I9ce556ac0b7bb21c5c5a27170c32af0152255b79
Related: OS#5275
Similar to the fix in Ie1aeaab29701946233ed73db3331039690d695da
for update_binary(), read_binary() also contained a bug when treating
non-zero offsets.
Change-Id: Ic5c2f0ad1c1ec9c4e9c97e72895382f7b6fa9470
Related: OS#5254
In Icc240d5c8c04198640eb118565ea99f10ba27466 we introduced support for
writing files > 255 bytes by splitting the write into multiple chunks.
However, at the same time, that commit broke support for writing data at
non-zero offsets. Unfortunately, this is used extensively within
pySim-prog e.g. for writing K + OP/OPc data to sysmoISIM-SJA2 and sysmoUSIM-SJS1
cards.
This commit fixes the related problem.
Change-Id: Ie1aeaab29701946233ed73db3331039690d695da
Fixes: Icc240d5c8c04198640eb118565ea99f10ba27466
Closes: OS#5254
The T0 protocol (selected in transport/pcsc.py) does not support extended APDU, so 255 bytes is the maximum number of bytes that can be transmitted at a time. We can divide large data into 255 byte chunks. The read_binary function already has code to read more than 255 bytes, so we can just adapt it to the update_binary function.
Change-Id: Icc240d5c8c04198640eb118565ea99f10ba27466
We cannot re-activate a deactivated file after we have selected somethng
else, as SELECT will fail on the deactivated file. Hence, the
deactivate_file command needs to be used with a file name as argument.
Change-Id: Ief4d2bf8ea90497a8f25d1986aeea935c615f9bb
There's little point in having a getter+setter for a property if
all it does is assigning a value to an attribute of self. That
works without any property methods
Change-Id: Id214cc83a29e8aa88f4e1413e07b419285c1b7ff
The code uses self.sel_ctrl everywhere except in the two @property
methods, where the _sel_ctrl variable is used. Let's just abandon
those property methods and make sure all users directly use the
[public] sel_ctrl member variable.
Change-Id: I10362300c1cf7b493d89bf71bbd3a10c80ef9a49
The method update_record as a "force_len" parameter, which is somewhat
irretatating. Some explainatory comments and a reformat of the if
statement will help to make it more understandable to the api user.
In the non force_len case the method determines the record length from
the select response and throws an exception if the data input does not
match that length. This makes sense if the data input exceeds the
record length of the file but if the data input is less then the record
length the situation is fixable by padding the input with 0xff. This
also a quite common case because in some situation it is not guaranteed
that the data will fill the entire record.
Change-Id: I9a5df0e46c3dd2e87d447c5c01cf15844b0eed07
Related: OS#4963
This adds support for a new EF file type: BER-TLV files. They are
different from transparent and linear fixed EFs in that they neither
operate on a byte stream nor fixed-sized records, but on BER-TLV encoded
objects. One can specify a tag value, and the card will return the
entire TLV for that tag.
As indicated in the spec, the magic tag value 0x5C (92) will return a
list of tags existing in the file.
Change-Id: Ibfcce757dcd477fd0d6857f64fbb4346d6d62e63
This adds support for AUTHENTICATE to the USIM and ISIM application,
based on the newly-introduced 'construct' encoder/decoder support.
Change-Id: Id5697463e29c3dceff98bcf80f5400f7f2bcaa6c
* add type annotations in-line with PEP484
* convert existing documentation to follow the
"Google Python Style Guide" format understood by
the sphinx.ext.napoleon' extension
* add much more documentation all over the code base
Change-Id: I6ac88e0662cf3c56ae32d86d50b18a8b4150571a
At the moment we only have a basic version of a verify_chv commnad, but
in order to handle any CHV/PIN related situation we also need commands
to enable, disable, change and unblock CHV.
- fix verify_chv commnad: more distinct parameter names, better help
strings, correct pin code encoding and add external source lookup
- Add unblock_chv, change_chv, enable_chv and disable_chv commands
- add/fix related functions in commands.py
Change-Id: Ic89446e6bd2021095e579fb6b20458df48ba6413
Related: OS#4963
When a record or a binary file is written the card goes throth a full
flash/eeprom write cycle at this location, even when the data does not
change. This can be optimized by reading before writing in order to
compere if the data we are about to write is actually different.
Change-Id: Ifd1b80d3ede15a7caa29077a37ac7cf58c9053f1
Related: OS#4963
At the moment we use the send_apdu_checksw() method to send the APDU for
ADM authentication. This method only checks if the command returns with
sw = 9000. If not it raises an exception that the sw is not as expected.
The user may think that this is a problem with thr reader, pcscd or
pySim in the first place and may try multiple times until the card is
permanently locked. A better execption string that also displays the
tries which are left may be helpful.
Change-Id: Icf428831094f8c1045eefaa8cb2b92e6a36b0c13
Related: OS#4963
This method, like select_adf(), only selects a single file ID
and unlike select_path() returns the actual status words returned by the
card.
Change-Id: I8bc86654c6d79f2428e196cc8a401e12d93a676b
In reality, the function is not a simple avstraction around the SELECT
command, but it iterates over a list/path and selects at each element.
Change-Id: I63e01155de4ae47aeed8500708c0eb6580c7b8d1
If the EF.EHPLMN exists, it contains the "Equivalent Home PLMN List".
The odd part of that list is that it is not just a list of additional
PLMN identities, but if the first digits of the IMSI are *not* listed
in EF.EHPLMN, then the MCC/MNC of the IMSI prefix is suddently no
longer considered the home network, but the subscriber is roaming.
See TS 23.122: "If the HPLMN code derived from the IMSI is not present
in the EHPLMN list, then it shall be treated as a Visited PLMN for PLMN
selection purposes."
Change-Id: I22d96ab4a424ec5bc1fb02f5e80165c646a748d3
When writing to files we often just write without making sure that the
actual file contents actually written. Lets add features to do a
read-after-write verification when writing to files.
Change-Id: I7be842004102f4998af376790c97647c107be3d5
For record oriented files we have the methods record_size() and
record_count() to determine the dimensions of a record oriented file,
however, we miss a similar function for regular binary files. Lets add a
method binary_size() to quickly determine the size of a non record
oriented file
Change-Id: I0593f2de7f34d5654a19e949dc567a236e44e20c
Unlike Python 2, in Python 3 strings also have attribute '__iter__'.
Because of that, a string could be passed to select_file(), that
actually expects a list as the first parameter.
P.S. Madness, Python 3 is just a new different language...
P.P.S. They should have renamed it not to confuse people.
Change-Id: I92af47abb6adff0271c55e7f278e8c5188f2be75
Fixes: OS#4419
In Python 3, traditional division operator returns a float,
while we need a floor integer in the most cases.
Change-Id: I5565eb64a1ddea7075cbb142eaacaa5d494c87bb
The sysmo-isim-sja2 cards are not yet supported by pysim. Lets add
support for writing KI and OPC in ADF.USIM and ADF.ISIM as well as the
remaining common simcard parameters.
Related: SYS#4466
Change-Id: I23e2b46eac0e0dbc2b271983d448999f6a459ecf
When working with USIM/ISIMs, The method __record_len() that is used
by the record_count() method returns the length of the file instead
the actual record count. This causes record_count() to return always 1
Change-Id: If810c691893c022e9e9d87218dd0a334c5b2d579
Without that fix we have:
$ python3 pySim-read.py
File "pySim-read.py", line 135
try:
^
TabError: inconsistent use of tabs and spaces in indentation
The following command was used to do the conversion:
sed 's# #\t#g' -i $(find -name "*.py")
Then the remaining spaces spotted during the review were
addressed manually.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Change-Id: I83f76a8e9b6e36098f16552a0135a8c22dde545f
The hexadecimal tag defintions of pytlv are case sensitive strings. So
'A5' is something different than 'a5'. Pytlv uses lower case letters for
the upper hexadecimal digits. Lets correct this.
Change-Id: I41a9933707783f6b1b68ebd91a365405ac0892d0
Related: OS#3850
Some of the USIM-Card programming implementations do not need to look
at card responses, which means they also do not have to parse TLV
data. Lets depend on pytlv only in cases where TLV data has to be
parsed so that useser of cards that do not need at can go without
installing pytlv.
Change-Id: Ida841d74d9581e7f395751b0f74556a06a038de6
Some of the methods SimCardCommands() have ways to determaine length
information from the card response. Regular sims use a format where
the length field is on a fixed position. USIMs use FCP templates
(format control parameters), which is a TLV encodecs string. So lets
distingish if we deal with an USIM (We can easily do this by looking
at the select control parameters) and extract the length info from
the FCP.
- If we deal with USIMs, use the FCP to determine length
information
Change-Id: I068cf8a532e1c79a2d208e9d275c155ddb72713c
Related: SYS#4245
sysmo-usim-sjs1 requires P2 to be set to 0x0C (request FCI) when
using the USIM application commands. The FCI is not used by pysim
anyway and might even cause problems with other cards.
This commit adds a pair of get/set methods to the SimCardCommands
class in order to set a default for the selection control
parameters (P1, P2). (Similar to the set/get methods for the class
byte)
The SysmoUSIMSJS1 class now calls the setter method for the
selection control parameters inside of its constructuor and sets
the selection control parameter default to "000C". This way we
can be sure that we only change the behaviour for sysmo-usim-sjs1
and do not break support for any other cards.
Change-Id: I1993a267c952bf37d5de1cb4e1107f445614c17b