laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38900?usp=email )
Change subject: [cosmetic] esim: Fix various typos in comments/messages/docs
......................................................................
[cosmetic] esim: Fix various typos in comments/messages/docs
Change-Id: I806c7a37951e72027ab9346169a3f8fe241f2c46
---
M pySim/esim/bsp.py
M pySim/esim/http_json_api.py
M pySim/esim/saip/personalization.py
M pySim/esim/x509_cert.py
4 files changed, 12 insertions(+), 12 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/esim/bsp.py b/pySim/esim/bsp.py
index 24634a7..862502f 100644
--- a/pySim/esim/bsp.py
+++ b/pySim/esim/bsp.py
@@ -225,7 +225,7 @@
return cls(s_enc, s_mac, initial_mcv)
def encrypt_and_mac_one(self, tag: int, plaintext:bytes) -> bytes:
- """Encrypt + MAC a single plaintext TLV. Returns the protected ciphertex."""
+ """Encrypt + MAC a single plaintext TLV. Returns the protected ciphertext."""
assert tag <= 255
assert len(plaintext) <= self.max_payload_size
logger.debug("encrypt_and_mac_one(tag=0x%x, plaintext=%s)", tag, b2h(plaintext))
@@ -250,11 +250,11 @@
return result
def mac_only_one(self, tag: int, plaintext: bytes) -> bytes:
- """MAC a single plaintext TLV. Returns the protected ciphertex."""
+ """MAC a single plaintext TLV. Returns the protected ciphertext."""
assert tag <= 255
assert len(plaintext) < self.max_payload_size
maced = self.m_algo.auth(tag, plaintext)
- # The data block counter for ICV caluclation is incremented also for each segment with C-MAC only.
+ # The data block counter for ICV calculation is incremented also for each segment with C-MAC only.
self.c_algo.block_nr += 1
return maced
@@ -288,7 +288,7 @@
def demac_only_one(self, ciphertext: bytes) -> bytes:
payload = self.m_algo.verify(ciphertext)
_tdict, _l, val, _remain = bertlv_parse_one(payload)
- # The data block counter for ICV caluclation is incremented also for each segment with C-MAC only.
+ # The data block counter for ICV calculation is incremented also for each segment with C-MAC only.
self.c_algo.block_nr += 1
return val
diff --git a/pySim/esim/http_json_api.py b/pySim/esim/http_json_api.py
index 6a803f2..ae32ba1 100644
--- a/pySim/esim/http_json_api.py
+++ b/pySim/esim/http_json_api.py
@@ -26,15 +26,15 @@
logger.setLevel(logging.DEBUG)
class ApiParam(abc.ABC):
- """A class reprsenting a single parameter in the API."""
+ """A class representing a single parameter in the API."""
@classmethod
def verify_decoded(cls, data):
- """Verify the decoded reprsentation of a value. Should raise an exception if somthing is odd."""
+ """Verify the decoded representation of a value. Should raise an exception if something is odd."""
pass
@classmethod
def verify_encoded(cls, data):
- """Verify the encoded reprsentation of a value. Should raise an exception if somthing is odd."""
+ """Verify the encoded representation of a value. Should raise an exception if something is odd."""
pass
@classmethod
diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py
index f9451d1..61973e7 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -67,7 +67,7 @@
If the string of digits is only 18 digits long, a Luhn check digit will be added."""
def validate(self):
- # convert to string as it migt be an integer
+ # convert to string as it might be an integer
iccid_str = str(self.input_value)
if len(iccid_str) < 18 or len(iccid_str) > 20:
raise ValueError('ICCID must be 18, 19 or 20 digits long')
@@ -86,7 +86,7 @@
the last digit of the IMSI."""
def validate(self):
- # convert to string as it migt be an integer
+ # convert to string as it might be an integer
imsi_str = str(self.input_value)
if len(imsi_str) < 6 or len(imsi_str) > 15:
raise ValueError('IMSI must be 6..15 digits long')
@@ -300,7 +300,7 @@
class AlgoConfig(ConfigurableParameter, metaclass=ClassVarMeta):
- """Configurable Algorithm parameter. bytes."""
+ """Configurable Algorithm parameter."""
key = None
def validate(self):
if not isinstance(self.input_value, (io.BytesIO, bytes, bytearray)):
diff --git a/pySim/esim/x509_cert.py b/pySim/esim/x509_cert.py
index 3bcf8a2..e951de7 100644
--- a/pySim/esim/x509_cert.py
+++ b/pySim/esim/x509_cert.py
@@ -31,7 +31,7 @@
"""Verify if 'signed' certificate was signed using 'signer'."""
# this code only works for ECDSA, but this is all we need for GSMA eSIM
pkey = signer.public_key()
- # this 'signed.signature_algorithm_parameters' below requires cryptopgraphy 41.0.0 :(
+ # this 'signed.signature_algorithm_parameters' below requires cryptography 41.0.0 :(
pkey.verify(signed.signature, signed.tbs_certificate_bytes, signed.signature_algorithm_parameters)
def cert_get_subject_key_id(cert: x509.Certificate) -> bytes:
@@ -189,7 +189,7 @@
def ecdsa_sign(self, plaintext: bytes) -> bytes:
"""Sign some input-data using an ECDSA signature compliant with SGP.22,
which internally refers to Global Platform 2.2 Annex E, which in turn points
- to BSI TS-03111 which states "concatengated raw R + S values". """
+ to BSI TS-03111 which states "concatenated raw R + S values". """
sig = self.priv_key.sign(plaintext, ec.ECDSA(hashes.SHA256()))
# convert from DER format to BSI TR-03111; first get long integers; then convert those to bytes
return ecdsa_dss_to_tr03111(sig)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38900?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: I806c7a37951e72027ab9346169a3f8fe241f2c46
Gerrit-Change-Number: 38900
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38906?usp=email )
Change subject: esim.saip.File: Re-compute file_size when changing body
......................................................................
esim.saip.File: Re-compute file_size when changing body
If the API user modifies the size of the body, we need to check if we
need to re-compute the file_size attribute which is later encoded into
the fileDescriptor. The size obviously must be large enough to fit the
body. Let's do this implicitly by introducing a setter for File.body
Change-Id: I1a908504b845b7c90f31294faf2a6e988bdd8049
---
M pySim/esim/saip/__init__.py
1 file changed, 20 insertions(+), 2 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index b83367e..163c91b 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -106,7 +106,7 @@
self.pe_name = pename
self._name = name
self.template = template
- self.body: Optional[bytes] = None
+ self._body: Optional[bytes] = None
self.node: Optional['FsNode'] = None
self.file_type = None
self.fid: Optional[int] = None
@@ -191,6 +191,24 @@
# All the files defined in the templates shall have, by default, shareable/not-shareable bit in the file descriptor set to "shareable".
self.shareable = True
self._template_derived = True
+ if hasattr(template, 'file_size'):
+ self._file_size = template.file_size
+
+ def _recompute_size(self):
+ """recompute the file size, if needed (body larger than current size)"""
+ body_size = len(self.body)
+ if self.file_size == None or self.file_size < body_size:
+ self._file_size = body_size
+
+ @property
+ def body(self):
+ return self._body
+
+ @body.setter
+ def body(self, value: bytes):
+ self._body = value
+ # we need to potentially update the file size after changing the body [size]
+ self._recompute_size()
def to_fileDescriptor(self) -> dict:
"""Convert from internal representation to 'fileDescriptor' as used by asn1tools for SAIP"""
@@ -332,7 +350,7 @@
if fd:
self.from_fileDescriptor(dict(fd))
# BODY
- self.body = self.file_content_from_tuples(l)
+ self._body = self.file_content_from_tuples(l)
@staticmethod
def path_from_gfm(bin_path: bytes):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38906?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: I1a908504b845b7c90f31294faf2a6e988bdd8049
Gerrit-Change-Number: 38906
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38907?usp=email )
Change subject: esim.saip.File: Proper ARR conversion of template (into) to file (bytes)
......................................................................
esim.saip.File: Proper ARR conversion of template (into) to file (bytes)
The encoding of the access rule reference is different in FileTemplate
vs File, let's make sure we properly convert it when instantiating a
File from a FileTemplate.
Change-Id: Ibb8afb85cc0006bc5c59230ebf28b2c0c1a8a8ed
---
M pySim/esim/saip/__init__.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 163c91b..40ef4ce 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -178,7 +178,7 @@
self.file_type = template.file_type
self.fid = template.fid
self.sfi = template.sfi
- self.arr = template.arr
+ self.arr = template.arr.to_bytes(1)
if hasattr(template, 'rec_len'):
self.rec_len = template.rec_len
else:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38907?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: Ibb8afb85cc0006bc5c59230ebf28b2c0c1a8a8ed
Gerrit-Change-Number: 38907
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38908?usp=email )
Change subject: esim.saip.File: Suppress encoding attributes that are like template
......................................................................
esim.saip.File: Suppress encoding attributes that are like template
The point of the SAIP template mechanism is to reduce the size of the
encoded profile. Therefore, our encoder in the to_fileDescriptor()
method should suppress generating attributes if their value is identical
to that of the template (if any).
Change-Id: I337ee6c7e882ec711bece17b7a0def9da36b0ad7
---
M pySim/esim/saip/__init__.py
1 file changed, 3 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 40ef4ce..94df453 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -216,13 +216,13 @@
fdb_dec = {}
pefi = {}
spfi = 0
- if self.fid:
+ if self.fid and self.fid != self.template.fid:
fileDescriptor['fileID'] = self.fid.to_bytes(2, 'big')
- if self.sfi:
+ if self.sfi and self.sfi != self.template.sfi:
fileDescriptor['shortEFID'] = bytes([self.sfi])
if self.df_name:
fileDescriptor['dfName'] = self.df_name
- if self.arr:
+ if self.arr and self.arr != self.template.arr.to_bytes(1):
fileDescriptor['securityAttributesReferenced'] = self.arr
if self.file_type in ['LF', 'CY']:
fdb_dec['file_type'] = 'working_ef'
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38908?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: I337ee6c7e882ec711bece17b7a0def9da36b0ad7
Gerrit-Change-Number: 38908
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38909?usp=email )
Change subject: esim.saip.FsProfileElement: Add create_file() method
......................................................................
esim.saip.FsProfileElement: Add create_file() method
So far we mainly created File() instances when parsing existing
profiles. However, sometimes we want to programmatically create Files
and we should offer a convenience helper to do so, rather than asking
API users to worry about low-level details.
Change-Id: I0817819af40f3d0dc0c3d2b91039c5748dd31ee2
---
M pySim/esim/saip/__init__.py
1 file changed, 8 insertions(+), 0 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 94df453..2552c8e 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -643,6 +643,14 @@
file = File(k, v, template.files_by_pename.get(k, None))
self.add_file(file)
+ def create_file(self, pename: str) -> File:
+ """Programatically create a file by its PE-Name."""
+ template = templates.ProfileTemplateRegistry.get_by_oid(self.templateID)
+ file = File(pename, None, template.files_by_pename.get(pename, None))
+ self.add_file(file)
+ self.decoded[pename] = []
+ return file
+
def _post_decode(self):
# not entirely sure about doing this this automatism
self.pe2files()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38909?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: I0817819af40f3d0dc0c3d2b91039c5748dd31ee2
Gerrit-Change-Number: 38909
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38897?usp=email )
Change subject: esim.saip: Compute number of records from efFileSize and record_len
......................................................................
esim.saip: Compute number of records from efFileSize and record_len
If we know the efFileSize and record_len, but Fcp doesn't contain
the number of records, we can simply compute it.
Change-Id: I0cc8e7241e37ee23df00c2622422904e7ccdca77
---
M pySim/esim/saip/__init__.py
1 file changed, 5 insertions(+), 2 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 6707802..3490f64 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -276,12 +276,15 @@
self.shareable = fdb_dec['shareable']
if fdb_dec['file_type'] == 'working_ef':
efFileSize = fileDescriptor.get('efFileSize', None)
- if efFileSize:
- self._file_size = self._decode_file_size(efFileSize)
if fd_dec['num_of_rec']:
self.nb_rec = fd_dec['num_of_rec']
if fd_dec['record_len']:
self.rec_len = fd_dec['record_len']
+ if efFileSize:
+ self._file_size = self._decode_file_size(efFileSize)
+ if self.rec_len and self.nb_rec == None:
+ # compute the number of records from file size and record length
+ self.nb_rec = self._file_size // self.rec_len
if fdb_dec['structure'] == 'linear_fixed':
self.file_type = 'LF'
elif fdb_dec['structure'] == 'cyclic':
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38897?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: I0cc8e7241e37ee23df00c2622422904e7ccdca77
Gerrit-Change-Number: 38897
Gerrit-PatchSet: 1
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/+/38895?usp=email )
Change subject: esim.saip: Fix parsing/generating fillPattern + repeatPattern
......................................................................
esim.saip: Fix parsing/generating fillPattern + repeatPattern
So far we only thought of default filling coming from a template.
However, filling can happen from the Fcp, and we need to properly parse
and [re-]encode that information.
Change-Id: Iff339cbe841112a01c9c617f43b0e69df2521b51
Related: OS#6643
---
M pySim/esim/saip/__init__.py
1 file changed, 13 insertions(+), 14 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 658810a..3c46ef8 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -116,6 +116,8 @@
self.high_update: bool = False
self.shareable: bool = True
self.df_name = None
+ self.fill_pattern = None
+ self.fill_pattern_repeat = False
# apply some defaults from profile
if self.template:
self.from_template(self.template)
@@ -174,8 +176,6 @@
self.fid = template.fid
self.sfi = template.sfi
self.arr = template.arr
- #self.default_val = template.default_val
- #self.default_val_repeat = template.default_val_repeat
if hasattr(template, 'rec_len'):
self.rec_len = template.rec_len
else:
@@ -234,14 +234,11 @@
fileDescriptor['fileDescriptor'] = build_construct(FileDescriptor._construct, fd_dict)
if self.high_update:
pefi['specialFileInformation'] = b'\x80' # TS 102 222 Table 5
- try:
- if self.template and self.template.default_val_repeat:
- pefi['repeatPattern'] = self.template.expand_default_value_pattern()
- elif self.template and self.template.default_val:
- pefi['fillPattern'] = self.template.expand_default_value_pattern()
- except ValueError:
- # ignore this here as without a file or record length we cannot do this
- pass
+ if self.fill_pattern:
+ if not self.fill_pattern_repeat:
+ pefi['fillPattern'] = self.fill_pattern
+ else:
+ pefi['repeatPattern'] = self.fill_pattern
if len(pefi.keys()):
# TODO: When overwriting the default "proprietaryEFInfo" for a template EF for which a
# default fill or repeat pattern is defined; it is hence recommended to provide the
@@ -292,11 +289,13 @@
specialFileInformation = pefi.get('specialFileInformation', None)
if specialFileInformation:
if specialFileInformation[0] & 0x80:
- self.hihgi_update = True
+ self.high_update = True
if 'repeatPattern' in pefi:
- self.repeat_pattern = pefi['repeatPattern']
- if 'defaultPattern' in pefi:
- self.repeat_pattern = pefi['defaultPattern']
+ self.fill_pattern = pefi['repeatPattern']
+ self.fill_pattern_repeat = True
+ if 'fillPattern' in pefi:
+ self.fill_pattern = pefi['fillPattern']
+ self.fill_pattern_repeat = False
elif fdb_dec['file_type'] == 'df':
# only set it, if an earlier call to from_template() didn't alrady set it, as
# the template can differentiate between MF, DF and ADF (unlike FDB)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38895?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: Iff339cbe841112a01c9c617f43b0e69df2521b51
Gerrit-Change-Number: 38895
Gerrit-PatchSet: 1
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 posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/pysim/+/38908?usp=email )
Change subject: esim.saip.File: Suppress encoding attributes that are like template
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38908?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I337ee6c7e882ec711bece17b7a0def9da36b0ad7
Gerrit-Change-Number: 38908
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Mon, 25 Nov 2024 15:48:13 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes