aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2018-06-12 17:56:07 +0200
committerHarald Welte <laforge@gnumonks.org>2018-06-18 09:43:56 +0000
commitd4ebb6fdf4e0900c4448f67cccf5fc29dbb214ac (patch)
treebd5bd1cb58b6794f61b24dc55c9a9f69d7946f5a
parentd9824887c9400e1be96fd06b6916b02db254e784 (diff)
__init__: allow wildcards in expected SW for send_apdu_checksw()
The method send_apdu_checksw() is used to check the SW of the final response against some pre defined value. However, in many cases the last two digits of the SW are used to return varying information (e.g. length information or a more specific status info). To cover those cases it would be helfpul to define status words that contain wildcards (e.g. 61**) in order to be able to accept all SWs from 6100 to 61ff. - When the user supplies an expected SW with wildcards, mask out those digits in the response before comparing Change-Id: I5bfc0522b4228b5d9b3415f6e708abcf0da0a7b7
-rw-r--r--pySim/transport/__init__.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index dd04bba..0a71117 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -77,12 +77,23 @@ class LinkBase(object):
"""send_apdu_checksw(pdu,sw): Sends an APDU and check returned SW
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
- sw : string of 4 hexadecimal characters (ex. "9000")
+ sw : string of 4 hexadecimal characters (ex. "9000"). The
+ user may mask out certain digits using a '?' to add some
+ ambiguity if needed.
return : tuple(data, sw), where
data : string (in hex) of returned data (ex. "074F4EFFFF")
sw : string (in hex) of status word (ex. "9000")
"""
rv = self.send_apdu(pdu)
- if sw.lower() != rv[1]:
+
+ # Create a masked version of the returned status word
+ sw_masked = ""
+ for i in range(0, 4):
+ if sw.lower()[i] == '?':
+ sw_masked = sw_masked + '?'
+ else:
+ sw_masked = sw_masked + rv[1][i].lower()
+
+ if sw.lower() != sw_masked:
raise RuntimeError("SW match failed ! Expected %s and got %s." % (sw.lower(), rv[1]))
return rv