pivotal-sentry 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +58 -0
- data/MIT-LICENSE +20 -0
- data/README +94 -0
- data/RUNNING_UNIT_TESTS +42 -0
- data/Rakefile +192 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/active_record/sentry.rb +94 -0
- data/lib/sentry.rb +46 -0
- data/lib/sentry/asymmetric_sentry.rb +144 -0
- data/lib/sentry/asymmetric_sentry_callback.rb +17 -0
- data/lib/sentry/sha_sentry.rb +41 -0
- data/lib/sentry/symmetric_sentry.rb +79 -0
- data/lib/sentry/symmetric_sentry_callback.rb +17 -0
- data/tasks/sentry.rake +9 -0
- data/test/abstract_unit.rb +44 -0
- data/test/asymmetric_sentry_callback_test.rb +72 -0
- data/test/asymmetric_sentry_test.rb +88 -0
- data/test/database.yml +18 -0
- data/test/fixtures/user.rb +26 -0
- data/test/fixtures/users.yml +10 -0
- data/test/keys/encrypted_private +12 -0
- data/test/keys/encrypted_public +4 -0
- data/test/keys/private +9 -0
- data/test/keys/public +4 -0
- data/test/schema.rb +10 -0
- data/test/sha_sentry_test.rb +35 -0
- data/test/symmetric_sentry_callback_test.rb +38 -0
- data/test/symmetric_sentry_test.rb +37 -0
- data/test/tests.rb +2 -0
- metadata +92 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class AsymmetricSentryTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@str = 'sentry'
|
6
|
+
@key = 'secret'
|
7
|
+
@public_key_file = File.dirname(__FILE__) + '/keys/public'
|
8
|
+
@private_key_file = File.dirname(__FILE__) + '/keys/private'
|
9
|
+
@encrypted_public_key_file = File.dirname(__FILE__) + '/keys/encrypted_public'
|
10
|
+
@encrypted_private_key_file = File.dirname(__FILE__) + '/keys/encrypted_private'
|
11
|
+
@sentry = Sentry::AsymmetricSentry.new
|
12
|
+
|
13
|
+
@orig = 'sentry'
|
14
|
+
@data = "vYfMxtVB8ezXmQKSNqTC9sPgi8TbsYRxWd7DVbpprzyuEdZ7gftJ/0IXsbXm\nXCU08bTAl0uEFm7dau+eJMXEJg==\n"
|
15
|
+
@encrypted_data = "q2obYAITmK93ylzVS01mJx1jSlnmylMX15nFpb4uKesVgnqvtzBRHZ/SK+Nm\nEzceIoAcJc3DHosVa4VUE/aK/A==\n"
|
16
|
+
Sentry::AsymmetricSentry.default_public_key_file = nil
|
17
|
+
Sentry::AsymmetricSentry.default_private_key_file = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_decrypt_files
|
21
|
+
set_key_files @public_key_file, @private_key_file
|
22
|
+
assert_equal @orig, @sentry.decrypt_from_base64(@data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_decrypt_files_with_encrypted_key
|
26
|
+
set_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
27
|
+
assert_equal @orig, @sentry.decrypt_from_base64(@encrypted_data, @key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_read_key_files
|
31
|
+
assert !@sentry.public?
|
32
|
+
assert !@sentry.private?
|
33
|
+
set_key_files @public_key_file, @private_key_file
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_read_encrypted_key_files
|
37
|
+
assert !@sentry.public?
|
38
|
+
assert !@sentry.private?
|
39
|
+
set_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_decrypt_files_with_default_key
|
43
|
+
set_default_key_files @public_key_file, @private_key_file
|
44
|
+
assert_equal @orig, @sentry.decrypt_from_base64(@data)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_decrypt_files_with_default_encrypted_key
|
48
|
+
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
49
|
+
assert_equal @orig, @sentry.decrypt_from_base64(@encrypted_data, @key)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_decrypt_files_with_default_key_using_class_method
|
53
|
+
set_default_key_files @public_key_file, @private_key_file
|
54
|
+
assert_equal @orig, Sentry::AsymmetricSentry.decrypt_from_base64(@data)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_decrypt_files_with_default_encrypted_key_using_class_method
|
58
|
+
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
59
|
+
assert_equal @orig, Sentry::AsymmetricSentry.decrypt_from_base64(@encrypted_data, @key)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_should_read_key_files_with_default_key
|
63
|
+
assert !@sentry.public?
|
64
|
+
assert !@sentry.private?
|
65
|
+
set_default_key_files @public_key_file, @private_key_file
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_read_encrypted_key_files_with_default_key
|
69
|
+
assert !@sentry.public?
|
70
|
+
assert !@sentry.private?
|
71
|
+
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def set_key_files(public_key, private_key)
|
76
|
+
@sentry.public_key_file = public_key
|
77
|
+
@sentry.private_key_file = private_key
|
78
|
+
assert @sentry.private?
|
79
|
+
assert @sentry.public?
|
80
|
+
end
|
81
|
+
|
82
|
+
def set_default_key_files(public_key, private_key)
|
83
|
+
Sentry::AsymmetricSentry.default_public_key_file = public_key
|
84
|
+
Sentry::AsymmetricSentry.default_private_key_file = private_key
|
85
|
+
assert @sentry.private?
|
86
|
+
assert @sentry.public?
|
87
|
+
end
|
88
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
|
+
:dbfile: sentry_plugin.sqlite.db
|
4
|
+
sqlite3:
|
5
|
+
:adapter: sqlite3
|
6
|
+
:dbfile: sentry_plugin.sqlite3.db
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:username: postgres
|
10
|
+
:password: postgres
|
11
|
+
:database: sentry_plugin_test
|
12
|
+
:min_messages: ERROR
|
13
|
+
mysql:
|
14
|
+
:adapter: mysql
|
15
|
+
:host: localhost
|
16
|
+
:username: root
|
17
|
+
:password: password
|
18
|
+
:database: sentry_plugin_test
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
#define_read_methods
|
3
|
+
generates_crypted :creditcard, :mode => :asymmetric
|
4
|
+
|
5
|
+
#def self.validates_password
|
6
|
+
# validates_presence_of :password
|
7
|
+
# validates_presence_of :password, :on => :create
|
8
|
+
# validates_length_of :password, :in => 4..40
|
9
|
+
#end
|
10
|
+
end
|
11
|
+
|
12
|
+
#class ShaUser < User
|
13
|
+
# validates_password
|
14
|
+
# validates_confirmation_of :password
|
15
|
+
# generates_crypted :password # sha is used by default
|
16
|
+
#end
|
17
|
+
#
|
18
|
+
#class DangerousUser < User # no password confirmation
|
19
|
+
## validates_password
|
20
|
+
# generates_crypted :password
|
21
|
+
#end
|
22
|
+
#
|
23
|
+
#class SymmetricUser < User
|
24
|
+
# validates_password
|
25
|
+
# generates_crypted :password, :mode => :symmetric
|
26
|
+
#end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
user_1:
|
2
|
+
id: 1
|
3
|
+
login: bob
|
4
|
+
password: "0XlmUuNpE2k=\n"
|
5
|
+
creditcard: "vYfMxtVB8ezXmQKSNqTC9sPgi8TbsYRxWd7DVbpprzyuEdZ7gftJ/0IXsbXm\nXCU08bTAl0uEFm7dau+eJMXEJg==\n"
|
6
|
+
user_2:
|
7
|
+
id: 2
|
8
|
+
login: fred
|
9
|
+
creditcard: "q2obYAITmK93ylzVS01mJx1jSlnmylMX15nFpb4uKesVgnqvtzBRHZ/SK+Nm\nEzceIoAcJc3DHosVa4VUE/aK/A==\n"
|
10
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
OBNa1q8kbx8pyZZjIpr/pZV0oulE2czh5JlPW/13XsBvoz+A2zxA9gchhi6c
|
2
|
+
3yvfqgcZdojcsep+IiTqeg3gOPB2xNbedpP1lm+9tEfgdb9r1CLzRcURh7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vv+pnZtazIWMq9
|
7
|
+
2IQwmn1oM2bJAiEAhgP869mVRIzzi091UCG79tn+4DU0FPLasI+P5VD1mcECIQDb
|
8
|
+
3ndvbPcElVvdJgabxyWJJsNtBBNZYPsuc6NrQyShOw==
|
9
|
+
-----END RSA PRIVATE KEY-----
|
data/test/keys/public
ADDED
data/test/schema.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 1) do
|
2
|
+
|
3
|
+
create_table "users", :force => true do |t|
|
4
|
+
t.column :password, :string, :limit => 255
|
5
|
+
t.column :creditcard, :string, :limit => 255
|
6
|
+
t.column :login, :string, :limit => 50
|
7
|
+
t.column :type, :string, :limit => 20
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/user'
|
3
|
+
|
4
|
+
class ShaSentryTest < Test::Unit::TestCase
|
5
|
+
def test_foo
|
6
|
+
assert true
|
7
|
+
end
|
8
|
+
|
9
|
+
#def setup
|
10
|
+
# Sentry::ShaSentry.salt = 'salt'
|
11
|
+
#end
|
12
|
+
#
|
13
|
+
#def test_should_encrypt
|
14
|
+
# assert_equal 'f438229716cab43569496f3a3630b3727524b81b', Sentry::ShaSentry.encrypt('test')
|
15
|
+
#end
|
16
|
+
#
|
17
|
+
#def test_should_encrypt_with_salt
|
18
|
+
# Sentry::ShaSentry.salt = 'different salt'
|
19
|
+
# assert_equal '18e3256d71529db8fa65b2eef24a69ddad7070f3', Sentry::ShaSentry.encrypt('test')
|
20
|
+
#end
|
21
|
+
#
|
22
|
+
#def test_should_encrypt_user_password
|
23
|
+
# u = ShaUser.new :login => 'bob'
|
24
|
+
# u.password = u.password_confirmation = 'test'
|
25
|
+
# assert u.save
|
26
|
+
# assert u.crypted_password = 'f438229716cab43569496f3a3630b3727524b81b'
|
27
|
+
#end
|
28
|
+
#
|
29
|
+
#def test_should_encrypt_user_password_without_confirmation
|
30
|
+
# u = DangerousUser.new :login => 'bob'
|
31
|
+
# u.password = 'test'
|
32
|
+
# assert u.save
|
33
|
+
# assert u.crypted_password = 'f438229716cab43569496f3a3630b3727524b81b'
|
34
|
+
#end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/user'
|
3
|
+
|
4
|
+
class SymmetricSentryCallbackTest < ActiveSupport::TestCase
|
5
|
+
#fixtures :users
|
6
|
+
#
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@str = 'sentry'
|
10
|
+
Sentry::SymmetricSentry.default_key = @key = 'secret'
|
11
|
+
@encrypted = "0XlmUuNpE2k=\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_foo
|
15
|
+
assert true
|
16
|
+
end
|
17
|
+
#
|
18
|
+
#def test_should_encrypt_user_password
|
19
|
+
# u = SymmetricUser.new :login => 'bob'
|
20
|
+
# u.password = @str
|
21
|
+
# assert u.save
|
22
|
+
# assert_equal @encrypted, u.crypted_password
|
23
|
+
#end
|
24
|
+
#
|
25
|
+
#def test_should_decrypted_user_password
|
26
|
+
# assert_equal @str, users(:user_1).password
|
27
|
+
#end
|
28
|
+
#
|
29
|
+
#def test_should_return_nil_on_invalid_key
|
30
|
+
# Sentry::SymmetricSentry.default_key = 'other secret'
|
31
|
+
# assert_nil users(:user_1).password
|
32
|
+
#end
|
33
|
+
#
|
34
|
+
#def test_should_raise_error_on_invalid_key
|
35
|
+
# Sentry::SymmetricSentry.default_key = 'other secret'
|
36
|
+
# assert_raises(OpenSSL::CipherError) { users(:user_1).password! }
|
37
|
+
#end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class SymmetricSentryTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@str = 'sentry'
|
6
|
+
@key = 'secret'
|
7
|
+
@encrypted = "0XlmUuNpE2k=\n"
|
8
|
+
@sentry = Sentry::SymmetricSentry.new
|
9
|
+
Sentry::SymmetricSentry.default_key = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_encrypt
|
13
|
+
assert_equal @encrypted, @sentry.encrypt_to_base64(@str, @key)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_decrypt
|
17
|
+
assert_equal @str, @sentry.decrypt_from_base64(@encrypted, @key)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_encrypt_with_default_key
|
21
|
+
Sentry::SymmetricSentry.default_key = @key
|
22
|
+
assert_equal @encrypted, @sentry.encrypt_to_base64(@str)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_decrypt_with_default_key
|
26
|
+
Sentry::SymmetricSentry.default_key = @key
|
27
|
+
assert_equal @str, @sentry.decrypt_from_base64(@encrypted)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_raise_error_when_encrypt_with_no_key
|
31
|
+
assert_raises(Sentry::NoKeyError) { @sentry.encrypt_to_base64(@str) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_raise_error_when_decrypt_with_no_key
|
35
|
+
assert_raises(Sentry::NoKeyError) { @sentry.decrypt_from_base64(@str) }
|
36
|
+
end
|
37
|
+
end
|
data/test/tests.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pivotal-sentry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Pelly
|
8
|
+
- David Stevenson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-07-29 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Asymmetric encryption of active record fields
|
18
|
+
email: commoncode@pivotallabs.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- CHANGELOG
|
28
|
+
- MIT-LICENSE
|
29
|
+
- README
|
30
|
+
- RUNNING_UNIT_TESTS
|
31
|
+
- Rakefile
|
32
|
+
- VERSION
|
33
|
+
- init.rb
|
34
|
+
- lib/active_record/sentry.rb
|
35
|
+
- lib/sentry.rb
|
36
|
+
- lib/sentry/asymmetric_sentry.rb
|
37
|
+
- lib/sentry/asymmetric_sentry_callback.rb
|
38
|
+
- lib/sentry/sha_sentry.rb
|
39
|
+
- lib/sentry/symmetric_sentry.rb
|
40
|
+
- lib/sentry/symmetric_sentry_callback.rb
|
41
|
+
- tasks/sentry.rake
|
42
|
+
- test/abstract_unit.rb
|
43
|
+
- test/asymmetric_sentry_callback_test.rb
|
44
|
+
- test/asymmetric_sentry_test.rb
|
45
|
+
- test/database.yml
|
46
|
+
- test/fixtures/user.rb
|
47
|
+
- test/fixtures/users.yml
|
48
|
+
- test/keys/encrypted_private
|
49
|
+
- test/keys/encrypted_public
|
50
|
+
- test/keys/private
|
51
|
+
- test/keys/public
|
52
|
+
- test/schema.rb
|
53
|
+
- test/sha_sentry_test.rb
|
54
|
+
- test/symmetric_sentry_callback_test.rb
|
55
|
+
- test/symmetric_sentry_test.rb
|
56
|
+
- test/tests.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/pivotal/sentry
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.2.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: Asymmetric encryption of active record fields
|
83
|
+
test_files:
|
84
|
+
- test/abstract_unit.rb
|
85
|
+
- test/asymmetric_sentry_callback_test.rb
|
86
|
+
- test/asymmetric_sentry_test.rb
|
87
|
+
- test/fixtures/user.rb
|
88
|
+
- test/schema.rb
|
89
|
+
- test/sha_sentry_test.rb
|
90
|
+
- test/symmetric_sentry_callback_test.rb
|
91
|
+
- test/symmetric_sentry_test.rb
|
92
|
+
- test/tests.rb
|