aboutsummaryrefslogtreecommitdiffstats
path: root/pySim-prog.py
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2018-06-15 07:31:50 +0200
committerDaniel Willmann <daniel@totalueberwachung.de>2019-09-03 20:11:48 +0200
commitf432b2ba9696fe965a3dc093a9bcdbc72eccb37d (patch)
tree5a15c323cf6e2ccc825f53c00484b9532bd95530 /pySim-prog.py
parentc46a4eba43facc98666c3ce0fbb6455823d87aca (diff)
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
Diffstat (limited to 'pySim-prog.py')
-rwxr-xr-xpySim-prog.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/pySim-prog.py b/pySim-prog.py
index e00c2d0..2ac4dad 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -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 {