aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2022-05-19 14:15:18 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2022-05-20 11:21:28 +0200
commitca9dc62e6038af7cd5f238b79d20a4260602a7cb (patch)
tree9595e04ecbc469e3c67deea8a01684ad86c7c2e7
parentf2ea5f83d279de106791a33f5ee210d379996ab8 (diff)
pySim-shell: make APDU command available on the lowest level
The apdu command is used to communicate with the card on the lowest possible level. Lets make it available even before a card profile (rs) is avalable. This is especially useful when the card has no files on it, in this situation pySim-shell will not be able to assign a profile to the card at all. We can then use the apdu command to equip the card with the most basic files and start over. Change-Id: I601b8f17bd6af41dcbf7bbb53c75903dd46beee7
-rwxr-xr-xpySim-shell.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index 8c70c0c..d1ed506 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -91,7 +91,7 @@ def init_card(sl):
profile = CardProfile.pick(scc)
if profile is None:
print("Unsupported card type!")
- return None, None
+ return None, card
print("Info: Card is of type: %s" % str(profile))
@@ -224,7 +224,10 @@ class PysimApp(cmd2.Cmd):
not self.numeric_path)
self.prompt = 'pySIM-shell (%s)> ' % ('/'.join(path_list))
else:
- self.prompt = 'pySIM-shell (no card)> '
+ if (self.card):
+ self.prompt = 'pySIM-shell (no card profile)> '
+ else:
+ self.prompt = 'pySIM-shell (no card)> '
@cmd2.with_category(CUSTOM_CATEGORY)
def do_intro(self, _):
@@ -241,6 +244,21 @@ class PysimApp(cmd2.Cmd):
rs, card = init_card(sl)
self.equip(card, rs)
+ 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.card._scc._tp.send_apdu(opts.APDU)
+ if data:
+ self.poutput("SW: %s, RESP: %s" % (sw, data))
+ else:
+ self.poutput("SW: %s" % sw)
+
class InterceptStderr(list):
def __init__(self):
self._stderr_backup = sys.stderr
@@ -739,18 +757,6 @@ 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):
@@ -996,7 +1002,7 @@ if __name__ == '__main__':
" it should also be noted that some readers may behave strangely when no card")
print(" is inserted.)")
print("")
- app = PysimApp(None, None, sl, ch, opts.script)
+ app = PysimApp(card, None, sl, ch, opts.script)
# If the user supplies an ADM PIN at via commandline args authenticate
# immediately so that the user does not have to use the shell commands