Add a feature to print out a URL for a QR code for the give TOTP
seed/name. Copy/pasting that into a browser will provide a QR code to
scan into a phone's OTP app.
diff --git a/otp.py b/otp.py
index f2b4d58..9bcdc29 100755
--- a/otp.py
+++ b/otp.py
@@ -24,6 +24,7 @@
PASSWORD_LEN = 20
ALGO_TOTP = 'totp'
+TOTP_QR_GEN = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=otpauth://totp/ASF%%20Infra?secret=%s&issuer=ASF'
def otp_path():
@@ -163,6 +164,8 @@
parser = argparse.ArgumentParser(description='Compute OTP strings.')
parser.add_argument('--test', help='Run the test suite.', nargs=0,
action=RunTests)
+ parser.add_argument('--qr', help='Print a URL for a QR code',
+ action='store_true')
parser.add_argument('args', nargs=argparse.REMAINDER)
# Note: this may exit, if tests are run.
@@ -217,7 +220,10 @@
assert processor, 'Unknown/unsupported algorithm: "%s"' % (algo,)
if algo == ALGO_TOTP:
- response = processor(pwd)
+ if parsed.qr:
+ response = TOTP_QR_GEN % (pwd.decode(),)
+ else:
+ response = processor(pwd)
else:
value = processor(seed + pwd, seq)
response = ' '.join(to_words(value))