laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35565?usp=email )
Change subject: ts_102_221: Better explain 'selected file invalidated'
......................................................................
ts_102_221: Better explain 'selected file invalidated'
Some specs call it 'invalidated', others call it 'deactivated'. If the
user is unfamiliar with this, the error message about "invalidated"
might not be obvious enough; let's also mention 'deactivated' in the
message and explicitly mention that it needs to be activated before use.
Change-Id: I91488b0e7dc25a8970022b09e575485a4165eefa
---
M docs/shell.rst
M pySim-shell.py
M pySim/ts_102_221.py
3 files changed, 37 insertions(+), 4 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/docs/shell.rst b/docs/shell.rst
index 4742b8e..7022b5a 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -400,7 +400,19 @@
deactivate_file
~~~~~~~~~~~~~~~
-Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11.
+Deactivate the currently selected file. A deactivated file can no longer be accessed
+for any further operation (such as selecting and subsequently reading or writing).
+
+Any access to a file that is deactivated will trigger the error
+*SW 6283 'Selected file invalidated/disabled'*
+
+In order to re-access a deactivated file, you need to activate it again, see the
+`activate_file` command below. Note that for *deactivation* the to-be-deactivated
+EF must be selected, but for *activation*, the DF above the to-be-activated
+EF must be selected!
+
+This command sends a DEACTIVATE FILE APDU to
+the card (used to be called INVALIDATE in TS 11.11 for classic SIM).
activate_file
diff --git a/pySim-shell.py b/pySim-shell.py
index 6ff484b..c645403 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -882,8 +882,15 @@
activate_file_parser.add_argument('NAME', type=str, help='File name or FID of file to activate')
@cmd2.with_argparser(activate_file_parser)
def do_activate_file(self, opts):
- """Activate the specified EF. This used to be called REHABILITATE in TS 11.11 for classic
- SIM. You need to specify the name or FID of the file to activate."""
+ """Activate the specified EF by sending an ACTIVATE FILE apdu command (used to be called REHABILITATE
+in TS 11.11 for classic SIM).
+
+This command is used to (re-)activate a file that is currently in deactivated (sometimes also called
+"invalidated") state. You need to call this from the DF above the to-be-activated EF and specify the name or
+FID of the file to activate.
+
+Note that for *deactivation* the to-be-deactivated EF must be selected, but for *activation*, the DF
+above the to-be-activated EF must be selected!"""
(data, sw) = self._cmd.lchan.activate_file(opts.NAME)
def complete_activate_file(self, text, line, begidx, endidx) -> List[str]:
diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py
index 308fc4a..65dd87d 100644
--- a/pySim/ts_102_221.py
+++ b/pySim/ts_102_221.py
@@ -808,7 +808,7 @@
'6200': 'No information given, state of non-volatile memory unchanged',
'6281': 'Part of returned data may be corrupted',
'6282': 'End of file/record reached before reading Le bytes or unsuccessful search',
- '6283': 'Selected file invalidated',
+ '6283': 'Selected file invalidated/disabled; needs to be activated before use',
'6284': 'Selected file in termination state',
'62f1': 'More data available',
'62f2': 'More data available and proactive command pending',
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35565?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I91488b0e7dc25a8970022b09e575485a4165eefa
Gerrit-Change-Number: 35565
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: jolly <andreas(a)eversberg.eu>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35569?usp=email )
Change subject: euicc: Implement EID checksum verification + computation
......................................................................
euicc: Implement EID checksum verification + computation
Change-Id: I2cb342783137ee7e4b1be3b14e9c3747316f1995
---
M pySim/euicc.py
A tests/test_euicc.py
2 files changed, 70 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/euicc.py b/pySim/euicc.py
index 96d95d6..e249f4f 100644
--- a/pySim/euicc.py
+++ b/pySim/euicc.py
@@ -32,6 +32,36 @@
from pySim.utils import Hexstr, SwHexstr
import pySim.global_platform
+def compute_eid_checksum(eid) -> str:
+ """Compute and add/replace check digits of an EID value according to GSMA SGP.29 Section 10."""
+ if type(eid) == str:
+ if len(eid) == 30:
+ # first pad by 2 digits
+ eid += "00"
+ elif len(eid) == 32:
+ # zero the last two digits
+ eid = eid[:-2] + "00"
+ else:
+ raise ValueError("and EID must be 30 or 32 digits")
+ eid_int = int(eid)
+ elif type(eid) == int:
+ eid_int = eid
+ if eid_int % 100:
+ # zero the last two digits
+ eid_int -= eid_int % 100
+ # Using the resulting 32 digits as a decimal integer, compute the remainder of that number on division by
+ # 97, Subtract the remainder from 98, and use the decimal result for the two check digits, if the result
+ # is one digit long, its value SHALL be prefixed by one digit of 0.
+ csum = 98 - (eid_int % 97)
+ eid_int += csum
+ return str(eid_int)
+
+def verify_eid_checksum(eid) -> bool:
+ """Verify the check digits of an EID value according to GSMA SGP.29 Section 10."""
+ # Using the 32 digits as a decimal integer, compute the remainder of that number on division by 97. If the
+ # remainder of the division is 1, the verification is successful; otherwise the EID is invalid.
+ return int(eid) % 97 == 1
+
class VersionAdapter(Adapter):
"""convert an EUICC Version (3-int array) to a textual representation."""
diff --git a/tests/test_euicc.py b/tests/test_euicc.py
new file mode 100755
index 0000000..05d71ed
--- /dev/null
+++ b/tests/test_euicc.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+import unittest
+
+from pySim.euicc import *
+
+class TestEid(unittest.TestCase):
+
+ def test_eid_verify(self):
+ for eid in ['89049032123451234512345678901235', '89086030202200000022000023022943',
+ '89044045116727494800000004479366', 89044045116727494800000004479366]:
+ self.assertTrue(verify_eid_checksum(eid))
+
+ def test_eid_verify_wrong(self):
+ self.assertFalse(verify_eid_checksum('89049032123451234512345678901234'))
+ self.assertFalse(verify_eid_checksum(89049032123451234512345678901234))
+
+ def test_eid_encode_with_32_digits(self):
+ self.assertEquals(compute_eid_checksum('89049032123451234512345678901200'), '89049032123451234512345678901235')
+ self.assertEquals(compute_eid_checksum('89086030202200000022000023022900'), '89086030202200000022000023022943')
+
+ def test_eid_encode_with_30digits(self):
+ self.assertEquals(compute_eid_checksum('890490321234512345123456789012'), '89049032123451234512345678901235')
+
+ def test_eid_encode_with_wrong_csum(self):
+ # input: EID with wrong checksum
+ self.assertEquals(compute_eid_checksum('89049032123451234512345678901299'), '89049032123451234512345678901235')
+ self.assertEquals(compute_eid_checksum(89049032123451234512345678901299), '89049032123451234512345678901235')
+
+if __name__ == "__main__":
+ unittest.main()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35569?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I2cb342783137ee7e4b1be3b14e9c3747316f1995
Gerrit-Change-Number: 35569
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
Attention is currently required from: osmith.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/35597?usp=email )
Change subject: vty: show mscs: add BSSMAP state
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35597?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I23ddba7d935e5cc5dae041458207c674ccb9d013
Gerrit-Change-Number: 35597
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 16 Jan 2024 18:16:47 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment