dexter has uploaded this change for review.
pySim-shell: use verify_adm command for commandline ADM auth
since the very early days, pySim-shell.py has a commandline option
where the user may supply an ADM pin as commandline parameter.
(-a / --pin-adm and -A --pin-adm-hex) This was introduced to simplify
the usage of pySim-shell.py with shellscripts.
Unfortunately the code that handles those commandline options
duplicates the code of the verify_adm commmand. Fortunately it is
very easy to call pySim-shell command methods directly, so we can
just replace the handler by calling the do_verify_adm method in the
app object.
So far we are only able to use ADM1 pins from the commandline, since
we now practically use the verify_adm commnad, we can add another
parameter to allow the verification of ADM as well.
Related: SYS#8239
Change-Id: I7164fad757048774aa7186a84041febde75c351c
---
M pySim-shell.py
1 file changed, 11 insertions(+), 13 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/37/43637/1
diff --git a/pySim-shell.py b/pySim-shell.py
index d31cf6a..6b563ad 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -1131,8 +1131,11 @@
adm_group = global_group.add_mutually_exclusive_group()
adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', default=None,
help='ADM PIN used for provisioning (overwrites default)')
-adm_group.add_argument('-A', '--pin-adm-hex', metavar='PIN_ADM1_HEX', dest='pin_adm_hex', default=None,
+adm_group.add_argument('-A', '--pin-adm-hex', metavar='PIN_ADM_HEX', dest='pin_adm_hex', default=None,
help='ADM PIN used for provisioning, as hex string (16 characters long)')
+global_group.add_argument('--pin-adm-type',
+ choices=[x for x in pin_names.values() if x.startswith('ADM')],
+ help='Override ADM number. Default is card-model-specific, usually 1')
option_parser.add_argument('-e', '--execute-command', action='append', default=[],
help='A pySim-shell command that will be executed at startup')
@@ -1182,18 +1185,13 @@
# 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
- pin_adm = sanitize_pin_adm(opts.pin_adm, opts.pin_adm_hex)
- if pin_adm:
- if not card:
- print("Card error, cannot do ADM verification with supplied ADM pin now.")
- try:
- card._scc.verify_chv(card._adm_chv_num, h2b(pin_adm))
- except Exception as e:
- startup_errors = True
- print("ADM verification (%s) failed with an exception:" % str(pin_adm))
- print("---------------------8<---------------------")
- print(e)
- print("---------------------8<---------------------")
+ pin_adm_type = ""
+ if opts.pin_adm_type:
+ pin_adm_type = "--adm-type %s" % opts.pin_adm_type
+ if opts.pin_adm:
+ app.do_verify_adm("%s %s" % (opts.pin_adm, pin_adm_type))
+ elif opts.pin_adm_hex:
+ app.do_verify_adm("%s --pin-is-hex %s" % (opts.pin_adm_hex, pin_adm_type))
# Run optional commands
for c in opts.execute_command:
To view, visit change 43637. To unsubscribe, or for help writing mail filters, visit settings.