Currently the random seed function _digits is not python3 compatible as it passes a unicode string to the sha1 function. It generates the following exception:
Using PC/SC reader interface
Card programming failed with an execption: ---------------------8<--------------------- Traceback (most recent call last): File "./pySim-prog.py", line 718, in <module> rc = process_card(opts, first, card_handler) File "./pySim-prog.py", line 643, in process_card cp = gen_parameters(opts) File "./pySim-prog.py", line 342, in gen_parameters iccid += _digits(opts.secret, 'ccid', ml, opts.num) File "./pySim-prog.py", line 228, in _digits s = hashlib.sha1(secret + usage + '%d' % num) TypeError: Unicode-objects must be encoded before hashing ---------------------8<---------------------
This patch fixes this problem.
Jeremy Herbert (1): make random seed function python3 compatible
pySim-prog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
--- pySim-prog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/pySim-prog.py b/pySim-prog.py index 942cfb0..e172d80 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -225,8 +225,9 @@ def parse_options():
def _digits(secret, usage, len, num): - s = hashlib.sha1(secret + usage + '%d' % num) - d = ''.join(['%02d'%ord(x) for x in s.digest()]) + seed = secret + usage + '%d' % num + s = hashlib.sha1(seed.encode()) + d = ''.join(['%02d' % x for x in s.digest()]) return d[0:len]
def _mcc_mnc_digits(mcc, mnc):
Hi Jeremy,
On Sun, Oct 25, 2020 at 08:56:04PM +1000, Jeremy Herbert wrote:
Currently the random seed function _digits is not python3 compatible as it passes a unicode string to the sha1 function. It generates the following exception:
thanks for your patch. I've pushed it into our gerrit, see https://gerrit.osmocom.org/c/pysim/+/20922
Regards, Harald
Hi Harald,
Thank you. Sorry, I looked but I must have missed the gerrit for this project.
Thanks, Jeremy
On Tue, 27 Oct 2020 at 04:00, Harald Welte laforge@osmocom.org wrote:
Hi Jeremy,
On Sun, Oct 25, 2020 at 08:56:04PM +1000, Jeremy Herbert wrote:
Currently the random seed function _digits is not python3 compatible as
it passes a unicode string to the sha1 function. It generates the following exception:
thanks for your patch. I've pushed it into our gerrit, see https://gerrit.osmocom.org/c/pysim/+/20922
Regards, Harald --
- Harald Welte laforge@osmocom.org
============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
On Tue, Oct 27, 2020 at 08:41:34AM +1000, Jeremy Herbert wrote:
Thank you. Sorry, I looked but I must have missed the gerrit for this project.
no worries. I don't mind pushing some patches from e-mail to gerrit.
Using gerrit is mostly important if you want to contribute more regularly (which you and anyone else is obviously very much invited to!)
Regards, Harald