laforge submitted this change.
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(-)
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 0a50dd3..60da704 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 change 43990. To unsubscribe, or for help writing mail filters, visit settings.