crypt_keeper 0.22.0 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +5 -1
  4. data/Appraisals +6 -6
  5. data/README.md +8 -20
  6. data/Rakefile +7 -3
  7. data/crypt_keeper.gemspec +5 -5
  8. data/gemfiles/{activerecord_4_1.gemfile → activerecord_5_0.gemfile} +2 -2
  9. data/lib/crypt_keeper.rb +1 -2
  10. data/lib/crypt_keeper/helper.rb +0 -18
  11. data/lib/crypt_keeper/log_subscriber/mysql_aes.rb +7 -9
  12. data/lib/crypt_keeper/log_subscriber/postgres_pgp.rb +7 -9
  13. data/lib/crypt_keeper/model.rb +14 -20
  14. data/lib/crypt_keeper/provider/aes_new.rb +1 -1
  15. data/lib/crypt_keeper/provider/base.rb +21 -0
  16. data/lib/crypt_keeper/provider/mysql_aes_new.rb +1 -1
  17. data/lib/crypt_keeper/provider/postgres_pgp.rb +2 -2
  18. data/lib/crypt_keeper/provider/postgres_pgp_public_key.rb +1 -1
  19. data/lib/crypt_keeper/version.rb +1 -1
  20. data/spec/crypt_keeper/log_subscriber/mysql_aes_spec.rb +56 -0
  21. data/spec/crypt_keeper/log_subscriber/postgres_pgp_spec.rb +94 -0
  22. data/spec/crypt_keeper/model_spec.rb +172 -0
  23. data/spec/crypt_keeper/provider/aes_new_spec.rb +41 -0
  24. data/spec/crypt_keeper/provider/mysql_aes_new_spec.rb +50 -0
  25. data/spec/crypt_keeper/provider/postgres_pgp_public_key_spec.rb +66 -0
  26. data/spec/crypt_keeper/provider/postgres_pgp_spec.rb +66 -0
  27. data/spec/spec_helper.rb +0 -1
  28. data/spec/support/encryptors.rb +9 -3
  29. data/spec/support/logging.rb +92 -0
  30. metadata +37 -44
  31. data/gemfiles/activerecord_4_1.gemfile.lock +0 -120
  32. data/gemfiles/activerecord_4_2.gemfile.lock +0 -120
  33. data/lib/crypt_keeper/provider/aes.rb +0 -66
  34. data/lib/crypt_keeper/provider/mysql_aes.rb +0 -47
  35. data/spec/log_subscriber/mysql_aes_spec.rb +0 -73
  36. data/spec/log_subscriber/postgres_pgp_spec.rb +0 -123
  37. data/spec/model_spec.rb +0 -169
  38. data/spec/provider/aes_new_spec.rb +0 -45
  39. data/spec/provider/aes_spec.rb +0 -67
  40. data/spec/provider/mysql_aes_new_spec.rb +0 -54
  41. data/spec/provider/mysql_aes_spec.rb +0 -35
  42. data/spec/provider/postgres_pgp_public_key_spec.rb +0 -70
  43. data/spec/provider/postgres_pgp_spec.rb +0 -70
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CryptKeeper
4
- module Provider
5
- describe AesNew do
6
- subject { AesNew.new(key: 'cake', salt: 'salt') }
7
-
8
- describe "#initialize" do
9
- let(:digested_key) do
10
- ::Armor.digest('cake', 'salt')
11
- end
12
-
13
- its(:key) { should == digested_key }
14
- specify { expect { AesNew.new }.to raise_error(ArgumentError, "Missing :key") }
15
- end
16
-
17
- describe "#encrypt" do
18
- let(:encrypted) do
19
- subject.encrypt 'string'
20
- end
21
-
22
- specify { encrypted.should_not == 'string' }
23
- specify { encrypted.should_not be_blank }
24
- end
25
-
26
- describe "#decrypt" do
27
- let(:decrypted) do
28
- subject.decrypt "V02ebRU2wLk25AizasROVg==$kE+IpRaUNdBfYqR+WjMqvA=="
29
- end
30
-
31
- specify { decrypted.should == 'string' }
32
- end
33
-
34
- describe "#search" do
35
- let(:records) do
36
- [{ name: 'Bob' }, { name: 'Tim' }]
37
- end
38
-
39
- it "finds the matching record" do
40
- expect(subject.search(records, :name, 'Bob')).to eql([records.first])
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CryptKeeper
4
- module Provider
5
- describe Aes do
6
- subject { Aes.new(key: 'cake') }
7
-
8
- describe "#initialize" do
9
- let(:hexed_key) do
10
- Digest::SHA256.digest('cake')
11
- end
12
-
13
- its(:key) { should == hexed_key }
14
- specify { expect { Aes.new }.to raise_error(ArgumentError, "Missing :key") }
15
- end
16
-
17
- describe "#encrypt" do
18
- let(:encrypted) do
19
- subject.encrypt 'string'
20
- end
21
-
22
- specify { encrypted.should_not == 'string' }
23
- specify { encrypted.should_not be_blank }
24
-
25
- context "an empty string" do
26
- let(:encrypted) do
27
- subject.encrypt ''
28
- end
29
-
30
- specify { encrypted.should == '' }
31
- end
32
-
33
- context "a nil" do
34
- let(:encrypted) do
35
- subject.encrypt nil
36
- end
37
-
38
- specify { encrypted.should be_nil }
39
- end
40
- end
41
-
42
- describe "#decrypt" do
43
- let(:decrypted) do
44
- subject.decrypt "MC41MDk5MjI2NjgxMDI1MDI2OmNyeXB0X2tlZXBlcjpPI/8dCqWXDMVj7Jqs\nuwf/\n"
45
- end
46
-
47
- specify { decrypted.should == 'string' }
48
-
49
- context "an empty string" do
50
- let(:decrypted) do
51
- subject.decrypt ''
52
- end
53
-
54
- specify { decrypted.should == '' }
55
- end
56
-
57
- context "a nil" do
58
- let(:decrypted) do
59
- subject.decrypt nil
60
- end
61
-
62
- specify { decrypted.should be_nil }
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CryptKeeper
4
- module Provider
5
- describe MysqlAesNew do
6
- use_mysql
7
-
8
- let(:plain_text) { 'test' }
9
-
10
- # MySQL stores AES encrypted strings in binary which you can't paste
11
- # into a spec :). This is a Base64 encoded string of 'test' AES encrypted
12
- # by AES_ENCRYPT()
13
- let(:cipher_text) do
14
- "fBN8i7bx/DGAA4NJ4EWi0A=="
15
- end
16
-
17
- subject { MysqlAesNew.new key: ENCRYPTION_PASSWORD, salt: 'salt' }
18
-
19
- its(:key) { should == "825e8c5e8ca394818b307b22b8cb7d3df2735e9c1e5838b476e7719135a4f499f2133022c1a0e8597c9ac1507b0f0c44328a40049f9704fab3598c5dec120724" }
20
-
21
- describe "#initialize" do
22
- specify { expect { MysqlAesNew.new }.to raise_error(ArgumentError, "Missing :key") }
23
- specify { expect { MysqlAesNew.new(key: 'blah') }.to raise_error(ArgumentError, "Missing :salt") }
24
- end
25
-
26
- describe "#encrypt" do
27
- specify { subject.encrypt(plain_text).should_not == plain_text }
28
- specify { subject.encrypt(plain_text).should_not be_blank }
29
- end
30
-
31
- describe "#decrypt" do
32
- specify { subject.decrypt(cipher_text).should == plain_text }
33
- end
34
-
35
- describe "#search" do
36
- subject { mysql_model }
37
-
38
- it "finds the matching record" do
39
- subject.create!(storage: 'blah2')
40
- match = subject.create!(storage: 'blah')
41
- results = subject.search_by_plaintext(:storage, 'blah').first.should == match
42
- end
43
-
44
- it "keeps the scope" do
45
- subject.create!(storage: 'blah')
46
- subject.create!(storage: 'blah')
47
-
48
- scope = subject.limit(1)
49
- expect(scope.search_by_plaintext(:storage, 'blah').count).to eql(1)
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CryptKeeper
4
- module Provider
5
- describe MysqlAes do
6
- use_mysql
7
-
8
- let(:plain_text) { 'test' }
9
-
10
- # MySQL stores AES encrypted strings in binary which you can't paste
11
- # into a spec :). This is a Base64 encoded string of 'test' AES encrypted
12
- # by AES_ENCRYPT()
13
- let(:cipher_text) do
14
- "nbKOoWn8kvAw9k/C2Mex6Q==\n"
15
- end
16
-
17
- subject { MysqlAes.new key: 'candy' }
18
-
19
- its(:key) { should == 'candy' }
20
-
21
- describe "#initialize" do
22
- specify { expect { MysqlAes.new }.to raise_error(ArgumentError, "Missing :key") }
23
- end
24
-
25
- describe "#encrypt" do
26
- specify { subject.encrypt(plain_text).should_not == plain_text }
27
- specify { subject.encrypt(plain_text).should_not be_blank }
28
- end
29
-
30
- describe "#decrypt" do
31
- specify { subject.decrypt(cipher_text).should == plain_text }
32
- end
33
- end
34
- end
35
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CryptKeeper
4
- module Provider
5
- describe PostgresPgpPublicKey do
6
- use_postgres
7
-
8
- let(:cipher_text) { '\xc1c04c036c401ad086beb9e3010800987d6c4ccd974322190caa75a3a01aba37bc1970182c4c1d3faec98edf186780520f0586101f286e0626096a1eca91a229ed4d4058a6913a8d13cdf49f29ea44e2b96d10347f9b1b860bb3c959f000a3b1b415a95d2cd07af8c74aa6df8cd10ab06b6a6f7db69cdf3185466d68c5b66b95b813acdfb3ddfb021cac92e0967d67e90df73332f27970c1d2b9a56ac74f602d4107b163ed73ef89fca560d9a0a0d2bc7a74005f29fa27babfbaf950ac07b1c809049db4ab126be4824cf76416c278571f7064f638edf830a1ae5ee1ab544d35fce0f974f21b9dcbbea3986077d27b0de34144dc23f369f471090b57e067a056901e680493ddf2a6b29e4af3462387d235010259556079d07daa249b6703e2bc79345da556cfb46f228cad40a8a5b569ac46f08865f9176acf89129a3e0ceb2a7b1991012f65' }
9
-
10
- let(:integer_cipher_text) { '\xc1c04c036c401ad086beb9e30107ff59e674ba05958eb053c2427b44355e0f333f1726e18a0b851130130510c648f580b13b3f6a223eb26e397008596867c5a511a4f5bfbf2ecc852d8929814480d63166e525fa2b259b6a8d4474b5b1373b4e1a4fe70a491d25442e1c0046fd3d69466ad30153c8d8d920e9b4260d4e4e421ef3ead162b3aba5d85408c4ef9f9d342b5655c7568d1bdc61c27ddb419133bf091f22f42e7bc91ec6d279b7b25b87ea65119568b85ae81079dd0a6a7258b58fb219c6cc4580f33cb46de97770a1eb0880bdf87426fd0529576a1e791e521d9b3c426e393e63d83321f319b00f9dc4027ea5a81dd57c0f5ba868fb86d73179c34f2287c437266e8becc072b45a929562d2320194be54464e03854635d0f7d7fb10813adbc6efe51efa9095a9bacc2a03fb5c41d1c1896384e4f36b100c0f00e81d4cff7d' }
11
-
12
- let(:integer_plain_text) { 1 }
13
- let(:plain_text) { 'test' }
14
-
15
- let(:public_key) do
16
- IO.read(File.join(SPEC_ROOT, 'fixtures', 'public.asc'))
17
- end
18
-
19
- let(:private_key) do
20
- IO.read(File.join(SPEC_ROOT, 'fixtures', 'private.asc'))
21
- end
22
-
23
- subject { PostgresPgpPublicKey.new key: ENCRYPTION_PASSWORD, public_key: public_key, private_key: private_key }
24
-
25
-
26
- its(:key) { should == ENCRYPTION_PASSWORD }
27
-
28
- describe "#initialize" do
29
- specify { expect { PostgresPgpPublicKey.new }.to raise_error(ArgumentError, "Missing :key") }
30
- end
31
-
32
- describe "#encrypt" do
33
- context "Strings" do
34
- specify { subject.encrypt(plain_text).should_not == plain_text }
35
- specify { subject.encrypt(plain_text).should_not be_empty }
36
-
37
- it "does not double encrypt" do
38
- pgp = PostgresPgpPublicKey.new key: ENCRYPTION_PASSWORD, public_key: public_key
39
- pgp.encrypt(cipher_text).should == cipher_text
40
- end
41
- end
42
-
43
- context "Integers" do
44
- specify { subject.encrypt(integer_plain_text).should_not == integer_plain_text }
45
- specify { subject.encrypt(integer_plain_text).should_not be_empty }
46
- end
47
- end
48
-
49
- describe "#decrypt" do
50
- specify { subject.decrypt(cipher_text).should == plain_text }
51
- specify { subject.decrypt(integer_cipher_text).should == integer_plain_text.to_s }
52
-
53
- it "does not decrypt w/o private key" do
54
- pgp = PostgresPgpPublicKey.new key: ENCRYPTION_PASSWORD, public_key: public_key
55
- pgp.decrypt(cipher_text).should eql(cipher_text)
56
- end
57
- end
58
-
59
- describe "#encrypted?" do
60
- it "returns true for encrypted strings" do
61
- subject.encrypted?(cipher_text).should be_true
62
- end
63
-
64
- it "returns false for non-encrypted strings" do
65
- subject.encrypted?(plain_text).should be_false
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CryptKeeper
4
- module Provider
5
- describe PostgresPgp do
6
- use_postgres
7
-
8
- let(:cipher_text) { '\xc30d04070302f1a092093988b26873d235017203ce086a53fce1925dc39b4e972e534f192d10b94af3dcf8589abc1f828456f5d3e20b225d56006ffd1e312e3b8a492a6010e9' }
9
- let(:plain_text) { 'test' }
10
-
11
- let(:integer_cipher_text) { '\xc30d04070302c8d266353bcf2fc07dd23201153f9d9c32fbb3c36b9b0db137bf8b6c609172210d89ded63f11dff23d1ddbf5111c0266549dde26175c4425e06bb4bd6f' }
12
-
13
- let(:integer_plain_text) { 1 }
14
-
15
- subject { PostgresPgp.new key: ENCRYPTION_PASSWORD }
16
-
17
- its(:key) { should == ENCRYPTION_PASSWORD }
18
-
19
- describe "#initialize" do
20
- specify { expect { PostgresPgp.new }.to raise_error(ArgumentError, "Missing :key") }
21
- end
22
-
23
- describe "#encrypt" do
24
- context "Strings" do
25
- specify { subject.encrypt(plain_text).should_not == plain_text }
26
- specify { subject.encrypt(plain_text).should_not be_empty }
27
- end
28
-
29
- context "Integers" do
30
- specify { subject.encrypt(integer_plain_text).should_not == integer_plain_text }
31
- specify { subject.encrypt(integer_plain_text).should_not be_empty }
32
- end
33
- end
34
-
35
- describe "#decrypt" do
36
- specify { subject.decrypt(cipher_text).should == plain_text }
37
- specify { subject.decrypt(integer_cipher_text).should == integer_plain_text.to_s }
38
- end
39
-
40
- describe "#search" do
41
- subject { postgres_model }
42
-
43
- it "finds the matching record" do
44
- subject.create!(storage: 'blah2')
45
- match = subject.create!(storage: 'blah')
46
- subject.search_by_plaintext(:storage, 'blah').first.should == match
47
- end
48
- end
49
-
50
- describe "Custom pgcrypto options" do
51
- let(:pgcrypto_options) { 'compress-level=0' }
52
-
53
- subject { PostgresPgp.new key: 'candy', pgcrypto_options: pgcrypto_options }
54
-
55
- it "reads and writes" do
56
- queries = logged_queries do
57
- encrypted = subject.encrypt(plain_text)
58
- subject.decrypt(encrypted).should == plain_text
59
- end
60
-
61
- queries.should_not be_empty
62
-
63
- queries.select { |query| query.include?("pgp_sym_encrypt") }.each do |q|
64
- q.should include(pgcrypto_options)
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end