From a1e0c4d6b17bcfc9029a6dd5262f3b8d346be9b7 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 21 Sep 2014 11:03:48 +0200 Subject: Support both issuer and username in totp urls --- oath-qr | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/oath-qr b/oath-qr index 2abd1b1..2f64fc5 100755 --- a/oath-qr +++ b/oath-qr @@ -25,6 +25,7 @@ import base64 import optparse import subprocess import sys +import urllib parser = optparse.OptionParser() @@ -33,8 +34,12 @@ parser.add_option("-r", "--raw", dest="raw", default=False, action="store_true", help="Encode just the base32 key, not an otpauth:// URL.") parser.add_option("-n", "--name", dest="name", help="Provide a name for this otpauth token.") +parser.add_option("-u", "--user", dest="user", + help="Provide a username for this otpauth token.") parser.add_option("-b", "--base32", dest="base32", default=False, action="store_true", help="Key already is in base32.") +parser.add_option("-v", "--verbose", dest="verbose", default=0, action="count", + help="Verbose output.") (options, args) = parser.parse_args() if len(args) >= 2: @@ -55,18 +60,20 @@ else: if options.raw: msg = b32key else: - if options.name is None: - msg = "otpauth://totp/token?secret=%s"%(b32key,) - else: - msg = "otpauth://totp/%s?secret=%s"%(options.name, b32key) + name = urllib.quote(options.name) if options.name is not None else 'token' + name += ':' + urllib.quote(options.user) if options.user is not None else '' + msg = "otpauth://totp/%s?secret=%s"%(name, b32key) + msg += '&issuer=%s'%(urllib.quote(options.name),) if options.name is not None else '' + +if options.verbose > 0: + print msg p = subprocess.Popen(['qrencode', '-s', '10', '-o', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) (out, dummy) = p.communicate(msg) if p.returncode != 0: raise Exception("qrencode failed.") - p = subprocess.Popen(['display'], stdin=subprocess.PIPE) p.communicate(out) if p.returncode != 0: - raise Exception("display failed.") + raise Exception("display failed (exitcode: %d)."%(p.returncode,)) -- cgit v1.2.3