bcrypt_hmac 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dc8ded37446060c52250bd5b78d9192b692a6ae
4
+ data.tar.gz: e74a7a2c83e4d54b0d58a663f50fec0a685a25e7
5
+ SHA512:
6
+ metadata.gz: e251ea5c2ae86722e37ebcb857736e4591c1a8b2d80ca6b31140cce51057870903166d3aa9cc0ced0917433512878f8b5ccff98f381b30325656740d8d522413
7
+ data.tar.gz: f9b152d4eed9407a807014a1edfce5ef50b6554467d9ed8024bee5806179c5052bbe2b3df324ca85c8de99847f8875f9a915b31701b98f72e7a8db1976c5d0eb
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,153 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bcrypt_hmac (0.1.2)
5
+ bcrypt (~> 3)
6
+ devise-encryptable (~> 0)
7
+ rails (~> 4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.6)
13
+ actionpack (= 4.2.6)
14
+ actionview (= 4.2.6)
15
+ activejob (= 4.2.6)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.6)
19
+ actionview (= 4.2.6)
20
+ activesupport (= 4.2.6)
21
+ rack (~> 1.6)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ actionview (4.2.6)
26
+ activesupport (= 4.2.6)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
+ activejob (4.2.6)
32
+ activesupport (= 4.2.6)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.6)
35
+ activesupport (= 4.2.6)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.6)
38
+ activemodel (= 4.2.6)
39
+ activesupport (= 4.2.6)
40
+ arel (~> 6.0)
41
+ activesupport (4.2.6)
42
+ i18n (~> 0.7)
43
+ json (~> 1.7, >= 1.7.7)
44
+ minitest (~> 5.1)
45
+ thread_safe (~> 0.3, >= 0.3.4)
46
+ tzinfo (~> 1.1)
47
+ arel (6.0.3)
48
+ bcrypt (3.1.11)
49
+ builder (3.2.2)
50
+ coderay (1.1.0)
51
+ concurrent-ruby (1.0.2)
52
+ devise (4.1.1)
53
+ bcrypt (~> 3.0)
54
+ orm_adapter (~> 0.1)
55
+ railties (>= 4.1.0, < 5.1)
56
+ responders
57
+ warden (~> 1.2.3)
58
+ devise-encryptable (0.2.0)
59
+ devise (>= 2.1.0)
60
+ diff-lcs (1.2.5)
61
+ erubis (2.7.0)
62
+ globalid (0.3.6)
63
+ activesupport (>= 4.1.0)
64
+ i18n (0.7.0)
65
+ json (1.8.3)
66
+ loofah (2.0.3)
67
+ nokogiri (>= 1.5.9)
68
+ mail (2.6.4)
69
+ mime-types (>= 1.16, < 4)
70
+ method_source (0.8.2)
71
+ mime-types (3.0)
72
+ mime-types-data (~> 3.2015)
73
+ mime-types-data (3.2016.0521)
74
+ mini_portile2 (2.1.0)
75
+ minitest (5.9.0)
76
+ nokogiri (1.6.8)
77
+ mini_portile2 (~> 2.1.0)
78
+ pkg-config (~> 1.1.7)
79
+ orm_adapter (0.5.0)
80
+ pkg-config (1.1.7)
81
+ pry (0.10.0)
82
+ coderay (~> 1.1.0)
83
+ method_source (~> 0.8.1)
84
+ slop (~> 3.4)
85
+ rack (1.6.4)
86
+ rack-test (0.6.3)
87
+ rack (>= 1.0)
88
+ rails (4.2.6)
89
+ actionmailer (= 4.2.6)
90
+ actionpack (= 4.2.6)
91
+ actionview (= 4.2.6)
92
+ activejob (= 4.2.6)
93
+ activemodel (= 4.2.6)
94
+ activerecord (= 4.2.6)
95
+ activesupport (= 4.2.6)
96
+ bundler (>= 1.3.0, < 2.0)
97
+ railties (= 4.2.6)
98
+ sprockets-rails
99
+ rails-deprecated_sanitizer (1.0.3)
100
+ activesupport (>= 4.2.0.alpha)
101
+ rails-dom-testing (1.0.7)
102
+ activesupport (>= 4.2.0.beta, < 5.0)
103
+ nokogiri (~> 1.6.0)
104
+ rails-deprecated_sanitizer (>= 1.0.1)
105
+ rails-html-sanitizer (1.0.3)
106
+ loofah (~> 2.0)
107
+ railties (4.2.6)
108
+ actionpack (= 4.2.6)
109
+ activesupport (= 4.2.6)
110
+ rake (>= 0.8.7)
111
+ thor (>= 0.18.1, < 2.0)
112
+ rake (10.3.2)
113
+ responders (2.2.0)
114
+ railties (>= 4.2.0, < 5.1)
115
+ rspec (3.0.0)
116
+ rspec-core (~> 3.0.0)
117
+ rspec-expectations (~> 3.0.0)
118
+ rspec-mocks (~> 3.0.0)
119
+ rspec-core (3.0.3)
120
+ rspec-support (~> 3.0.0)
121
+ rspec-expectations (3.0.3)
122
+ diff-lcs (>= 1.2.0, < 2.0)
123
+ rspec-support (~> 3.0.0)
124
+ rspec-mocks (3.0.3)
125
+ rspec-support (~> 3.0.0)
126
+ rspec-support (3.0.3)
127
+ slop (3.6.0)
128
+ sprockets (3.6.0)
129
+ concurrent-ruby (~> 1.0)
130
+ rack (> 1, < 3)
131
+ sprockets-rails (3.0.4)
132
+ actionpack (>= 4.0)
133
+ activesupport (>= 4.0)
134
+ sprockets (>= 3.0.0)
135
+ thor (0.19.1)
136
+ thread_safe (0.3.5)
137
+ tzinfo (1.2.2)
138
+ thread_safe (~> 0.1)
139
+ warden (1.2.6)
140
+ rack (>= 1.0)
141
+
142
+ PLATFORMS
143
+ ruby
144
+
145
+ DEPENDENCIES
146
+ bcrypt_hmac!
147
+ bundler (~> 1.6)
148
+ pry (~> 0.10)
149
+ rake (~> 10.0)
150
+ rspec (~> 3.0)
151
+
152
+ BUNDLED WITH
153
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Spreemo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ bcrypt_hmac
2
+ ===========
3
+
4
+ bcrypt + hmac password encryption for devise
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bcrypt_hmac/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bcrypt_hmac'
8
+ spec.version = BcryptHmac::VERSION
9
+ spec.authors = ['ben lamothe']
10
+ spec.email = ['ben.lamothe@spreemo.com']
11
+ spec.summary = 'Devise BCrypt + SHA256-HMAC Encryptor'
12
+ spec.homepage = 'https://github.com/spreemo/bcrypt_hmac'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'bcrypt', '~> 3'
21
+ spec.add_dependency 'devise-encryptable', '~> 0'
22
+ spec.add_dependency 'rails', '~> 4'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'pry', '~> 0.10'
28
+ end
@@ -0,0 +1,51 @@
1
+ require 'devise'
2
+ require 'devise-encryptable'
3
+ require 'bcrypt'
4
+ require 'bcrypt_hmac/railtie' if defined?(Rails)
5
+
6
+ module BcryptHmac
7
+ class Encryptor < Devise::Encryptable::Encryptors::Base
8
+ def self.digest(password, stretches = nil, _salt = nil, pepper = nil)
9
+ pre_bcrypt_hash = prepare_for_bcrypt(password, pepper.to_s)
10
+
11
+ if stretches
12
+ BCrypt::Password.create(pre_bcrypt_hash, cost: stretches.to_i)
13
+ else
14
+ BCrypt::Password.create(pre_bcrypt_hash)
15
+ end
16
+ end
17
+
18
+ def self.compare(encrypted_password, password, _stretches = nil,
19
+ _salt = nil, pepper = nil)
20
+ sanitized_bcrypt_hash = ruby_sanitize(encrypted_password)
21
+ correct_password = BCrypt::Password.new(sanitized_bcrypt_hash)
22
+ proposed_password = prepare_for_bcrypt(password, pepper.to_s)
23
+
24
+ correct_password == proposed_password
25
+ end
26
+
27
+ # bcrypt-ruby doesn't support the '2y' prefix in hashes generated in php and
28
+ # other languages. '2y' has to be replaced with '2a' in order to recognize
29
+ # these hashes in ruby. See http://stackoverflow.com/a/20981781/1545518
30
+ def self.ruby_sanitize(bcrypt_hash)
31
+ if bcrypt_hash.starts_with?('$2y')
32
+ bcrypt_hash.sub('$2y', '$2a')
33
+ else
34
+ bcrypt_hash
35
+ end
36
+ end
37
+ private_class_method :ruby_sanitize
38
+
39
+ def self.prepare_for_bcrypt(password, hmac_key)
40
+ Base64.encode64(sha256_hash(password, hmac_key))
41
+ end
42
+ private_class_method :prepare_for_bcrypt
43
+
44
+ def self.sha256_hash(password, hmac_key)
45
+ sha256 = OpenSSL::Digest.new('sha256')
46
+ OpenSSL::HMAC.digest(sha256, hmac_key, password)
47
+ end
48
+ private_class_method :sha256_hash
49
+
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ require 'devise'
2
+ require 'devise-encryptable'
3
+
4
+ module BcryptHmac
5
+ class Railtie < Rails::Railtie
6
+ initializer 'bcrypt_hmac.define_devise_encryptor' do
7
+ Devise::Encryptable::Encryptors.const_set 'BcryptHmac', BcryptHmac::Encryptor
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module BcryptHmac
2
+ VERSION = '0.1.2'.freeze
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe BcryptHmac::Encryptor do
4
+ let(:hmac_key) do
5
+ 'MzFjMzFlNGQ5MjQ3YmViZGYyOGI3NTkyYzA2YzE5NDQ1OWE2ZTMxYw=='
6
+ end
7
+
8
+ let(:bcrypt_cost) { '12' }
9
+
10
+ let(:password) { 'super secret password' }
11
+
12
+ let(:sha256_hmac_hashed_password) do
13
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), hmac_key, password)
14
+ end
15
+
16
+ let(:base64_encoded_hmac_hash) do
17
+ Base64.encode64(sha256_hmac_hashed_password)
18
+ end
19
+
20
+ let(:bcrypt_hashed_password) do
21
+ BCrypt::Password.create(base64_encoded_hmac_hash, cost: bcrypt_cost.to_i)
22
+ end
23
+
24
+ describe '::digest' do
25
+ subject do
26
+ BcryptHmac::Encryptor.digest(password, bcrypt_cost, nil, hmac_key)
27
+ end
28
+
29
+ it { is_expected.to eq(base64_encoded_hmac_hash) }
30
+ end
31
+
32
+ describe '::compare' do
33
+ subject do
34
+ BcryptHmac::Encryptor.compare(bcrypt_hashed_password, password,
35
+ bcrypt_cost, nil, hmac_key)
36
+ end
37
+
38
+ it { is_expected.to be_truthy }
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ require 'bcrypt_hmac'
2
+ require 'pry'
3
+
4
+ require 'bundler/setup'
5
+ Bundler.setup
6
+
7
+ RSpec.configure do |config|
8
+ config.filter_run :focus
9
+ config.run_all_when_everything_filtered = true
10
+
11
+ config.default_formatter = 'doc' if config.files_to_run.one?
12
+
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.syntax = :expect
15
+ end
16
+
17
+ config.mock_with :rspec do |mocks|
18
+ mocks.syntax = :expect
19
+ mocks.verify_partial_doubles = true
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcrypt_hmac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - ben lamothe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: devise-encryptable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ description:
112
+ email:
113
+ - ben.lamothe@spreemo.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - bcrypt_hmac.gemspec
126
+ - lib/bcrypt_hmac.rb
127
+ - lib/bcrypt_hmac/railtie.rb
128
+ - lib/bcrypt_hmac/version.rb
129
+ - spec/bcrypt_hmac_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: https://github.com/spreemo/bcrypt_hmac
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Devise BCrypt + SHA256-HMAC Encryptor
155
+ test_files:
156
+ - spec/bcrypt_hmac_spec.rb
157
+ - spec/spec_helper.rb
158
+ has_rdoc: