loyal3-sentry 0.5.0 → 0.5.2

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/Rakefile CHANGED
@@ -9,7 +9,7 @@ require 'rake/testtask'
9
9
  require 'rake/contrib/rubyforgepublisher'
10
10
 
11
11
  PKG_NAME = 'sentry'
12
- PKG_VERSION = '0.3.1'
12
+ PKG_VERSION = '0.5.2'
13
13
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
14
14
  PROD_HOST = "technoweenie@bidwell.textdrive.com"
15
15
  RUBY_FORGE_PROJECT = 'sentry'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.2
@@ -32,11 +32,12 @@ module ActiveRecord # :nodoc:
32
32
  define_method("#{attr_name}_with_decryption") do |*optional|
33
33
  begin
34
34
  crypted_value = self.send("#{attr_name}_without_decryption")
35
+ #puts "crypted value: #{crypted_value}"
35
36
  return nil if crypted_value.nil?
36
37
  key = optional.shift || (options[:key].is_a?(Proc) ? options[:key].call : options[:key]) || ::Sentry.default_key
37
- decrypted_value = ::Sentry::AsymmetricSentry.decrypt_from_base64(crypted_value, key)
38
- return decrypted_value[8,decrypted_value.length-8]
39
- rescue
38
+ decrypted_value = ::Sentry::AsymmetricSentry.decrypt_large_from_base64(crypted_value, key)
39
+ return decrypted_value
40
+ rescue Exception => e
40
41
  nil
41
42
  end
42
43
  end
@@ -58,8 +59,7 @@ module ActiveRecord # :nodoc:
58
59
 
59
60
  def encrypt_for_sentry(string)
60
61
  return nil if string.nil?
61
- padded_value = ActiveRecord::Sentry.rand_string + string
62
- encrypted_value = ::Sentry::AsymmetricSentry.encrypt_to_base64(padded_value)
62
+ return ::Sentry::AsymmetricSentry.encrypt_large_to_base64(string)
63
63
  end
64
64
 
65
65
  private
@@ -13,8 +13,8 @@ module Sentry
13
13
  # * <tt>:symmetric_algorithm</tt> - algorithm to use for SymmetricSentry
14
14
  def initialize(options = {})
15
15
  @public_key = @private_key = nil
16
- private_key_file = options[:private_key_file]
17
- public_key_file = options[:public_key_file] || @@default_public_key_file
16
+ self.private_key_file = options[:private_key_file]
17
+ self.public_key_file = options[:public_key_file] || @@default_public_key_file
18
18
  @symmetric_algorithm = options[:symmetric_algorithm] || @@default_symmetric_algorithm
19
19
  end
20
20
 
@@ -25,9 +25,10 @@ module Sentry
25
25
  end
26
26
 
27
27
  def decrypt_large_from_base64(data, key=nil)
28
- padding_length = data[0]
29
28
  chunk_length = public_rsa.max_encryptable_length + 11 # 11 is magic padding for RSA encoding
30
- data = Base64.decode64(data[1,data.length])
29
+ b64_decoded = Base64.decode64(data)
30
+ padding_length = b64_decoded[0]
31
+ data = b64_decoded[1, data.length]
31
32
  return (0...data.length).step(chunk_length).inject("") { |accum, idx| accum + decrypt_with_padding(data.slice(idx, chunk_length), padding_length, key)}
32
33
  end
33
34
 
@@ -38,7 +39,7 @@ module Sentry
38
39
  def encrypt_large_to_base64(data)
39
40
  padding_length = 8
40
41
  chunk_length = chunk_size(padding_length)
41
- return padding_length.chr + Base64.encode64( (0...data.length).step(chunk_length).inject("") {|accum, idx| accum + encrypt_with_padding( data.slice(idx, chunk_length), padding_length)} )
42
+ return Base64.encode64(padding_length.chr + (0...data.length).step(chunk_length).inject("") {|accum, idx| accum + encrypt_with_padding( data.slice(idx, chunk_length), padding_length)} )
42
43
  end
43
44
 
44
45
  def decrypt_with_padding(data, padding_length, key=nil)
@@ -110,11 +111,19 @@ module Sentry
110
111
  def encrypt_to_base64(data)
111
112
  self.new.encrypt_to_base64(data)
112
113
  end
114
+
115
+ def encrypt_large_to_base64(data)
116
+ self.new.encrypt_large_to_base64(data)
117
+ end
113
118
 
114
119
  def decrypt(data, key = nil)
115
120
  self.new.decrypt(data, key)
116
121
  end
117
122
 
123
+ def decrypt_large_from_base64(data, key = nil)
124
+ self.new.decrypt_large_from_base64(data, key)
125
+ end
126
+
118
127
  def decrypt_from_base64(data, key = nil)
119
128
  self.new.decrypt_from_base64(data, key)
120
129
  end
@@ -156,6 +165,7 @@ module Sentry
156
165
  if @private_key_file and File.file?(@private_key_file)
157
166
  @private_key = File.open(@private_key_file) { |f| f.read }
158
167
  end
168
+ return @private_key
159
169
  end
160
170
 
161
171
  def load_public_key
@@ -5,18 +5,17 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sentry}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Pelly", "David Stevenson"]
12
- s.date = %q{2009-08-18}
12
+ s.date = %q{2009-08-19}
13
13
  s.description = %q{Asymmetric encryption of active record fields}
14
14
  s.email = %q{commoncode@pivotallabs.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
19
  "CHANGELOG",
21
20
  "MIT-LICENSE",
22
21
  "README",
@@ -98,6 +98,10 @@ class AsymmetricSentryCallbackTest < ActiveSupport::TestCase
98
98
  assert_nil users(:user_2).creditcard('other secret')
99
99
  end
100
100
 
101
+ def test_do_encryption
102
+ use_encrypted_keys
103
+ end
104
+
101
105
  def test_should_encrypt_encrypted_creditcard
102
106
  use_encrypted_keys
103
107
  u = User.create :login => 'jones'
@@ -2,6 +2,8 @@ require 'abstract_unit'
2
2
 
3
3
  class AsymmetricSentryTest < Test::Unit::TestCase
4
4
  def setup
5
+ Sentry::AsymmetricSentry.default_public_key_file = nil
6
+ Sentry::AsymmetricSentry.default_private_key_file = nil
5
7
  @str = 'sentry'
6
8
  @key = 'secret'
7
9
  @public_key_file = File.dirname(__FILE__) + '/keys/public'
@@ -13,8 +15,6 @@ class AsymmetricSentryTest < Test::Unit::TestCase
13
15
  @orig = 'sentry'
14
16
  @data = "vYfMxtVB8ezXmQKSNqTC9sPgi8TbsYRxWd7DVbpprzyuEdZ7gftJ/0IXsbXm\nXCU08bTAl0uEFm7dau+eJMXEJg==\n"
15
17
  @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
18
  end
19
19
 
20
20
  def test_should_decrypt_files
@@ -62,13 +62,6 @@ class AsymmetricSentryTest < Test::Unit::TestCase
62
62
  assert_equal @orig, Sentry::AsymmetricSentry.decrypt_from_base64(@data)
63
63
  end
64
64
 
65
- def test_foo
66
- puts "^^^^^^^"
67
- puts `ruby -v`
68
- puts (1...20).step(3).inspect
69
-
70
- end
71
-
72
65
  def test_should_decrypt_files_with_default_encrypted_key_using_class_method
73
66
  set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
74
67
  assert_equal @orig, Sentry::AsymmetricSentry.decrypt_from_base64(@encrypted_data, @key)
@@ -2,8 +2,8 @@ user_1:
2
2
  id: 1
3
3
  login: bob
4
4
  password: "0XlmUuNpE2k=\n"
5
- creditcard: "n0DW3do8BTv5caPgR52CVtZJ4IXh8Fmkpt7k2QnHaxIx63I9ILG+GKKzXuIM\nohtHRSnzcw3gk1gkeDpYml9CoQ==\n" # "sentry" with 8 characters of prepadding
5
+ creditcard: "CBUI2TcYh/ATRB7fYpDBb0t1ifOWPb5jfpO2M8Zy9D/8Gua6/uA+ILHwKtGY\nOgrooPYSxwpBzEZoH18mXqJE7yk=\n" # "sentry" with 8 characters of prepadding
6
6
  user_2:
7
7
  id: 2
8
8
  login: fred
9
- creditcard: "MiIZuZmc7znWzqZuPWYPVATXeJUrfxCNyVYibefs2hfvpna7Godk6RWILXfi\nqRRU0WehLLo1Mq5EuMTTnPi09A==\n" # "sentry" with 8 different characters of prepadding
9
+ creditcard: "CEUx1Ufxi7leQVp0xHhMWKqBcvrb0p3VvX5rqJBXSwddH+Alscs73TEX8Ctn\n9WnV5Ii8txpa20UfM3h5msLpm20=\n" # "sentry" with 8 different characters of prepadding
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loyal3-sentry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Pelly
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-18 00:00:00 -07:00
13
+ date: 2009-08-19 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -23,7 +23,6 @@ extensions: []
23
23
  extra_rdoc_files:
24
24
  - README
25
25
  files:
26
- - .gitignore
27
26
  - CHANGELOG
28
27
  - MIT-LICENSE
29
28
  - README
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- .idea/*
2
- *.log
3
-