attr_keyring 0.2.0 → 0.2.1
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/Gemfile.lock +1 -1
- data/README.md +8 -2
- data/lib/attr_keyring.rb +1 -0
- data/lib/attr_keyring/active_record.rb +1 -1
- data/lib/attr_keyring/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6057a2d9269b3ae803d4a0b83687ef89d5ca9dff7b9570711b433b0c7a9b7f58
|
4
|
+
data.tar.gz: e43bda559349979df6e77fef9a17c3f81e5ad96d9dde229ca82c4d781555ee24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 914e18b4fefad514bc4b1d4a802ac213308348e0512e6c8daadffc40327e7aec20ec80064dd98b85140d75bea81ab099ae2da6d8856d377dbb5573e7458ffdd2
|
7
|
+
data.tar.gz: '08410c37300a6cb5156a6b8f1e00bf8f3c01b9729fb0840c98c83c0cb275e015a9cbde54ad91859e8a8f4f7ede86d2fa4f46526c38a769655c381c8bcfafd7c3'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -121,6 +121,12 @@ To generate keys, use `bs=32` instead.
|
|
121
121
|
$ dd if=/dev/urandom bs=32 count=1 2>/dev/null | openssl base64
|
122
122
|
```
|
123
123
|
|
124
|
+
#### About the encrypted message
|
125
|
+
|
126
|
+
Initialization vectors (IV) should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; it is important to remember that an attacker must not be able to predict ahead of time what a given IV will be.
|
127
|
+
|
128
|
+
With that in mind, attr_keyring uses `unencrypted iv + encrypted message` as the value of `encrypted_<column>`. If you're planning to migrate from other encryption mechanisms or read encrypted values from the database without using attr_keyring, make sure you account for this. The IV length can be retrieved by `OpenSSL::Cipher#iv_len`, e.g. `OpenSSL::Cipher.new("AES-128-CBC").iv_len`.
|
129
|
+
|
124
130
|
### Keyring
|
125
131
|
|
126
132
|
Keys are managed through a keyring--a short JSON document describing your encryption keys. The keyring must be a JSON object mapping numeric ids of the keys to the key values. A keyring must have at least one key. For example:
|
@@ -161,10 +167,10 @@ User.where(twitter_oauth_token: "241F596D-79FF-4C08-921A-A19E533B4F52")
|
|
161
167
|
|
162
168
|
is trivial with plain text fields, but impossible with the model defined as above.
|
163
169
|
|
164
|
-
If add a column `<attribute>_digest` exists, then a
|
170
|
+
If add a column `<attribute>_digest` exists, then a SHA1 digest from the value will be saved. This will allow you to lookup by that value instead and add unique indexes.
|
165
171
|
|
166
172
|
```ruby
|
167
|
-
User.where(twitter_oauth_token_digest: Digest::
|
173
|
+
User.where(twitter_oauth_token_digest: Digest::SHA1.hexdigest("241F596D-79FF-4C08-921A-A19E533B4F52"))
|
168
174
|
```
|
169
175
|
|
170
176
|
### Key Rotation
|
data/lib/attr_keyring.rb
CHANGED
@@ -49,7 +49,7 @@ module AttrKeyring
|
|
49
49
|
|
50
50
|
private def attr_encrypt_digest(attribute, value)
|
51
51
|
digest_column = "#{attribute}_digest"
|
52
|
-
public_send("#{digest_column}=", Digest::
|
52
|
+
public_send("#{digest_column}=", Digest::SHA1.hexdigest(value)) if respond_to?(digest_column)
|
53
53
|
end
|
54
54
|
|
55
55
|
private def migrate_to_latest_encryption_key
|
data/lib/attr_keyring/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_keyring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|