blackbox 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Rakefile +2 -2
- data/blackbox.gemspec +1 -1
- data/coverage/.resultset.json +8 -8
- data/coverage/index.html +20 -20
- data/doc/BB.html +3 -3
- data/doc/BB/Crypto.html +4 -4
- data/doc/BB/Crypto/ControlToken.html +2 -2
- data/doc/BB/Gem.html +2 -2
- data/doc/BB/Hash.html +2 -2
- data/doc/BB/Number.html +2 -2
- data/doc/BB/String.html +2 -2
- data/doc/BB/Unix.html +2 -2
- data/doc/_index.html +2 -2
- data/doc/file.README.html +2 -2
- data/doc/index.html +2 -2
- data/doc/top-level-namespace.html +2 -2
- data/lib/blackbox/crypto.rb +2 -2
- data/lib/blackbox/version.rb +1 -1
- data/spec/crypto_spec.rb +66 -14
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3aeb32000fc9cea63d18215bc7f87c550cfa382
|
|
4
|
+
data.tar.gz: 2e0bfcaefc68dbba17d672754cf565e51fcbb05b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1856230d97fb5745cddc3b471022913c81ac20643fe083bd0a34199ee32fc80fb583c428967851b1252383e919b06e8fe88e30b1745378c7e6a56435f69527ec
|
|
7
|
+
data.tar.gz: b9e9a6d21021a558d83fbced43074804c279d7acff918d6b2bfedc5a6555e1233f9432d43115676b58a6276e242f67f7d159db726b1a97e907500b215f4640f5
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.4.0
|
data/Rakefile
CHANGED
|
@@ -11,9 +11,9 @@ RSpec::Core::RakeTask.new('test:spec') do |t|
|
|
|
11
11
|
|
|
12
12
|
extra_opts = []
|
|
13
13
|
extra_opts << if e.nil? && f.nil?
|
|
14
|
-
'-f progress'
|
|
14
|
+
'-f progress --fail-fast'
|
|
15
15
|
else
|
|
16
|
-
'--color
|
|
16
|
+
'--color -f documentation'
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
extra_opts << " -e #{e}" unless e.nil?
|
data/blackbox.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
20
20
|
gem.require_paths = ['lib']
|
|
21
|
-
gem.required_ruby_version = '>= 2.
|
|
21
|
+
gem.required_ruby_version = '>= 2.4.0'
|
|
22
22
|
|
|
23
23
|
gem.add_development_dependency 'rake'
|
|
24
24
|
gem.add_development_dependency 'rspec'
|
data/coverage/.resultset.json
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
702,
|
|
25
25
|
702,
|
|
26
26
|
700,
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
430,
|
|
28
|
+
430,
|
|
29
29
|
null,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
270,
|
|
31
|
+
270,
|
|
32
32
|
null,
|
|
33
33
|
null,
|
|
34
34
|
null,
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
372,
|
|
45
45
|
372,
|
|
46
46
|
372,
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
282,
|
|
48
|
+
282,
|
|
49
49
|
null,
|
|
50
|
-
|
|
50
|
+
90,
|
|
51
51
|
null,
|
|
52
52
|
372,
|
|
53
53
|
null,
|
|
@@ -608,6 +608,6 @@
|
|
|
608
608
|
null
|
|
609
609
|
]
|
|
610
610
|
},
|
|
611
|
-
"timestamp":
|
|
611
|
+
"timestamp": 1482682020
|
|
612
612
|
}
|
|
613
613
|
}
|
data/coverage/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<img src="./assets/0.10.0/loading.gif" alt="loading"/>
|
|
15
15
|
</div>
|
|
16
16
|
<div id="wrapper" style="display:none;">
|
|
17
|
-
<div class="timestamp">Generated <abbr class="timeago" title="2016-
|
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2016-12-25T17:07:00+01:00">2016-12-25T17:07:00+01:00</abbr></div>
|
|
18
18
|
<ul class="group_tabs"></ul>
|
|
19
19
|
|
|
20
20
|
<div id="content">
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
covered at
|
|
26
26
|
<span class="covered_strength">
|
|
27
27
|
<span class="green">
|
|
28
|
-
38.
|
|
28
|
+
38.51
|
|
29
29
|
</span>
|
|
30
30
|
</span> hits/line)
|
|
31
31
|
</h2>
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
<td>48</td>
|
|
58
58
|
<td>48</td>
|
|
59
59
|
<td>0</td>
|
|
60
|
-
<td>156.
|
|
60
|
+
<td>156.8</td>
|
|
61
61
|
</tr>
|
|
62
62
|
|
|
63
63
|
<tr>
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
</div>
|
|
120
120
|
|
|
121
121
|
<div id="footer">
|
|
122
|
-
Generated by <a href="http://github.com/colszowka/simplecov">simplecov</a> v0.
|
|
122
|
+
Generated by <a href="http://github.com/colszowka/simplecov">simplecov</a> v0.12.0
|
|
123
123
|
and simplecov-html v0.10.0<br/>
|
|
124
124
|
using RSpec
|
|
125
125
|
</div>
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
<li class="covered" data-hits="702" data-linenumber="19">
|
|
252
252
|
<span class="hits">702</span>
|
|
253
253
|
|
|
254
|
-
<code class="ruby"> cipher = OpenSSL::Cipher
|
|
254
|
+
<code class="ruby"> cipher = OpenSSL::Cipher.new(cipher_type)</code>
|
|
255
255
|
</li>
|
|
256
256
|
|
|
257
257
|
<li class="covered" data-hits="702" data-linenumber="20">
|
|
@@ -272,14 +272,14 @@
|
|
|
272
272
|
<code class="ruby"> if iv.nil?</code>
|
|
273
273
|
</li>
|
|
274
274
|
|
|
275
|
-
<li class="covered" data-hits="
|
|
276
|
-
<span class="hits">
|
|
275
|
+
<li class="covered" data-hits="430" data-linenumber="23">
|
|
276
|
+
<span class="hits">430</span>
|
|
277
277
|
|
|
278
278
|
<code class="ruby"> iv = cipher.random_iv</code>
|
|
279
279
|
</li>
|
|
280
280
|
|
|
281
|
-
<li class="covered" data-hits="
|
|
282
|
-
<span class="hits">
|
|
281
|
+
<li class="covered" data-hits="430" data-linenumber="24">
|
|
282
|
+
<span class="hits">430</span>
|
|
283
283
|
|
|
284
284
|
<code class="ruby"> [iv.length].pack('C') + iv + cipher.update(plaintext) + cipher.final</code>
|
|
285
285
|
</li>
|
|
@@ -290,14 +290,14 @@
|
|
|
290
290
|
<code class="ruby"> else</code>
|
|
291
291
|
</li>
|
|
292
292
|
|
|
293
|
-
<li class="covered" data-hits="
|
|
294
|
-
<span class="hits">
|
|
293
|
+
<li class="covered" data-hits="270" data-linenumber="26">
|
|
294
|
+
<span class="hits">270</span>
|
|
295
295
|
|
|
296
296
|
<code class="ruby"> cipher.iv = iv</code>
|
|
297
297
|
</li>
|
|
298
298
|
|
|
299
|
-
<li class="covered" data-hits="
|
|
300
|
-
<span class="hits">
|
|
299
|
+
<li class="covered" data-hits="270" data-linenumber="27">
|
|
300
|
+
<span class="hits">270</span>
|
|
301
301
|
|
|
302
302
|
<code class="ruby"> cipher.update(plaintext) + cipher.final</code>
|
|
303
303
|
</li>
|
|
@@ -371,7 +371,7 @@
|
|
|
371
371
|
<li class="covered" data-hits="372" data-linenumber="39">
|
|
372
372
|
<span class="hits">372</span>
|
|
373
373
|
|
|
374
|
-
<code class="ruby"> cipher = OpenSSL::Cipher
|
|
374
|
+
<code class="ruby"> cipher = OpenSSL::Cipher.new(cipher_type)</code>
|
|
375
375
|
</li>
|
|
376
376
|
|
|
377
377
|
<li class="covered" data-hits="372" data-linenumber="40">
|
|
@@ -392,14 +392,14 @@
|
|
|
392
392
|
<code class="ruby"> if iv.nil?</code>
|
|
393
393
|
</li>
|
|
394
394
|
|
|
395
|
-
<li class="covered" data-hits="
|
|
396
|
-
<span class="hits">
|
|
395
|
+
<li class="covered" data-hits="282" data-linenumber="43">
|
|
396
|
+
<span class="hits">282</span>
|
|
397
397
|
|
|
398
398
|
<code class="ruby"> iv_len = ciphertext.slice!(0).unpack('C')[0]</code>
|
|
399
399
|
</li>
|
|
400
400
|
|
|
401
|
-
<li class="covered" data-hits="
|
|
402
|
-
<span class="hits">
|
|
401
|
+
<li class="covered" data-hits="282" data-linenumber="44">
|
|
402
|
+
<span class="hits">282</span>
|
|
403
403
|
|
|
404
404
|
<code class="ruby"> cipher.iv = ciphertext.slice!(0..iv_len - 1) unless 0 == iv_len</code>
|
|
405
405
|
</li>
|
|
@@ -410,8 +410,8 @@
|
|
|
410
410
|
<code class="ruby"> else</code>
|
|
411
411
|
</li>
|
|
412
412
|
|
|
413
|
-
<li class="covered" data-hits="
|
|
414
|
-
<span class="hits">
|
|
413
|
+
<li class="covered" data-hits="90" data-linenumber="46">
|
|
414
|
+
<span class="hits">90</span>
|
|
415
415
|
|
|
416
416
|
<code class="ruby"> cipher.iv = iv</code>
|
|
417
417
|
</li>
|
data/doc/BB.html
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
<dt id="VERSION-constant" class="">VERSION =
|
|
116
116
|
|
|
117
117
|
</dt>
|
|
118
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>
|
|
118
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>4.0.0</span><span class='tstring_end'>'</span></span></pre></dd>
|
|
119
119
|
|
|
120
120
|
</dl>
|
|
121
121
|
|
|
@@ -131,9 +131,9 @@
|
|
|
131
131
|
</div>
|
|
132
132
|
|
|
133
133
|
<div id="footer">
|
|
134
|
-
Generated on
|
|
134
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
135
135
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
136
|
-
0.8.7.6 (ruby-2.
|
|
136
|
+
0.8.7.6 (ruby-2.4.0).
|
|
137
137
|
</div>
|
|
138
138
|
|
|
139
139
|
</body>
|
data/doc/BB/Crypto.html
CHANGED
|
@@ -406,7 +406,7 @@
|
|
|
406
406
|
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 38</span>
|
|
407
407
|
|
|
408
408
|
<span class='kw'>def</span> <span class='id identifier rubyid_decrypt'>decrypt</span><span class='lparen'>(</span><span class='id identifier rubyid_ciphertext'>ciphertext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
409
|
-
<span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='
|
|
409
|
+
<span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='rparen'>)</span>
|
|
410
410
|
<span class='id identifier rubyid_cipher'>cipher</span><span class='period'>.</span><span class='id identifier rubyid_decrypt'>decrypt</span>
|
|
411
411
|
<span class='id identifier rubyid_cipher'>cipher</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='id identifier rubyid_key'>key</span>
|
|
412
412
|
<span class='kw'>if</span> <span class='id identifier rubyid_iv'>iv</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
|
@@ -831,7 +831,7 @@
|
|
|
831
831
|
<pre class="code"><span class="info file"># File 'lib/blackbox/crypto.rb', line 18</span>
|
|
832
832
|
|
|
833
833
|
<span class='kw'>def</span> <span class='id identifier rubyid_encrypt'>encrypt</span><span class='lparen'>(</span><span class='id identifier rubyid_plaintext'>plaintext</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_cipher_type'>cipher_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>aes-256-cbc</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_iv'>iv</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
834
|
-
<span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='
|
|
834
|
+
<span class='id identifier rubyid_cipher'>cipher</span> <span class='op'>=</span> <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>Cipher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_cipher_type'>cipher_type</span><span class='rparen'>)</span>
|
|
835
835
|
<span class='id identifier rubyid_cipher'>cipher</span><span class='period'>.</span><span class='id identifier rubyid_encrypt'>encrypt</span>
|
|
836
836
|
<span class='id identifier rubyid_cipher'>cipher</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='id identifier rubyid_key'>key</span>
|
|
837
837
|
<span class='kw'>if</span> <span class='id identifier rubyid_iv'>iv</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
|
@@ -1142,9 +1142,9 @@
|
|
|
1142
1142
|
</div>
|
|
1143
1143
|
|
|
1144
1144
|
<div id="footer">
|
|
1145
|
-
Generated on
|
|
1145
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
1146
1146
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
1147
|
-
0.8.7.6 (ruby-2.
|
|
1147
|
+
0.8.7.6 (ruby-2.4.0).
|
|
1148
1148
|
</div>
|
|
1149
1149
|
|
|
1150
1150
|
</body>
|
|
@@ -520,9 +520,9 @@
|
|
|
520
520
|
</div>
|
|
521
521
|
|
|
522
522
|
<div id="footer">
|
|
523
|
-
Generated on
|
|
523
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
524
524
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
525
|
-
0.8.7.6 (ruby-2.
|
|
525
|
+
0.8.7.6 (ruby-2.4.0).
|
|
526
526
|
</div>
|
|
527
527
|
|
|
528
528
|
</body>
|
data/doc/BB/Gem.html
CHANGED
|
@@ -428,9 +428,9 @@ version?</p>
|
|
|
428
428
|
</div>
|
|
429
429
|
|
|
430
430
|
<div id="footer">
|
|
431
|
-
Generated on
|
|
431
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
432
432
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
433
|
-
0.8.7.6 (ruby-2.
|
|
433
|
+
0.8.7.6 (ruby-2.4.0).
|
|
434
434
|
</div>
|
|
435
435
|
|
|
436
436
|
</body>
|
data/doc/BB/Hash.html
CHANGED
|
@@ -432,9 +432,9 @@ BB::Hash.flatten_prop_style(input)
|
|
|
432
432
|
</div>
|
|
433
433
|
|
|
434
434
|
<div id="footer">
|
|
435
|
-
Generated on
|
|
435
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
436
436
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
437
|
-
0.8.7.6 (ruby-2.
|
|
437
|
+
0.8.7.6 (ruby-2.4.0).
|
|
438
438
|
</div>
|
|
439
439
|
|
|
440
440
|
</body>
|
data/doc/BB/Number.html
CHANGED
|
@@ -920,9 +920,9 @@ can customize the format in the <code>options</code> hash.</p>
|
|
|
920
920
|
</div>
|
|
921
921
|
|
|
922
922
|
<div id="footer">
|
|
923
|
-
Generated on
|
|
923
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
924
924
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
925
|
-
0.8.7.6 (ruby-2.
|
|
925
|
+
0.8.7.6 (ruby-2.4.0).
|
|
926
926
|
</div>
|
|
927
927
|
|
|
928
928
|
</body>
|
data/doc/BB/String.html
CHANGED
|
@@ -231,9 +231,9 @@
|
|
|
231
231
|
</div>
|
|
232
232
|
|
|
233
233
|
<div id="footer">
|
|
234
|
-
Generated on
|
|
234
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
235
235
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
236
|
-
0.8.7.6 (ruby-2.
|
|
236
|
+
0.8.7.6 (ruby-2.4.0).
|
|
237
237
|
</div>
|
|
238
238
|
|
|
239
239
|
</body>
|
data/doc/BB/Unix.html
CHANGED
|
@@ -411,9 +411,9 @@
|
|
|
411
411
|
</div>
|
|
412
412
|
|
|
413
413
|
<div id="footer">
|
|
414
|
-
Generated on
|
|
414
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
415
415
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
416
|
-
0.8.7.6 (ruby-2.
|
|
416
|
+
0.8.7.6 (ruby-2.4.0).
|
|
417
417
|
</div>
|
|
418
418
|
|
|
419
419
|
</body>
|
data/doc/_index.html
CHANGED
|
@@ -198,9 +198,9 @@
|
|
|
198
198
|
</div>
|
|
199
199
|
|
|
200
200
|
<div id="footer">
|
|
201
|
-
Generated on
|
|
201
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
202
202
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
203
|
-
0.8.7.6 (ruby-2.
|
|
203
|
+
0.8.7.6 (ruby-2.4.0).
|
|
204
204
|
</div>
|
|
205
205
|
|
|
206
206
|
</body>
|
data/doc/file.README.html
CHANGED
|
@@ -95,9 +95,9 @@ BB::String.strip_ansi( ... )
|
|
|
95
95
|
</div></div>
|
|
96
96
|
|
|
97
97
|
<div id="footer">
|
|
98
|
-
Generated on
|
|
98
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
99
99
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
100
|
-
0.8.7.6 (ruby-2.
|
|
100
|
+
0.8.7.6 (ruby-2.4.0).
|
|
101
101
|
</div>
|
|
102
102
|
|
|
103
103
|
</body>
|
data/doc/index.html
CHANGED
|
@@ -95,9 +95,9 @@ BB::String.strip_ansi( ... )
|
|
|
95
95
|
</div></div>
|
|
96
96
|
|
|
97
97
|
<div id="footer">
|
|
98
|
-
Generated on
|
|
98
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
99
99
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
100
|
-
0.8.7.6 (ruby-2.
|
|
100
|
+
0.8.7.6 (ruby-2.4.0).
|
|
101
101
|
</div>
|
|
102
102
|
|
|
103
103
|
</body>
|
|
@@ -103,9 +103,9 @@
|
|
|
103
103
|
</div>
|
|
104
104
|
|
|
105
105
|
<div id="footer">
|
|
106
|
-
Generated on
|
|
106
|
+
Generated on Sun Dec 25 17:07:01 2016 by
|
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
108
|
-
0.8.7.6 (ruby-2.
|
|
108
|
+
0.8.7.6 (ruby-2.4.0).
|
|
109
109
|
</div>
|
|
110
110
|
|
|
111
111
|
</body>
|
data/lib/blackbox/crypto.rb
CHANGED
|
@@ -16,7 +16,7 @@ module BB
|
|
|
16
16
|
# @return [String] When iv == nil: iv_length+iv+ciphertext
|
|
17
17
|
# @return [String] When iv != nil: ciphertext
|
|
18
18
|
def encrypt(plaintext, key, cipher_type = 'aes-256-cbc', iv = nil)
|
|
19
|
-
cipher = OpenSSL::Cipher
|
|
19
|
+
cipher = OpenSSL::Cipher.new(cipher_type)
|
|
20
20
|
cipher.encrypt
|
|
21
21
|
cipher.key = key
|
|
22
22
|
if iv.nil?
|
|
@@ -36,7 +36,7 @@ module BB
|
|
|
36
36
|
# @param [String] iv Initialization vector
|
|
37
37
|
# @return [String] Plaintext
|
|
38
38
|
def decrypt(ciphertext, key, cipher_type = 'aes-256-cbc', iv = nil)
|
|
39
|
-
cipher = OpenSSL::Cipher
|
|
39
|
+
cipher = OpenSSL::Cipher.new(cipher_type)
|
|
40
40
|
cipher.decrypt
|
|
41
41
|
cipher.key = key
|
|
42
42
|
if iv.nil?
|
data/lib/blackbox/version.rb
CHANGED
data/spec/crypto_spec.rb
CHANGED
|
@@ -13,6 +13,50 @@ OPENSSL_CIPHERS = %w(aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc
|
|
|
13
13
|
%w(rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb) +
|
|
14
14
|
%w(rc4 rc4-40)
|
|
15
15
|
|
|
16
|
+
CIPHER_KEY_IV_SIZE = {
|
|
17
|
+
'aes-128-cbc': [16, 16],
|
|
18
|
+
'aes-128-ecb': [16, 1],
|
|
19
|
+
'aes-192-cbc': [24, 16],
|
|
20
|
+
'aes-192-ecb': [24, 1],
|
|
21
|
+
'aes-256-cbc': [32, 16],
|
|
22
|
+
'aes-256-ecb': [32, 1],
|
|
23
|
+
'bf': [16, 8],
|
|
24
|
+
'bf-cbc': [16, 8],
|
|
25
|
+
'bf-cfb': [16, 8],
|
|
26
|
+
'bf-ecb': [16, 1],
|
|
27
|
+
'bf-ofb': [16, 8],
|
|
28
|
+
'cast': [16, 8],
|
|
29
|
+
'cast-cbc': [16, 8],
|
|
30
|
+
'cast5-cbc': [16, 8],
|
|
31
|
+
'cast5-cfb': [16, 8],
|
|
32
|
+
'cast5-ecb': [16, 1],
|
|
33
|
+
'cast5-ofb': [16, 8],
|
|
34
|
+
'des': [8, 8],
|
|
35
|
+
'des-cbc': [8, 8],
|
|
36
|
+
'des-cfb': [8, 8],
|
|
37
|
+
'des-ecb': [8, 1],
|
|
38
|
+
'des-ede': [16, 1],
|
|
39
|
+
'des-ede-cbc': [16, 8],
|
|
40
|
+
'des-ede-cfb': [16, 8],
|
|
41
|
+
'des-ede-ofb': [16, 8],
|
|
42
|
+
'des-ede3': [24, 1],
|
|
43
|
+
'des-ede3-cbc': [24, 8],
|
|
44
|
+
'des-ede3-cfb': [24, 8],
|
|
45
|
+
'des-ede3-ofb': [24, 8],
|
|
46
|
+
'des-ofb': [8, 8],
|
|
47
|
+
'des3': [24, 8],
|
|
48
|
+
'desx': [24, 8],
|
|
49
|
+
'rc2': [16, 8],
|
|
50
|
+
'rc2-40-cbc': [5, 8],
|
|
51
|
+
'rc2-64-cbc': [8, 8],
|
|
52
|
+
'rc2-cbc': [16, 8],
|
|
53
|
+
'rc2-cfb': [16, 8],
|
|
54
|
+
'rc2-ecb': [16, 1],
|
|
55
|
+
'rc2-ofb': [16, 8],
|
|
56
|
+
'rc4': [16, 1],
|
|
57
|
+
'rc4-40': [5, 1]
|
|
58
|
+
}.freeze
|
|
59
|
+
|
|
16
60
|
TEST_KEY = '12345678901234567890123456789012'
|
|
17
61
|
TEST_IV = 'x234567890123456789012345678901x'
|
|
18
62
|
TEST_TEXT_SHORT = '[SHORT_TEST]' * 16
|
|
@@ -27,26 +71,34 @@ describe BB::Crypto do
|
|
|
27
71
|
m_enc, m_dec = e
|
|
28
72
|
describe "#{m_enc}, #{m_dec}" do
|
|
29
73
|
it 'can decrypt what it encrypted (short string, random iv)' do
|
|
30
|
-
|
|
31
|
-
|
|
74
|
+
test_key = TEST_KEY[0..CIPHER_KEY_IV_SIZE.fetch(cipher.to_sym)[0] - 1]
|
|
75
|
+
ct = BB::Crypto.send(m_enc, TEST_TEXT_SHORT, test_key, cipher)
|
|
76
|
+
pt = BB::Crypto.send(m_dec, ct, test_key, cipher)
|
|
32
77
|
expect(pt).to eq(TEST_TEXT_SHORT)
|
|
33
78
|
end
|
|
34
79
|
|
|
35
80
|
it 'can decrypt what it encrypted (long string, random iv)' do
|
|
36
|
-
|
|
37
|
-
|
|
81
|
+
test_key = TEST_KEY[0..CIPHER_KEY_IV_SIZE.fetch(cipher.to_sym)[0] - 1]
|
|
82
|
+
ct = BB::Crypto.send(m_enc, TEST_TEXT_LONG, test_key, cipher)
|
|
83
|
+
pt = BB::Crypto.send(m_dec, ct, test_key, cipher)
|
|
38
84
|
expect(pt).to eq(TEST_TEXT_LONG)
|
|
39
85
|
end
|
|
40
86
|
|
|
41
87
|
it 'can decrypt what it encrypted (long string, static iv)' do
|
|
42
|
-
|
|
43
|
-
|
|
88
|
+
test_key = TEST_KEY[0..CIPHER_KEY_IV_SIZE.fetch(cipher.to_sym)[0] - 1]
|
|
89
|
+
test_iv = TEST_IV[0..CIPHER_KEY_IV_SIZE.fetch(cipher.to_sym)[1] - 1]
|
|
90
|
+
test_iv = nil if test_iv.length == 1
|
|
91
|
+
ct = BB::Crypto.send(m_enc, TEST_TEXT_LONG, test_key, cipher, test_iv)
|
|
92
|
+
pt = BB::Crypto.send(m_dec, ct, test_key, cipher, test_iv)
|
|
44
93
|
expect(pt).to eq(TEST_TEXT_LONG)
|
|
45
94
|
end
|
|
46
95
|
|
|
47
96
|
it 'returns consistent output with static iv' do
|
|
48
|
-
|
|
49
|
-
|
|
97
|
+
test_key = TEST_KEY[0..CIPHER_KEY_IV_SIZE.fetch(cipher.to_sym)[0] - 1]
|
|
98
|
+
test_iv = TEST_IV[0..CIPHER_KEY_IV_SIZE.fetch(cipher.to_sym)[1] - 1]
|
|
99
|
+
test_iv = nil if test_iv.length == 1
|
|
100
|
+
a = BB::Crypto.send(m_enc, TEST_TEXT_SHORT, test_key, cipher, test_iv)
|
|
101
|
+
b = BB::Crypto.send(m_enc, TEST_TEXT_SHORT, test_key, cipher, test_iv)
|
|
50
102
|
expect(a).to eq(b)
|
|
51
103
|
end
|
|
52
104
|
end
|
|
@@ -69,7 +121,7 @@ describe BB::Crypto do
|
|
|
69
121
|
end
|
|
70
122
|
|
|
71
123
|
describe BB::Crypto::ControlToken do
|
|
72
|
-
|
|
124
|
+
test_key = '12345678901234567890123456789012'
|
|
73
125
|
it "raises an Exception when no key is given and ENV['CONTROLTOKEN_SECRET'] is blank" do
|
|
74
126
|
expect do
|
|
75
127
|
subject.class.create('foo', [])
|
|
@@ -79,18 +131,18 @@ describe BB::Crypto do
|
|
|
79
131
|
it 'raises an Exception when key is too short (via parameter)' do
|
|
80
132
|
expect do
|
|
81
133
|
subject.class.create('foo', [], 911, 'key')
|
|
82
|
-
end.to raise_error(
|
|
134
|
+
end.to raise_error(ArgumentError)
|
|
83
135
|
end
|
|
84
136
|
|
|
85
137
|
it 'raises an Exception when key is too short (via ENV)' do
|
|
86
138
|
expect do
|
|
87
139
|
ENV['CONTROLTOKEN_SECRET'] = 'x'
|
|
88
140
|
subject.class.create('foo', [], 911)
|
|
89
|
-
end.to raise_error(
|
|
141
|
+
end.to raise_error(ArgumentError)
|
|
90
142
|
end
|
|
91
143
|
|
|
92
144
|
it 'decodes all elements of token payload as Strings' do
|
|
93
|
-
v = subject.class.parse(subject.class.create('foo', ['a', 2, :c], 5,
|
|
145
|
+
v = subject.class.parse(subject.class.create('foo', ['a', 2, :c], 5, test_key), test_key)
|
|
94
146
|
expect(v[:op]).to eq('foo')
|
|
95
147
|
expect(v[:args]).to eq(%w(a 2 c))
|
|
96
148
|
expect(v[:expired]).to eq(false)
|
|
@@ -98,12 +150,12 @@ describe BB::Crypto do
|
|
|
98
150
|
|
|
99
151
|
it 'raises an Exception when parsing expired Token with force=false' do
|
|
100
152
|
expect do
|
|
101
|
-
subject.class.parse(subject.class.create('foo', ['a', 2, :c], -1,
|
|
153
|
+
subject.class.parse(subject.class.create('foo', ['a', 2, :c], -1, test_key), test_key)
|
|
102
154
|
end.to raise_error(ArgumentError)
|
|
103
155
|
end
|
|
104
156
|
|
|
105
157
|
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,
|
|
158
|
+
v = subject.class.parse(subject.class.create('foo', ['a', 2, :c], -1, test_key), test_key, true)
|
|
107
159
|
expect(v[:expired]).to eq(true)
|
|
108
160
|
end
|
|
109
161
|
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:
|
|
4
|
+
version: 4.0.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-12-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -358,7 +358,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
358
358
|
requirements:
|
|
359
359
|
- - ">="
|
|
360
360
|
- !ruby/object:Gem::Version
|
|
361
|
-
version: 2.
|
|
361
|
+
version: 2.4.0
|
|
362
362
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
363
363
|
requirements:
|
|
364
364
|
- - ">="
|
|
@@ -366,7 +366,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
366
366
|
version: '0'
|
|
367
367
|
requirements: []
|
|
368
368
|
rubyforge_project:
|
|
369
|
-
rubygems_version: 2.
|
|
369
|
+
rubygems_version: 2.6.8
|
|
370
370
|
signing_key:
|
|
371
371
|
specification_version: 4
|
|
372
372
|
summary: Various little helpers
|