pySim-shell: introduce 'apdu' command for sending raw APDU to card

This can be useful when playing around with cards, for example
sending commands for which pySim-shell doesn't yet have proper support.

Change-Id: Ib504431d26ed2b6f71f77a143ff0a7fb4f5ea02e
This commit is contained in:
Harald Welte 2022-02-11 16:03:06 +01:00
parent 08b11abc2f
commit afb8d3f925
1 changed files with 11 additions and 0 deletions

View File

@ -673,6 +673,17 @@ class PySimCommands(CommandSet):
else:
raise ValueError("error: cannot authenticate, no adm-pin!")
apdu_cmd_parser = argparse.ArgumentParser()
apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string')
@cmd2.with_argparser(apdu_cmd_parser)
def do_apdu(self, opts):
"""Send a raw APDU to the card, and print SW + Response.
DANGEROUS: pySim-shell will not know any card state changes, and
not continue to work as expected if you e.g. select a different file."""
data, sw = self._cmd.card._scc._tp.send_apdu(opts.APDU)
self._cmd.poutput("SW: %s %s, RESP: %s" % (sw, self._cmd.rs.interpret_sw(sw), data))
@with_default_category('ISO7816 Commands')
class Iso7816Commands(CommandSet):