crypt_keeper 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/gemfiles/activerecord_3_1.gemfile.lock +2 -2
- data/gemfiles/activerecord_3_2.gemfile.lock +2 -2
- data/gemfiles/activerecord_4_0.gemfile.lock +2 -2
- data/gemfiles/activerecord_4_1.gemfile.lock +1 -1
- data/lib/crypt_keeper/model.rb +16 -0
- data/lib/crypt_keeper/version.rb +1 -1
- data/spec/model_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad20b829cfe76208db3c0bc6cf992a278bbd9659
|
4
|
+
data.tar.gz: 15c42c4227ed3505c4eb0af0c511d81b258ba937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df0c80648cd1bf39b88b81b5fd2e5b6fb404d01bbf529452453ab1bbd4c1654b578f274fc35a82f36d66014c62804c88363c2762af6383127e8ecc437c8b02ff
|
7
|
+
data.tar.gz: aa457783481ed45731f0d1191907044a4904ec702365c6b9325e7219678329c86632ccf20e16cc2f9e7ff9008218741114d2a3fe0f8de57eea72baaf0c6baf64
|
data/README.md
CHANGED
@@ -47,6 +47,35 @@ expected behavior, and has its use cases. An example would be migrating from
|
|
47
47
|
one type of encryption to another. Using `update_column` would allow you to
|
48
48
|
update the content without going through the current encryptor.
|
49
49
|
|
50
|
+
## Encodings
|
51
|
+
|
52
|
+
You can force an encoding on the plaintext before encryption and after decryption by using the `encoding` option. This is useful when dealing with multibyte strings:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class MyModel < ActiveRecord::Base
|
56
|
+
crypt_keeper :field, :other_field, :encryptor => :aes_new, :key => 'super_good_password', salt: 'salt', :encoding => 'UTF-8'
|
57
|
+
end
|
58
|
+
|
59
|
+
model = MyModel.new(field: 'Tromsø')
|
60
|
+
model.save! #=> Your data is now encrypted
|
61
|
+
model.field #=> 'Tromsø'
|
62
|
+
model.field.encoding #=> #<Encoding:UTF-8>
|
63
|
+
```
|
64
|
+
|
65
|
+
## Adding encryption to an existing table
|
66
|
+
|
67
|
+
If you are working with an existing table you would like to encrypt, you must use the `MyExistingModel.encrypt_table!` class method.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class MyExistingModel < ActiveRecord::Base
|
71
|
+
crypt_keeper :field, :other_field, :encryptor => :aes_new, :key => 'super_good_password', salt: 'salt'
|
72
|
+
end
|
73
|
+
|
74
|
+
MyExistingModel.encrypt_table!
|
75
|
+
```
|
76
|
+
|
77
|
+
Running `encrypt_table!` will encrypt all rows in the database using the encryption method specificed by the `crypt_keeper` line in your model.
|
78
|
+
|
50
79
|
## Supported Available Encryptors
|
51
80
|
|
52
81
|
There are four supported encryptors: `aes_new`, `mysql_aes_new`, `postgresql_pgp`, `postgres_pgp_public_key`.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/justin/work/jmazzi/crypt_keeper
|
3
3
|
specs:
|
4
|
-
crypt_keeper (0.
|
4
|
+
crypt_keeper (0.17.0)
|
5
5
|
activerecord (>= 3.1, < 4.2)
|
6
6
|
activesupport (>= 3.1, < 4.2)
|
7
7
|
aes (~> 0.5.0)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
bundler
|
27
27
|
rake
|
28
28
|
arel (2.2.3)
|
29
|
-
armor (0.0.
|
29
|
+
armor (0.0.3)
|
30
30
|
builder (3.0.4)
|
31
31
|
coderay (1.0.9)
|
32
32
|
coveralls (0.7.0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/justin/work/jmazzi/crypt_keeper
|
3
3
|
specs:
|
4
|
-
crypt_keeper (0.
|
4
|
+
crypt_keeper (0.17.0)
|
5
5
|
activerecord (>= 3.1, < 4.2)
|
6
6
|
activesupport (>= 3.1, < 4.2)
|
7
7
|
aes (~> 0.5.0)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
bundler
|
27
27
|
rake
|
28
28
|
arel (3.0.2)
|
29
|
-
armor (0.0.
|
29
|
+
armor (0.0.3)
|
30
30
|
builder (3.0.4)
|
31
31
|
coderay (1.0.9)
|
32
32
|
coveralls (0.7.0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/justin/work/jmazzi/crypt_keeper
|
3
3
|
specs:
|
4
|
-
crypt_keeper (0.
|
4
|
+
crypt_keeper (0.17.0)
|
5
5
|
activerecord (>= 3.1, < 4.2)
|
6
6
|
activesupport (>= 3.1, < 4.2)
|
7
7
|
aes (~> 0.5.0)
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
bundler
|
31
31
|
rake
|
32
32
|
arel (4.0.0)
|
33
|
-
armor (0.0.
|
33
|
+
armor (0.0.3)
|
34
34
|
atomic (1.1.14)
|
35
35
|
builder (3.1.4)
|
36
36
|
coderay (1.0.9)
|
data/lib/crypt_keeper/model.rb
CHANGED
@@ -80,6 +80,22 @@ module CryptKeeper
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
# Public: Encrypt a table for the first time.
|
84
|
+
def encrypt_table!
|
85
|
+
enc = encryptor_klass.new(crypt_keeper_options)
|
86
|
+
tmp_table = Class.new(ActiveRecord::Base).tap { |c| c.table_name = self.table_name }
|
87
|
+
|
88
|
+
transaction do
|
89
|
+
tmp_table.find_each do |r|
|
90
|
+
crypt_keeper_fields.each do |field|
|
91
|
+
r.send("#{field}=", enc.encrypt(r[field])) if r[field].present?
|
92
|
+
end
|
93
|
+
|
94
|
+
r.save!
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
83
99
|
private
|
84
100
|
|
85
101
|
# Private: The encryptor class
|
data/lib/crypt_keeper/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -112,5 +112,20 @@ module CryptKeeper
|
|
112
112
|
expect(record.storage.encoding.name).to eql('UTF-8')
|
113
113
|
end
|
114
114
|
end
|
115
|
+
|
116
|
+
context "Initial Table Encryption" do
|
117
|
+
before do
|
118
|
+
SensitiveData.crypt_keeper :storage, key: 'tool', salt: 'salt', encryptor: :aes_new, encoding: 'utf-8'
|
119
|
+
SensitiveData.delete_all
|
120
|
+
c = Class.new(ActiveRecord::Base).tap {|c| c.table_name = 'sensitive_data' }
|
121
|
+
5.times { |i| c.create! storage: "testing#{i}" }
|
122
|
+
end
|
123
|
+
|
124
|
+
it "encrypts the table" do
|
125
|
+
expect { SensitiveData.first(5) }.to raise_error(OpenSSL::Cipher::CipherError)
|
126
|
+
SensitiveData.encrypt_table!
|
127
|
+
expect { SensitiveData.first(5) }.not_to raise_error
|
128
|
+
end
|
129
|
+
end
|
115
130
|
end
|
116
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypt_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Mazzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|