From d9824887c9400e1be96fd06b6916b02db254e784 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Wed, 13 Jun 2018 09:21:59 +0200 Subject: [PATCH] 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 --- pySim-prog.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pySim-prog.py b/pySim-prog.py index 0c9f7492..d70eac91 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)") else: pin_adm = None