hampushellsberg has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/44216?usp=email ) Change subject: esim.saip: select a DF created by a GFM PE ...................................................................... esim.saip: select a DF created by a GFM PE SAIP V3.4.1 8.3.5: a DF or ADF created by createFCP is selected automatically, and the files that follow are created in it until a filePath selects another DF; an ADF itself is not created within the current DF. ProfileElementGFM.pe2files() kept the path of the last filePath, so those files were placed beside the DF. perform() now returns the current DF after the file it created, and creates a file with a dfName at MF level. The folder osmocom-pysim-saip-gfm-df-select of hampushellsberg-dev/PySIM-upstream-patches on GitHub has the analysis and a repro. Change-Id: I1895083980b87431738438035bd75d682d60da0e --- M pySim/esim/saip/__init__.py M tests/unittests/test_esim_saip.py 2 files changed, 52 insertions(+), 9 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/16/44216/1 diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py index e18ac8a..a2595fb 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -880,14 +880,23 @@ def pe2files(self): """Update the "files" member with the contents of the "decoded" member.""" - def perform(self, path: List[int], file_elements): - if len(file_elements): - if self.pe_sequence: - self.pe_sequence.cd(path) - file = File(None, file_elements) - file.path = path - file.pe_name = self.path_str(path + [file.fid]) - self.add_file(file, path + [file.fid]) + def perform(self, path: List[int], file_elements) -> List[int]: + """Create the file; return the current DF after it.""" + if not len(file_elements): + return path + file = File(None, file_elements) + if file.df_name: + # an ADF is not created within the current DF (SAIP V3.4.1 8.3.5) + path = [0x3f00] + if self.pe_sequence: + self.pe_sequence.cd(path) + file.path = path + file.pe_name = self.path_str(path + [file.fid]) + self.add_file(file, path + [file.fid]) + # a created DF/ADF is selected automatically (SAIP V3.4.1 8.3.5) + if file.file_type in ['MF', 'DF', 'ADF']: + return [0x3f00] if file.fid == 0x3f00 else path + [file.fid] + return path logger.debug("="*70 + " " + self.type) #logger.debug(self.decoded) @@ -907,7 +916,7 @@ #logger.debug("filePath %s -> path=%s" % (fmc2[1], path)) elif fmc2[0] == 'createFCP': # new FCP means new file; perform the old one - perform(self, path, file_elements) + path = perform(self, path, file_elements) file_elements = [('fileDescriptor', fmc2[1])] elif fmc2[0] == 'fillFileOffset' or fmc2[0] == 'fillFileContent': file_elements.append(fmc2) diff --git a/tests/unittests/test_esim_saip.py b/tests/unittests/test_esim_saip.py index 5d44de3..a300803 100755 --- a/tests/unittests/test_esim_saip.py +++ b/tests/unittests/test_esim_saip.py @@ -97,6 +97,40 @@ pe = ProfileElement.from_der(asn1.encode('ProfileElement', ('securityDomain', decoded))) self.assertEqual(pe.keys[3].to_saip_dict()['keyCounterValue'], h2b('0000000001')) + def test_gfm_created_df_is_selected(self): + """Test that the files after a DF created by a GFM PE are created in that DF.""" + def fcp(fid, fd, **kwargs): + return ('createFCP', dict(fileDescriptor=h2b(fd), fileID=h2b(fid), + securityAttributesReferenced=b'\x01', **kwargs)) + cmds = [[fcp('7f2f', '7821', pinStatusTemplateDO=h2b('010a')), + fcp('5f01', '7821', pinStatusTemplateDO=h2b('010a')), + fcp('6f01', '4121', efFileSize=b'\x02'), + ('filePath', h2b('7f2f')), + fcp('6f02', '4121', efFileSize=b'\x02')]] + gfm_der = asn1.encode('ProfileElement', ('genericFileManagement', { + 'gfm-header': {'mandated': None, 'identification': 99}, 'fileManagementCMD': cmds})) + tlvs = [] + remainder = self.per_input + while len(remainder): + first_tlv, remainder = bertlv_first_segment(remainder) + tlvs.append(first_tlv) + pes = ProfileElementSequence.from_der(b''.join(tlvs[:-1]) + gfm_der + tlvs[-1]) + gfm = pes.pe_list[-2] + self.assertEqual(sorted(gfm.files.keys()), + ['3F00/7F2F', '3F00/7F2F/5F01', '3F00/7F2F/5F01/6F01', '3F00/7F2F/6F02']) + # an ADF is created at MF level, whatever the current DF + cmds = [[fcp('7f2f', '7821', pinStatusTemplateDO=h2b('010a')), + fcp('7f5f', '7821', dfName=h2b('a000000063504b43532d3135'), + pinStatusTemplateDO=h2b('010a')), + fcp('5031', '4121', efFileSize=b'\x02'), + ('filePath', h2b('7f5f')), + fcp('5032', '4121', efFileSize=b'\x02')]] + gfm_der = asn1.encode('ProfileElement', ('genericFileManagement', { + 'gfm-header': {'mandated': None, 'identification': 99}, 'fileManagementCMD': cmds})) + pes = ProfileElementSequence.from_der(b''.join(tlvs[:-1]) + gfm_der + tlvs[-1]) + self.assertEqual(sorted(pes.pe_list[-2].files.keys()), + ['3F00/7F2F', '3F00/7F5F', '3F00/7F5F/5031', '3F00/7F5F/5032']) + def test_sequence_helpers(self): """Verify that the convenience helpers worked as expected.""" self.assertEqual([x.type for x in self.pes.pe_list], self.expected_pet_list) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/44216?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: I1895083980b87431738438035bd75d682d60da0e Gerrit-Change-Number: 44216 Gerrit-PatchSet: 1 Gerrit-Owner: hampushellsberg <hampushellsberg@gmail.com>