jleclanche / python-bna

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

new line at the end of provisioning URI results in invalid QR code #24

Closed josefschabasser closed 5 years ago

josefschabasser commented 5 years ago

Hello!

If I run bna show-url then the URL is missing : between the serial number and the ?:

$ bna show-url
otpauth://totp/Blizzard:EU123412341234?secret=ASFAS75ASDF75889G9AD7S69AS7697AS&issuer=Blizzard&digits=8

This URL results in an invalid QR code if generated via qrencode. The URL in the readme is correct, though.

Best Regards Josef

PS: the readme is incorrect about the QR code genration. The readme still shows bna --otpauth-url which should be changed to bna show-url.

josefschabasser commented 5 years ago

Workaround:

bna show-url | awk -v ORS= '{gsub(/\?/,":?");}1' | qrencode -t UTF8

or

bna show-url | sed -r 's/[?]+/:?/g' | tr -d "\n" | qrencode -t UTF8
jleclanche commented 5 years ago

I use the PyOTP library to generate that URL, could you report the issue there?

I fixed the readme.

josefschabasser commented 5 years ago

I found the real issue. I couldn't reproduce it with pyotp on my own, but I found something different. The provisioning URI is working and correct, but python-bna is always adding a new line at the end. This is messing up the resulting QR code.

python-bna:

$ bna show-url | qrencode -t PNG -o otpauth.png
$ zbarimg --xml otpauth.png
<barcodes xmlns='http://zbar.sourceforge.net/2008/barcode'>
<source href='otpauth.png'>
<index num='0'>
<symbol type='QR-Code' quality='1'><data><![CDATA[otpauth://totp/Blizzard:EU123412341234?secret=ASFAS75ASDF75889G9AD7S69AS7697AS&issuer=Blizzard&digits=8
]]></data></symbol>
</index>
</source>
</barcodes>
scanned 1 barcode symbols from 1 images

python-bna with newline trimmed:

$ bna show-url | tr -d "\n" | qrencode -t PNG -o otpauth.png
$ zbarimg --xml otpauth.png
<barcodes xmlns='http://zbar.sourceforge.net/2008/barcode'>
<source href='otpauth.png'>
<index num='0'>
<symbol type='QR-Code' quality='1'><data><![CDATA[otpauth://totp/Blizzard:EU123412341234?secret=ASFAS75ASDF75889G9AD7S69AS7697AS&issuer=Blizzard&digits=8]]></data></symbol>
</index>
</source>
</barcodes>
scanned 1 barcode symbols from 1 images
jleclanche commented 5 years ago

Fixed thanks!

josefschabasser commented 5 years ago

I'm glad I could help! Thanks for fixing it!