jleclanche / python-bna

Python implementation of the mobile Blizzard Authenticator (TOTP)
https://eu.battle.net/support/en/article/24520
MIT License
250 stars 38 forks source link

--restore crashes with ValueError #11

Closed WhyNotHugo closed 5 years ago

WhyNotHugo commented 7 years ago

Attempting to restore crashes:

$ bna --restore EU123412341234 12345678
Traceback (most recent call last):
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 313, in <module>
    exit(main())
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 309, in main
    return authenticator.run()
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 251, in run
    serial, secret = self.restore_serial(*self.args.restore)
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 132, in restore_serial
    secret = bna.restore(serial, code)
  File "/home/hugo/.local/share/virtualenvs/tmp/lib/python3.5/site-packages/bna.py", line 224, in restore
    raise ValueError("invalid restore code (should be 10 bytes): %r" % (code))
ValueError: invalid restore code (should be 10 bytes): '12345678'

Including the dashes from the serial seems to make no difference:

$ bna --restore EU-1234-1234-1234 12345678
Traceback (most recent call last):
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 313, in <module>
    exit(main())
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 309, in main
    return authenticator.run()
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 251, in run
    serial, secret = self.restore_serial(*self.args.restore)
  File "/home/hugo/.local/share/virtualenvs/tmp/bin/bna", line 132, in restore_serial
    secret = bna.restore(serial, code)
  File "/home/hugo/.local/share/virtualenvs/tmp/lib/python3.5/site-packages/bna.py", line 224, in restore
    raise ValueError("invalid restore code (should be 10 bytes): %r" % (code))
ValueError: invalid restore code (should be 10 bytes): '12345678'

Relevant information:

$ python --version
Python 3.5.2
$ pip freeze
bna==4.1.0

I tried installing via pip, or the latest from master, and always got the same result.

jleclanche commented 7 years ago

Hmm, I haven't touched the restore code stuff in a long time. I think the way it's done is different now.

I'd love a PR. I'll try to look into it otherwise.

WhyNotHugo commented 5 years ago

Thanks!

jleclanche commented 5 years ago

Let me know if you still encounter the issue, I haven't been able to reproduce it but I saw that this fixes at least one instance of that crash.