cqr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cqr +8 -4
- data/bin/qrotp +67 -9
- data/lib/cqr.rb +3 -0
- data/lib/cqr/otp/builder.rb +46 -4
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58db2f409a021efe800e37254cd64a8b2de3ca4c
|
4
|
+
data.tar.gz: 49c7ff066c867ebee2153adc460694e2494779df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9241d7f04016a719464e4d5a6977f29bef3319591bc25f43874b8c5669219e2aa3e88a04c77e3416cb419f741727c38adfc75c9e23d4d7aff8c8a4d9d91cd9c
|
7
|
+
data.tar.gz: 5d7367e56c5e685d7c7314eca7745c07f36e7b89b720526199859b62fe74e92a29902f9c3e3537ea47441a29350f63067577009d7775327301ac7b13108c5549
|
data/bin/cqr
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'cqr'
|
4
4
|
require 'optparse'
|
5
5
|
require 'pathname'
|
6
|
+
require 'io/console'
|
6
7
|
|
7
8
|
basename = Pathname.new(__FILE__).basename
|
8
9
|
|
@@ -11,10 +12,6 @@ options = { margin: 4, invert: true }
|
|
11
12
|
opt_parser = OptionParser.new do |opts|
|
12
13
|
opts.banner = "Usage: #{basename} [options] TEXT"
|
13
14
|
|
14
|
-
opts.on("-s SECRET", "--secret=SECRET", String, "[required] OTP secret") do |secret|
|
15
|
-
options[:secret] = secret
|
16
|
-
end
|
17
|
-
|
18
15
|
opts.on("-m MARGIN", "--margin=MARGIN", Integer, "margin size in characters (default 4)") do |margin|
|
19
16
|
options[:margin] = margin
|
20
17
|
end
|
@@ -27,6 +24,9 @@ opt_parser = OptionParser.new do |opts|
|
|
27
24
|
puts opt_parser
|
28
25
|
exit
|
29
26
|
end
|
27
|
+
|
28
|
+
opts.separator ""
|
29
|
+
opts.separator "for stdin input pass \"-\" as TEXT"
|
30
30
|
end
|
31
31
|
|
32
32
|
opt_parser.parse!
|
@@ -38,6 +38,10 @@ end
|
|
38
38
|
|
39
39
|
text = ARGV.pop
|
40
40
|
|
41
|
+
if text == "-"
|
42
|
+
text = STDIN.read
|
43
|
+
end
|
44
|
+
|
41
45
|
if !text || text.empty?
|
42
46
|
puts opt_parser
|
43
47
|
exit 1
|
data/bin/qrotp
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
require 'cqr/otp'
|
4
4
|
require 'optparse'
|
5
5
|
require 'base32'
|
6
|
+
require 'io/console'
|
6
7
|
|
7
|
-
options = { margin: 4, invert: true }
|
8
|
+
options = { margin: 4, invert: true, type: 'totp' }
|
8
9
|
|
9
10
|
opt_parser = OptionParser.new do |opts|
|
10
|
-
opts.on("-
|
11
|
-
options[:
|
11
|
+
opts.on("-l LABEL", "--label=LABEL", String, "[required] displayed label") do |label|
|
12
|
+
options[:label] = label
|
12
13
|
end
|
13
14
|
|
14
15
|
opts.on("-s SECRET", "--secret=SECRET", String, "[required] OTP secret") do |secret|
|
@@ -28,19 +29,69 @@ opt_parser = OptionParser.new do |opts|
|
|
28
29
|
options[:invert] = invert
|
29
30
|
end
|
30
31
|
|
32
|
+
opts.on("-e", "--echo", "don't hide stdin") do |echo|
|
33
|
+
options[:echo] = echo
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("--issuer=ISSUER", String, "issuer of the secret") do |issuer|
|
37
|
+
options[:issuer] = issuer
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("-d DIGITS", "--digits=DIGITS", Integer, "hotp/totp, default to totp") do |digits|
|
41
|
+
options[:digits] = digits
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-c COUNTER", "--counter=COUNTER", Integer, "counter state, required with hotp") do |counter|
|
45
|
+
options[:counter] = counter
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("-t TYPE", "--type=TYPE", String, "hotp/totp, default to totp") do |type|
|
49
|
+
options[:type] = type
|
50
|
+
end
|
51
|
+
|
31
52
|
opts.on("-h", "--help", "display this message") do
|
32
53
|
puts opt_parser
|
33
54
|
exit
|
34
55
|
end
|
56
|
+
|
57
|
+
opts.separator ""
|
58
|
+
opts.separator "for stdin input pass \"-\" as NAME/SECRET"
|
35
59
|
end
|
36
60
|
|
37
61
|
opt_parser.parse!
|
38
62
|
|
39
|
-
|
63
|
+
|
64
|
+
if !options.has_key?(:secret) || !options.has_key?(:label)
|
40
65
|
puts opt_parser
|
41
66
|
exit -1
|
42
67
|
end
|
43
68
|
|
69
|
+
if options.has_key?(:type) && options[:type] == "hotp" && !options.has_key?(:counter)
|
70
|
+
puts opt_parser
|
71
|
+
exit -1
|
72
|
+
end
|
73
|
+
|
74
|
+
if options[:secret] == "-"
|
75
|
+
print "Enter secret: "
|
76
|
+
if options[:echo]
|
77
|
+
options[:secret] = STDIN.gets.chomp
|
78
|
+
else
|
79
|
+
options[:secret] = STDIN.noecho(&:gets).chomp
|
80
|
+
puts
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if options[:label] == "-"
|
85
|
+
print "Enter label: "
|
86
|
+
if options[:echo]
|
87
|
+
options[:label] = STDIN.gets.chomp
|
88
|
+
else
|
89
|
+
options[:label] = STDIN.noecho(&:gets).chomp
|
90
|
+
puts
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
44
95
|
|
45
96
|
if !options[:base32]
|
46
97
|
binary = [options[:secret]].pack("H*")
|
@@ -49,10 +100,17 @@ end
|
|
49
100
|
|
50
101
|
|
51
102
|
|
52
|
-
instance = CQR::OTP::Builder.new(
|
53
|
-
instance.
|
54
|
-
instance.
|
55
|
-
|
56
|
-
|
103
|
+
instance = CQR::OTP::Builder.new()
|
104
|
+
instance.secret = options[:secret]
|
105
|
+
instance.issuer = options[:issuer]
|
106
|
+
instance.type = options[:type]
|
107
|
+
instance.digits = options[:digits]
|
108
|
+
instance.counter = options[:counter]
|
109
|
+
instance.period = options[:period]
|
110
|
+
instance.label = options[:label]
|
57
111
|
|
112
|
+
qr_code = instance.to_qr
|
113
|
+
qr_code.margin = options[:margin]
|
114
|
+
qr_code.invert = options[:invert]
|
58
115
|
|
116
|
+
puts qr_code.to_s
|
data/lib/cqr.rb
CHANGED
data/lib/cqr/otp/builder.rb
CHANGED
@@ -3,12 +3,54 @@ require 'cqr'
|
|
3
3
|
module CQR
|
4
4
|
module OTP
|
5
5
|
class Builder
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
VALID_TYPES = [ "hotp", "totp" ].freeze
|
7
|
+
VALID_DIGITS = [ 6, 8, nil ].freeze
|
8
|
+
VALID_PERIOD = [ 30, 60, nil ].freeze
|
9
|
+
|
10
|
+
attr_accessor :secret, :label, :issuer, :type, :digits, :counter, :period
|
9
11
|
|
10
12
|
def to_qr
|
11
|
-
QRFormatter.new(
|
13
|
+
QRFormatter.new(url)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
url
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def build_type
|
23
|
+
raise CQRException.new("unknown type") unless VALID_TYPES.member?(type)
|
24
|
+
type
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_digits
|
28
|
+
raise CQRException.new("wrong number of digits") unless VALID_DIGITS.member?(digits)
|
29
|
+
digits ? "&digits=#{digits}" : ""
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_period
|
33
|
+
raise CQRException.new("wrong period") unless VALID_PERIOD.member?(period)
|
34
|
+
abort "period wit hotp" if period && type == "hotp"
|
35
|
+
period ? "&period=#{period}" : ""
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_digits
|
39
|
+
digits ? "&digits=#{digits}" : ""
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_issuer
|
43
|
+
issuer ? "&issuer=#{issuer}" : ""
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_counter
|
47
|
+
raise CQRException.new("counter with non-hotp") if counter && type != "hotp"
|
48
|
+
counter ? "&counter=#{counter}" : ""
|
49
|
+
end
|
50
|
+
|
51
|
+
def url
|
52
|
+
"otpauth://#{build_type}/#{label}?secret=#{secret}#{build_digits}" +
|
53
|
+
"#{build_period}#{build_counter}#{build_issuer}"
|
12
54
|
end
|
13
55
|
end
|
14
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cqr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiusz Hiler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rqrcode
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.2.0
|
41
|
-
description: CQR is
|
41
|
+
description: CQR is command-line tool for creating and displaying QR Codes.
|
42
42
|
email:
|
43
43
|
- arkadiusz@hiler.pl
|
44
44
|
executables:
|
@@ -47,14 +47,16 @@ executables:
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
+
- lib/cqr/otp.rb
|
50
51
|
- lib/cqr/otp/builder.rb
|
51
52
|
- lib/cqr/qr_formatter.rb
|
52
|
-
- lib/cqr/otp.rb
|
53
53
|
- lib/cqr.rb
|
54
54
|
- bin/cqr
|
55
55
|
- bin/qrotp
|
56
56
|
homepage: https://github.com/ivyl/cqr
|
57
|
-
licenses:
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
- GPL-2
|
58
60
|
metadata: {}
|
59
61
|
post_install_message:
|
60
62
|
rdoc_options: []
|