bcrypt 3.1.16-java → 3.1.17-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +57 -0
- data/.gitignore +1 -0
- data/CHANGELOG +6 -1
- data/README.md +4 -5
- data/bcrypt.gemspec +2 -2
- data/lib/bcrypt/engine.rb +14 -5
- data/lib/bcrypt/password.rb +12 -2
- data/lib/bcrypt_ext.jar +0 -0
- data/spec/bcrypt/engine_spec.rb +21 -2
- data/spec/bcrypt/password_spec.rb +7 -0
- metadata +7 -7
- data/.travis.yml +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 982723920ec5f97cff8b34987babf6a5f1ee632e8f942e40cf28246940e067d6
|
4
|
+
data.tar.gz: ab2bb1ace746eb5efa5b2ce1d9b1bcc9fe5445899ae3c78510198a6df19152d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79951a4c7612737f25550f701d387d7c7325798eae87d898cccefd83762cf713d9817a19ca29d95b950ed85b32915efbdf7dd93e146a08230135309876a26a27
|
7
|
+
data.tar.gz: d3618098d76210298bb5e05b39f75469cc4f64dfea5e55cc5cebf0372eb8a529b076d771f184e311c564a6d08932b7160fb46355e09188592f7de1608dd65d83
|
@@ -0,0 +1,57 @@
|
|
1
|
+
name: Test Suite
|
2
|
+
|
3
|
+
# Run against all commits and pull requests.
|
4
|
+
on: [ push, pull_request ]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test_matrix:
|
8
|
+
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
os:
|
13
|
+
- ubuntu
|
14
|
+
- macos
|
15
|
+
- windows
|
16
|
+
ruby:
|
17
|
+
- 2.1
|
18
|
+
- 2.2
|
19
|
+
- 2.3
|
20
|
+
- 2.4
|
21
|
+
- 2.5
|
22
|
+
- 2.6
|
23
|
+
- 2.7
|
24
|
+
- '3.0'
|
25
|
+
- 3.1
|
26
|
+
- head
|
27
|
+
- jruby
|
28
|
+
- jruby-head
|
29
|
+
- truffleruby
|
30
|
+
- truffleruby-head
|
31
|
+
- mingw
|
32
|
+
exclude:
|
33
|
+
- { os: ubuntu, ruby: jruby }
|
34
|
+
- { os: ubuntu, ruby: jruby-head }
|
35
|
+
- { os: ubuntu, ruby: mingw }
|
36
|
+
- { os: macos, ruby: mingw }
|
37
|
+
- { os: windows, ruby: truffleruby }
|
38
|
+
- { os: windows, ruby: truffleruby-head }
|
39
|
+
|
40
|
+
runs-on: ${{ matrix.os }}-latest
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- name: Set up Ruby
|
45
|
+
uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: ${{ matrix.ruby }}
|
48
|
+
bundler-cache: true
|
49
|
+
- name: Run tests
|
50
|
+
run: bundle exec rake default
|
51
|
+
|
52
|
+
finish:
|
53
|
+
runs-on: ubuntu-latest
|
54
|
+
needs: [ test_matrix ]
|
55
|
+
steps:
|
56
|
+
- name: Wait for status checks
|
57
|
+
run: echo "All Green!"
|
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
3.1.17 Mar 14 2022
|
2
|
+
- Fix regex in validators to use \A and \z instead of ^ and $ [GH #121]
|
3
|
+
- Truncate secrets greater than 72 bytes in hash_secret [GH #255]
|
4
|
+
- Assorted test and doc improvements
|
5
|
+
|
1
6
|
3.1.16 Sep 3 2020
|
2
7
|
- Fix compilation on FreeBSD. [GH #234]
|
3
8
|
|
@@ -16,7 +21,7 @@
|
|
16
21
|
|
17
22
|
3.1.12 May 16 2018
|
18
23
|
- Add support for Ruby 2.3, 2.4, and 2.5 in compiled Windows binaries
|
19
|
-
- Fix compatibility with libxcrypt [GH #164 by @besser82]
|
24
|
+
- Fix compatibility with libxcrypt - Fixes hash errors in Fedora 28 and Ubuntu 20 [GH #164 by @besser82]
|
20
25
|
|
21
26
|
3.1.11 Mar 06 2016
|
22
27
|
- Add support for Ruby 2.2 in compiled Windows binaries
|
data/README.md
CHANGED
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
An easy way to keep your users' passwords secure.
|
4
4
|
|
5
|
-
* https://github.com/
|
5
|
+
* https://github.com/bcrypt-ruby/bcrypt-ruby/tree/master
|
6
6
|
|
7
|
-
[![
|
7
|
+
[![Github Actions Build Status](https://github.com/bcrypt-ruby/bcrypt-ruby/actions/workflows/ruby.yml/badge.svg?branch=master)](https://github.com/bcrypt-ruby/bcrypt-ruby/actions/workflows/ruby.yml)
|
8
8
|
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/6fplerx9lnaf0hyo?svg=true)](https://ci.appveyor.com/project/TJSchuck35975/bcrypt-ruby)
|
9
9
|
|
10
|
-
|
11
10
|
## Why you should use `bcrypt()`
|
12
11
|
|
13
12
|
If you store user passwords in the clear, then an attacker who steals a copy of your database has a giant list of emails
|
@@ -32,8 +31,8 @@ re-hash those passwords. This vulnerability only affected the JRuby gem.
|
|
32
31
|
The bcrypt gem is available on the following Ruby platforms:
|
33
32
|
|
34
33
|
* JRuby
|
35
|
-
* RubyInstaller 2.0 –
|
36
|
-
* Any 2.0 –
|
34
|
+
* RubyInstaller 2.0 – 3.0 builds on Windows with the DevKit
|
35
|
+
* Any 2.0 – 3.0 Ruby on a BSD/OS X/Linux system with a compiler
|
37
36
|
|
38
37
|
## How to use `bcrypt()` in your Rails application
|
39
38
|
|
data/bcrypt.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'bcrypt'
|
3
|
-
s.version = '3.1.
|
3
|
+
s.version = '3.1.17'
|
4
4
|
|
5
5
|
s.summary = "OpenBSD's bcrypt() password hashing algorithm."
|
6
6
|
s.description = <<-EOF
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.authors = ["Coda Hale"]
|
24
24
|
s.email = "coda.hale@gmail.com"
|
25
|
-
s.homepage = "https://github.com/
|
25
|
+
s.homepage = "https://github.com/bcrypt-ruby/bcrypt-ruby"
|
26
26
|
s.license = "MIT"
|
27
27
|
end
|
data/lib/bcrypt/engine.rb
CHANGED
@@ -7,6 +7,14 @@ module BCrypt
|
|
7
7
|
MIN_COST = 4
|
8
8
|
# The maximum cost supported by the algorithm.
|
9
9
|
MAX_COST = 31
|
10
|
+
# Maximum possible size of bcrypt() secrets.
|
11
|
+
# Older versions of the bcrypt library would truncate passwords longer
|
12
|
+
# than 72 bytes, but newer ones do not. We truncate like the old library for
|
13
|
+
# forward compatibility. This way users upgrading from Ubuntu 18.04 to 20.04
|
14
|
+
# will not have their user passwords invalidated, for example.
|
15
|
+
# A max secret length greater than 255 leads to bcrypt returning nil.
|
16
|
+
# https://github.com/bcrypt-ruby/bcrypt-ruby/issues/225#issuecomment-875908425
|
17
|
+
MAX_SECRET_BYTESIZE = 72
|
10
18
|
# Maximum possible size of bcrypt() salts.
|
11
19
|
MAX_SALT_LENGTH = 16
|
12
20
|
|
@@ -43,14 +51,16 @@ module BCrypt
|
|
43
51
|
end
|
44
52
|
|
45
53
|
# Given a secret and a valid salt (see BCrypt::Engine.generate_salt) calculates
|
46
|
-
# a bcrypt() password hash.
|
54
|
+
# a bcrypt() password hash. Secrets longer than 72 bytes are truncated.
|
47
55
|
def self.hash_secret(secret, salt, _ = nil)
|
48
56
|
if valid_secret?(secret)
|
49
57
|
if valid_salt?(salt)
|
50
58
|
if RUBY_PLATFORM == "java"
|
51
59
|
Java.bcrypt_jruby.BCrypt.hashpw(secret.to_s.to_java_bytes, salt.to_s)
|
52
60
|
else
|
53
|
-
|
61
|
+
secret = secret.to_s
|
62
|
+
secret = secret.byteslice(0, MAX_SECRET_BYTESIZE) if secret && secret.bytesize > MAX_SECRET_BYTESIZE
|
63
|
+
__bc_crypt(secret, salt)
|
54
64
|
end
|
55
65
|
else
|
56
66
|
raise Errors::InvalidSalt.new("invalid salt")
|
@@ -70,8 +80,7 @@ module BCrypt
|
|
70
80
|
if RUBY_PLATFORM == "java"
|
71
81
|
Java.bcrypt_jruby.BCrypt.gensalt(cost)
|
72
82
|
else
|
73
|
-
|
74
|
-
__bc_salt(prefix, cost, OpenSSL::Random.random_bytes(MAX_SALT_LENGTH))
|
83
|
+
__bc_salt("$2a$", cost, OpenSSL::Random.random_bytes(MAX_SALT_LENGTH))
|
75
84
|
end
|
76
85
|
else
|
77
86
|
raise Errors::InvalidCost.new("cost must be numeric and > 0")
|
@@ -80,7 +89,7 @@ module BCrypt
|
|
80
89
|
|
81
90
|
# Returns true if +salt+ is a valid bcrypt() salt, false if not.
|
82
91
|
def self.valid_salt?(salt)
|
83
|
-
!!(salt =~
|
92
|
+
!!(salt =~ /\A\$[0-9a-z]{2,}\$[0-9]{2,}\$[A-Za-z0-9\.\/]{22,}\z/)
|
84
93
|
end
|
85
94
|
|
86
95
|
# Returns true if +secret+ is a valid bcrypt() secret, false if not.
|
data/lib/bcrypt/password.rb
CHANGED
@@ -47,7 +47,7 @@ module BCrypt
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def valid_hash?(h)
|
50
|
-
|
50
|
+
/\A\$[0-9a-z]{2}\$[0-9]{2}\$[A-Za-z0-9\.\/]{53}\z/ === h
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -62,6 +62,17 @@ module BCrypt
|
|
62
62
|
end
|
63
63
|
|
64
64
|
# Compares a potential secret against the hash. Returns true if the secret is the original secret, false otherwise.
|
65
|
+
#
|
66
|
+
# Comparison edge case/gotcha:
|
67
|
+
#
|
68
|
+
# secret = "my secret"
|
69
|
+
# @password = BCrypt::Password.create(secret)
|
70
|
+
#
|
71
|
+
# @password == secret # => True
|
72
|
+
# @password == @password # => False
|
73
|
+
# @password == @password.to_s # => False
|
74
|
+
# @password.to_s == @password # => True
|
75
|
+
# @password.to_s == @password.to_s # => True
|
65
76
|
def ==(secret)
|
66
77
|
super(BCrypt::Engine.hash_secret(secret, @salt))
|
67
78
|
end
|
@@ -83,5 +94,4 @@ module BCrypt
|
|
83
94
|
return v.to_str, c.to_i, h[0, 29].to_str, mash[-31, 31].to_str
|
84
95
|
end
|
85
96
|
end
|
86
|
-
|
87
97
|
end
|
data/lib/bcrypt_ext.jar
CHANGED
Binary file
|
data/spec/bcrypt/engine_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
require 'securerandom'
|
2
3
|
|
3
4
|
describe 'BCrypt::Engine' do
|
4
5
|
describe '.calibrate(upper_time_limit_in_ms)' do
|
@@ -12,8 +13,11 @@ end
|
|
12
13
|
|
13
14
|
describe "The BCrypt engine" do
|
14
15
|
specify "should calculate the optimal cost factor to fit in a specific time" do
|
15
|
-
|
16
|
-
|
16
|
+
start_time = Time.now
|
17
|
+
BCrypt::Password.create("testing testing", :cost => BCrypt::Engine::MIN_COST + 1)
|
18
|
+
min_time_ms = (Time.now - start_time) * 1000
|
19
|
+
first = BCrypt::Engine.calibrate(min_time_ms)
|
20
|
+
second = BCrypt::Engine.calibrate(min_time_ms * 4)
|
17
21
|
expect(second).to be > first
|
18
22
|
end
|
19
23
|
end
|
@@ -154,4 +158,19 @@ describe "Generating BCrypt hashes" do
|
|
154
158
|
expect(BCrypt::Engine.hash_secret(secret, salt)).to eql(test_vector)
|
155
159
|
end
|
156
160
|
end
|
161
|
+
|
162
|
+
specify "should truncate long 1-byte character secrets to 72 bytes" do
|
163
|
+
# 'b' as a base triggers the failure at 256 characters, but 'a' does not.
|
164
|
+
too_long_secret = 'b'*(BCrypt::Engine::MAX_SECRET_BYTESIZE + 1)
|
165
|
+
just_right_secret = 'b'*BCrypt::Engine::MAX_SECRET_BYTESIZE
|
166
|
+
expect(BCrypt::Engine.hash_secret(too_long_secret, @salt)).to eq(BCrypt::Engine.hash_secret(just_right_secret, @salt))
|
167
|
+
end
|
168
|
+
|
169
|
+
specify "should truncate long multi-byte character secrets to 72 bytes" do
|
170
|
+
# 256 times causes bcrypt to return nil for libxcrypt > 4.4.18-4.
|
171
|
+
too_long_secret = '𐐷'*256
|
172
|
+
# 𐐷 takes 4 bytes in UTF-8. 18 times is 72 bytes
|
173
|
+
just_right_secret = '𐐷'*18
|
174
|
+
expect(BCrypt::Engine.hash_secret(too_long_secret, @salt)).to eq(BCrypt::Engine.hash_secret(just_right_secret, @salt))
|
175
|
+
end
|
157
176
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
require 'securerandom'
|
2
3
|
|
3
4
|
describe "Creating a hashed password" do
|
4
5
|
|
@@ -26,6 +27,10 @@ describe "Creating a hashed password" do
|
|
26
27
|
expect { BCrypt::Password.create( "" ) }.not_to raise_error
|
27
28
|
expect { BCrypt::Password.create( String.new ) }.not_to raise_error
|
28
29
|
end
|
30
|
+
|
31
|
+
specify "should tolerate very long string secrets" do
|
32
|
+
expect { BCrypt::Password.create("abcd"*1024) }.not_to raise_error
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
describe "Reading a hashed password" do
|
@@ -108,6 +113,7 @@ end
|
|
108
113
|
describe "Validating a generated salt" do
|
109
114
|
specify "should not accept an invalid salt" do
|
110
115
|
expect(BCrypt::Engine.valid_salt?("invalid")).to eq(false)
|
116
|
+
expect(BCrypt::Engine.valid_salt?("invalid\n#{BCrypt::Engine.generate_salt}\ninvalid")).to eq(false)
|
111
117
|
end
|
112
118
|
specify "should accept a valid salt" do
|
113
119
|
expect(BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt)).to eq(true)
|
@@ -117,6 +123,7 @@ end
|
|
117
123
|
describe "Validating a password hash" do
|
118
124
|
specify "should not accept an invalid password" do
|
119
125
|
expect(BCrypt::Password.valid_hash?("i_am_so_not_valid")).to be(false)
|
126
|
+
expect(BCrypt::Password.valid_hash?("invalid\n#{BCrypt::Password.create "i_am_so_valid"}\ninvalid")).to be(false)
|
120
127
|
end
|
121
128
|
specify "should accept a valid password" do
|
122
129
|
expect(BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid")).to be(true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcrypt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.17
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Coda Hale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -17,8 +17,8 @@ dependencies:
|
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: 0.9.2
|
19
19
|
name: rake-compiler
|
20
|
-
type: :development
|
21
20
|
prerelease: false
|
21
|
+
type: :development
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
@@ -31,8 +31,8 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3'
|
33
33
|
name: rspec
|
34
|
-
type: :development
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
@@ -54,9 +54,9 @@ extra_rdoc_files:
|
|
54
54
|
- lib/bcrypt/engine.rb
|
55
55
|
- lib/bcrypt/error.rb
|
56
56
|
files:
|
57
|
+
- ".github/workflows/ruby.yml"
|
57
58
|
- ".gitignore"
|
58
59
|
- ".rspec"
|
59
|
-
- ".travis.yml"
|
60
60
|
- CHANGELOG
|
61
61
|
- COPYING
|
62
62
|
- Gemfile
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- spec/bcrypt/error_spec.rb
|
87
87
|
- spec/bcrypt/password_spec.rb
|
88
88
|
- spec/spec_helper.rb
|
89
|
-
homepage: https://github.com/
|
89
|
+
homepage: https://github.com/bcrypt-ruby/bcrypt-ruby
|
90
90
|
licenses:
|
91
91
|
- MIT
|
92
92
|
metadata: {}
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.2.29
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: OpenBSD's bcrypt() password hashing algorithm.
|
data/.travis.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
before_install:
|
3
|
-
- "echo 'gem: --no-rdoc --no-ri' > ~/.gemrc"
|
4
|
-
rvm:
|
5
|
-
- 2.0
|
6
|
-
- 2.1
|
7
|
-
- 2.2
|
8
|
-
- 2.3
|
9
|
-
- 2.4
|
10
|
-
- 2.5
|
11
|
-
- 2.6
|
12
|
-
- 2.7
|
13
|
-
- ruby-head
|
14
|
-
- jruby-head
|
15
|
-
- rbx-3
|
16
|
-
matrix:
|
17
|
-
allow_failures:
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
20
|
-
- rvm: rbx-3
|
21
|
-
fast_finish: true
|
22
|
-
script: bundle exec rake
|