From 98552ef1bd3aec4c642e2b7eba1e650a375250c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ams=C3=BCss?= Date: Thu, 11 Aug 2022 19:29:37 +0200 Subject: [PATCH] proactive: Avoid clobbering the output of the command that triggered the FETCH Change-Id: I2b794a5c5bc808b9703b4bc679c119341a0ed41c --- pySim/transport/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index 04e6b22c..fb042098 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -160,13 +160,18 @@ class LinkBase(abc.ABC): sw : string (in hex) of status word (ex. "9000") """ rv = self.send_apdu(pdu) + last_sw = rv[1] - while sw == '9000' and sw_match(rv[1], '91xx'): + while sw == '9000' and sw_match(last_sw, '91xx'): + # It *was* successful after all -- the extra pieces FETCH handled + # need not concern the caller. + rv = (rv[0], '9000') # proactive sim as per TS 102 221 Setion 7.4.2 - rv = self.send_apdu_checksw('80120000' + rv[1][2:], sw) - print("FETCH: %s" % rv[0]) + fetch_rv = self.send_apdu_checksw('80120000' + last_sw[2:], sw) + last_sw = fetch_rv[1] + print("FETCH: %s" % fetch_rv[0]) if self.proactive_handler: - self.proactive_handler.receive_fetch_raw(rv[0]) + self.proactive_handler.receive_fetch_raw(fetch_rv[0]) if not sw_match(rv[1], sw): raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter) return rv