crypt_keeper 0.5.0 → 0.6.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.
- data/README.md +1 -1
- data/gemfiles/activerecord_3_0.gemfile.lock +1 -1
- data/gemfiles/activerecord_3_1.gemfile.lock +1 -1
- data/gemfiles/activerecord_3_2.gemfile.lock +1 -1
- data/lib/crypt_keeper.rb +1 -5
- data/lib/crypt_keeper/helper.rb +13 -0
- data/lib/crypt_keeper/model.rb +4 -0
- data/lib/crypt_keeper/provider/mysql_aes.rb +6 -10
- data/lib/crypt_keeper/provider/postgres_pgp.rb +2 -9
- data/lib/crypt_keeper/version.rb +1 -1
- data/spec/log_subscriber/{mysql_aes.rb → mysql_aes_spec.rb} +2 -2
- data/spec/log_subscriber/{postgres_pgp.rb → postgres_pgp_spec.rb} +2 -2
- data/spec/provider/mysql_aes_spec.rb +1 -1
- data/spec/provider/postgres_pgp_spec.rb +9 -1
- metadata +9 -8
data/README.md
CHANGED
@@ -15,7 +15,7 @@ is a simple class that does 3 things.
|
|
15
15
|
Note: Any options defined using `crypt_keeper` will be passed to `new` as a
|
16
16
|
hash.
|
17
17
|
|
18
|
-
You can see an AES example [here](/jmazzi/crypt_keeper/blob/master/lib/crypt_keeper/provider/aes.rb).
|
18
|
+
You can see an AES example [here](https://github.com/jmazzi/crypt_keeper/blob/master/lib/crypt_keeper/provider/aes.rb).
|
19
19
|
|
20
20
|
## Why?
|
21
21
|
|
data/lib/crypt_keeper.rb
CHANGED
@@ -2,14 +2,10 @@ require 'active_record'
|
|
2
2
|
|
3
3
|
require 'crypt_keeper/version'
|
4
4
|
require 'crypt_keeper/model'
|
5
|
-
|
5
|
+
require 'crypt_keeper/helper'
|
6
6
|
require 'crypt_keeper/provider/aes'
|
7
7
|
require 'crypt_keeper/provider/mysql_aes'
|
8
8
|
require 'crypt_keeper/provider/postgres_pgp'
|
9
9
|
|
10
10
|
module CryptKeeper
|
11
11
|
end
|
12
|
-
|
13
|
-
ActiveSupport.on_load :active_record do
|
14
|
-
include CryptKeeper::Model
|
15
|
-
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CryptKeeper
|
2
|
+
module Helper
|
3
|
+
module SQL
|
4
|
+
private
|
5
|
+
|
6
|
+
# Private: Sanitize an sql query and then execute it
|
7
|
+
def escape_and_execute_sql(query)
|
8
|
+
query = ::ActiveRecord::Base.send :sanitize_sql_array, query
|
9
|
+
::ActiveRecord::Base.connection.execute(query).first
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/crypt_keeper/model.rb
CHANGED
@@ -3,6 +3,8 @@ require 'crypt_keeper/log_subscriber/mysql_aes'
|
|
3
3
|
module CryptKeeper
|
4
4
|
module Provider
|
5
5
|
class MysqlAes
|
6
|
+
include CryptKeeper::Helper::SQL
|
7
|
+
|
6
8
|
attr_accessor :key
|
7
9
|
|
8
10
|
# Public: Initializes the encryptor
|
@@ -18,22 +20,16 @@ module CryptKeeper
|
|
18
20
|
#
|
19
21
|
# Returns an encrypted string
|
20
22
|
def encrypt(value)
|
21
|
-
escape_and_execute_sql(
|
23
|
+
Base64.encode64 escape_and_execute_sql(
|
24
|
+
["SELECT AES_ENCRYPT(?, ?)", value, key]).first
|
22
25
|
end
|
23
26
|
|
24
27
|
# Public: Decrypts a string
|
25
28
|
#
|
26
29
|
# Returns a plaintext string
|
27
30
|
def decrypt(value)
|
28
|
-
escape_and_execute_sql(
|
29
|
-
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Private: Sanitize an sql query and then execute it
|
34
|
-
def escape_and_execute_sql(query)
|
35
|
-
query = ::ActiveRecord::Base.send :sanitize_sql_array, query
|
36
|
-
::ActiveRecord::Base.connection.execute(query).first
|
31
|
+
escape_and_execute_sql(
|
32
|
+
["SELECT AES_DECRYPT(?, ?)", Base64.decode64(value), key]).first
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
@@ -3,6 +3,7 @@ require 'crypt_keeper/log_subscriber/postgres_pgp'
|
|
3
3
|
module CryptKeeper
|
4
4
|
module Provider
|
5
5
|
class PostgresPgp
|
6
|
+
include CryptKeeper::Helper::SQL
|
6
7
|
attr_accessor :key
|
7
8
|
|
8
9
|
# Public: Initializes the encryptor
|
@@ -18,7 +19,7 @@ module CryptKeeper
|
|
18
19
|
#
|
19
20
|
# Returns an encrypted string
|
20
21
|
def encrypt(value)
|
21
|
-
escape_and_execute_sql(["SELECT pgp_sym_encrypt(?, ?)", value, key])['pgp_sym_encrypt']
|
22
|
+
escape_and_execute_sql(["SELECT pgp_sym_encrypt(?, ?)", value.to_s, key])['pgp_sym_encrypt']
|
22
23
|
end
|
23
24
|
|
24
25
|
# Public: Decrypts a string
|
@@ -27,14 +28,6 @@ module CryptKeeper
|
|
27
28
|
def decrypt(value)
|
28
29
|
escape_and_execute_sql(["SELECT pgp_sym_decrypt(?, ?)", value, key])['pgp_sym_decrypt']
|
29
30
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Private: Sanitize an sql query and then execute it
|
34
|
-
def escape_and_execute_sql(query)
|
35
|
-
query = ::ActiveRecord::Base.send :sanitize_sql_array, query
|
36
|
-
::ActiveRecord::Base.connection.execute(query).first
|
37
|
-
end
|
38
31
|
end
|
39
32
|
end
|
40
33
|
end
|
data/lib/crypt_keeper/version.rb
CHANGED
@@ -11,7 +11,7 @@ module CryptKeeper
|
|
11
11
|
# into a spec :). This is a Base64 encoded string of 'test' AES encrypted
|
12
12
|
# by AES_ENCRYPT()
|
13
13
|
let(:cipher_text) do
|
14
|
-
|
14
|
+
"nbKOoWn8kvAw9k/C2Mex6Q==\n"
|
15
15
|
end
|
16
16
|
|
17
17
|
subject { MysqlAes.new key: 'candy' }
|
@@ -6,7 +6,10 @@ module CryptKeeper
|
|
6
6
|
use_postgres
|
7
7
|
|
8
8
|
let(:cipher_text) { '\\xc30d0407030283b15f71b6a7d0296cd23501bd2c8fe3c7a56005ff4619527c4291509a78c77a6758cddd2a14acbde589fa10b3e0686865182d3beadaf237b9f928e7ba1810b8' }
|
9
|
-
let(:plain_text)
|
9
|
+
let(:plain_text) { 'test' }
|
10
|
+
|
11
|
+
let(:integer_cipher_text) { '\xc30d040703028c65c58c0e9d015360d2320125112fc38f094e57cce1c0313f3eea4a7fc3e95c048bc319e25003ab6f29ceabe3609089d12094508c1eb79a2d70f95233' }
|
12
|
+
let(:integer_plain_text) { 1 }
|
10
13
|
|
11
14
|
subject { PostgresPgp.new key: 'candy' }
|
12
15
|
|
@@ -23,6 +26,11 @@ module CryptKeeper
|
|
23
26
|
subject.encrypt(plain_text).should_not == plain_text
|
24
27
|
subject.encrypt(plain_text).should_not be_empty
|
25
28
|
end
|
29
|
+
|
30
|
+
it "encrypts integers" do
|
31
|
+
subject.encrypt(integer_plain_text).should_not == integer_plain_text
|
32
|
+
subject.encrypt(integer_plain_text).should_not be_empty
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
36
|
describe "#decrypt" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypt_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- gemfiles/activerecord_3_2.gemfile
|
196
196
|
- gemfiles/activerecord_3_2.gemfile.lock
|
197
197
|
- lib/crypt_keeper.rb
|
198
|
+
- lib/crypt_keeper/helper.rb
|
198
199
|
- lib/crypt_keeper/log_subscriber/mysql_aes.rb
|
199
200
|
- lib/crypt_keeper/log_subscriber/postgres_pgp.rb
|
200
201
|
- lib/crypt_keeper/model.rb
|
@@ -203,8 +204,8 @@ files:
|
|
203
204
|
- lib/crypt_keeper/provider/postgres_pgp.rb
|
204
205
|
- lib/crypt_keeper/version.rb
|
205
206
|
- spec/default.database.yml
|
206
|
-
- spec/log_subscriber/
|
207
|
-
- spec/log_subscriber/
|
207
|
+
- spec/log_subscriber/mysql_aes_spec.rb
|
208
|
+
- spec/log_subscriber/postgres_pgp_spec.rb
|
208
209
|
- spec/model_spec.rb
|
209
210
|
- spec/provider/aes_spec.rb
|
210
211
|
- spec/provider/mysql_aes_spec.rb
|
@@ -226,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
226
227
|
version: '0'
|
227
228
|
segments:
|
228
229
|
- 0
|
229
|
-
hash:
|
230
|
+
hash: 4508045864759288754
|
230
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
232
|
none: false
|
232
233
|
requirements:
|
@@ -235,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
236
|
version: '0'
|
236
237
|
segments:
|
237
238
|
- 0
|
238
|
-
hash:
|
239
|
+
hash: 4508045864759288754
|
239
240
|
requirements: []
|
240
241
|
rubyforge_project:
|
241
242
|
rubygems_version: 1.8.23
|
@@ -244,8 +245,8 @@ specification_version: 3
|
|
244
245
|
summary: Transparent encryption for ActiveRecord that isn't over-engineered
|
245
246
|
test_files:
|
246
247
|
- spec/default.database.yml
|
247
|
-
- spec/log_subscriber/
|
248
|
-
- spec/log_subscriber/
|
248
|
+
- spec/log_subscriber/mysql_aes_spec.rb
|
249
|
+
- spec/log_subscriber/postgres_pgp_spec.rb
|
249
250
|
- spec/model_spec.rb
|
250
251
|
- spec/provider/aes_spec.rb
|
251
252
|
- spec/provider/mysql_aes_spec.rb
|