From 1e41568c12ac5c49004b329bf367c769964e0127 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Mon, 14 Sep 2026 12:35:50 +0200 Subject: [PATCH] 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 commands directly using the CMD2 onecmd_plus_hooks method, so we can just call the verify_adm and replace the duplicated code with that. 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 --- pySim-shell.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pySim-shell.py b/pySim-shell.py index d31cf6a4..4f845142 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -1129,10 +1129,13 @@ global_group.add_argument("--verbose", help="Enable verbose logging", action='store_true', default=False) adm_group = global_group.add_mutually_exclusive_group() -adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', default=None, +adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM', 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,15 @@ if __name__ == '__main__': # 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.onecmd_plus_hooks("verify_adm %s %s" % + (opts.pin_adm, pin_adm_type), add_to_history = False) + elif opts.pin_adm_hex: + app.onecmd_plus_hooks("verify_adm %s --pin-is-hex %s" % + (opts.pin_adm_hex, pin_adm_type), add_to_history = False) # Run optional commands for c in opts.execute_command: