crypt_keeper 0.16.0.pre → 1.1.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/.gitignore +1 -1
- data/.travis.yml +22 -13
- data/Appraisals +6 -16
- data/README.md +43 -21
- data/Rakefile +7 -3
- data/crypt_keeper.gemspec +9 -9
- data/gemfiles/activerecord_4_2.gemfile +8 -0
- data/gemfiles/activerecord_5_1.gemfile +8 -0
- data/lib/crypt_keeper/helper.rb +31 -21
- data/lib/crypt_keeper/log_subscriber/mysql_aes.rb +11 -11
- data/lib/crypt_keeper/log_subscriber/postgres_pgp.rb +29 -10
- data/lib/crypt_keeper/model.rb +64 -17
- data/lib/crypt_keeper/provider/aes_new.rb +1 -1
- data/lib/crypt_keeper/provider/base.rb +21 -0
- data/lib/crypt_keeper/provider/mysql_aes_new.rb +2 -2
- data/lib/crypt_keeper/provider/postgres_base.rb +28 -0
- data/lib/crypt_keeper/provider/postgres_pgp.rb +27 -8
- data/lib/crypt_keeper/provider/postgres_pgp_public_key.rb +4 -20
- data/lib/crypt_keeper/version.rb +1 -1
- data/lib/crypt_keeper.rb +11 -2
- data/spec/crypt_keeper/log_subscriber/mysql_aes_spec.rb +50 -0
- data/spec/crypt_keeper/log_subscriber/postgres_pgp_spec.rb +78 -0
- data/spec/crypt_keeper/model_spec.rb +178 -0
- data/spec/crypt_keeper/provider/aes_new_spec.rb +41 -0
- data/spec/crypt_keeper/provider/mysql_aes_new_spec.rb +50 -0
- data/spec/crypt_keeper/provider/postgres_pgp_public_key_spec.rb +67 -0
- data/spec/crypt_keeper/provider/postgres_pgp_spec.rb +87 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/active_record.rb +36 -26
- data/spec/support/encryptors.rb +9 -3
- data/spec/support/logging.rb +89 -0
- metadata +84 -92
- data/bin/crypt_keeper +0 -99
- data/gemfiles/activerecord_3_1.gemfile +0 -8
- data/gemfiles/activerecord_3_1.gemfile.lock +0 -109
- data/gemfiles/activerecord_3_2.gemfile +0 -8
- data/gemfiles/activerecord_3_2.gemfile.lock +0 -109
- data/gemfiles/activerecord_4_0.gemfile +0 -8
- data/gemfiles/activerecord_4_0.gemfile.lock +0 -117
- data/gemfiles/activerecord_4_1.gemfile +0 -8
- data/gemfiles/activerecord_4_1.gemfile.lock +0 -117
- data/lib/crypt_keeper/provider/aes.rb +0 -66
- data/lib/crypt_keeper/provider/mysql_aes.rb +0 -47
- data/spec/log_subscriber/postgres_pgp_spec.rb +0 -98
- data/spec/model_spec.rb +0 -95
- data/spec/provider/aes_new_spec.rb +0 -45
- data/spec/provider/aes_spec.rb +0 -67
- data/spec/provider/mysql_aes_new_spec.rb +0 -52
- data/spec/provider/mysql_aes_spec.rb +0 -35
- data/spec/provider/postgres_pgp_public_key_spec.rb +0 -70
- data/spec/provider/postgres_pgp_spec.rb +0 -68
data/bin/crypt_keeper
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
$:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
|
|
3
|
-
require 'crypt_keeper'
|
|
4
|
-
require 'yaml'
|
|
5
|
-
require 'active_support/core_ext'
|
|
6
|
-
require 'active_record/log_subscriber'
|
|
7
|
-
require 'optparse'
|
|
8
|
-
|
|
9
|
-
if !File.exists?('config/database.yml')
|
|
10
|
-
puts "Please run this from the root of the rails project"
|
|
11
|
-
exit 1
|
|
12
|
-
else
|
|
13
|
-
config = YAML::load_file('./config/database.yml')
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
options = {}
|
|
17
|
-
OptionParser.new do |opts|
|
|
18
|
-
opts.banner = "Usage: crypt_keeper [options]"
|
|
19
|
-
|
|
20
|
-
opts.on("--old-key [key]", "The old encryption key") do |v|
|
|
21
|
-
options[:old_key] = v
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
opts.on("--new-key [key]", "The new encryption key") do |v|
|
|
25
|
-
options[:new_key] = v
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
opts.on("--salt [salt]", "The salt for the new encryption") do |v|
|
|
29
|
-
options[:salt] = v
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
opts.on("--table-name [table_name]", "The name of the table") do |v|
|
|
33
|
-
options[:table_name] = v
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
opts.on("--columns [field1,field2]", "A comma separated list of column names which are encrypted") do |v|
|
|
37
|
-
options[:columns] = v
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
opts.on("--old-encryptor [old encryptor]", "The old encryptor") do |v|
|
|
41
|
-
options[:old_encryptor] = v
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
opts.on("--query-log [file]", "ActiveRecord query log") do |v|
|
|
45
|
-
options[:query_log] = v
|
|
46
|
-
end
|
|
47
|
-
end.parse!
|
|
48
|
-
|
|
49
|
-
def get_required_arg(arg, options)
|
|
50
|
-
options.fetch(arg) { raise ArgumentError, "--#{arg.to_s.sub('_', '-')} is a required option"}
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
old_key = get_required_arg(:old_key, options)
|
|
54
|
-
new_key = get_required_arg(:new_key, options)
|
|
55
|
-
salt = get_required_arg(:salt, options)
|
|
56
|
-
table_name = get_required_arg(:table_name, options)
|
|
57
|
-
columns = get_required_arg(:columns, options).split(',')
|
|
58
|
-
encryptor = get_required_arg(:old_encryptor, options)
|
|
59
|
-
env = ENV.fetch('RAILS_ENV', 'development')
|
|
60
|
-
|
|
61
|
-
if options[:query_log].present?
|
|
62
|
-
ActiveRecord::Base.logger = Logger.new(options[:query_log])
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
if encryptor == "aes"
|
|
66
|
-
old_encryptor = CryptKeeper::Provider::Aes.new(key: old_key)
|
|
67
|
-
new_encryptor = CryptKeeper::Provider::AesNew.new(key: new_key, salt: salt)
|
|
68
|
-
elsif encryptor == "mysql_aes"
|
|
69
|
-
old_encryptor = CryptKeeper::Provider::MysqlAes.new(key: old_key)
|
|
70
|
-
new_encryptor = CryptKeeper::Provider::MysqlAesNew.new(key: new_key, salt: salt)
|
|
71
|
-
else
|
|
72
|
-
puts "#{encryptor} is not a known encryptor that can be migrated"
|
|
73
|
-
exit 1
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
class MigrateData < ActiveRecord::Base
|
|
77
|
-
def self.reencrypt_all(encrypted_fields, old_encryptor, new_encryptor)
|
|
78
|
-
ActiveRecord::Base.transaction do
|
|
79
|
-
find_each do |record|
|
|
80
|
-
new_hash = {}
|
|
81
|
-
encrypted_fields.each do |f|
|
|
82
|
-
plaintext = old_encryptor.decrypt(record[f])
|
|
83
|
-
ciphertext = new_encryptor.encrypt(plaintext)
|
|
84
|
-
new_hash[f] = ciphertext
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
record.update_attributes! new_hash
|
|
88
|
-
yield record if block_given?
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
ActiveRecord::Base.establish_connection(config.fetch(env))
|
|
95
|
-
MigrateData.table_name = table_name
|
|
96
|
-
|
|
97
|
-
MigrateData.reencrypt_all(columns, old_encryptor, new_encryptor) do |r|
|
|
98
|
-
puts "#{r.id} is now re-encrypted"
|
|
99
|
-
end
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: /Users/justin/work/jmazzi/crypt_keeper
|
|
3
|
-
specs:
|
|
4
|
-
crypt_keeper (0.16.0.pre)
|
|
5
|
-
activerecord (>= 3.1, < 4.2)
|
|
6
|
-
activesupport (>= 3.1, < 4.2)
|
|
7
|
-
aes (~> 0.5.0)
|
|
8
|
-
armor (~> 0.0.2)
|
|
9
|
-
|
|
10
|
-
GEM
|
|
11
|
-
remote: https://rubygems.org/
|
|
12
|
-
specs:
|
|
13
|
-
activemodel (3.1.12)
|
|
14
|
-
activesupport (= 3.1.12)
|
|
15
|
-
builder (~> 3.0.0)
|
|
16
|
-
i18n (~> 0.6)
|
|
17
|
-
activerecord (3.1.12)
|
|
18
|
-
activemodel (= 3.1.12)
|
|
19
|
-
activesupport (= 3.1.12)
|
|
20
|
-
arel (~> 2.2.3)
|
|
21
|
-
tzinfo (~> 0.3.29)
|
|
22
|
-
activesupport (3.1.12)
|
|
23
|
-
multi_json (~> 1.0)
|
|
24
|
-
aes (0.5.0)
|
|
25
|
-
appraisal (0.5.2)
|
|
26
|
-
bundler
|
|
27
|
-
rake
|
|
28
|
-
arel (2.2.3)
|
|
29
|
-
armor (0.0.2)
|
|
30
|
-
builder (3.0.4)
|
|
31
|
-
coderay (1.0.9)
|
|
32
|
-
coveralls (0.7.0)
|
|
33
|
-
multi_json (~> 1.3)
|
|
34
|
-
rest-client
|
|
35
|
-
simplecov (>= 0.7)
|
|
36
|
-
term-ansicolor
|
|
37
|
-
thor
|
|
38
|
-
diff-lcs (1.2.4)
|
|
39
|
-
ffi (1.9.0)
|
|
40
|
-
formatador (0.2.4)
|
|
41
|
-
guard (1.8.3)
|
|
42
|
-
formatador (>= 0.2.4)
|
|
43
|
-
listen (~> 1.3)
|
|
44
|
-
lumberjack (>= 1.0.2)
|
|
45
|
-
pry (>= 0.9.10)
|
|
46
|
-
thor (>= 0.14.6)
|
|
47
|
-
guard-rspec (2.5.4)
|
|
48
|
-
guard (>= 1.1)
|
|
49
|
-
rspec (~> 2.11)
|
|
50
|
-
i18n (0.6.5)
|
|
51
|
-
listen (1.3.1)
|
|
52
|
-
rb-fsevent (>= 0.9.3)
|
|
53
|
-
rb-inotify (>= 0.9)
|
|
54
|
-
rb-kqueue (>= 0.2)
|
|
55
|
-
lumberjack (1.0.4)
|
|
56
|
-
method_source (0.8.2)
|
|
57
|
-
mime-types (1.25)
|
|
58
|
-
multi_json (1.8.2)
|
|
59
|
-
mysql2 (0.3.13)
|
|
60
|
-
pg (0.15.1)
|
|
61
|
-
pry (0.9.12.2)
|
|
62
|
-
coderay (~> 1.0.5)
|
|
63
|
-
method_source (~> 0.8)
|
|
64
|
-
slop (~> 3.4)
|
|
65
|
-
rake (10.0.4)
|
|
66
|
-
rb-fsevent (0.9.3)
|
|
67
|
-
rb-inotify (0.9.2)
|
|
68
|
-
ffi (>= 0.5.0)
|
|
69
|
-
rb-kqueue (0.2.0)
|
|
70
|
-
ffi (>= 0.5.0)
|
|
71
|
-
rest-client (1.6.7)
|
|
72
|
-
mime-types (>= 1.16)
|
|
73
|
-
rspec (2.13.0)
|
|
74
|
-
rspec-core (~> 2.13.0)
|
|
75
|
-
rspec-expectations (~> 2.13.0)
|
|
76
|
-
rspec-mocks (~> 2.13.0)
|
|
77
|
-
rspec-core (2.13.1)
|
|
78
|
-
rspec-expectations (2.13.0)
|
|
79
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
|
80
|
-
rspec-mocks (2.13.1)
|
|
81
|
-
simplecov (0.7.1)
|
|
82
|
-
multi_json (~> 1.0)
|
|
83
|
-
simplecov-html (~> 0.7.1)
|
|
84
|
-
simplecov-html (0.7.1)
|
|
85
|
-
slop (3.4.6)
|
|
86
|
-
sqlite3 (1.3.8)
|
|
87
|
-
term-ansicolor (1.2.2)
|
|
88
|
-
tins (~> 0.8)
|
|
89
|
-
thor (0.18.1)
|
|
90
|
-
tins (0.12.0)
|
|
91
|
-
tzinfo (0.3.38)
|
|
92
|
-
|
|
93
|
-
PLATFORMS
|
|
94
|
-
ruby
|
|
95
|
-
|
|
96
|
-
DEPENDENCIES
|
|
97
|
-
activerecord (~> 3.1.10)
|
|
98
|
-
activesupport (~> 3.1.10)
|
|
99
|
-
appraisal (~> 0.5.2)
|
|
100
|
-
coveralls
|
|
101
|
-
crypt_keeper!
|
|
102
|
-
guard (~> 1.8.0)
|
|
103
|
-
guard-rspec (~> 2.5.4)
|
|
104
|
-
mysql2 (~> 0.3.11)
|
|
105
|
-
pg (~> 0.15.1)
|
|
106
|
-
rake (~> 10.0.3)
|
|
107
|
-
rb-fsevent (~> 0.9.1)
|
|
108
|
-
rspec (~> 2.13.0)
|
|
109
|
-
sqlite3
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: /Users/justin/work/jmazzi/crypt_keeper
|
|
3
|
-
specs:
|
|
4
|
-
crypt_keeper (0.16.0.pre)
|
|
5
|
-
activerecord (>= 3.1, < 4.2)
|
|
6
|
-
activesupport (>= 3.1, < 4.2)
|
|
7
|
-
aes (~> 0.5.0)
|
|
8
|
-
armor (~> 0.0.2)
|
|
9
|
-
|
|
10
|
-
GEM
|
|
11
|
-
remote: https://rubygems.org/
|
|
12
|
-
specs:
|
|
13
|
-
activemodel (3.2.14)
|
|
14
|
-
activesupport (= 3.2.14)
|
|
15
|
-
builder (~> 3.0.0)
|
|
16
|
-
activerecord (3.2.14)
|
|
17
|
-
activemodel (= 3.2.14)
|
|
18
|
-
activesupport (= 3.2.14)
|
|
19
|
-
arel (~> 3.0.2)
|
|
20
|
-
tzinfo (~> 0.3.29)
|
|
21
|
-
activesupport (3.2.14)
|
|
22
|
-
i18n (~> 0.6, >= 0.6.4)
|
|
23
|
-
multi_json (~> 1.0)
|
|
24
|
-
aes (0.5.0)
|
|
25
|
-
appraisal (0.5.2)
|
|
26
|
-
bundler
|
|
27
|
-
rake
|
|
28
|
-
arel (3.0.2)
|
|
29
|
-
armor (0.0.2)
|
|
30
|
-
builder (3.0.4)
|
|
31
|
-
coderay (1.0.9)
|
|
32
|
-
coveralls (0.7.0)
|
|
33
|
-
multi_json (~> 1.3)
|
|
34
|
-
rest-client
|
|
35
|
-
simplecov (>= 0.7)
|
|
36
|
-
term-ansicolor
|
|
37
|
-
thor
|
|
38
|
-
diff-lcs (1.2.4)
|
|
39
|
-
ffi (1.9.0)
|
|
40
|
-
formatador (0.2.4)
|
|
41
|
-
guard (1.8.3)
|
|
42
|
-
formatador (>= 0.2.4)
|
|
43
|
-
listen (~> 1.3)
|
|
44
|
-
lumberjack (>= 1.0.2)
|
|
45
|
-
pry (>= 0.9.10)
|
|
46
|
-
thor (>= 0.14.6)
|
|
47
|
-
guard-rspec (2.5.4)
|
|
48
|
-
guard (>= 1.1)
|
|
49
|
-
rspec (~> 2.11)
|
|
50
|
-
i18n (0.6.5)
|
|
51
|
-
listen (1.3.1)
|
|
52
|
-
rb-fsevent (>= 0.9.3)
|
|
53
|
-
rb-inotify (>= 0.9)
|
|
54
|
-
rb-kqueue (>= 0.2)
|
|
55
|
-
lumberjack (1.0.4)
|
|
56
|
-
method_source (0.8.2)
|
|
57
|
-
mime-types (1.25)
|
|
58
|
-
multi_json (1.8.2)
|
|
59
|
-
mysql2 (0.3.13)
|
|
60
|
-
pg (0.15.1)
|
|
61
|
-
pry (0.9.12.2)
|
|
62
|
-
coderay (~> 1.0.5)
|
|
63
|
-
method_source (~> 0.8)
|
|
64
|
-
slop (~> 3.4)
|
|
65
|
-
rake (10.0.4)
|
|
66
|
-
rb-fsevent (0.9.3)
|
|
67
|
-
rb-inotify (0.9.2)
|
|
68
|
-
ffi (>= 0.5.0)
|
|
69
|
-
rb-kqueue (0.2.0)
|
|
70
|
-
ffi (>= 0.5.0)
|
|
71
|
-
rest-client (1.6.7)
|
|
72
|
-
mime-types (>= 1.16)
|
|
73
|
-
rspec (2.13.0)
|
|
74
|
-
rspec-core (~> 2.13.0)
|
|
75
|
-
rspec-expectations (~> 2.13.0)
|
|
76
|
-
rspec-mocks (~> 2.13.0)
|
|
77
|
-
rspec-core (2.13.1)
|
|
78
|
-
rspec-expectations (2.13.0)
|
|
79
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
|
80
|
-
rspec-mocks (2.13.1)
|
|
81
|
-
simplecov (0.7.1)
|
|
82
|
-
multi_json (~> 1.0)
|
|
83
|
-
simplecov-html (~> 0.7.1)
|
|
84
|
-
simplecov-html (0.7.1)
|
|
85
|
-
slop (3.4.6)
|
|
86
|
-
sqlite3 (1.3.8)
|
|
87
|
-
term-ansicolor (1.2.2)
|
|
88
|
-
tins (~> 0.8)
|
|
89
|
-
thor (0.18.1)
|
|
90
|
-
tins (0.12.0)
|
|
91
|
-
tzinfo (0.3.38)
|
|
92
|
-
|
|
93
|
-
PLATFORMS
|
|
94
|
-
ruby
|
|
95
|
-
|
|
96
|
-
DEPENDENCIES
|
|
97
|
-
activerecord (~> 3.2.14)
|
|
98
|
-
activesupport (~> 3.2.14)
|
|
99
|
-
appraisal (~> 0.5.2)
|
|
100
|
-
coveralls
|
|
101
|
-
crypt_keeper!
|
|
102
|
-
guard (~> 1.8.0)
|
|
103
|
-
guard-rspec (~> 2.5.4)
|
|
104
|
-
mysql2 (~> 0.3.11)
|
|
105
|
-
pg (~> 0.15.1)
|
|
106
|
-
rake (~> 10.0.3)
|
|
107
|
-
rb-fsevent (~> 0.9.1)
|
|
108
|
-
rspec (~> 2.13.0)
|
|
109
|
-
sqlite3
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: /Users/justin/work/jmazzi/crypt_keeper
|
|
3
|
-
specs:
|
|
4
|
-
crypt_keeper (0.16.0.pre)
|
|
5
|
-
activerecord (>= 3.1, < 4.2)
|
|
6
|
-
activesupport (>= 3.1, < 4.2)
|
|
7
|
-
aes (~> 0.5.0)
|
|
8
|
-
armor (~> 0.0.2)
|
|
9
|
-
|
|
10
|
-
GEM
|
|
11
|
-
remote: https://rubygems.org/
|
|
12
|
-
specs:
|
|
13
|
-
activemodel (4.0.0)
|
|
14
|
-
activesupport (= 4.0.0)
|
|
15
|
-
builder (~> 3.1.0)
|
|
16
|
-
activerecord (4.0.0)
|
|
17
|
-
activemodel (= 4.0.0)
|
|
18
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
|
19
|
-
activesupport (= 4.0.0)
|
|
20
|
-
arel (~> 4.0.0)
|
|
21
|
-
activerecord-deprecated_finders (1.0.3)
|
|
22
|
-
activesupport (4.0.0)
|
|
23
|
-
i18n (~> 0.6, >= 0.6.4)
|
|
24
|
-
minitest (~> 4.2)
|
|
25
|
-
multi_json (~> 1.3)
|
|
26
|
-
thread_safe (~> 0.1)
|
|
27
|
-
tzinfo (~> 0.3.37)
|
|
28
|
-
aes (0.5.0)
|
|
29
|
-
appraisal (0.5.2)
|
|
30
|
-
bundler
|
|
31
|
-
rake
|
|
32
|
-
arel (4.0.0)
|
|
33
|
-
armor (0.0.2)
|
|
34
|
-
atomic (1.1.14)
|
|
35
|
-
builder (3.1.4)
|
|
36
|
-
coderay (1.0.9)
|
|
37
|
-
coveralls (0.7.0)
|
|
38
|
-
multi_json (~> 1.3)
|
|
39
|
-
rest-client
|
|
40
|
-
simplecov (>= 0.7)
|
|
41
|
-
term-ansicolor
|
|
42
|
-
thor
|
|
43
|
-
diff-lcs (1.2.4)
|
|
44
|
-
ffi (1.9.0)
|
|
45
|
-
formatador (0.2.4)
|
|
46
|
-
guard (1.8.3)
|
|
47
|
-
formatador (>= 0.2.4)
|
|
48
|
-
listen (~> 1.3)
|
|
49
|
-
lumberjack (>= 1.0.2)
|
|
50
|
-
pry (>= 0.9.10)
|
|
51
|
-
thor (>= 0.14.6)
|
|
52
|
-
guard-rspec (2.5.4)
|
|
53
|
-
guard (>= 1.1)
|
|
54
|
-
rspec (~> 2.11)
|
|
55
|
-
i18n (0.6.5)
|
|
56
|
-
listen (1.3.1)
|
|
57
|
-
rb-fsevent (>= 0.9.3)
|
|
58
|
-
rb-inotify (>= 0.9)
|
|
59
|
-
rb-kqueue (>= 0.2)
|
|
60
|
-
lumberjack (1.0.4)
|
|
61
|
-
method_source (0.8.2)
|
|
62
|
-
mime-types (1.25)
|
|
63
|
-
minitest (4.7.5)
|
|
64
|
-
multi_json (1.8.2)
|
|
65
|
-
mysql2 (0.3.13)
|
|
66
|
-
pg (0.15.1)
|
|
67
|
-
pry (0.9.12.2)
|
|
68
|
-
coderay (~> 1.0.5)
|
|
69
|
-
method_source (~> 0.8)
|
|
70
|
-
slop (~> 3.4)
|
|
71
|
-
rake (10.0.4)
|
|
72
|
-
rb-fsevent (0.9.3)
|
|
73
|
-
rb-inotify (0.9.2)
|
|
74
|
-
ffi (>= 0.5.0)
|
|
75
|
-
rb-kqueue (0.2.0)
|
|
76
|
-
ffi (>= 0.5.0)
|
|
77
|
-
rest-client (1.6.7)
|
|
78
|
-
mime-types (>= 1.16)
|
|
79
|
-
rspec (2.13.0)
|
|
80
|
-
rspec-core (~> 2.13.0)
|
|
81
|
-
rspec-expectations (~> 2.13.0)
|
|
82
|
-
rspec-mocks (~> 2.13.0)
|
|
83
|
-
rspec-core (2.13.1)
|
|
84
|
-
rspec-expectations (2.13.0)
|
|
85
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
|
86
|
-
rspec-mocks (2.13.1)
|
|
87
|
-
simplecov (0.7.1)
|
|
88
|
-
multi_json (~> 1.0)
|
|
89
|
-
simplecov-html (~> 0.7.1)
|
|
90
|
-
simplecov-html (0.7.1)
|
|
91
|
-
slop (3.4.6)
|
|
92
|
-
sqlite3 (1.3.8)
|
|
93
|
-
term-ansicolor (1.2.2)
|
|
94
|
-
tins (~> 0.8)
|
|
95
|
-
thor (0.18.1)
|
|
96
|
-
thread_safe (0.1.3)
|
|
97
|
-
atomic
|
|
98
|
-
tins (0.12.0)
|
|
99
|
-
tzinfo (0.3.38)
|
|
100
|
-
|
|
101
|
-
PLATFORMS
|
|
102
|
-
ruby
|
|
103
|
-
|
|
104
|
-
DEPENDENCIES
|
|
105
|
-
activerecord (~> 4.0.0)
|
|
106
|
-
activesupport (~> 4.0.0)
|
|
107
|
-
appraisal (~> 0.5.2)
|
|
108
|
-
coveralls
|
|
109
|
-
crypt_keeper!
|
|
110
|
-
guard (~> 1.8.0)
|
|
111
|
-
guard-rspec (~> 2.5.4)
|
|
112
|
-
mysql2 (~> 0.3.11)
|
|
113
|
-
pg (~> 0.15.1)
|
|
114
|
-
rake (~> 10.0.3)
|
|
115
|
-
rb-fsevent (~> 0.9.1)
|
|
116
|
-
rspec (~> 2.13.0)
|
|
117
|
-
sqlite3
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: /Users/justin/work/jmazzi/crypt_keeper
|
|
3
|
-
specs:
|
|
4
|
-
crypt_keeper (0.16.0.pre)
|
|
5
|
-
activerecord (>= 3.1, < 4.2)
|
|
6
|
-
activesupport (>= 3.1, < 4.2)
|
|
7
|
-
aes (~> 0.5.0)
|
|
8
|
-
armor (~> 0.0.2)
|
|
9
|
-
|
|
10
|
-
GEM
|
|
11
|
-
remote: https://rubygems.org/
|
|
12
|
-
specs:
|
|
13
|
-
activemodel (4.1.0)
|
|
14
|
-
activesupport (= 4.1.0)
|
|
15
|
-
builder (~> 3.1)
|
|
16
|
-
activerecord (4.1.0)
|
|
17
|
-
activemodel (= 4.1.0)
|
|
18
|
-
activesupport (= 4.1.0)
|
|
19
|
-
arel (~> 5.0.0)
|
|
20
|
-
activesupport (4.1.0)
|
|
21
|
-
i18n (~> 0.6, >= 0.6.9)
|
|
22
|
-
json (~> 1.7, >= 1.7.7)
|
|
23
|
-
minitest (~> 5.1)
|
|
24
|
-
thread_safe (~> 0.1)
|
|
25
|
-
tzinfo (~> 1.1)
|
|
26
|
-
aes (0.5.0)
|
|
27
|
-
appraisal (0.5.2)
|
|
28
|
-
bundler
|
|
29
|
-
rake
|
|
30
|
-
arel (5.0.1.20140414130214)
|
|
31
|
-
armor (0.0.3)
|
|
32
|
-
builder (3.2.2)
|
|
33
|
-
coderay (1.1.0)
|
|
34
|
-
coveralls (0.7.0)
|
|
35
|
-
multi_json (~> 1.3)
|
|
36
|
-
rest-client
|
|
37
|
-
simplecov (>= 0.7)
|
|
38
|
-
term-ansicolor
|
|
39
|
-
thor
|
|
40
|
-
diff-lcs (1.2.5)
|
|
41
|
-
docile (1.1.3)
|
|
42
|
-
ffi (1.9.3)
|
|
43
|
-
formatador (0.2.4)
|
|
44
|
-
guard (1.8.3)
|
|
45
|
-
formatador (>= 0.2.4)
|
|
46
|
-
listen (~> 1.3)
|
|
47
|
-
lumberjack (>= 1.0.2)
|
|
48
|
-
pry (>= 0.9.10)
|
|
49
|
-
thor (>= 0.14.6)
|
|
50
|
-
guard-rspec (2.5.4)
|
|
51
|
-
guard (>= 1.1)
|
|
52
|
-
rspec (~> 2.11)
|
|
53
|
-
i18n (0.6.9)
|
|
54
|
-
json (1.8.1)
|
|
55
|
-
listen (1.3.1)
|
|
56
|
-
rb-fsevent (>= 0.9.3)
|
|
57
|
-
rb-inotify (>= 0.9)
|
|
58
|
-
rb-kqueue (>= 0.2)
|
|
59
|
-
lumberjack (1.0.5)
|
|
60
|
-
method_source (0.8.2)
|
|
61
|
-
mime-types (2.2)
|
|
62
|
-
minitest (5.3.3)
|
|
63
|
-
multi_json (1.9.2)
|
|
64
|
-
mysql2 (0.3.15)
|
|
65
|
-
pg (0.15.1)
|
|
66
|
-
pry (0.9.12.6)
|
|
67
|
-
coderay (~> 1.0)
|
|
68
|
-
method_source (~> 0.8)
|
|
69
|
-
slop (~> 3.4)
|
|
70
|
-
rake (10.0.4)
|
|
71
|
-
rb-fsevent (0.9.4)
|
|
72
|
-
rb-inotify (0.9.3)
|
|
73
|
-
ffi (>= 0.5.0)
|
|
74
|
-
rb-kqueue (0.2.2)
|
|
75
|
-
ffi (>= 0.5.0)
|
|
76
|
-
rest-client (1.6.7)
|
|
77
|
-
mime-types (>= 1.16)
|
|
78
|
-
rspec (2.13.0)
|
|
79
|
-
rspec-core (~> 2.13.0)
|
|
80
|
-
rspec-expectations (~> 2.13.0)
|
|
81
|
-
rspec-mocks (~> 2.13.0)
|
|
82
|
-
rspec-core (2.13.1)
|
|
83
|
-
rspec-expectations (2.13.0)
|
|
84
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
|
85
|
-
rspec-mocks (2.13.1)
|
|
86
|
-
simplecov (0.8.2)
|
|
87
|
-
docile (~> 1.1.0)
|
|
88
|
-
multi_json
|
|
89
|
-
simplecov-html (~> 0.8.0)
|
|
90
|
-
simplecov-html (0.8.0)
|
|
91
|
-
slop (3.5.0)
|
|
92
|
-
sqlite3 (1.3.9)
|
|
93
|
-
term-ansicolor (1.3.0)
|
|
94
|
-
tins (~> 1.0)
|
|
95
|
-
thor (0.19.1)
|
|
96
|
-
thread_safe (0.3.3)
|
|
97
|
-
tins (1.1.0)
|
|
98
|
-
tzinfo (1.1.0)
|
|
99
|
-
thread_safe (~> 0.1)
|
|
100
|
-
|
|
101
|
-
PLATFORMS
|
|
102
|
-
ruby
|
|
103
|
-
|
|
104
|
-
DEPENDENCIES
|
|
105
|
-
activerecord (~> 4.1.0)
|
|
106
|
-
activesupport (~> 4.1.0)
|
|
107
|
-
appraisal (~> 0.5.2)
|
|
108
|
-
coveralls
|
|
109
|
-
crypt_keeper!
|
|
110
|
-
guard (~> 1.8.0)
|
|
111
|
-
guard-rspec (~> 2.5.4)
|
|
112
|
-
mysql2 (~> 0.3.11)
|
|
113
|
-
pg (~> 0.15.1)
|
|
114
|
-
rake (~> 10.0.3)
|
|
115
|
-
rb-fsevent (~> 0.9.1)
|
|
116
|
-
rspec (~> 2.13.0)
|
|
117
|
-
sqlite3
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
require 'digest/sha2'
|
|
2
|
-
require 'openssl'
|
|
3
|
-
require 'base64'
|
|
4
|
-
|
|
5
|
-
module CryptKeeper
|
|
6
|
-
module Provider
|
|
7
|
-
class Aes
|
|
8
|
-
SEPARATOR = ":crypt_keeper:"
|
|
9
|
-
|
|
10
|
-
# Public: The encryption key
|
|
11
|
-
attr_accessor :key
|
|
12
|
-
|
|
13
|
-
# Public: An instance of OpenSSL::Cipher::Cipher
|
|
14
|
-
attr_accessor :aes
|
|
15
|
-
|
|
16
|
-
# Public: Initializes the class
|
|
17
|
-
#
|
|
18
|
-
# options - A hash of options. :key is required
|
|
19
|
-
def initialize(options = {})
|
|
20
|
-
legacy
|
|
21
|
-
@aes = ::OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
|
22
|
-
@aes.padding = 1
|
|
23
|
-
|
|
24
|
-
key = options.fetch(:key) do
|
|
25
|
-
raise ArgumentError, "Missing :key"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
@key = Digest::SHA256.digest(key)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Public: Encrypt a string
|
|
32
|
-
#
|
|
33
|
-
# Note: nil and empty strings are not encryptable with AES.
|
|
34
|
-
# When they are encountered, the orignal value is returned.
|
|
35
|
-
# Otherwise, returns the encrypted string
|
|
36
|
-
def encrypt(value)
|
|
37
|
-
return value if value == '' || value.nil?
|
|
38
|
-
aes.encrypt
|
|
39
|
-
aes.key = key
|
|
40
|
-
Base64::encode64("#{aes.random_iv}#{SEPARATOR}#{aes.update(value.to_s) + aes.final}")
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Public: Decrypt a string
|
|
44
|
-
#
|
|
45
|
-
# Note: nil and empty strings are not encryptable with AES (and thus cannot be decrypted).
|
|
46
|
-
# When they are encountered, the orignal value is returned.
|
|
47
|
-
# Otherwise, returns the decrypted string
|
|
48
|
-
def decrypt(value)
|
|
49
|
-
return value if value == '' || value.nil?
|
|
50
|
-
iv, value = Base64::decode64(value.to_s).split(SEPARATOR)
|
|
51
|
-
aes.decrypt
|
|
52
|
-
aes.key = key
|
|
53
|
-
aes.iv = iv
|
|
54
|
-
aes.update(value) + aes.final
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
def legacy
|
|
60
|
-
unless ENV['CRYPT_KEEPER_IGNORE_LEGACY_DEPRECATION']
|
|
61
|
-
warn "[DEPRECATION] AES Legacy is now deprecated. Please see http://git.io/uYcp2A"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require 'crypt_keeper/log_subscriber/mysql_aes'
|
|
2
|
-
|
|
3
|
-
module CryptKeeper
|
|
4
|
-
module Provider
|
|
5
|
-
class MysqlAes
|
|
6
|
-
include CryptKeeper::Helper::SQL
|
|
7
|
-
|
|
8
|
-
attr_accessor :key
|
|
9
|
-
|
|
10
|
-
# Public: Initializes the encryptor
|
|
11
|
-
#
|
|
12
|
-
# options - A hash, :key is required
|
|
13
|
-
def initialize(options = {})
|
|
14
|
-
legacy
|
|
15
|
-
ActiveSupport.run_load_hooks(:crypt_keeper_mysql_aes_log, self)
|
|
16
|
-
|
|
17
|
-
@key = options.fetch(:key) do
|
|
18
|
-
raise ArgumentError, "Missing :key"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Public: Encrypts a string
|
|
23
|
-
#
|
|
24
|
-
# Returns an encrypted string
|
|
25
|
-
def encrypt(value)
|
|
26
|
-
Base64.encode64 escape_and_execute_sql(
|
|
27
|
-
["SELECT AES_ENCRYPT(?, ?)", value, key]).first
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Public: Decrypts a string
|
|
31
|
-
#
|
|
32
|
-
# Returns a plaintext string
|
|
33
|
-
def decrypt(value)
|
|
34
|
-
escape_and_execute_sql(
|
|
35
|
-
["SELECT AES_DECRYPT(?, ?)", Base64.decode64(value), key]).first
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def legacy
|
|
41
|
-
unless ENV['CRYPT_KEEPER_IGNORE_LEGACY_DEPRECATION']
|
|
42
|
-
warn "[DEPRECATION] MySqlAes Legacy is now deprecated. Please see http://git.io/nXXOlg"
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|