Add qr code generator for third party apps.

This commit is contained in:
Andreas Thienemann 2019-03-20 11:57:20 +01:00
parent aa4807cc6a
commit 75bec452a4
3 changed files with 34 additions and 5 deletions

View File

@ -30,3 +30,9 @@ If everything worked you can then generate a code by running:
Warning: These are HOTP tokens and generate codes increments a counter. If you
get too far out of sync with the server it will stop accepting your codes.
```
./duo_export.py
```
Export the duo hotp secret as a QR code for inclusion in third-party hotp apps
like freeotp.

24
duo_export.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import pyotp
import pyqrcode
import json
import base64
import sys
file_json = "response.json"
with open('response.json', "r") as f:
response = json.loads(f.read())['response']
with open('duotoken.hotp', "r") as f:
counter = int(f.readlines()[1])
label = response['customer_name']
issuer = 'Duo'
# base32 encoded hotp secret, with the padding ("=") stripped.
secret = base64.b32encode(bytes(response['hotp_secret'], 'utf-8')).decode('utf-8').replace('=', '')
qrdata = 'otpauth://hotp/{label}?secret={secret}&issuer={issuer}&counter={counter}'.format(label=label, secret=secret, issuer=issuer, counter=counter)
qrcode = pyqrcode.create(qrdata)
print(qrcode.terminal(quiet_zone=1))
print(qrdata)

View File

@ -22,4 +22,3 @@ print("Code:", hotp.at(count))
f.seek(offset)
f.write(str(count + 1))
f.close()