encryptor 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +7 -1
- data/README.md +6 -2
- data/checksum/encryptor-2.0.0.gem.sha256 +1 -0
- data/checksum/encryptor-2.0.0.gem.sha512 +1 -0
- data/encryptor.gemspec +5 -0
- data/lib/encryptor.rb +7 -3
- data/lib/encryptor/version.rb +1 -1
- data/test/compatibility_test.rb +25 -0
- data/test/encryptor_test.rb +9 -0
- metadata +16 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5d4bcdbbba4b2892936b7090113f5163e0d6a3f
|
4
|
+
data.tar.gz: 640677c6479a699550063209e5962948130d4cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b47895d39c43829d4a3d4b3734514d52d1ac9011ac51a14707401535517810a4e79c513b031879300ae0fb47a3051d22506096169dd5abc7cb1cbbe59015128
|
7
|
+
data.tar.gz: 74835ac60295fecdb2ec482c87f739d25a1bdedb3e934d8011aeb70d0c13a0df0081d80e646457550867850ef9bbe2a524a5f5b921d4bc042e431a59f1c3bbb3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Encryptor #
|
2
2
|
|
3
|
-
##
|
3
|
+
## 3.0.0 ##
|
4
|
+
|
5
|
+
* Fixed: GCM algorithms were not using IV. See https://github.com/attr-encrypted/encryptor/pull/22 for more info (@borama)
|
6
|
+
* Data previously encrypted with GCM will not be decryptable by default. See the README for info regarding a workaround.
|
7
|
+
* Added: New option to enable backwards compatibility to allow decryption of data encrypted with AES-*-GCM algorithms from Encryptor v2.0.0. (@saghaulor)
|
8
|
+
|
9
|
+
## 2.0.0 ##
|
4
10
|
|
5
11
|
* Added support for MRI 2.1, 2.2, 2.3, and Rubinius. (@saghaulor)
|
6
12
|
* Added support for Authenticated Encryption Authentiation Data (AEAD) via aes-###-gcm. (@saghaulor)
|
data/README.md
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
A simple wrapper for the standard Ruby OpenSSL library
|
6
6
|
|
7
|
+
## Upgrading from v2.0.0 to v3.0.0 ##
|
8
|
+
A bug was discovered in Encryptor 2.0.0 wherein the IV was not being used when using an AES-\*-GCM algorithm. Unfornately fixing this major security issue results in the inability to decrypt records encrypted using an AES-\*-GCM algorithm from Encryptor v2.0.0. While the behavior change is minimal between v2.0.0 and v3.0.0, the change has a significant impact on users that used v2.0.0 and encrypted data using an AES-\*-GCM algorithm, which is the default algorithm for v2.0.0. Consequently, we decided to increment the version with a major bump to help people avoid a confusing situation where some of their data will not decrypt. A new option is available in Encryptor 3.0.0 that allows decryption of data encrypted using an AES-\*-GCM algorithm from Encryptor v2.0.0.
|
9
|
+
|
7
10
|
### Installation
|
8
11
|
|
9
12
|
```bash
|
@@ -56,10 +59,11 @@ decrypted_value = Encryptor.decrypt(encrypted_value, key: secret_key, iv: iv)
|
|
56
59
|
{ algorithm: 'aes-256-gcm',
|
57
60
|
auth_data: '',
|
58
61
|
insecure_mode: false,
|
59
|
-
hmac_iterations: 2000
|
62
|
+
hmac_iterations: 2000,
|
63
|
+
v2_gcm_iv: false }
|
60
64
|
```
|
61
65
|
|
62
|
-
Older versions of Encryptor allowed you to use it in a less secure way. Namely, you were allowed to run Encryptor without an IV, or with a key of insufficient length. Encryptor now requires a key and IV of the correct length respective to the algorithm that you use. However, to maintain backwards compatibility you can run Encryptor with the `:insecure_mode` option.
|
66
|
+
Older versions of Encryptor allowed you to use it in a less secure way. Namely, you were allowed to run Encryptor without an IV, or with a key of insufficient length. Encryptor now requires a key and IV of the correct length respective to the algorithm that you use. However, to maintain backwards compatibility you can run Encryptor with the `:insecure_mode` option. Additionally, when using AES-\*-GCM algorithms in Encryptor v2.0.0, the IV was set incorrectly and was not used. The `:v2_gcm_iv` option is available to allow Encryptor to set the IV as it was set in Encryptor v2.0.0. This is provided to assist with migrating data that unsafely encrypted using an AES-\*-GCM algorithm from Encryptor v2.0.0.
|
63
67
|
|
64
68
|
You may also pass an `:algorithm`,`:salt`, and `hmac_iterations` option, however none of these options are required. If you pass the `:salt` option, a new unique key will be derived from the key that you passed in using PKCS5 with a default of 2000 iterations. You can change the number of PKCS5 iterations with the `hmac_iterations` option. As PKCS5 is slow, it is optional behavior, but it does provide more security to use a unique IV and key for every encryption operation.
|
65
69
|
|
@@ -0,0 +1 @@
|
|
1
|
+
f144a0dd2485a61651c302a4870b6d56d3a0da22d48ce4c1dd0630cd14527b34
|
@@ -0,0 +1 @@
|
|
1
|
+
c37d971669b34a0272e1e0918426ff519413a3547d100ebf972786c3faadc76348d39ac9d150186be28eae521971e6d734de93a54fe94cdc2d525eac47ec9fdd
|
data/encryptor.gemspec
CHANGED
@@ -38,4 +38,9 @@ Gem::Specification.new do |s|
|
|
38
38
|
|
39
39
|
s.cert_chain = ['certs/saghaulor.pem']
|
40
40
|
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
|
41
|
+
|
42
|
+
s.post_install_message = "\n\n\nPlease be aware that Encryptor v2.0.0 had a major security bug when using AES-*-GCM algorithms.\n
|
43
|
+
By default You will not be able to decrypt data that was previously encrypted using an AES-*-GCM algorithm.\n
|
44
|
+
Please see the README and https://github.com/attr-encrypted/encryptor/pull/22 for more information.\n\n\n"
|
45
|
+
|
41
46
|
end
|
data/lib/encryptor.rb
CHANGED
@@ -11,14 +11,16 @@ module Encryptor
|
|
11
11
|
# Defaults to { algorithm: 'aes-256-gcm',
|
12
12
|
# auth_data: '',
|
13
13
|
# insecure_mode: false,
|
14
|
-
# hmac_iterations: 2000
|
14
|
+
# hmac_iterations: 2000,
|
15
|
+
# v2_gcm_iv: false }
|
15
16
|
#
|
16
17
|
# Run 'openssl list-cipher-commands' in your terminal to view a list all cipher algorithms that are supported on your platform
|
17
18
|
def default_options
|
18
19
|
@default_options ||= { algorithm: 'aes-256-gcm',
|
19
20
|
auth_data: '',
|
20
21
|
insecure_mode: false,
|
21
|
-
hmac_iterations: 2000
|
22
|
+
hmac_iterations: 2000,
|
23
|
+
v2_gcm_iv: false }
|
22
24
|
end
|
23
25
|
|
24
26
|
# Encrypts a <tt>:value</tt> with a specified <tt>:key</tt> and <tt>:iv</tt>.
|
@@ -60,7 +62,8 @@ module Encryptor
|
|
60
62
|
raise ArgumentError.new("iv must be #{cipher.iv_len} bytes or longer") if options[:iv].bytesize < cipher.iv_len
|
61
63
|
end
|
62
64
|
if options[:iv]
|
63
|
-
|
65
|
+
# This is here for backwards compatibility for Encryptor v2.0.0.
|
66
|
+
cipher.iv = options[:iv] if options[:v2_gcm_iv]
|
64
67
|
if options[:salt].nil?
|
65
68
|
# Use a non-salted cipher.
|
66
69
|
# This behaviour is retained for backwards compatibility. This mode
|
@@ -73,6 +76,7 @@ module Encryptor
|
|
73
76
|
# secure) mode of operation.
|
74
77
|
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(options[:key], options[:salt], options[:hmac_iterations], cipher.key_len)
|
75
78
|
end
|
79
|
+
cipher.iv = options[:iv] unless options[:v2_gcm_iv]
|
76
80
|
else
|
77
81
|
# This is deprecated and needs to be changed.
|
78
82
|
cipher.pkcs5_keyivgen(options[:key])
|
data/lib/encryptor/version.rb
CHANGED
data/test/compatibility_test.rb
CHANGED
@@ -93,5 +93,30 @@ class CompatibilityTest < Minitest::Test
|
|
93
93
|
assert_equal 'my-fixed-input', result
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
def test_ciphertext_encrypted_with_v2_decrypts_with_v2_gcm_iv_option
|
98
|
+
result = Encryptor.decrypt(@decoded_options)
|
99
|
+
assert_equal @decoded_options[:plaintext], result
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_ciphertext_encrypted_with_v2_does_not_decrypt_without_v2_gcm_iv_option
|
103
|
+
assert_raises OpenSSL::Cipher::CipherError do
|
104
|
+
@decoded_options.delete(:v2_gcm_iv)
|
105
|
+
Encryptor.decrypt(@decoded_options)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def setup
|
110
|
+
encoded_v2_options = {
|
111
|
+
plaintext: "9H/D+Sm9qMAHHsmWvEu7LGutbEspL6akB1Qb7pLtH0+YOvB9YhZxVuIpugv9\nB8PXrYFnxO+bSvspPgp4KFm4bA==\n",
|
112
|
+
value: "JR44j1NhT9WOR9SH1n6xYJMcjcGagbsYtnTtGZIe+BSavKZBR8gOtgAFJSTs\nwqtIhr28O8SC7uQepdEctnclahtNf9Nh1j/Wc76Fxlb81KI=\n",
|
113
|
+
key: "AquHbz6lrUKowAns+qRdwnfEupSbViADKuBMTe7DUpQ=\n",
|
114
|
+
iv: "YFQ4l87YMy/qQNc10AvmtQ==\n",
|
115
|
+
salt: "qy3crVknWZpYEjxr89IHUg==\n",
|
116
|
+
}
|
117
|
+
|
118
|
+
@decoded_options = { algorithm: 'aes-256-gcm' , v2_gcm_iv: true }
|
119
|
+
encoded_v2_options.each_with_object(@decoded_options) { |(k, v), memo| memo[k] = v.unpack("m").first }
|
120
|
+
end
|
96
121
|
end
|
97
122
|
|
data/test/encryptor_test.rb
CHANGED
@@ -6,6 +6,7 @@ class EncryptorTest < Minitest::Test
|
|
6
6
|
|
7
7
|
key = SecureRandom.random_bytes(32)
|
8
8
|
iv = SecureRandom.random_bytes(16)
|
9
|
+
iv2 = SecureRandom.random_bytes(16)
|
9
10
|
salt = SecureRandom.random_bytes(16)
|
10
11
|
original_value = SecureRandom.random_bytes(64)
|
11
12
|
auth_data = SecureRandom.random_bytes(64)
|
@@ -80,6 +81,14 @@ class EncryptorTest < Minitest::Test
|
|
80
81
|
|
81
82
|
OpenSSLHelper::AUTHENTICATED_ENCRYPTION_ALGORITHMS.each do |algorithm|
|
82
83
|
|
84
|
+
define_method 'test_should_use_iv_to_initialize_encryption' do
|
85
|
+
encrypted_value_iv1 = Encryptor.encrypt(value: original_value, key: key, iv: iv, salt: salt, algorithm: algorithm)
|
86
|
+
encrypted_value_iv2 = Encryptor.encrypt(value: original_value, key: key, iv: iv2, salt: salt, algorithm: algorithm)
|
87
|
+
refute_equal original_value, encrypted_value_iv1
|
88
|
+
refute_equal original_value, encrypted_value_iv2
|
89
|
+
refute_equal encrypted_value_iv1, encrypted_value_iv2
|
90
|
+
end
|
91
|
+
|
83
92
|
define_method 'test_should_use_the_default_authentication_data_if_it_is_not_specified' do
|
84
93
|
encrypted_value = Encryptor.encrypt(value: original_value, key: key, iv: iv, salt: salt, algorithm: algorithm)
|
85
94
|
decrypted_value = Encryptor.decrypt(value: encrypted_value, key: key, iv: iv, salt: salt, algorithm: algorithm)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encryptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
@@ -33,7 +33,7 @@ cert_chain:
|
|
33
33
|
ZjeLmnSDiwL6doiP5IiwALH/dcHU67ck3NGf6XyqNwQrrmtPY0mv1WVVL4Uh+vYE
|
34
34
|
kHoFzE2no0BfBg78Re8fY69P5yES5ncC
|
35
35
|
-----END CERTIFICATE-----
|
36
|
-
date: 2016-
|
36
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
37
37
|
dependencies:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: minitest
|
@@ -124,6 +124,8 @@ files:
|
|
124
124
|
- README.md
|
125
125
|
- Rakefile
|
126
126
|
- certs/saghaulor.pem
|
127
|
+
- checksum/encryptor-2.0.0.gem.sha256
|
128
|
+
- checksum/encryptor-2.0.0.gem.sha512
|
127
129
|
- encryptor.gemspec
|
128
130
|
- lib/encryptor.rb
|
129
131
|
- lib/encryptor/string.rb
|
@@ -139,7 +141,17 @@ homepage: http://github.com/attr-encrypted/encryptor
|
|
139
141
|
licenses:
|
140
142
|
- MIT
|
141
143
|
metadata: {}
|
142
|
-
post_install_message:
|
144
|
+
post_install_message: |2+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
Please be aware that Encryptor v2.0.0 had a major security bug when using AES-*-GCM algorithms.
|
149
|
+
|
150
|
+
By default You will not be able to decrypt data that was previously encrypted using an AES-*-GCM algorithm.
|
151
|
+
|
152
|
+
Please see the README and https://github.com/attr-encrypted/encryptor/pull/22 for more information.
|
153
|
+
|
154
|
+
|
143
155
|
rdoc_options:
|
144
156
|
- "--charset=UTF-8"
|
145
157
|
- "--inline-source"
|
@@ -173,3 +185,4 @@ test_files:
|
|
173
185
|
- test/legacy_encryptor_test.rb
|
174
186
|
- test/openssl_helper.rb
|
175
187
|
- test/test_helper.rb
|
188
|
+
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|