laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/43983?usp=email ) Change subject: personalization: SmspTpScAddr edits record 1 of EF.SMSP only ...................................................................... personalization: SmspTpScAddr edits record 1 of EF.SMSP only SmspTpScAddr decoded the whole EF.SMSP body as record 1 and wrote one encoded record back as the whole body. EF.SMSP is linear fixed and a profile can declare more than one record: both TS.48 v5 profiles in smdpp-data/upp carry a fileDescriptor with record length 42 and no record count, and efFileSize 84, so two records. While pySim takes the record count from the template (one record) this goes unnoticed; once the count follows efFileSize, the body holds both records, decoding all 84 bytes as one record fails on the alpha identifier, and test_configurable_parameters fails. Decode and encode record 1 only, and keep the records after it. The folder osmocom-pysim-saip-record-count of hampushellsberg-dev/PySIM-upstream-patches on GitHub carries this patch next to the record count fix that needs it. Change-Id: I47b1abc97d7b8caad0c74d7af2e5da38e9a895b1 --- M pySim/esim/saip/personalization.py M tests/unittests/test_configurable_parameters.py 2 files changed, 29 insertions(+), 5 deletions(-) Approvals: Jenkins Builder: Verified neels: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py index 5ccface..9e5b7fd 100644 --- a/pySim/esim/saip/personalization.py +++ b/pySim/esim/saip/personalization.py @@ -614,8 +614,10 @@ #print("SMSP (orig): %s" % f_smsp.body) # instantiate the pySim.ts_51_011.EF_SMSP class for decode/encode ef_smsp = EF_SMSP() - # decode the existing file body - ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body, 1) + # decode the first record; a profile may declare more than one (efFileSize), and the + # File body then holds all of them + rec_len = f_smsp.rec_len + ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body[:rec_len], 1) # patch the actual number ef_smsp_dec['tp_sc_addr']['call_number'] = digits # patch the NPI to isdn_e164 @@ -644,8 +646,9 @@ # f_smsp.rec_len = 42 # but leave rec_len unchanged to keep the same length as was found in the eSIM template. - # re-encode into the File body. - f_smsp.body = ef_smsp.encode_record_bin(ef_smsp_dec, 1, total_len=f_smsp.rec_len) + # re-encode the first record into the File body, keeping any records after it. + record = ef_smsp.encode_record_bin(ef_smsp_dec, 1, total_len=rec_len) + f_smsp.body = record + f_smsp.body[rec_len:] # re-generate the pe.decoded member from the File instance pe.file2pe(f_smsp) @@ -654,7 +657,7 @@ for pe in pes.get_pes_for_type('usim'): f_smsp = pe.files['ef-smsp'] ef_smsp = EF_SMSP() - ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body, 1) + ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body[:f_smsp.rec_len], 1) tp_sc_addr = ef_smsp_dec.get('tp_sc_addr', None) diff --git a/tests/unittests/test_configurable_parameters.py b/tests/unittests/test_configurable_parameters.py index 15f434a..7ff05c6 100755 --- a/tests/unittests/test_configurable_parameters.py +++ b/tests/unittests/test_configurable_parameters.py @@ -728,6 +728,27 @@ self.assertEqual(p13n.AlgorithmID.clean_name_str('foo bar!'), 'foobar') +class TestSmspTpScAddr(unittest.TestCase): + """SmspTpScAddr edits record 1 of EF.SMSP and keeps the records after it.""" + + def test_records_after_the_first_are_kept(self): + der = resources.read_binary(smdpp_data.upp, 'TS48v5_SAIP2.1A_NoBERTLV.der') + for nb_rec in (1, 2): + with self.subTest(nb_rec=nb_rec): + pes = ProfileElementSequence.from_der(der) + f_smsp = pes.get_pes_for_type('usim')[0].files['ef-smsp'] + rec_len = f_smsp.rec_len + tail = bytes(range(rec_len)) * (nb_rec - 1) + f_smsp.body = f_smsp.body[:rec_len] + tail + param = p13n.SmspTpScAddr('+1234567') + param.validate() + param.apply(pes) + self.assertEqual(len(f_smsp.body), nb_rec * rec_len) + self.assertEqual(f_smsp.body[rec_len:], tail) + self.assertEqual(tuple(p13n.SmspTpScAddr.get_values_from_pes(pes)), + ({'SMSP-TP-SC-ADDR': '+1234567'},)) + + if __name__ == "__main__": if '-u' in sys.argv: update_expected_output = True -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43983?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: I47b1abc97d7b8caad0c74d7af2e5da38e9a895b1 Gerrit-Change-Number: 43983 Gerrit-PatchSet: 4 Gerrit-Owner: laforge <laforge@osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier@sysmocom.de> Gerrit-Reviewer: laforge <laforge@osmocom.org> Gerrit-Reviewer: neels <nhofmeyr@sysmocom.de> Gerrit-CC: hampushellsberg <hampushellsberg@gmail.com>