clearance_crypto 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2009-02-12
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/README.rdoc ADDED
@@ -0,0 +1,64 @@
1
+ = ClearanceCrypto
2
+
3
+ http://github.com/pixels-and-bits/clearance_crypto/tree/master
4
+
5
+ == DESCRIPTION:
6
+
7
+ Provides the ability to choose the encryption method used in the Clearance gem
8
+ like Authlogic
9
+
10
+ == SYNOPSIS:
11
+
12
+ If you want to use a different hashing method than SHA1 with Clearance.
13
+
14
+ You really shouldn't use AES for anything other than hiding info that you need
15
+ to be able to reverse the hash. By default it uses the generated salt. You can
16
+ override this behavior by setting the key before you create the user.
17
+
18
+ class User < ActiveRecord::Base
19
+ include Clearance::App::Models::User
20
+ include ClearanceCrypto::AES256
21
+ end
22
+
23
+ class User < ActiveRecord::Base
24
+ include Clearance::App::Models::User
25
+ include ClearanceCrypto::BCrypt
26
+ end
27
+
28
+ class User < ActiveRecord::Base
29
+ include Clearance::App::Models::User
30
+ include ClearanceCrypto::SHA512
31
+ end
32
+
33
+ == REQUIREMENTS:
34
+
35
+ * Clearance
36
+
37
+ == INSTALL:
38
+
39
+ sudo gem install clearance_crypto
40
+
41
+ == LICENSE:
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2009 FIXME full name
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
64
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ require "digest/sha2"
2
+
3
+ module ClearanceCrypto
4
+ module AES256
5
+ def self.included(model)
6
+ model.send(:include, InstanceMethods)
7
+ end
8
+
9
+ module InstanceMethods
10
+ attr_writer :key
11
+
12
+ def encrypt(string)
13
+ aes.encrypt
14
+ aes.key = @key
15
+ [aes.update(string) + aes.final].pack("m").chomp
16
+ end
17
+
18
+ def authenticated?(string)
19
+ aes.decrypt
20
+ aes.key = @key
21
+ (aes.update(encrypted_password.unpack("m").first) + aes.final) == string
22
+ rescue OpenSSL::CipherError
23
+ false
24
+ end
25
+
26
+ def aes_plain
27
+ aes.decrypt
28
+ aes.key = @key
29
+ (aes.update(encrypted_password.unpack("m").first) + aes.final)
30
+ rescue OpenSSL::CipherError
31
+ ''
32
+ end
33
+
34
+ private
35
+
36
+ def aes
37
+ @key ||= salt
38
+ @aes ||= OpenSSL::Cipher::Cipher.new("AES-256-ECB")
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require "bcrypt"
2
+
3
+ module ClearanceCrypto
4
+ module BCrypt
5
+ def self.included(model)
6
+ model.send(:include, InstanceMethods)
7
+ end
8
+
9
+ module InstanceMethods
10
+ def cost
11
+ @cost ||= 10
12
+ end
13
+ attr_writer :cost
14
+
15
+ # Creates a BCrypt hash for the password passed.
16
+ def encrypt(string)
17
+ ::BCrypt::Password.create(string)
18
+ end
19
+
20
+ # Does the hash match the tokens? Uses the same tokens that were used to encrypt.
21
+ def authenticated?(string)
22
+ ::BCrypt::Password.new(self.encrypted_password) == string rescue false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require "digest/sha2"
2
+
3
+ module ClearanceCrypto
4
+ module SHA512
5
+ def self.included(model)
6
+ model.send(:include, InstanceMethods)
7
+ end
8
+
9
+ module InstanceMethods
10
+ # The number of times to loop through the encryption.
11
+ def stretches
12
+ @stretches ||= 20
13
+ end
14
+ attr_writer :stretches
15
+
16
+ # Turns your raw password into a Sha512 hash.
17
+ def encrypt(string)
18
+ digest = "--#{salt}--#{string}--"
19
+ stretches.times { digest = Digest::SHA512.hexdigest(digest) }
20
+ digest
21
+ end
22
+
23
+ def authenticated?(string)
24
+ encrypt(string) == encrypted_password
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module ClearanceCrypto
5
+ VERSION = '0.1.0'
6
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestClearanceCrypto < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/clearance_crypto'
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clearance_crypto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Moen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-13 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ version:
35
+ description: Provides the ability to choose the encryption method used in the Clearance gem like Authlogic
36
+ email:
37
+ - michael@underpantsgnome.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - README.rdoc
45
+ files:
46
+ - lib/clearance_crypto.rb
47
+ - lib/clearance_crypto/aes256.rb
48
+ - lib/clearance_crypto/sha512.rb
49
+ - lib/clearance_crypto/bcrypt.rb
50
+ - History.txt
51
+ - README.rdoc
52
+ has_rdoc: true
53
+ homepage: http://github.com/pixels-and-bits/clearance_crypto/tree/master
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --main
57
+ - README.rdoc
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project: underpantsgnome
75
+ rubygems_version: 1.3.1
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: Provides the ability to choose the encryption method used in the Clearance gem like Authlogic
79
+ test_files:
80
+ - test/test_clearance_crypto.rb
81
+ - test/test_helper.rb