laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/43990?usp=email )


Change subject: esim.saip: the keyList of a PE-SecurityDomain is optional
......................................................................

esim.saip: the keyList of a PE-SecurityDomain is optional

keyList is OPTIONAL in the SecurityDomain PE, with SIZE (1..MAX).
ProfileElementSD._post_decode() read it unconditionally, so an SD
without keys raised KeyError: 'keyList', and _pre_encode() always wrote
it, so an SD without keys was encoded with an empty keyList.

Read the member with a default, and write it only when there is a key.

The folder osmocom-pysim-saip-sd-optional-key-list of
hampushellsberg-dev/PySIM-upstream-patches on GitHub has the analysis
and a repro.

Change-Id: Ibcc371edc36ea19cf9b0f58586fdd3bb42dc8dac
---
M pySim/esim/saip/__init__.py
1 file changed, 6 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/90/43990/1

diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 955a772..db61397 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -1224,10 +1224,14 @@
     def _post_decode(self):
         self.usip = self.C9()
         
self.usip.from_bytes(self.decoded['instance']['applicationSpecificParametersC9'])
-        self.keys = [SecurityDomainKey.from_saip_dict(x) for x in 
self.decoded['keyList']]
+        # keyList is OPTIONAL (SIZE (1..MAX)): an SD without keys omits it
+        self.keys = [SecurityDomainKey.from_saip_dict(x) for x in 
self.decoded.get('keyList', [])]

     def _pre_encode(self):
-        self.decoded['keyList'] = [x.to_saip_dict() for x in self.keys]
+        if self.keys:
+            self.decoded['keyList'] = [x.to_saip_dict() for x in self.keys]
+        else:
+            self.decoded.pop('keyList', None)
         self.decoded['instance']['applicationSpecificParametersC9'] = 
self.usip.to_bytes()

     def has_scp(self, scp: int) -> bool:

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/43990?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: Ibcc371edc36ea19cf9b0f58586fdd3bb42dc8dac
Gerrit-Change-Number: 43990
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-CC: hampushellsberg <[email protected]>

Reply via email to