Attention is currently required from: jolly.
Hello jolly,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/pysim/+/38939?usp=email
to look at the new patch set (#2).
Change subject: docs: Add documentation about contrib/sim-rest-{server,client}
......................................................................
docs: Add documentation about contrib/sim-rest-{server,client}
Those programs have been around since 2021 but we never had any
documentation here. Let's fix that.
Change-Id: I7c471cac9500db063a0c8f5c5eb7b6861b3234ed
---
M docs/index.rst
A docs/sim-rest.rst
2 files changed, 119 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/39/38939/2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38939?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I7c471cac9500db063a0c8f5c5eb7b6861b3234ed
Gerrit-Change-Number: 38939
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: jolly <andreas(a)eversberg.eu>
Gerrit-CC: Jenkins Builder
Gerrit-Attention: jolly <andreas(a)eversberg.eu>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38939?usp=email )
Change subject: docs: Add documentation about contrib/sim-reset-{server,client}
......................................................................
docs: Add documentation about contrib/sim-reset-{server,client}
Those programs have been around since 2021 but we never had any
documentation here. Let's fix that.
Change-Id: I7c471cac9500db063a0c8f5c5eb7b6861b3234ed
---
M docs/index.rst
A docs/sim-rest.rst
2 files changed, 119 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/39/38939/1
diff --git a/docs/index.rst b/docs/index.rst
index bcbc7f0..228fb79 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -43,6 +43,7 @@
legacy
library
osmo-smdpp
+ sim-rest
Indices and tables
diff --git a/docs/sim-rest.rst b/docs/sim-rest.rst
new file mode 100644
index 0000000..41a6d1d
--- /dev/null
+++ b/docs/sim-rest.rst
@@ -0,0 +1,118 @@
+sim-rest-server
+===============
+
+Sometimes there are use cases where a [remote] application will need
+access to a USIM for authentication purposes. This is, for example, in
+case an IMS test client needs to perform USIM based authentication
+against an IMS core.
+
+The pysim repository contains two programs: `sim-rest-server.py` and
+`sim-rest-client.py` that implement a simple approach to achieve the
+above:
+
+`sim-rest-server.py` speaks to a [usually local] USIM via the PC/SC
+API and provides a high-level REST API towards [local or remote]
+applications that wish to perform UMTS AKA using the USIM.
+
+`sim-rest-client.py` implements a small example client program to
+illustrate how the REST API provided by `sim-rest-server.py` can be
+used.
+
+REST API Calls
+--------------
+
+POST /sim-auth-api/v1/slot/SLOT_NR
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+where SLOT_NR is the integer-encoded slot number (corresponds to PC/SC
+reader number). When using a single sysmoOCTSIM board, this is in the range of 0..7
+
+Example: `/sim-auth-api/v1/slot/0` for the first slot.
+
+Request Body
+############
+
+The request body is a JSON document, comprising of
+ 1. the RAND and AUTN parameters as hex-encoded string
+ 2. the application against which to authenticate (USIM, ISIM)
+
+Example:
+::
+
+ {
+ "rand": "bb685a4b2fc4d697b9d6a129dd09a091",
+ "autn": "eea7906f8210000004faf4a7df279b56"
+ }
+
+HTTP Status Codes
+#################
+
+HTTP status codes are used to represent errors within the REST server
+and the SIM reader hardware. They are not used to communicate protocol
+level errors reported by the SIM Card. An unsuccessful authentication
+will hence have a `200 OK` HTTP Status code and then encode the SIM
+specific error information in the Response Body.
+
+====== =========== ================================
+Status Code Description
+------ ----------- --------------------------------
+200 OK Successful execution
+400 Bad Request Request body is malformed
+404 Not Found Specified SIM Slot doesn't exist
+410 Gone No SIM card inserted in slot
+====== =========== ================================
+
+Response Body
+#############
+
+The response body is a JSON document, either
+
+#. a successful outcome; encoding RES, CK, IK as hex-encoded string
+#. a sync failure; encoding AUTS as hex-encoded string
+#. errors
+ #. authentication error (incorrect MAC)
+ #. authentication error (security context not supported)
+ #. key freshness failure
+ #. unspecified card error
+
+Example (succcess):
+::
+
+ {
+ "successful_3g_authentication": {
+ "res": "b15379540ec93985",
+ "ck": "713fde72c28cbd282a4cd4565f3d6381",
+ "ik": "2e641727c95781f1020d319a0594f31a",
+ "kc": "771a2c995172ac42"
+ }
+ }
+
+Example (re-sync case):
+::
+
+ {
+ "synchronisation_failure": {
+ "auts": "dc2a591fe072c92d7c46ecfe97e5"
+ }
+ }
+
+Concrete example using the included sysmoISIM-SJA2
+--------------------------------------------------
+
+This was tested using SIMs ending in IMSI numbers 45890...45899
+
+The following command were executed successfully:
+
+Slot 0
+::
+
+ $ /usr/local/src/pysim/contrib/sim-rest-client.py -c 1 -n 0 -k 841EAD87BC9D974ECA1C167409357601 -o 3211CACDD64F51C3FD3013ECD9A582A0
+ -> {'rand': 'fb195c7873b20affa278887920b9dd57', 'autn': 'd420895a6aa2000089cd016f8d8ae67c'}
+ <- {'successful_3g_authentication': {'res': '131004db2ff1ce8e', 'ck': 'd42eb5aa085307903271b2422b698bad', 'ik': '485f81e6fd957fe3cad374adf12fe1ca', 'kc': '64d3f2a32f801214'}}
+
+Slot 1
+::
+
+ $ /usr/local/src/pysim/contrib/sim-rest-client.py -c 1 -n 1 -k 5C2CE9633FF9B502B519A4EACD16D9DF -o 9834D619E71A02CD76F00CC7AA34FB32
+ -> {'rand': '433dc5553db95588f1d8b93870930b66', 'autn': '126bafdcbe9e00000026a208da61075d'}
+ <- {'successful_3g_authentication': {'res': '026d7ac42d379207', 'ck': '83a90ba331f47a95c27a550b174c4a1f', 'ik': '31e1d10329ffaf0ca1684a1bf0b0a14a', 'kc': 'd15ac5b0fff73ecc'}}
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38939?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I7c471cac9500db063a0c8f5c5eb7b6861b3234ed
Gerrit-Change-Number: 38939
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38899?usp=email )
Change subject: [cosmetic] esim.saip: Fix various typos in comments/docs/messages
......................................................................
[cosmetic] esim.saip: Fix various typos in comments/docs/messages
Change-Id: I4fc603634a0f2b53e432a77f05e811a38ba065c2
---
M pySim/esim/saip/__init__.py
1 file changed, 6 insertions(+), 6 deletions(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, approved
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 355e6b9..1fcf61f 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -450,7 +450,7 @@
@property
def header_name(self) -> str:
"""Return the name of the header field within the profile element."""
- # unneccessarry compliaction by inconsistent naming :(
+ # unnecessary complication by inconsistent naming :(
if self.type.startswith('opt-'):
return self.type.replace('-','') + '-header'
if self.type in self.header_name_translation_dict:
@@ -933,7 +933,7 @@
'macLength': self.mac_length}
class SecurityDomainKey:
- """Represenation of a key used for SCP access to a security domain."""
+ """Representation of a key used for SCP access to a security domain."""
def __init__(self, key_version_number: int, key_id: int, key_usage_qualifier: dict,
key_components: List[SecurityDomainKeyComponent]):
self.key_usage_qualifier = key_usage_qualifier
@@ -1276,7 +1276,7 @@
sequence."""
def __init__(self):
"""After calling the constructor, you have to further initialize the instance by either
- calling the parse_der() method, or by manually adding individual PEs, including the hedaer and
+ calling the parse_der() method, or by manually adding individual PEs, including the header and
end PEs."""
self.pe_list: List[ProfileElement] = []
self.pe_by_type: Dict = {}
@@ -1298,7 +1298,7 @@
def add_hdr_and_end(self):
"""Initialize the PE Sequence with a header and end PE."""
if len(self.pe_list):
- raise ValueError("Cannot add header + end PE to a non-enmpty PE-Sequence")
+ raise ValueError("Cannot add header + end PE to a non-empty PE-Sequence")
# start with a minimal/empty sequence of header + end
self.append(ProfileElementHeader())
self.append(ProfileElementEnd())
@@ -1315,7 +1315,7 @@
def get_pe_for_type(self, tname: str) -> Optional[ProfileElement]:
"""Return a single profile element for given profile element type. Works only for
- types of which there is only a signle instance in the PE Sequence!"""
+ types of which there is only a single instance in the PE Sequence!"""
l = self.get_pes_for_type(tname)
if len(l) == 0:
return None
@@ -1323,7 +1323,7 @@
return l[0]
def get_pes_for_templateID(self, tid: oid.OID) -> List[ProfileElement]:
- """Return list of profile elements present for given profile eleemnt type."""
+ """Return list of profile elements present for given profile element type."""
res = []
for pe in self.pe_list:
if not pe.templateID:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38899?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4fc603634a0f2b53e432a77f05e811a38ba065c2
Gerrit-Change-Number: 38899
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38898?usp=email )
Change subject: esim.saip: Fix computation of file content
......................................................................
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
---
M pySim/esim/saip/__init__.py
M pySim/ts_102_222.py
2 files changed, 27 insertions(+), 4 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 3490f64..355e6b9 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -18,6 +18,7 @@
import logging
import abc
import io
+import os
from typing import Tuple, List, Optional, Dict, Union
from collections import OrderedDict
import asn1tools
@@ -25,6 +26,7 @@
from osmocom.tlv import BER_TLV_IE, bertlv_parse_tag, bertlv_parse_len
from osmocom.construct import build_construct, parse_construct, GreedyInteger
+from pySim import ts_102_222
from pySim.utils import dec_imsi
from pySim.ts_102_221 import FileDescriptor
from pySim.filesystem import CardADF, Path
@@ -352,18 +354,29 @@
ret += self.file_content_to_tuples()
return ret
- @staticmethod
- def file_content_from_tuples(l: List[Tuple]) -> Optional[bytes]:
+ def expand_fill_pattern(self) -> bytes:
+ """Expand the fill/repeat pattern as per TS 102 222 Section 6.3.2.2.2"""
+ return ts_102_222.expand_pattern(self.fill_pattern, self.fill_pattern_repeat, self.file_size)
+
+ def file_content_from_tuples(self, l: List[Tuple]) -> Optional[bytes]:
"""linearize a list of fillFileContent / fillFileOffset tuples into a stream of bytes."""
stream = io.BytesIO()
+ # Providing file content within "fillFileContent" / "fillFileOffset" shall have the same effect as
+ # creating a file with a fill/repeat pattern and thereafter updating the content via Update.
+ # Step 1: Fill with pattern from Fcp or Template
+ if self.fill_pattern:
+ stream.write(self.expand_fill_pattern())
+ elif self.template and self.template.default_val:
+ stream.write(self.template.expand_default_value_pattern(self.file_size))
+ stream.seek(0)
+ # then process the fillFileContent/fillFileOffset
for k, v in l:
if k == 'doNotCreate':
return None
if k == 'fileDescriptor':
pass
elif k == 'fillFileOffset':
- # FIXME: respect the fillPattern!
- stream.write(b'\xff' * v)
+ stream.seek(v, os.SEEK_CUR)
elif k == 'fillFileContent':
stream.write(v)
else:
diff --git a/pySim/ts_102_222.py b/pySim/ts_102_222.py
index e54c196..74eb2c3 100644
--- a/pySim/ts_102_222.py
+++ b/pySim/ts_102_222.py
@@ -25,6 +25,16 @@
from pySim.ts_102_221 import *
+def expand_pattern(pattern: bytes, repeat: bool, size: int) -> bytes:
+ """Expand the fill/repeat pattern as per TS 102 222 Section 6.3.2.2.2 Tags C1/C2."""
+ if not repeat:
+ pad_len = size - len(pattern)
+ return pattern + pattern[-1:] * pad_len
+ else:
+ count = size // len(pattern)
+ part_len = size - count * len(pattern)
+ return pattern * count + pattern[:part_len]
+
@with_default_category('TS 102 222 Administrative Commands')
class Ts102222Commands(CommandSet):
"""Administrative commands for telecommunication applications."""
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38898?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I822bb5fbec11a3be35910a496af7168458fd949c
Gerrit-Change-Number: 38898
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38905?usp=email )
Change subject: esim.saip: New methods for inserting ProfileElement into sequence
......................................................................
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
---
M pySim/esim/saip/__init__.py
1 file changed, 22 insertions(+), 3 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 1fcf61f..b83367e 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -1500,6 +1500,27 @@
pe.header['identification'] = i
i += 1
+ def get_index_by_pe(self, pe: ProfileElement) -> int:
+ """Return a list with the indicies of all instances of PEs of petype."""
+ ret = []
+ i = 0
+ for cur in self.pe_list:
+ if cur == pe:
+ return i
+ i += 1
+ raise ValueError('PE %s is not part of PE Sequence' % (pe))
+
+ def insert_at_index(self, idx: int, pe: ProfileElement) -> None:
+ """Insert a given [new] ProfileElement at given index into the PE Sequence."""
+ self.pe_list.insert(idx, pe)
+ self._process_pelist()
+ self.renumber_identification()
+
+ def insert_after_pe(self, pe_before: ProfileElement, pe_new: ProfileElement) -> None:
+ """Insert a given [new] ProfileElement after a given [existing] PE in the PE Sequence."""
+ idx = self.get_index_by_pe(pe_before)
+ self.insert_at_index(idx+1, pe_new)
+
def get_index_by_type(self, petype: str) -> List[int]:
"""Return a list with the indicies of all instances of PEs of petype."""
ret = []
@@ -1515,9 +1536,7 @@
# find MNO-SD index
idx = self.get_index_by_type('securityDomain')[0]
# insert _after_ MNO-SD
- self.pe_list.insert(idx+1, ssd)
- self._process_pelist()
- self.renumber_identification()
+ self.insert_at_index(idx+1, ssd)
def remove_naas_of_type(self, naa: Naa) -> None:
"""Remove all instances of NAAs of given type. This can be used, for example,
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38905?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4424926127b4867931c2157e9340bacd2682ff0c
Gerrit-Change-Number: 38905
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>