blackbox 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/blackbox.gemspec +4 -3
- data/coverage/.last_run.json +1 -1
- data/coverage/.resultset.json +62 -19
- data/coverage/index.html +538 -280
- data/doc/BB.html +2 -2
- data/doc/BB/Crypto.html +30 -20
- data/doc/BB/Crypto/ControlToken.html +529 -0
- data/doc/BB/Gem.html +1 -1
- data/doc/BB/Hash.html +1 -1
- data/doc/BB/Number.html +9 -11
- data/doc/BB/String.html +1 -1
- data/doc/BB/Unix.html +1 -1
- data/doc/_index.html +8 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +18 -6
- data/doc/top-level-namespace.html +1 -1
- data/lib/blackbox/crypto.rb +45 -1
- data/lib/blackbox/number.rb +1 -2
- data/lib/blackbox/version.rb +1 -1
- data/spec/crypto_spec.rb +49 -9
- metadata +29 -14
data/doc/BB/Gem.html
CHANGED
@@ -428,7 +428,7 @@ version?</p>
|
|
428
428
|
</div>
|
429
429
|
|
430
430
|
<div id="footer">
|
431
|
-
Generated on
|
431
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
432
432
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
433
433
|
0.8.7.6 (ruby-2.3.1).
|
434
434
|
</div>
|
data/doc/BB/Hash.html
CHANGED
@@ -432,7 +432,7 @@ BB::Hash.flatten_prop_style(input)
|
|
432
432
|
</div>
|
433
433
|
|
434
434
|
<div id="footer">
|
435
|
-
Generated on
|
435
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
436
436
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
437
437
|
0.8.7.6 (ruby-2.3.1).
|
438
438
|
</div>
|
data/doc/BB/Number.html
CHANGED
@@ -447,8 +447,7 @@ the format in the <code>options</code> hash.</p>
|
|
447
447
|
80
|
448
448
|
81
|
449
449
|
82
|
450
|
-
83
|
451
|
-
84</pre>
|
450
|
+
83</pre>
|
452
451
|
</td>
|
453
452
|
<td>
|
454
453
|
<pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 46</span>
|
@@ -484,8 +483,7 @@ the format in the <code>options</code> hash.</p>
|
|
484
483
|
<span class='id identifier rubyid_formatted_number'>formatted_number</span> <span class='op'>=</span> <span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='comma'>,</span>
|
485
484
|
<span class='label'>precision:</span> <span class='id identifier rubyid_precision'>precision</span><span class='comma'>,</span>
|
486
485
|
<span class='label'>separator:</span> <span class='id identifier rubyid_separator'>separator</span><span class='comma'>,</span>
|
487
|
-
<span class='label'>delimiter:</span> <span class='id identifier rubyid_delimiter'>delimiter</span>
|
488
|
-
<span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_escaped_separator'>escaped_separator</span><span class='embexpr_end'>}</span><span class='tstring_content'>)(\d*[1-9])?0+\z</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>\1\2</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_escaped_separator'>escaped_separator</span><span class='embexpr_end'>}</span><span class='tstring_content'>\z</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
486
|
+
<span class='label'>delimiter:</span> <span class='id identifier rubyid_delimiter'>delimiter</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_escaped_separator'>escaped_separator</span><span class='embexpr_end'>}</span><span class='tstring_content'>)(\d*[1-9])?0+\z</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>\1\2</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_escaped_separator'>escaped_separator</span><span class='embexpr_end'>}</span><span class='tstring_content'>\z</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
489
487
|
<span class='id identifier rubyid_storage_units_format'>storage_units_format</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%n</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='id identifier rubyid_formatted_number'>formatted_number</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%u</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='id identifier rubyid_unit'>unit</span><span class='rparen'>)</span>
|
490
488
|
<span class='kw'>end</span>
|
491
489
|
<span class='kw'>rescue</span>
|
@@ -649,6 +647,7 @@ the format in the <code>options</code> hash.</p>
|
|
649
647
|
<pre class="lines">
|
650
648
|
|
651
649
|
|
650
|
+
160
|
652
651
|
161
|
653
652
|
162
|
654
653
|
163
|
@@ -666,11 +665,10 @@ the format in the <code>options</code> hash.</p>
|
|
666
665
|
175
|
667
666
|
176
|
668
667
|
177
|
669
|
-
178
|
670
|
-
179</pre>
|
668
|
+
178</pre>
|
671
669
|
</td>
|
672
670
|
<td>
|
673
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line
|
671
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 160</span>
|
674
672
|
|
675
673
|
<span class='kw'>def</span> <span class='id identifier rubyid_with_delimiter'>with_delimiter</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
676
674
|
<span class='kw'>begin</span>
|
@@ -864,6 +862,7 @@ can customize the format in the <code>options</code> hash.</p>
|
|
864
862
|
<pre class="lines">
|
865
863
|
|
866
864
|
|
865
|
+
112
|
867
866
|
113
|
868
867
|
114
|
869
868
|
115
|
@@ -884,11 +883,10 @@ can customize the format in the <code>options</code> hash.</p>
|
|
884
883
|
130
|
885
884
|
131
|
886
885
|
132
|
887
|
-
133
|
888
|
-
134</pre>
|
886
|
+
133</pre>
|
889
887
|
</td>
|
890
888
|
<td>
|
891
|
-
<pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line
|
889
|
+
<pre class="code"><span class="info file"># File 'lib/blackbox/number.rb', line 112</span>
|
892
890
|
|
893
891
|
<span class='kw'>def</span> <span class='id identifier rubyid_with_precision'>with_precision</span><span class='lparen'>(</span><span class='id identifier rubyid_number'>number</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
894
892
|
<span class='kw'>begin</span>
|
@@ -922,7 +920,7 @@ can customize the format in the <code>options</code> hash.</p>
|
|
922
920
|
</div>
|
923
921
|
|
924
922
|
<div id="footer">
|
925
|
-
Generated on
|
923
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
926
924
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
927
925
|
0.8.7.6 (ruby-2.3.1).
|
928
926
|
</div>
|
data/doc/BB/String.html
CHANGED
@@ -231,7 +231,7 @@
|
|
231
231
|
</div>
|
232
232
|
|
233
233
|
<div id="footer">
|
234
|
-
Generated on
|
234
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
235
235
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
236
236
|
0.8.7.6 (ruby-2.3.1).
|
237
237
|
</div>
|
data/doc/BB/Unix.html
CHANGED
@@ -411,7 +411,7 @@
|
|
411
411
|
</div>
|
412
412
|
|
413
413
|
<div id="footer">
|
414
|
-
Generated on
|
414
|
+
Generated on Sat Jul 30 17:08:31 2016 by
|
415
415
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
416
416
|
0.8.7.6 (ruby-2.3.1).
|
417
417
|
</div>
|
data/doc/_index.html
CHANGED
@@ -97,6 +97,13 @@
|
|
97
97
|
<li class="letter">C</li>
|
98
98
|
<ul>
|
99
99
|
|
100
|
+
<li>
|
101
|
+
<span class='object_link'><a href="BB/Crypto/ControlToken.html" title="BB::Crypto::ControlToken (class)">ControlToken</a></span>
|
102
|
+
|
103
|
+
<small>(BB::Crypto)</small>
|
104
|
+
|
105
|
+
</li>
|
106
|
+
|
100
107
|
<li>
|
101
108
|
<span class='object_link'><a href="BB/Crypto.html" title="BB::Crypto (module)">Crypto</a></span>
|
102
109
|
|
@@ -191,7 +198,7 @@
|
|
191
198
|
</div>
|
192
199
|
|
193
200
|
<div id="footer">
|
194
|
-
Generated on
|
201
|
+
Generated on Sat Jul 30 17:08:30 2016 by
|
195
202
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
196
203
|
0.8.7.6 (ruby-2.3.1).
|
197
204
|
</div>
|
data/doc/class_list.html
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
<ul id="full_list" class="class">
|
52
52
|
<li><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></li>
|
53
|
-
<li><a class='toggle'></a> <span class='object_link'><a href="BB.html" title="BB (module)">BB</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="BB/Crypto.html" title="BB::Crypto (module)">Crypto</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Gem.html" title="BB::Gem (module)">Gem</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Hash.html" title="BB::Hash (module)">Hash</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Number.html" title="BB::Number (module)">Number</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/String.html" title="BB::String (module)">String</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Unix.html" title="BB::Unix (module)">Unix</a></span><small class='search_info'>BB</small></li></ul>
|
53
|
+
<li><a class='toggle'></a> <span class='object_link'><a href="BB.html" title="BB (module)">BB</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><a class='toggle'></a> <span class='object_link'><a href="BB/Crypto.html" title="BB::Crypto (module)">Crypto</a></span><small class='search_info'>BB</small></li><ul><li><span class='object_link'><a href="BB/Crypto/ControlToken.html" title="BB::Crypto::ControlToken (class)">ControlToken</a></span> < Object<small class='search_info'>BB::Crypto</small></li></ul><li><span class='object_link'><a href="BB/Gem.html" title="BB::Gem (module)">Gem</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Hash.html" title="BB::Hash (module)">Hash</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Number.html" title="BB::Number (module)">Number</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/String.html" title="BB::String (module)">String</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Unix.html" title="BB::Unix (module)">Unix</a></span><small class='search_info'>BB</small></li></ul>
|
54
54
|
|
55
55
|
</ul>
|
56
56
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -95,7 +95,7 @@ BB::String.strip_ansi( ... )
|
|
95
95
|
</div></div>
|
96
96
|
|
97
97
|
<div id="footer">
|
98
|
-
Generated on
|
98
|
+
Generated on Sat Jul 30 17:08:30 2016 by
|
99
99
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
100
100
|
0.8.7.6 (ruby-2.3.1).
|
101
101
|
</div>
|
data/doc/index.html
CHANGED
@@ -95,7 +95,7 @@ BB::String.strip_ansi( ... )
|
|
95
95
|
</div></div>
|
96
96
|
|
97
97
|
<div id="footer">
|
98
|
-
Generated on
|
98
|
+
Generated on Sat Jul 30 17:08:30 2016 by
|
99
99
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
100
100
|
0.8.7.6 (ruby-2.3.1).
|
101
101
|
</div>
|
data/doc/method_list.html
CHANGED
@@ -52,47 +52,59 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
<li class="r1 ">
|
55
|
+
<span class='object_link'><a href="BB/Crypto/ControlToken.html#create-class_method" title="BB::Crypto::ControlToken.create (method)">create</a></span>
|
56
|
+
<small>BB::Crypto::ControlToken</small>
|
57
|
+
</li>
|
58
|
+
|
59
|
+
|
60
|
+
<li class="r2 ">
|
55
61
|
<span class='object_link'><a href="BB/Crypto.html#decrypt-class_method" title="BB::Crypto.decrypt (method)">decrypt</a></span>
|
56
62
|
<small>BB::Crypto</small>
|
57
63
|
</li>
|
58
64
|
|
59
65
|
|
60
|
-
<li class="
|
66
|
+
<li class="r1 ">
|
61
67
|
<span class='object_link'><a href="BB/Crypto.html#decrypt_base64-class_method" title="BB::Crypto.decrypt_base64 (method)">decrypt_base64</a></span>
|
62
68
|
<small>BB::Crypto</small>
|
63
69
|
</li>
|
64
70
|
|
65
71
|
|
66
|
-
<li class="
|
72
|
+
<li class="r2 ">
|
67
73
|
<span class='object_link'><a href="BB/Crypto.html#decrypt_urlsafe_base64-class_method" title="BB::Crypto.decrypt_urlsafe_base64 (method)">decrypt_urlsafe_base64</a></span>
|
68
74
|
<small>BB::Crypto</small>
|
69
75
|
</li>
|
70
76
|
|
71
77
|
|
72
|
-
<li class="
|
78
|
+
<li class="r1 ">
|
73
79
|
<span class='object_link'><a href="BB/Crypto.html#encrypt-class_method" title="BB::Crypto.encrypt (method)">encrypt</a></span>
|
74
80
|
<small>BB::Crypto</small>
|
75
81
|
</li>
|
76
82
|
|
77
83
|
|
78
|
-
<li class="
|
84
|
+
<li class="r2 ">
|
79
85
|
<span class='object_link'><a href="BB/Crypto.html#encrypt_base64-class_method" title="BB::Crypto.encrypt_base64 (method)">encrypt_base64</a></span>
|
80
86
|
<small>BB::Crypto</small>
|
81
87
|
</li>
|
82
88
|
|
83
89
|
|
84
|
-
<li class="
|
90
|
+
<li class="r1 ">
|
85
91
|
<span class='object_link'><a href="BB/Crypto.html#encrypt_urlsafe_base64-class_method" title="BB::Crypto.encrypt_urlsafe_base64 (method)">encrypt_urlsafe_base64</a></span>
|
86
92
|
<small>BB::Crypto</small>
|
87
93
|
</li>
|
88
94
|
|
89
95
|
|
90
|
-
<li class="
|
96
|
+
<li class="r2 ">
|
91
97
|
<span class='object_link'><a href="BB/Hash.html#flatten_prop_style-class_method" title="BB::Hash.flatten_prop_style (method)">flatten_prop_style</a></span>
|
92
98
|
<small>BB::Hash</small>
|
93
99
|
</li>
|
94
100
|
|
95
101
|
|
102
|
+
<li class="r1 ">
|
103
|
+
<span class='object_link'><a href="BB/Crypto/ControlToken.html#parse-class_method" title="BB::Crypto::ControlToken.parse (method)">parse</a></span>
|
104
|
+
<small>BB::Crypto::ControlToken</small>
|
105
|
+
</li>
|
106
|
+
|
107
|
+
|
96
108
|
<li class="r2 ">
|
97
109
|
<span class='object_link'><a href="BB/Unix.html#run_each-class_method" title="BB::Unix.run_each (method)">run_each</a></span>
|
98
110
|
<small>BB::Unix</small>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Sat Jul 30 17:08:30 2016 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7.6 (ruby-2.3.1).
|
109
109
|
</div>
|
data/lib/blackbox/crypto.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'openssl'
|
3
3
|
require 'base64'
|
4
|
+
require 'chronic_duration'
|
4
5
|
|
5
6
|
module BB
|
6
7
|
# Crypto utilities.
|
@@ -93,5 +94,48 @@ module BB
|
|
93
94
|
decrypt(Base64.urlsafe_decode64(ciphertext), key, cipher_type, iv)
|
94
95
|
end
|
95
96
|
end
|
96
|
-
|
97
|
+
|
98
|
+
# Secure Control Token.
|
99
|
+
class ControlToken
|
100
|
+
class << self
|
101
|
+
# Encode and encrypt an urlsafe ControlToken.
|
102
|
+
#
|
103
|
+
# @param [String] op Operation id
|
104
|
+
# @param [Array] args Arguments (Strings)
|
105
|
+
# @param [Fixnum] expire_in
|
106
|
+
# @param [String] key Encryption key
|
107
|
+
# @param [String] cipher_type OpenSSL cipher
|
108
|
+
# @return [String] ControlToken (urlsafe base64)
|
109
|
+
def create(op, args, expire_in = 900, key = ENV['CONTROLTOKEN_SECRET'], cipher_type = 'aes-256-cbc')
|
110
|
+
raise ArgumentError, 'key can not be blank' if key.nil? || key.empty?
|
111
|
+
# If you're reading this in the year 2038: Hi there! :-)
|
112
|
+
[Time.now.to_i + expire_in].pack('l<')
|
113
|
+
body = ([[Time.now.to_i + expire_in].pack('l<'), op] + args).join("\x00")
|
114
|
+
BB::Crypto.encrypt_urlsafe_base64(body, key, cipher_type)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Decrypt and parse an urlsafe ControlToken.
|
118
|
+
#
|
119
|
+
# @param [String] token Input String (urlsafe base64)
|
120
|
+
# @param [String] key Encryption key
|
121
|
+
# @param [Boolean] force Decode expired token (suppress ArgumentError)
|
122
|
+
# @param [String] cipher_type OpenSSL cipher
|
123
|
+
# @return [Hash] Token payload
|
124
|
+
def parse(token, key = ENV['CONTROLTOKEN_SECRET'], force = false, cipher_type = 'aes-256-cbc')
|
125
|
+
raise ArgumentError, 'key can not be blank' if key.nil? || key.empty?
|
126
|
+
body = BB::Crypto.decrypt_urlsafe_base64(token, key, cipher_type)
|
127
|
+
valid_until, op, *args = body.split("\x00")
|
128
|
+
valid_until = valid_until.unpack('l<')[0]
|
129
|
+
expired = Time.now.to_i > valid_until
|
130
|
+
if expired && !force
|
131
|
+
raise ArgumentError, "Token expired at #{Time.at(valid_until)} (#{ChronicDuration.output(Time.now.to_i - valid_until)} ago)"
|
132
|
+
end
|
133
|
+
{ valid_until: valid_until,
|
134
|
+
op: op,
|
135
|
+
args: args,
|
136
|
+
expired: expired }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end # /BB::Crypto::Token
|
140
|
+
end # /BB::Crypto
|
97
141
|
end
|
data/lib/blackbox/number.rb
CHANGED
@@ -74,8 +74,7 @@ module BB
|
|
74
74
|
formatted_number = with_precision(number,
|
75
75
|
precision: precision,
|
76
76
|
separator: separator,
|
77
|
-
delimiter: delimiter
|
78
|
-
).sub(/(#{escaped_separator})(\d*[1-9])?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '')
|
77
|
+
delimiter: delimiter).sub(/(#{escaped_separator})(\d*[1-9])?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '')
|
79
78
|
storage_units_format.gsub(/%n/, formatted_number).gsub(/%u/, unit)
|
80
79
|
end
|
81
80
|
rescue
|
data/lib/blackbox/version.rb
CHANGED
data/spec/crypto_spec.rb
CHANGED
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
require 'blackbox/crypto'
|
4
4
|
require 'base64'
|
5
5
|
|
6
|
-
OPENSSL_CIPHERS = %w(aes-128-cbc
|
7
|
-
%w(aes-256-ecb
|
8
|
-
%w(bf-ecb
|
9
|
-
%w(cast5-cfb
|
10
|
-
%w(des-cfb
|
11
|
-
%w(des-ede-ofb
|
12
|
-
%w(des-ofb
|
13
|
-
%w(rc2-64-cbc
|
14
|
-
%w(rc4
|
6
|
+
OPENSSL_CIPHERS = %w(aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc) +
|
7
|
+
%w(aes-256-ecb bf bf-cbc bf-cfb) +
|
8
|
+
%w(bf-ecb bf-ofb cast cast-cbc cast5-cbc) +
|
9
|
+
%w(cast5-cfb cast5-ecb cast5-ofb des des-cbc) +
|
10
|
+
%w(des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb) +
|
11
|
+
%w(des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb) +
|
12
|
+
%w(des-ofb des3 desx rc2 rc2-40-cbc) +
|
13
|
+
%w(rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb) +
|
14
|
+
%w(rc4 rc4-40)
|
15
15
|
|
16
16
|
TEST_KEY = '12345678901234567890123456789012'
|
17
17
|
TEST_IV = 'x234567890123456789012345678901x'
|
@@ -67,4 +67,44 @@ describe BB::Crypto do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
describe BB::Crypto::ControlToken do
|
72
|
+
TEST_KEY = '12345678901234567890123456789012'
|
73
|
+
it "raises an Exception when no key is given and ENV['CONTROLTOKEN_SECRET'] is blank" do
|
74
|
+
expect do
|
75
|
+
subject.class.create('foo', [])
|
76
|
+
end.to raise_error(ArgumentError)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'raises an Exception when key is too short (via parameter)' do
|
80
|
+
expect do
|
81
|
+
subject.class.create('foo', [], 911, 'key')
|
82
|
+
end.to raise_error(OpenSSL::Cipher::CipherError)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'raises an Exception when key is too short (via ENV)' do
|
86
|
+
expect do
|
87
|
+
ENV['CONTROLTOKEN_SECRET'] = 'x'
|
88
|
+
subject.class.create('foo', [], 911)
|
89
|
+
end.to raise_error(OpenSSL::Cipher::CipherError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'decodes all elements of token payload as Strings' do
|
93
|
+
v = subject.class.parse(subject.class.create('foo', ['a', 2, :c], 5, TEST_KEY), TEST_KEY)
|
94
|
+
expect(v[:op]).to eq('foo')
|
95
|
+
expect(v[:args]).to eq(%w(a 2 c))
|
96
|
+
expect(v[:expired]).to eq(false)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'raises an Exception when parsing expired Token with force=false' do
|
100
|
+
expect do
|
101
|
+
subject.class.parse(subject.class.create('foo', ['a', 2, :c], -1, TEST_KEY), TEST_KEY)
|
102
|
+
end.to raise_error(ArgumentError)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns token with expired=true when parsing expired Token with force=true' do
|
106
|
+
v = subject.class.parse(subject.class.create('foo', ['a', 2, :c], -1, TEST_KEY), TEST_KEY, true)
|
107
|
+
expect(v[:expired]).to eq(true)
|
108
|
+
end
|
109
|
+
end
|
70
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -168,44 +168,58 @@ dependencies:
|
|
168
168
|
name: gem_update_checker
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 0.2.0
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 0.2.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: lolcat
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 42.1.43
|
188
188
|
type: :runtime
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 42.1.43
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: rainbow
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- - "
|
199
|
+
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
201
|
+
version: 2.1.0
|
202
202
|
type: :runtime
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- - "
|
206
|
+
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
208
|
+
version: 2.1.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: chronic_duration
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 0.10.6
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 0.10.6
|
209
223
|
description: Various little helpers
|
210
224
|
email:
|
211
225
|
- moe@busyloop.net
|
@@ -296,6 +310,7 @@ files:
|
|
296
310
|
- coverage/index.html
|
297
311
|
- doc/BB.html
|
298
312
|
- doc/BB/Crypto.html
|
313
|
+
- doc/BB/Crypto/ControlToken.html
|
299
314
|
- doc/BB/Gem.html
|
300
315
|
- doc/BB/Hash.html
|
301
316
|
- doc/BB/Number.html
|