lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

July 2024

  • 1 participants
  • 1379 discussions
[M] Change in pysim[master]: pySim.esim.saip: Move initialization of PE header to base class
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37422?usp=email ) Change subject: pySim.esim.saip: Move initialization of PE header to base class ...................................................................... pySim.esim.saip: Move initialization of PE header to base class Let's avoid the copy+paste in the subclass constructors and initialize the profile element header in the base class constructor. Change-Id: I6e69ae1f0d33d963247fc506db33b3840c10c19a --- M pySim/esim/saip/__init__.py 1 file changed, 36 insertions(+), 47 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 e5173d7..2f69522 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -197,8 +197,15 @@ 'securityDomain': 'sd-Header', } - def __init__(self, decoded = None): - self.decoded = decoded + def __init__(self, decoded = None, mandated: bool = True): + if decoded: + self.decoded = decoded + else: + self.decoded = OrderedDict() + if self.header_name: + self.decoded[self.header_name] = { 'identification': None} + if mandated: + self.decoded[self.header_name] = { 'mandated': None} def _fixup_sqnInit_dec(self) -> None: """asn1tools has a bug when working with SEQUENCE OF that have DEFAULT values. Let's work around @@ -305,13 +312,10 @@ type = 'mf' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults - self.decoded = OrderedDict() - self.decoded['mf-header'] = { 'mandated': None, 'identification': None} self.decoded['templateID'] = str(oid.MF) for fname in ['mf', 'ef-iccid', 'ef-dir', 'ef-arr']: self.decoded[fname] = [] @@ -321,13 +325,10 @@ type = 'pukCodes' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults - self.decoded = OrderedDict() - self.decoded['puk-Header'] = { 'mandated': None, 'identification': None} self.decoded['pukCodes'] = [] self.add_puk(0x01, b'11111111') self.add_puk(0x81, b'22222222') @@ -354,13 +355,10 @@ type = 'pinCodes' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults - self.decoded = OrderedDict() - self.decoded['pin-Header'] = { 'mandated': None, 'identification': None} self.decoded['pinCodes'] = ('pinconfig', []) self.add_pin(0x01, b'0000\xff\xff\xff\xff', unblock_ref=1, pin_attrib=6) self.add_pin(0x10, b'11111111', pin_attrib=3) @@ -393,13 +391,10 @@ type = 'telecom' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['telecom-header'] = { 'mandated': None, 'identification': None} self.decoded['templateID'] = str(oid.DF_TELECOM_v2) for fname in ['df-telecom', 'ef-arr']: self.decoded[fname] = [] @@ -467,12 +462,10 @@ pass def __init__(self, decoded: Optional[dict] = None): + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['sd-Header'] = { 'mandated': None, 'identification': None } self.decoded['instance'] = { 'applicationLoadPackageAID': h2b('A0000001515350'), 'classAID': h2b('A000000251535041'), @@ -543,8 +536,10 @@ class ProfileElementSSD(ProfileElementSD): """Class representing a securityDomain ProfileElement for a SSD.""" - def __init__(self): - super().__init__() + def __init__(self, decoded: Optional[dict] = None): + super().__init__(decoded) + if decoded: + return # defaults [overriding ProfileElementSD) taken from SAIP v2.3.1 Section 11.2.12 self.decoded['instance']['instanceAID'] = h2b('A00000055910100102736456616C7565') self.decoded['instance']['applicationPrivileges'] = h2b('808000') @@ -560,14 +555,11 @@ inst_aid: Optional[bytes] = None, sd_aid: Optional[bytes] = None, adf_aid: Optional[bytes] = None, tar_list: Optional[List[bytes]] = [], msl: Optional[int] = 0x06): - super().__init__() + super().__init__(decoded) ADM1_ACCESS = h2b('02000100') if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['rfm-header'] = { 'mandated': None, 'identification': None} self.decoded['instanceAID'] = inst_aid self.decoded['securityDomainAID'] = sd_aid self.decoded['tarList'] = tar_list @@ -585,13 +577,10 @@ type = 'usim' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['usim-header'] = { 'mandated': None, 'identification': None} self.decoded['templateID'] = str(oid.ADF_USIM_by_default_v2) for fname in ['adf-usim', 'ef-imsi', 'ef-arr', 'ef-ust', 'ef-spn', 'ef-est', 'ef-acc', 'ef-ecc']: self.decoded[fname] = [] @@ -609,26 +598,20 @@ type = 'opt-usim' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['optusim-header'] = { 'mandated': None, 'identification': None} self.decoded['templateID'] = str(oid.ADF_USIMopt_not_by_default_v2) class ProfileElementISIM(ProfileElement): type = 'isim' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['isim-header'] = { 'mandated': None, 'identification': None} self.decoded['templateID'] = str(oid.ADF_ISIM_by_default) for fname in ['adf-isim', 'ef-impi', 'ef-impu', 'ef-domain', 'ef-ist', 'ef-arr']: self.decoded[fname] = [] @@ -641,13 +624,10 @@ type = 'opt-isim' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['optisim-header'] = { 'mandated': None, 'identification': None} self.decoded['templateID'] = str(oid.ADF_ISIMopt_not_by_default_v2) @@ -655,13 +635,10 @@ type = 'akaParameter' def __init__(self, decoded: Optional[dict] = None): - super().__init__() + super().__init__(decoded) if decoded: - self.decoded = decoded return # provide some reasonable defaults for a MNO-SD - self.decoded = OrderedDict() - self.decoded['aka-header'] = { 'mandated': None, 'identification': None} self.set_milenage(b'\x00'*16, b'\x00'*16) def set_milenage(self, k: bytes, opc: bytes): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37422?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: I6e69ae1f0d33d963247fc506db33b3840c10c19a Gerrit-Change-Number: 37422 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pySim.esim.saip: ProfileElement{Header,End} classes
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37423?usp=email ) Change subject: pySim.esim.saip: ProfileElement{Header,End} classes ...................................................................... pySim.esim.saip: ProfileElement{Header,End} classes Change-Id: I88e18c1ee4907eeac3ae5d04d7bc30d6765f91fa --- M pySim/esim/saip/__init__.py M tests/test_esim_saip.py 2 files changed, 39 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 2f69522..7dffcb2 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -22,7 +22,7 @@ import asn1tools -from pySim.utils import bertlv_parse_tag, bertlv_parse_len, b2h, h2b, dec_imsi +from pySim.utils import bertlv_parse_tag, bertlv_parse_len, b2h, h2b, dec_imsi, Hexstr from pySim.ts_102_221 import FileDescriptor from pySim.construct import build_construct from pySim.esim import compile_asn1_subdir @@ -187,6 +187,7 @@ # names, so we have to manually translate the exceptions here... header_name_translation_dict = { 'header': None, + 'end': 'end-header', 'genericFileManagement': 'gfm-header', 'akaParameter': 'aka-header', 'cdmaParameter': 'cdma-header', @@ -281,6 +282,8 @@ 'isim': ProfileElementISIM, 'opt-isim': ProfileElementOptISIM, 'akaParameter': ProfileElementAKA, + 'header': ProfileElementHeader, + 'end': ProfileElementEnd, } """Construct an instance from given raw, DER encoded bytes.""" pe_type, decoded = asn1.decode('ProfileElement', der) @@ -676,6 +679,30 @@ 'mappingSource': aid, }) +class ProfileElementHeader(ProfileElement): + type = 'header' + def __init__(self, decoded: Optional[dict] = None, + ver_major: Optional[int] = 2, ver_minor: Optional[int] = 3, + iccid: Optional[Hexstr] = '0'*20, profile_type: Optional[str] = None): + super().__init__(decoded) + if decoded: + return + # provide some reasonable defaults + self.decoded = { + 'major-version': ver_major, + 'minor-version': ver_minor, + 'iccid': h2b(iccid), + 'eUICC-Mandatory-services': {}, # needs to be recomputed at the end + 'eUICC-Mandatory-GFSTEList': [], # needs to be recomputed at the end + } + if profile_type: + self.decoded['profileType'] = profile_type + +class ProfileElementEnd(ProfileElement): + type = 'end' + def __init__(self, decoded: Optional[dict] = None): + super().__init__(decoded) + def bertlv_first_segment(binary: bytes) -> Tuple[bytes, bytes]: """obtain the first segment of a binary concatenation of BER-TLV objects. Returns: tuple of first TLV and remainder.""" diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py index e87a073..82ed692 100755 --- a/tests/test_esim_saip.py +++ b/tests/test_esim_saip.py @@ -67,7 +67,8 @@ """Test that DER-encoding of PE created by "empty" constructor works without raising exception.""" for cls in [ProfileElementMF, ProfileElementPuk, ProfileElementPin, ProfileElementTelecom, ProfileElementUSIM, ProfileElementISIM, ProfileElementAKA, ProfileElementSD, - ProfileElementSSD, ProfileElementOptUSIM, ProfileElementOptISIM]: + ProfileElementSSD, ProfileElementOptUSIM, ProfileElementOptISIM, + ProfileElementHeader, ProfileElementEnd]: with self.subTest(cls.__name__): pes = ProfileElementSequence() inst = cls() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37423?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: I88e18c1ee4907eeac3ae5d04d7bc30d6765f91fa Gerrit-Change-Number: 37423 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: pySim.esim.saip: Add methods to rebuild "mandatory" lists in ProfileH...
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37424?usp=email ) Change subject: pySim.esim.saip: Add methods to rebuild "mandatory" lists in ProfileHeader ...................................................................... pySim.esim.saip: Add methods to rebuild "mandatory" lists in ProfileHeader The ProfileHeader PE contain lists of template-oids and services that are mandatory in this profile. Let's add methods that can be used to (re-) compute those lists based on the actual PE contents of the sequence. The idea is that during programmatic construction of a profile, those methods would be called after appending all PEs, just before encoding the profile as DER. Change-Id: Ib43db8695c6eb63965756364fda7546d82df0beb --- M pySim/esim/saip/__init__.py 1 file changed, 88 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 7dffcb2..abaa679 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -787,6 +787,76 @@ self.pes_by_naa[cur_naa] = [] self.pes_by_naa[cur_naa].append(cur_naa_list) + def rebuild_mandatory_services(self): + """(Re-)build the eUICC Mandatory services list of the ProfileHeader based on what's in the + PE-Sequence.""" + # services that we cannot auto-determine and which must hence be manually specified + manual_services = ['contactless', 'mbms', 'cat-tp', 'suciCalculatorApi', 'dns-resolution', + 'scp11ac', 'scp11c-authorization-mechanism', 's16mode', 'eaka'] + svc_set = set() + # rebuild mandatory NAAs + for naa in self.pes_by_naa.keys(): + if naa not in ['usim', 'isim', 'csim']: + continue + # see if any of the instances is mandatory + for inst in self.pes_by_naa[naa]: + if 'mandated' in inst[0].header: + svc_set.add(naa) + # rebuild algorithms of all mandatory akaParameters + for aka in self.get_pes_for_type('akaParameter'): + if 'mandated' in aka.header: + if aka.decoded['algoConfiguration'][0] == 'algoParameter': + algo_par = aka.decoded['algoConfiguration'][1] + algo_id = algo_par['algorithmID'] + if algo_id == 1: + svc_set.add('milenage') + elif algo_id == 2: + if len(algo_par['key']) == 32: + svc_set.add('tuak256') + else: + svc_set.add('tuak128') + elif algo_id == 3: + svc_set.add('usim-test-algorithm') + # rebuild algorithms of all mandatory cdmaParameter + for cdma in self.get_pes_for_type('cdmaParameter'): + if 'mandated' in cdma.header: + svc_set.add('cave') + # TODO: gba-{usim,isim} (determine from EF.GBA* ?) + # determine if EAP is mandatory + for eap in self.get_pes_for_type('eap'): + if 'mandated' in eap.header: + svc_set.add('eap') + # determine if javacard is mandatory + for app in self.get_pes_for_type('application'): + if 'mandated' in app.header: + # javacard / multos distinction is not automatically possible, but multos is hypothetical + svc_set.add('javacard') + # recompute multiple-{usim,isim,csim} + for naa_name in ['usim','isim','csim']: + if naa_name in self.pes_by_naa[naa]: + if len(self.pes_by_naa[naa]) > 1: + svc_set.add('multiple-' + naa_name) + # TODO: BER-TLV (scan all files for related type?) + # TODO: dfLinked files (scan all files, check for non-empty Fcp.linkPath presence of DFs) + # TODO: 5G related bits (derive from EF.UST or file presence?) + hdr_pe = self.get_pe_for_type('header') + # patch in the 'manual' services from the existing list: + for old_svc in hdr_pe.decoded['eUICC-Mandatory-services'].keys(): + if old_svc in manual_services: + svc_set.add(old_svc) + hdr_pe.decoded['eUICC-Mandatory-services'] = {x: None for x in svc_set} + + def rebuild_mandatory_gfstelist(self): + """(Re-)build the eUICC Mandatory GFSTEList of the ProfileHeader based on what's in the + PE-Sequence.""" + template_set = set() + for pe in self.pe_list: + if pe.header and 'mandated' in pe.header: + if 'templateID' in pe.decoded: + template_set.add(pe.decoded['templateID']) + hdr_pe = self.get_pe_for_type('header') + hdr_pe.decoded['eUICC-Mandatory-GFSTEList'] = list(template_set) + @classmethod def from_der(cls, der: bytes) -> 'ProfileElementSequence': """Construct an instance from given raw, DER encoded bytes.""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37424?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: Ib43db8695c6eb63965756364fda7546d82df0beb Gerrit-Change-Number: 37424 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: saip-tool: Dump information about security domains from "info" command
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37428?usp=email ) Change subject: saip-tool: Dump information about security domains from "info" command ...................................................................... saip-tool: Dump information about security domains from "info" command output looks like this: Number of security domains: 1 Security domain Instance AID: a000000151000000 KVN=0x01, KID=0x01, [SdKeyComp(type=aes, mac_len=8, data=00000000000000000000000000000000)] KVN=0x01, KID=0x02, [SdKeyComp(type=aes, mac_len=8, data=00000000000000000000000000000000)] KVN=0x01, KID=0x03, [SdKeyComp(type=aes, mac_len=8, data=00000000000000000000000000000000)] Change-Id: Ia25f5ca6d7e888f7032301dd2561d066a3870010 --- M contrib/saip-tool.py 1 file changed, 27 insertions(+), 1 deletion(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/contrib/saip-tool.py b/contrib/saip-tool.py index 6f2a2a4..4a9bec9 100755 --- a/contrib/saip-tool.py +++ b/contrib/saip-tool.py @@ -180,7 +180,16 @@ print("\tLoad Block Size: %s" % len(app_pe.decoded['loadBlock']['loadBlockObject'])) for inst in app_pe.decoded.get('instanceList', []): print("\tInstance AID: %s" % b2h(inst['instanceAID'])) - pass + + # security domains + print() + sds = pes.pe_by_type.get('securityDomain', []) + print("Number of security domains: %u" % len(sds)) + for sd in sds: + print("Security domain Instance AID: %s" % b2h(sd.decoded['instance']['instanceAID'])) + # FIXME: 'applicationSpecificParametersC9' parsing to figure out enabled SCP + for key in sd.keys: + print("\tKVN=0x%02x, KID=0x%02x, %s" % (key.key_version_number, key.key_identifier, key.key_components)) def do_extract_apps(pes:ProfileElementSequence, opts): apps = pes.pe_by_type.get('application', []) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37428?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: Ia25f5ca6d7e888f7032301dd2561d066a3870010 Gerrit-Change-Number: 37428 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: saip-tool: Also dump RFM information in "info" command
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37429?usp=email ) Change subject: saip-tool: Also dump RFM information in "info" command ...................................................................... saip-tool: Also dump RFM information in "info" command example output: Number of RFM instances: 2 RFM instanceAID: d276000005aa060200000000b00000 (-> TAR: b00000) MSL: 0x16 RFM instanceAID: d276000005aa060200000000b00001 (-> TAR: b00001) MSL: 0x16 ADF AID: a0000000871002ff33ffff8901010100 Change-Id: I534267c7420fc5bd96eaded6078e986161729073 --- M contrib/saip-tool.py 1 file changed, 30 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/contrib/saip-tool.py b/contrib/saip-tool.py index 4a9bec9..d73cc90 100755 --- a/contrib/saip-tool.py +++ b/contrib/saip-tool.py @@ -191,6 +191,18 @@ for key in sd.keys: print("\tKVN=0x%02x, KID=0x%02x, %s" % (key.key_version_number, key.key_identifier, key.key_components)) + # RFM + print() + rfms = pes.pe_by_type.get('rfm', []) + print("Number of RFM instances: %u" % len(rfms)) + for rfm in rfms: + inst_aid = rfm.decoded['instanceAID'] + print("RFM instanceAID: %s (-> TAR: %s)" % (b2h(inst_aid), b2h(inst_aid[-3:]))) + print("\tMSL: 0x%02x" % rfm.decoded['minimumSecurityLevel'][0]) + adf = rfm.decoded.get('adfRFMAccess', None) + if adf: + print("\tADF AID: %s" % b2h(adf['adfAID'])) + def do_extract_apps(pes:ProfileElementSequence, opts): apps = pes.pe_by_type.get('application', []) for app_pe in apps: -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37429?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: I534267c7420fc5bd96eaded6078e986161729073 Gerrit-Change-Number: 37429 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pySim.esim.saip: Add ProfileElementOpt{USIM,ISIM} classes
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37420?usp=email ) Change subject: pySim.esim.saip: Add ProfileElementOpt{USIM,ISIM} classes ...................................................................... pySim.esim.saip: Add ProfileElementOpt{USIM,ISIM} classes Change-Id: Iebff2e767baa19f272eeddc62d7d5b3a8f665db5 --- M pySim/esim/saip/__init__.py M tests/test_esim_saip.py 2 files changed, 39 insertions(+), 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 6e17de3..e87e5c0 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -270,7 +270,9 @@ 'pinCodes': ProfileElementPin, 'telecom': ProfileElementTelecom, 'usim': ProfileElementUSIM, + 'opt-usim': ProfileElementOptUSIM, 'isim': ProfileElementISIM, + 'opt-isim': ProfileElementOptISIM, 'akaParameter': ProfileElementAKA, } """Construct an instance from given raw, DER encoded bytes.""" @@ -575,6 +577,19 @@ f = File('ef-imsi', self.decoded['ef-imsi']) return dec_imsi(b2h(f.stream.getvalue())) +class ProfileElementOptUSIM(ProfileElement): + type = 'opt-usim' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['optusim-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.ADF_USIMopt_not_by_default_v2) + class ProfileElementISIM(ProfileElement): type = 'isim' @@ -594,6 +609,20 @@ def adf_name(self) -> str: return b2h(self.decoded['adf-isim'][0][1]['dfName']) +class ProfileElementOptISIM(ProfileElement): + type = 'opt-isim' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['optisim-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.ADF_ISIMopt_not_by_default_v2) + + class ProfileElementAKA(ProfileElement): type = 'akaParameter' diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py index 4c1b936..5a1284e 100755 --- a/tests/test_esim_saip.py +++ b/tests/test_esim_saip.py @@ -67,7 +67,7 @@ """Test that DER-encoding of PE created by "empty" constructor works without raising exception.""" for cls in [ProfileElementMF, ProfileElementPuk, ProfileElementPin, ProfileElementTelecom, ProfileElementUSIM, ProfileElementISIM, ProfileElementAKA, ProfileElementSD, - ProfileElementSSD]: + ProfileElementSSD, ProfileElementOptUSIM, ProfileElementOptISIM]: with self.subTest(cls.__name__): pes = ProfileElementSequence() inst = cls() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37420?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: Iebff2e767baa19f272eeddc62d7d5b3a8f665db5 Gerrit-Change-Number: 37420 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pySim.esim: Allow calling compile_asn1_subdir() with non-DER coddec
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37416?usp=email ) Change subject: pySim.esim: Allow calling compile_asn1_subdir() with non-DER coddec ...................................................................... pySim.esim: Allow calling compile_asn1_subdir() with non-DER coddec this isn't needed for the on-wire format, but can be useful for debug output in GSER or JER. Change-Id: I1de4b9506a92d60f582c328a180760332584f9e4 --- M pySim/esim/__init__.py 1 file changed, 14 insertions(+), 2 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/esim/__init__.py b/pySim/esim/__init__.py index 1f7ea16..fbb90b9 100644 --- a/pySim/esim/__init__.py +++ b/pySim/esim/__init__.py @@ -3,7 +3,7 @@ from importlib import resources -def compile_asn1_subdir(subdir_name:str): +def compile_asn1_subdir(subdir_name:str, codec='der'): """Helper function that compiles ASN.1 syntax from all files within given subdir""" import asn1tools asn_txt = '' @@ -14,7 +14,7 @@ asn_txt += "\n" #else: #print(resources.read_text(__name__, 'asn1/rsp.asn')) - return asn1tools.compile_string(asn_txt, codec='der') + return asn1tools.compile_string(asn_txt, codec=codec) # SGP.22 section 4.1 Activation Code -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37416?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: I1de4b9506a92d60f582c328a180760332584f9e4 Gerrit-Change-Number: 37416 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: pySim.esim.saip: Meaningful defaults in PE Constructor + test
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37415?usp=email ) Change subject: pySim.esim.saip: Meaningful defaults in PE Constructor + test ...................................................................... pySim.esim.saip: Meaningful defaults in PE Constructor + test Let's make sure the constructor of ProfileElement subclasses set meaningful defaults to the self.decoded member, so that the to_der() method can actually encode it. This is required when constructing a profile from scratch, as opposed to loading an existing one from DER. Also, add a test to verify that the encoder passes without exception; doesn't test the generated binary data. Change-Id: I401bca16e58461333733877ec79102a5ae7fe410 --- M pySim/esim/saip/__init__.py M tests/test_esim_saip.py 2 files changed, 170 insertions(+), 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 e690e6c..e35e1a5 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -265,6 +265,10 @@ def from_der(cls, der: bytes) -> 'ProfileElement': class4petype = { 'securityDomain': ProfileElementSD, + 'mf': ProfileElementMF, + 'pukCodes': ProfileElementPuk, + 'pinCodes': ProfileElementPin, + 'telecom': ProfileElementTelecom, 'usim': ProfileElementUSIM, 'isim': ProfileElementISIM, } @@ -294,6 +298,110 @@ def __str__(self) -> str: return self.type +class ProfileElementMF(ProfileElement): + type = 'mf' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults + self.decoded = OrderedDict() + self.decoded['mf-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.MF) + for fname in ['mf', 'ef-iccid', 'ef-dir', 'ef-arr']: + self.decoded[fname] = [] + # TODO: resize EF.DIR? + +class ProfileElementPuk(ProfileElement): + type = 'pukCodes' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults + self.decoded = OrderedDict() + self.decoded['puk-Header'] = { 'mandated': None, 'identification': None} + self.decoded['pukCodes'] = [] + self.add_puk(0x01, b'11111111') + self.add_puk(0x81, b'22222222') + + def add_puk(self, key_ref: int, puk_value: bytes, max_attempts:int = 10, retries_left:int = 10): + """Add a PUK to the pukCodes ProfileElement""" + if key_ref < 0 or key_ref > 0xff: + raise ValueError('key_ref must be uint8') + if len(puk_value) != 8: + raise ValueError('puk_value must be 8 bytes long') + if max_attempts < 0 or max_attempts > 0xf: + raise ValueError('max_attempts must be 4 bit') + if retries_left < 0 or max_attempts > 0xf: + raise ValueError('retries_left must be 4 bit') + puk = { + 'keyReference': key_ref, + 'pukValue': puk_value, + 'maxNumOfAttemps-retryNumLeft': (max_attempts << 4) | retries_left, + } + self.decoded['pukCodes'].append(puk) + + +class ProfileElementPin(ProfileElement): + type = 'pinCodes' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults + self.decoded = OrderedDict() + self.decoded['pin-Header'] = { 'mandated': None, 'identification': None} + self.decoded['pinCodes'] = ('pinconfig', []) + self.add_pin(0x01, b'0000\xff\xff\xff\xff', unblock_ref=1, pin_attrib=6) + self.add_pin(0x10, b'11111111', pin_attrib=3) + + def add_pin(self, key_ref: int, pin_value: bytes, max_attempts : int = 3, retries_left : int = 3, + unblock_ref: Optional[int] = None, pin_attrib: int = 7): + """Add a PIN to the pinCodes ProfileElement""" + if key_ref < 0 or key_ref > 0xff: + raise ValueError('key_ref must be uint8') + if pin_attrib < 0 or pin_attrib > 0xff: + raise ValueError('pin_attrib must be uint8') + if len(pin_value) != 8: + raise ValueError('pin_value must be 8 bytes long') + if max_attempts < 0 or max_attempts > 0xf: + raise ValueError('max_attempts must be 4 bit') + if retries_left < 0 or max_attempts > 0xf: + raise ValueError('retries_left must be 4 bit') + pin = { + 'keyReference': key_ref, + 'pinValue': pin_value, + 'maxNumOfAttemps-retryNumLeft': (max_attempts << 4) | retries_left, + 'pinAttributes': pin_attrib, + } + if unblock_ref: + pin['unblockingPINReference'] = unblock_ref + self.decoded['pinCodes'][1].append(pin) + + +class ProfileElementTelecom(ProfileElement): + type = 'telecom' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['telecom-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.DF_TELECOM_v2) + for fname in ['df-telecom', 'ef-arr']: + self.decoded[fname] = [] + + class SecurityDomainKeyComponent: """Representation of a key-component of a key for a security domain.""" def __init__(self, key_type: str, key_data: bytes, mac_length: int = 8): @@ -444,9 +552,23 @@ class ProfileElementUSIM(ProfileElement): type = 'usim' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['usim-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.ADF_USIM_by_default_v2) + for fname in ['adf-usim', 'ef-imsi', 'ef-arr', 'ef-ust', 'ef-spn', 'ef-est', 'ef-acc', 'ef-ecc']: + self.decoded[fname] = [] + @property def adf_name(self) -> str: return b2h(self.decoded['adf-usim'][0][1]['dfName']) + @property def imsi(self) -> Optional[str]: f = File('ef-imsi', self.decoded['ef-imsi']) @@ -454,6 +576,19 @@ class ProfileElementISIM(ProfileElement): type = 'isim' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['isim-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.ADF_ISIM_by_default) + for fname in ['adf-isim', 'ef-impi', 'ef-impu', 'ef-domain', 'ef-ist', 'ef-arr']: + self.decoded[fname] = [] + @property def adf_name(self) -> str: return b2h(self.decoded['adf-isim'][0][1]['dfName']) @@ -470,10 +605,16 @@ class ProfileElementSequence: """A sequence of ProfileElement objects, which is the overall representation of an eSIM profile.""" def __init__(self): - self.pe_list: List[ProfileElement] = None + self.pe_list: List[ProfileElement] = [] self.pe_by_type: Dict = {} self.pes_by_naa: Dict = {} + def append(self, pe: ProfileElement): + """Append a PE to the PE Sequence""" + self.pe_list.append(pe) + self._process_pelist() + self.renumber_identification() + def get_pes_for_type(self, tname: str) -> List[ProfileElement]: """Return list of profile elements present for given profile element type.""" return self.pe_by_type.get(tname, []) diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py index a70c149..a43a139 100755 --- a/tests/test_esim_saip.py +++ b/tests/test_esim_saip.py @@ -63,6 +63,17 @@ # TODO: we don't actually test the results here, but we just verify there is no exception pes.to_der() + def test_constructor_encode(self): + """Test that DER-encoding of PE created by "empty" constructor works without raising exception.""" + for cls in [ProfileElementMF, ProfileElementPuk, ProfileElementPin, ProfileElementTelecom, + ProfileElementUSIM, ProfileElementISIM]: + with self.subTest(cls.__name__): + pes = ProfileElementSequence() + inst = cls() + pes.append(inst) + pes.to_der() + + if __name__ == "__main__": unittest.main() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37415?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: I401bca16e58461333733877ec79102a5ae7fe410 Gerrit-Change-Number: 37415 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: pySim.esim.saip: Add ProfileElementAKA constructor + methods
by laforge 10 Jul '24

10 Jul '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37417?usp=email ) Change subject: pySim.esim.saip: Add ProfileElementAKA constructor + methods ...................................................................... pySim.esim.saip: Add ProfileElementAKA constructor + methods This helps us to construct an akaParameter PE from scratch. Change-Id: I4cc42c98bf82aec085ab7f48aea4ff7efa0eae9e --- M pySim/esim/saip/__init__.py M tests/test_esim_saip.py 2 files changed, 61 insertions(+), 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 e35e1a5..2cddbe8 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -271,6 +271,7 @@ 'telecom': ProfileElementTelecom, 'usim': ProfileElementUSIM, 'isim': ProfileElementISIM, + 'akaParameter': ProfileElementAKA, } """Construct an instance from given raw, DER encoded bytes.""" pe_type, decoded = asn1.decode('ProfileElement', der) @@ -593,6 +594,54 @@ def adf_name(self) -> str: return b2h(self.decoded['adf-isim'][0][1]['dfName']) +class ProfileElementAKA(ProfileElement): + type = 'akaParameter' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['aka-header'] = { 'mandated': None, 'identification': None} + self.set_milenage(b'\x00'*16, b'\x00'*16) + + def set_milenage(self, k: bytes, opc: bytes): + """Configure akaParametes for MILENAGE.""" + self.decoded['algoConfiguration'] = ('algoParameter', { + 'algorithmID': 1, + 'algorithmOptions': b'\x00', # not relevant for milenage + 'key': k, + 'opc': opc, + }) + + def set_xor3g(self, k: bytes): + """Configure akaParametes for XOR-3G.""" + self.decoded['algoConfiguration'] = ('algoParameter', { + 'algorithmID': 3, + 'algorithmOptions': b'\x00', # not relevant for milenage + 'key': k, + 'opc': b'', # not used for MILENAGE + }) + + def set_tuak(self, k: bytes, topc: bytes, num_of_keccak: int = 1): + """Configure akaParametes for TUAK.""" + self.decoded['algoConfiguration'] = ('algoParameter', { + 'algorithmID': 2, + 'algorithmOptions': b'\x00', # not relevant for milenage + 'key': k, + 'opc': topc, + 'numberOfKeccak': bytes([num_of_keccak]), + }) + + def set_mapping(self, aid: bytes, options: int = 6): + """Configure akaParametes for a mapping from another AID.""" + self.decoded['algoConfiguration'] = ('mappingParamete', { + 'mappingOptions': bytes([options]), + 'mappingSource': aid, + }) + def bertlv_first_segment(binary: bytes) -> Tuple[bytes, bytes]: """obtain the first segment of a binary concatenation of BER-TLV objects. Returns: tuple of first TLV and remainder.""" diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py index a43a139..704f513 100755 --- a/tests/test_esim_saip.py +++ b/tests/test_esim_saip.py @@ -66,7 +66,7 @@ def test_constructor_encode(self): """Test that DER-encoding of PE created by "empty" constructor works without raising exception.""" for cls in [ProfileElementMF, ProfileElementPuk, ProfileElementPin, ProfileElementTelecom, - ProfileElementUSIM, ProfileElementISIM]: + ProfileElementUSIM, ProfileElementISIM, ProfileElementAKA]: with self.subTest(cls.__name__): pes = ProfileElementSequence() inst = cls() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37417?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: I4cc42c98bf82aec085ab7f48aea4ff7efa0eae9e Gerrit-Change-Number: 37417 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: saip-tool: Also dump RFM information in "info" command
by laforge 10 Jul '24

10 Jul '24
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/37429?usp=email ) Change subject: saip-tool: Also dump RFM information in "info" command ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37429?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: I534267c7420fc5bd96eaded6078e986161729073 Gerrit-Change-Number: 37429 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Comment-Date: Wed, 10 Jul 2024 06:51:19 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • ...
  • 138
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.