summaryrefslogtreecommitdiff
path: root/oath-qr
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2014-09-21 11:03:48 +0200
committerPeter Palfrader <peter@palfrader.org>2014-09-21 11:03:48 +0200
commita1e0c4d6b17bcfc9029a6dd5262f3b8d346be9b7 (patch)
treebc097426356aedaf8718a59c357d554e05e23365 /oath-qr
parentb69c6d5ea71f2678acfda8b2699f599ae11d6d34 (diff)
Support both issuer and username in totp urls
Diffstat (limited to 'oath-qr')
-rwxr-xr-xoath-qr19
1 files 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,))