diff options
authorPhilipp Maier <pmaier@sysmocom.de>2018-06-13 09:21:59 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2018-06-13 09:30:53 +0200
commitd9824887c9400e1be96fd06b6916b02db254e784 (patch)
parent9eeadfc46bd219227011df61635d64f902eb4e12 (diff)
pysim-prog: also allow raw hex adm pins besides numeric ascii
At the momemnt pysim takes the supplied ADM pin number and interprets it as ascii string. This ascii string (max 8 digitis) is then padded with 0xff bytes if necessary and sent to the card. This limits the range of possible ADM keys and it is not possible to deal with situataions where the ADM pin consists of arbitrary bytes. At the momemnt pysim-prog forbis anything that is longer than 8 digits. Lets also check if there are 16 digits and if yes interpret them as raw bytes. - when the adm pin is 16 digits long, interpret the string as raw bytes (hex). Change-Id: If0ac0d328c64b57bc4d45d985a4a516930053344 Related: SYS#4245
1 files changed, 7 insertions, 4 deletions
diff --git a/pySim-prog.py b/pySim-prog.py
index 0c9f749..d70eac9 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -361,10 +361,13 @@ def gen_parameters(opts):
opc = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
if opts.pin_adm is not None:
- if len(opts.pin_adm) > 8:
- raise ValueError("PIN-ADM needs to be <=8 digits")
- pin_adm = ''.join(['%02x'%(ord(x)) for x in opts.pin_adm])
- pin_adm = rpad(pin_adm, 16)
+ 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)")
pin_adm = None