bcrypt4 4.0.0

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: 5871335afc77bc0f3fdce7abeb73ade14a8e22bb
4
+ data.tar.gz: 0b65214f452642a96c0445c7cf14b488e09bea51
5
+ SHA512:
6
+ metadata.gz: 8ef66298da8777c5f3e6c7c509d7bf0a923911eaeefe796fd2a620a99186a412b3c44e5da0561f30bc15ebac414fa41cc2849dff78788d4e077e9c312af0c3ca
7
+ data.tar.gz: 3e7a0dd8e904e85f2b07f5cb91871fe8530168a5f85339d8bde538d54243907164e29231c0f354215b080b5815aa316bcc1a2ebf1bed6c5658d2d8fe134c5bc0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ doc
2
+ pkg
3
+ tmp
4
+ *.o
5
+ *.bundle
6
+ *.so
7
+ *.jar
8
+ .DS_Store
9
+ .rbenv-gemsets
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --backtrace
3
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - 2.2.0
9
+ - 2.3.0
10
+ - ruby-head
11
+ - jruby-18mode
12
+ - jruby-19mode
13
+ - jruby-head
14
+ - rbx-2
15
+ - ree
16
+ script: bundle exec rake
data/CHANGELOG ADDED
@@ -0,0 +1,87 @@
1
+ 1.0.0 Feb 27 2007
2
+ - Initial release.
3
+
4
+ 2.0.0 Mar 07 2007
5
+ - Removed BCrypt::Password#exactly_equals -- use BCrypt::Password#eql? instead.
6
+ - Added BCrypt::Password#is_password?.
7
+ - Refactored out BCrypt::Internals into more useful BCrypt::Engine.
8
+ - Added validation of secrets -- nil is not healthy.
9
+
10
+ 2.0.1 Mar 09 2007
11
+ - Fixed load path issues
12
+ - Fixed crashes when hashing weird values (e.g., false, etc.)
13
+
14
+ 2.0.2 Jun 06 2007
15
+ - Fixed example code in the README [Winson]
16
+ - Fixed Solaris compatibility [Jeremy LaTrasse, Twitter crew]
17
+
18
+ 2.0.3 May 07 2008
19
+ - Made exception classes descend from StandardError, not Exception [Dan42]
20
+ - Changed BCrypt::Engine.hash to BCrypt::Engine.hash_secret to avoid Merb
21
+ sorting issues. [Lee Pope]
22
+
23
+ 2.0.4 Mar 09 2009
24
+ - Added Ruby 1.9 compatibility. [Genki Takiuchi]
25
+ - Fixed segfaults on some different types of empty strings. [Mike Pomraning]
26
+
27
+ 2.0.5 Mar 11 2009
28
+ - Fixed Ruby 1.8.5 compatibility. [Mike Pomraning]
29
+
30
+ 2.1.0 Aug 12 2009
31
+ - Improved code coverage, unit tests, and build chain. [Hongli Lai]
32
+ - Ruby 1.9 compatibility fixes. [Hongli Lai]
33
+ - JRuby support, using Damien Miller's jBCrypt. [Hongli Lai]
34
+ - Ruby 1.9 GIL releasing for high-cost hashes. [Hongli Lai]
35
+
36
+ 2.1.1 Aug 14 2009
37
+ - JVM 1.4/1.5 compatibility [Hongli Lai]
38
+
39
+ 2.1.2 Sep 16 2009
40
+ - Fixed support for Solaris, OpenSolaris.
41
+
42
+ 3.0.0 Aug 24 2011
43
+ - Bcrypt C implementation replaced with a public domain implementation.
44
+ - License changed to MIT
45
+
46
+ 3.0.1 Sep 12 2011
47
+ - create raises an exception if the cost is higher than 31. GH #27
48
+
49
+ 3.1.0 May 07 2013
50
+ - Add BCrypt::Password.valid_hash?(str) to check if a string is a valid bcrypt password hash
51
+ - BCrypt::Password cost should be set to DEFAULT_COST if nil
52
+ - Add BCrypt::Engine.cost attribute for getting/setting a default cost externally
53
+
54
+ 3.1.1 Jul 10 2013
55
+ - Remove support for Ruby 1.8 in compiled win32 binaries
56
+
57
+ 3.1.2 Aug 26 2013
58
+ - Add support for Ruby 1.8 and 2.0 (in addition to 1.9) in compiled Windows binaries
59
+ - Add support for 64-bit Windows
60
+
61
+ 3.1.3 Feb 21 2014
62
+ - Add support for Ruby 2.1 in compiled Windows binaries
63
+ - Rename gem from "bcrypt-ruby" to just "bcrypt". [GH #86 by @sferik]
64
+
65
+ 3.1.6 Feb 21 2014
66
+ - Dummy version of "bcrypt-ruby" needed a couple version bumps to fix some
67
+ bugs. It felt wrong to have that at a higher version than the real gem, so
68
+ the real gem is getting bumped to 3.1.6.
69
+
70
+ 3.1.7 Feb 24 2014
71
+ - Rebuild corrupt Java binary version of gem [GH #90]
72
+ - The 2.1 support for Windows binaries alleged in 3.1.3 was a lie -- documentation removed
73
+
74
+ 3.1.8 Oct 23 2014
75
+ - Add support for Ruby 2.1 in compiled Windows binaries [GH #102]
76
+
77
+ 3.1.9 Oct 23 2014
78
+ - Rebuild corrupt binaries
79
+
80
+ 3.1.10 Jan 28 2015
81
+ - Fix issue with dumping a BCrypt::Password instance to YAML in Ruby 2.2 [GH #107 by @mattwildig]
82
+
83
+ 3.1.11 Mar 06 2016
84
+ - Add support for Ruby 2.2 in compiled Windows binaries
85
+
86
+ 4.0.0 Jul 14 2017
87
+ - Fork of project to update blowfish 1.1 to 1.3
data/COPYING ADDED
@@ -0,0 +1,28 @@
1
+ (The MIT License)
2
+
3
+ Copyright 2007-2011:
4
+
5
+ * Coda Hale <coda.hale@gmail.com>
6
+
7
+ C implementation of the BCrypt algorithm by Solar Designer and placed in the
8
+ public domain.
9
+ jBCrypt is Copyright (c) 2006 Damien Miller <djm@mindrot.org>.
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining
12
+ a copy of this software and associated documentation files (the
13
+ 'Software'), to deal in the Software without restriction, including
14
+ without limitation the rights to use, copy, modify, merge, publish,
15
+ distribute, sublicense, and/or sell copies of the Software, and to
16
+ permit persons to whom the Software is furnished to do so, subject to
17
+ the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be
20
+ included in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bcrypt4 (4.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ json (1.8.3)
11
+ json (1.8.3-java)
12
+ rake (10.4.2)
13
+ rake-compiler (0.9.5)
14
+ rake
15
+ rdoc (3.12.2)
16
+ json (~> 1.4)
17
+ rspec (3.3.0)
18
+ rspec-core (~> 3.3.0)
19
+ rspec-expectations (~> 3.3.0)
20
+ rspec-mocks (~> 3.3.0)
21
+ rspec-core (3.3.2)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-expectations (3.3.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-mocks (3.3.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-support (3.3.0)
30
+
31
+ PLATFORMS
32
+ java
33
+ ruby
34
+ x64-mingw32
35
+ x86-mingw32
36
+
37
+ DEPENDENCIES
38
+ bcrypt4!
39
+ rake-compiler (~> 0.9.2)
40
+ rdoc (~> 3.12)
41
+ rspec (>= 3)
42
+
43
+ BUNDLED WITH
44
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # bcrypt-ruby
2
+
3
+ An easy way to keep your users' passwords secure.
4
+
5
+ * http://github.com/codahale/bcrypt-ruby/tree/master
6
+
7
+ [![Build Status](https://travis-ci.org/codahale/bcrypt-ruby.png?branch=master)](https://travis-ci.org/codahale/bcrypt-ruby)
8
+
9
+ ## Why you should use `bcrypt()`
10
+
11
+ If you store user passwords in the clear, then an attacker who steals a copy of your database has a giant list of emails
12
+ and passwords. Some of your users will only have one password -- for their email account, for their banking account, for
13
+ your application. A simple hack could escalate into massive identity theft.
14
+
15
+ It's your responsibility as a web developer to make your web application secure -- blaming your users for not being
16
+ security experts is not a professional response to risk.
17
+
18
+ `bcrypt()` allows you to easily harden your application against these kinds of attacks.
19
+
20
+ *Note*: JRuby versions of the bcrypt gem `<= 2.1.3` had a [security
21
+ vulnerability](http://www.mindrot.org/files/jBCrypt/internat.adv) that
22
+ was fixed in `>= 2.1.4`. If you used a vulnerable version to hash
23
+ passwords with international characters in them, you will need to
24
+ re-hash those passwords. This vulnerability only affected the JRuby gem.
25
+
26
+ ## How to install bcrypt
27
+
28
+ gem install bcrypt4
29
+
30
+ The bcrypt gem is available on the following ruby platforms:
31
+
32
+ * JRuby
33
+ * RubyInstaller 1.8, 1.9, 2.0, 2.1, and 2.2 builds on win32
34
+ * Any 1.8, 1.9, 2.0, 2.1, 2.2, or 2.3 Ruby on a BSD/OS X/Linux system with a compiler
35
+
36
+ ## How to use `bcrypt()` in your Rails application
37
+
38
+ *Note*: Rails versions >= 3 ship with `ActiveModel::SecurePassword` which uses bcrypt-ruby.
39
+ `has_secure_password` [docs](http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password)
40
+ implements a similar authentication strategy to the code below.
41
+
42
+ ### The _User_ model
43
+
44
+ require 'bcrypt'
45
+
46
+ class User < ActiveRecord::Base
47
+ # users.password_hash in the database is a :string
48
+ include BCrypt
49
+
50
+ def password
51
+ @password ||= Password.new(password_hash)
52
+ end
53
+
54
+ def password=(new_password)
55
+ @password = Password.create(new_password)
56
+ self.password_hash = @password
57
+ end
58
+ end
59
+
60
+ ### Creating an account
61
+
62
+ def create
63
+ @user = User.new(params[:user])
64
+ @user.password = params[:password]
65
+ @user.save!
66
+ end
67
+
68
+ ### Authenticating a user
69
+
70
+ def login
71
+ @user = User.find_by_email(params[:email])
72
+ if @user.password == params[:password]
73
+ give_token
74
+ else
75
+ redirect_to home_url
76
+ end
77
+ end
78
+
79
+ ## How to use bcrypt-ruby in general
80
+
81
+ require 'bcrypt'
82
+
83
+ my_password = BCrypt::Password.create("my password")
84
+ #=> "$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"
85
+
86
+ my_password.version #=> "2a"
87
+ my_password.cost #=> 10
88
+ my_password == "my password" #=> true
89
+ my_password == "not my password" #=> false
90
+
91
+ my_password = BCrypt::Password.new("$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa")
92
+ my_password == "my password" #=> true
93
+ my_password == "not my password" #=> false
94
+
95
+ Check the rdocs for more details -- BCrypt, BCrypt::Password.
96
+
97
+ ## How `bcrypt()` works
98
+
99
+ `bcrypt()` is a hashing algorithm designed by Niels Provos and David Mazières of the OpenBSD Project.
100
+
101
+ ### Background
102
+
103
+ Hash algorithms take a chunk of data (e.g., your user's password) and create a "digital fingerprint," or hash, of it.
104
+ Because this process is not reversible, there's no way to go from the hash back to the password.
105
+
106
+ In other words:
107
+
108
+ hash(p) #=> <unique gibberish>
109
+
110
+ You can store the hash and check it against a hash made of a potentially valid password:
111
+
112
+ <unique gibberish> =? hash(just_entered_password)
113
+
114
+ ### Rainbow Tables
115
+
116
+ But even this has weaknesses -- attackers can just run lists of possible passwords through the same algorithm, store the
117
+ results in a big database, and then look up the passwords by their hash:
118
+
119
+ PrecomputedPassword.find_by_hash(<unique gibberish>).password #=> "secret1"
120
+
121
+ ### Salts
122
+
123
+ The solution to this is to add a small chunk of random data -- called a salt -- to the password before it's hashed:
124
+
125
+ hash(salt + p) #=> <really unique gibberish>
126
+
127
+ The salt is then stored along with the hash in the database, and used to check potentially valid passwords:
128
+
129
+ <really unique gibberish> =? hash(salt + just_entered_password)
130
+
131
+ bcrypt-ruby automatically handles the storage and generation of these salts for you.
132
+
133
+ Adding a salt means that an attacker has to have a gigantic database for each unique salt -- for a salt made of 4
134
+ letters, that's 456,976 different databases. Pretty much no one has that much storage space, so attackers try a
135
+ different, slower method -- throw a list of potential passwords at each individual password:
136
+
137
+ hash(salt + "aadvark") =? <really unique gibberish>
138
+ hash(salt + "abacus") =? <really unique gibberish>
139
+ etc.
140
+
141
+ This is much slower than the big database approach, but most hash algorithms are pretty quick -- and therein lies the
142
+ problem. Hash algorithms aren't usually designed to be slow, they're designed to turn gigabytes of data into secure
143
+ fingerprints as quickly as possible. `bcrypt()`, though, is designed to be computationally expensive:
144
+
145
+ Ten thousand iterations:
146
+ user system total real
147
+ md5 0.070000 0.000000 0.070000 ( 0.070415)
148
+ bcrypt 22.230000 0.080000 22.310000 ( 22.493822)
149
+
150
+ If an attacker was using Ruby to check each password, they could check ~140,000 passwords a second with MD5 but only
151
+ ~450 passwords a second with `bcrypt()`.
152
+
153
+ ### Cost Factors
154
+
155
+ In addition, `bcrypt()` allows you to increase the amount of work required to hash a password as computers get faster. Old
156
+ passwords will still work fine, but new passwords can keep up with the times.
157
+
158
+ The default cost factor used by bcrypt-ruby is 10, which is fine for session-based authentication. If you are using a
159
+ stateless authentication architecture (e.g., HTTP Basic Auth), you will want to lower the cost factor to reduce your
160
+ server load and keep your request times down. This will lower the security provided you, but there are few alternatives.
161
+
162
+ To change the default cost factor used by bcrypt-ruby, use `BCrypt::Engine.cost = new_value`:
163
+
164
+ BCrypt::Password.create('secret').cost
165
+ #=> 10, the default provided by bcrypt-ruby
166
+
167
+ # set a new default cost
168
+ BCrypt::Engine.cost = 8
169
+ BCrypt::Password.create('secret').cost
170
+ #=> 8
171
+
172
+ The default cost can be overridden as needed by passing an options hash with a different cost:
173
+
174
+ BCrypt::Password.create('secret', :cost => 6).cost #=> 6
175
+
176
+ ## More Information
177
+
178
+ `bcrypt()` is currently used as the default password storage hash in OpenBSD, widely regarded as the most secure operating
179
+ system available.
180
+
181
+ For a more technical explanation of the algorithm and its design criteria, please read Niels Provos and David Mazières'
182
+ Usenix99 paper:
183
+ http://www.usenix.org/events/usenix99/provos.html
184
+
185
+ If you'd like more down-to-earth advice regarding cryptography, I suggest reading <i>Practical Cryptography</i> by Niels
186
+ Ferguson and Bruce Schneier:
187
+ http://www.schneier.com/book-practical.html
188
+
189
+ # Etc
190
+
191
+ * Author :: Coda Hale <coda.hale@gmail.com>
192
+ * Website :: http://blog.codahale.com
data/Rakefile ADDED
@@ -0,0 +1,93 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'rubygems/package_task'
3
+ require 'rake/extensiontask'
4
+ require 'rake/javaextensiontask'
5
+ require 'rake/clean'
6
+ require 'rdoc/task'
7
+ require 'benchmark'
8
+
9
+ CLEAN.include(
10
+ "tmp",
11
+ "lib/1.8",
12
+ "lib/1.9",
13
+ "lib/2.0",
14
+ "lib/2.1",
15
+ "lib/bcrypt_ext.jar",
16
+ "lib/bcrypt_ext.so"
17
+ )
18
+ CLOBBER.include(
19
+ "doc",
20
+ "pkg"
21
+ )
22
+
23
+ GEMSPEC = Gem::Specification.load("bcrypt.gemspec")
24
+
25
+ task :default => [:compile, :spec]
26
+
27
+ desc "Run all specs"
28
+ RSpec::Core::RakeTask.new do |t|
29
+ t.pattern = 'spec/**/*_spec.rb'
30
+ t.ruby_opts = '-w'
31
+ end
32
+
33
+ desc "Run all specs, with coverage testing"
34
+ RSpec::Core::RakeTask.new(:rcov) do |t|
35
+ t.pattern = 'spec/**/*_spec.rb'
36
+ t.rcov = true
37
+ t.rcov_path = 'doc/coverage'
38
+ t.rcov_opts = ['--exclude', 'rspec,diff-lcs,rcov,_spec,_helper']
39
+ end
40
+
41
+ desc 'Generate RDoc'
42
+ RDoc::Task.new do |rdoc|
43
+ rdoc.rdoc_dir = 'doc/rdoc'
44
+ rdoc.options += GEMSPEC.rdoc_options
45
+ rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE']
46
+ rdoc.rdoc_files.include(*GEMSPEC.extra_rdoc_files)
47
+ end
48
+
49
+ Gem::PackageTask.new(GEMSPEC) do |pkg|
50
+ pkg.need_zip = true
51
+ pkg.need_tar = true
52
+ end
53
+
54
+ if RUBY_PLATFORM =~ /java/
55
+ Rake::JavaExtensionTask.new('bcrypt_ext', GEMSPEC) do |ext|
56
+ ext.ext_dir = 'ext/jruby'
57
+ end
58
+ else
59
+ Rake::ExtensionTask.new("bcrypt_ext", GEMSPEC) do |ext|
60
+ ext.ext_dir = 'ext/mri'
61
+ ext.cross_compile = true
62
+ ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
63
+ end
64
+
65
+ ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
66
+ platforms = {
67
+ "x86-mingw32" => "i686-w64-mingw32",
68
+ "x64-mingw32" => "x86_64-w64-mingw32"
69
+ }
70
+ platforms.each do |platform, prefix|
71
+ task "copy:bcrypt_ext:#{platform}:#{ruby_version}" do |t|
72
+ %w[lib tmp/#{platform}/stage/lib].each do |dir|
73
+ so_file = "#{dir}/#{ruby_version[/^\d+\.\d+/]}/bcrypt_ext.so"
74
+ if File.exists?(so_file)
75
+ sh "#{prefix}-strip -S #{so_file}"
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ desc "Run a set of benchmarks on the compiled extension."
84
+ task :benchmark do
85
+ TESTS = 100
86
+ TEST_PWD = "this is a test"
87
+ require File.expand_path(File.join(File.dirname(__FILE__), "lib", "bcrypt"))
88
+ Benchmark.bmbm do |results|
89
+ 4.upto(10) do |n|
90
+ results.report("cost #{n}:") { TESTS.times { BCrypt::Password.create(TEST_PWD, :cost => n) } }
91
+ end
92
+ end
93
+ end
data/bcrypt4.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'bcrypt4'
3
+ s.version = '4.0.0'
4
+
5
+ s.summary = "OpenBSD's bcrypt() password hashing algorithm."
6
+ s.description = <<-EOF
7
+ bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project
8
+ for hashing passwords. The bcrypt Ruby gem provides a simple wrapper for safely handling
9
+ passwords.
10
+ EOF
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.require_path = 'lib'
14
+
15
+ s.add_development_dependency 'rake-compiler', '~> 0.9.2'
16
+ s.add_development_dependency 'rspec', '>= 3'
17
+ s.add_development_dependency 'rdoc', '~> 3.12'
18
+
19
+ s.has_rdoc = true
20
+ s.rdoc_options += ['--title', 'bcrypt-ruby', '--line-numbers', '--inline-source', '--main', 'README.md']
21
+ s.extra_rdoc_files += ['README.md', 'COPYING', 'CHANGELOG', *Dir['lib/**/*.rb']]
22
+
23
+ s.extensions = 'ext/mri/extconf.rb'
24
+
25
+ s.authors = ["Coda Hale"]
26
+ s.email = "coda.hale@gmail.com"
27
+ s.homepage = "https://github.com/dissolve/bcrypt-ruby"
28
+ s.license = "MIT"
29
+ end