[XS] Change in pysim[master]: pySim-shell: allow checking of APDU responses
dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38606?usp=email ) Change subject: pySim-shell: allow checking of APDU responses ...................................................................... pySim-shell: allow checking of APDU responses The "apdu" command allows us to send custom APDUs to a card. This command is often used in low level initialization scripts or tests. To stop the script execution in case of an error, the command allows us to specify a status word that must match the status word of the response. But we have no such mechanism for the response itself. Let's add another parameter where we can pass a regex that the response must match. Related: OS#6367 Change-Id: I97bbcdf37bdcf00ad50a875b96940c211de7073d --- M pySim-shell.py 1 file changed, 6 insertions(+), 0 deletions(-) Approvals: laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim-shell.py b/pySim-shell.py index 37d58ae..f53efd3 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -21,6 +21,7 @@ import json import traceback +import re import cmd2 from packaging import version @@ -239,6 +240,7 @@ apdu_cmd_parser = argparse.ArgumentParser() apdu_cmd_parser.add_argument('--expect-sw', help='expect a specified status word', type=str, default=None) + apdu_cmd_parser.add_argument('--expect-response-regex', help='match response against regex', type=str, default=None) apdu_cmd_parser.add_argument('--raw', help='Bypass the logical channel (and secure channel)', action='store_true') apdu_cmd_parser.add_argument('APDU', type=is_hexstr, help='APDU as hex string') @@ -264,6 +266,10 @@ if opts.expect_sw: if not sw_match(sw, opts.expect_sw): raise SwMatchError(sw, opts.expect_sw) + if opts.expect_response_regex: + response_regex_compiled = re.compile(opts.expect_response_regex) + if re.match(response_regex_compiled, data) is None: + raise ValueError("RESP does not match regex \'%s\'" % opts.expect_response_regex) @cmd2.with_category(CUSTOM_CATEGORY) def do_reset(self, opts): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/38606?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: I97bbcdf37bdcf00ad50a875b96940c211de7073d Gerrit-Change-Number: 38606 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier@sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> Gerrit-Reviewer: laforge <laforge@osmocom.org>
participants (1)
-
dexter