mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-17 02:48:34 +03:00
pySim-prog: Add option for hex ADM keys
pySim-prog would implicitly try to use the raw or hex-escaped format depending on the length of the parameter, now there is the option "-A" to explicitly specify the hex-escaped ADM1 key. pysim-test.sh: Explicitly use the "-A" option to pass the hex adm1 key for wavemobile cards Change-Id: Id75a03482aa7f8cc3bdbb8d5967f1e8ab45c179a
This commit is contained in:
@@ -73,6 +73,9 @@ def parse_options():
|
||||
parser.add_option("-a", "--pin-adm", dest="pin_adm",
|
||||
help="ADM PIN used for provisioning (overwrites default)",
|
||||
)
|
||||
parser.add_option("-A", "--pin-adm-hex", dest="pin_adm_hex",
|
||||
help="ADM PIN used for provisioning, as hex string (16 characters long",
|
||||
)
|
||||
parser.add_option("-e", "--erase", dest="erase", action='store_true',
|
||||
help="Erase beforehand [default: %default]",
|
||||
default=False,
|
||||
@@ -376,17 +379,27 @@ def gen_parameters(opts):
|
||||
else:
|
||||
opc = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
|
||||
|
||||
|
||||
pin_adm = None
|
||||
|
||||
if opts.pin_adm is not None:
|
||||
if len(opts.pin_adm) <= 8:
|
||||
pin_adm = ''.join(['%02x'%(ord(x)) for x in opts.pin_adm])
|
||||
pin_adm = rpad(pin_adm, 16)
|
||||
elif len(opts.pin_adm) == 16:
|
||||
pin_adm = opts.pin_adm
|
||||
else:
|
||||
raise ValueError("PIN-ADM needs to be <=8 digits (ascii) or exactly 16 digits (raw hex)")
|
||||
else:
|
||||
pin_adm = None
|
||||
|
||||
else:
|
||||
raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
|
||||
|
||||
if opts.pin_adm_hex is not None:
|
||||
if len(opts.pin_adm_hex) == 16:
|
||||
pin_adm = opts.pin_adm_hex
|
||||
# Ensure that it's hex-encoded
|
||||
try:
|
||||
try_encode = h2b(pin_adm)
|
||||
except ValueError:
|
||||
raise ValueError("PIN-ADM needs to be hex encoded using this option")
|
||||
else:
|
||||
raise ValueError("PIN-ADM needs to be exactly 16 digits (hex encoded)")
|
||||
|
||||
# Return that
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user