diff options
| author | mokha <mokha@cisco.com> | 2018-12-02 22:32:48 -0700 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-12-02 22:32:48 -0700 |
| commit | e3229bbc175455f0f4d059a41c53e3b5afeaf834 (patch) | |
| tree | c4477a1f6148dd58a83782be6ac912aa696ff647 | |
| parent | 949568259bc1da4f8bcd52c92745e9893c27d930 (diff) | |
add uri format
| -rw-r--r-- | lib/tfa/cli.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/tfa/cli.rb b/lib/tfa/cli.rb index 529d2f8..2f923a4 100644 --- a/lib/tfa/cli.rb +++ b/lib/tfa/cli.rb @@ -1,4 +1,7 @@ -require "thor" +require 'rqrcode' +require 'socket' +require 'thor' +require 'uri' module TFA class CLI < Thor @@ -19,16 +22,17 @@ module TFA end desc "show NAME", "shows the secret for the given key" - method_option :format, default: "raw", enum: ["raw", "qrcode"], desc: "The format to export" + method_option :format, default: "raw", enum: ["raw", "qrcode", "uri"], desc: "The format to export" def show(name = nil) if name secret = storage.secret_for(name) case options[:format] when "qrcode" - require 'rqrcode' - RQRCode::QRCode.new("otpauth://totp/unknown@example.org?secret=#{secret}&issuer=#{name}").as_ansi( + RQRCode::QRCode.new(uri_for(name, secret)).as_ansi( light: "\033[47m", dark: "\033[40m", fill_character: ' ', quiet_zone_size: 1 ) + when "uri" + uri_for(name, secret) else secret end @@ -141,5 +145,9 @@ module TFA def upgraded? !File.exist?(pstore_path) && File.exist?(secure_path) end + + def uri_for(issuer, secret) + URI.encode("otpauth://totp/#{issuer}/#{ENV['LOGNAME']}@#{Socket.gethostname}?secret=#{secret}&issuer=#{issuer}") + end end end |
