fixeria submitted this change.
SmspTpScAddr: fix SMSP record length and alpha_id padding
apply_val() was re-encoding the SMSP with the minimum total_len of 28,
which produces a 28-byte body with no alpha_id field. After a DER
round-trip, the profile machinery re-pads the body to the original
record length using the template's fill pattern, which may not be 0xFF.
Those non-0xFF fill bytes end up in the alpha_id area, and GSM 7-bit
decoding then fails with a KeyError when the modified profile is read
back.
Fix by:
- setting alpha_id = '' so the field is present but empty
- setting f_smsp.rec_len = 42 (28 fixed bytes + 14 bytes of alpha_id
padding) so the re-encoded body carries 0xFF-padded alpha_id space
and the efFileSize in the fileDescriptor stays consistent
- passing total_len=f_smsp.rec_len to encode_record_bin() so the
alpha_id area is actually padded to that length
Change-Id: Ief6e02517f3e96158a2509d763b88aec4bd5a296
Jenkins: skip-card-test
---
M pySim/esim/saip/personalization.py
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py
index 86c71f5..5565f6f 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -612,10 +612,28 @@
ef_smsp_dec['tp_sc_addr']['ton_npi']['type_of_number'] = 'international' if international else 'unknown'
# ensure the parameter_indicators.tp_sc_addr is True
ef_smsp_dec['parameter_indicators']['tp_sc_addr'] = True
- # re-encode into the File body
- f_smsp.body = ef_smsp.encode_record_bin(ef_smsp_dec, 1)
+
+ # alpha_id padding: to make room for a human readable SMSC name that can be provisioned to the profile later
+ # on, alpha_id needs to be empty but padded 0xff to some length.
+ # - alpha_id is optional, setting alpha_id = '' ensures the IE is present.
+ # - the length of the file is 28+Y where Y is the length of the alpha_id -- here the intended length of our padding
+ # (see 3GPP TS 31.102 4.2.27 EF.SMSP). So if we want a maximum length of alpha_id = 14, we set the total
+ # file size to 28+14 = 42.
+ # - this file size has to go in two places: encode_record_bin() needs to know the length to encode the right
+ # length of fillFileContent.
+ # - the f_smsp needs to show the right file size in the PES, as in
+ # 'ef-smsp': [('fileDescriptor', {'efFileSize': '2a', ...
+ # (where 2a == 42)
+ # - To generate the right amount of fillFileContent, pass total_len=42 to encode_record_bin().
+ # - To show the right size in the PES, set f_smsp.rec_len = 42
+ ef_smsp_dec['alpha_id'] = ''
+ f_smsp.rec_len = 42
+
+ # re-encode into the File body.
+ #
#print("SMSP (new): %s" % f_smsp.body)
# re-generate the pe.decoded member from the File instance
+ f_smsp.body = ef_smsp.encode_record_bin(ef_smsp_dec, 1, total_len=f_smsp.rec_len)
pe.file2pe(f_smsp)
@classmethod
To view, visit change 42674. To unsubscribe, or for help writing mail filters, visit settings.