From 2de962d7cac0e79b80d098ba2051ebaf833ef6db Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 22 Mar 2013 11:31:05 +0000 Subject: oath->qr tool git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@601 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- oath-qr | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 oath-qr (limited to 'oath-qr') diff --git a/oath-qr b/oath-qr new file mode 100755 index 0000000..a5a2759 --- /dev/null +++ b/oath-qr @@ -0,0 +1,67 @@ +#!/usr/bin/python + +# Copyright 2013 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import base64 +import optparse +import subprocess +import sys + + +parser = optparse.OptionParser() +parser.set_usage("%prog [options] [key]") +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.") +(options, args) = parser.parse_args() + +if len(args) >= 2: + parser.print_help() + sys.exit(1) +elif len(args) == 1: + hexkey = args[0] +else: + print "Enter key: ", + hexkey = sys.stdin.readline().rstrip() + +binkey = base64.b16decode(hexkey, True) +b32key = base64.b32encode(binkey) + +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) + +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.") -- cgit v1.2.3