diff options
Diffstat (limited to 'oath-qr')
-rwxr-xr-x | oath-qr | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -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,)) |