bcrypt 3.1.17 → 3.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a762862a2c11b386ab9e3177bf8dee1832c1909d7cdb0133dfe43b09cac84b51
4
- data.tar.gz: abcd7395ac2dc6cefad250754e7b7e2c0d12fd730dab276f8ed66ebae313ec32
3
+ metadata.gz: 3d928c8b1764d15c593b64010a766c6dd8ed28c6cc634710aa1ef22616e9ce92
4
+ data.tar.gz: '0485ba6c9431e9cef69201de5d207181325385247a32e89d2e33ca87e57d184f'
5
5
  SHA512:
6
- metadata.gz: 055b9e3d854570d1a55b14ffbe0a904074579e3070366f4fa046c108f581239aa2a4cb59621ab0c312e4d8f0560fd116a961cb125d196d1874459653d52d9dda
7
- data.tar.gz: 1967cda6bc354819f66c56815cfd355ed197e5cfb09fdcb0b64156eea49a8d7ed7c9bdab1d8a86816f5832dbf711ccf8068e4754921ca7062ee8803ad6dd060c
6
+ metadata.gz: ac2844a3ab59a8ca724a362cf68dd68083ae2059769479f00d198097fb3efc7a37e8461aeea3b67fdbf6aa48167ea5de7be520a52339b8991954baa373652dec
7
+ data.tar.gz: 89ab8573f7567b61fa7ad4ed4edbd5c4e222400b7bf8b38e357d36276f853050c3f3d416911d5a74f7a7a5cdae19852cee8a06c5baba3d72e830eb637e331ecc
@@ -30,8 +30,6 @@ jobs:
30
30
  - truffleruby-head
31
31
  - mingw
32
32
  exclude:
33
- - { os: ubuntu, ruby: jruby }
34
- - { os: ubuntu, ruby: jruby-head }
35
33
  - { os: ubuntu, ruby: mingw }
36
34
  - { os: macos, ruby: mingw }
37
35
  - { os: windows, ruby: truffleruby }
@@ -46,8 +44,12 @@ jobs:
46
44
  with:
47
45
  ruby-version: ${{ matrix.ruby }}
48
46
  bundler-cache: true
47
+ env:
48
+ JAVA_OPTS: -Djdk.io.File.enableADS=true
49
49
  - name: Run tests
50
50
  run: bundle exec rake default
51
+ env:
52
+ JAVA_OPTS: -Djdk.io.File.enableADS=true
51
53
 
52
54
  finish:
53
55
  runs-on: ubuntu-latest
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 3.1.19 June 22 2023
2
+ - Deprecate passing the third argument to `BCrypt::Engine.hash_secret` [GH #207 by @sergey-alekseev]
3
+ - Add GC guards so the C compiler won't optimize out references [GH #270]
4
+
5
+ 3.1.18 May 16 2022
6
+ - Unlock GVL when calculating hashes and salts [GH #260]
7
+ - Fix compilation warnings in `ext/mri/bcrypt_ext.c` [GH #261]
8
+
1
9
  3.1.17 Mar 14 2022
2
10
  - Fix regex in validators to use \A and \z instead of ^ and $ [GH #121]
3
11
  - Truncate secrets greater than 72 bytes in hash_secret [GH #255]
data/README.md CHANGED
@@ -5,7 +5,6 @@ An easy way to keep your users' passwords secure.
5
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
- [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/6fplerx9lnaf0hyo?svg=true)](https://ci.appveyor.com/project/TJSchuck35975/bcrypt-ruby)
9
8
 
10
9
  ## Why you should use `bcrypt()`
11
10
 
data/Rakefile CHANGED
@@ -50,8 +50,8 @@ end
50
50
  if RUBY_PLATFORM =~ /java/
51
51
  Rake::JavaExtensionTask.new('bcrypt_ext', GEMSPEC) do |ext|
52
52
  ext.ext_dir = 'ext/jruby'
53
- ext.source_version = "1.7"
54
- ext.target_version = "1.7"
53
+ ext.source_version = "1.8"
54
+ ext.target_version = "1.8"
55
55
  end
56
56
  else
57
57
  Rake::ExtensionTask.new("bcrypt_ext", GEMSPEC) do |ext|
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.17'
3
+ s.version = '3.1.19'
4
4
 
5
5
  s.summary = "OpenBSD's bcrypt() password hashing algorithm."
6
6
  s.description = <<-EOF
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n")
13
13
  s.require_path = 'lib'
14
14
 
15
- s.add_development_dependency 'rake-compiler', '~> 0.9.2'
15
+ s.add_development_dependency 'rake-compiler', '~> 1.2.0'
16
16
  s.add_development_dependency 'rspec', '>= 3'
17
17
 
18
18
  s.rdoc_options += ['--title', 'bcrypt-ruby', '--line-numbers', '--inline-source', '--main', 'README.md']
data/ext/mri/bcrypt_ext.c CHANGED
@@ -1,53 +1,110 @@
1
1
  #include <ruby.h>
2
2
  #include <ow-crypt.h>
3
3
 
4
+ #ifdef HAVE_RUBY_THREAD_H
5
+ #include <ruby/thread.h>
6
+ #endif
7
+
4
8
  static VALUE mBCrypt;
5
9
  static VALUE cBCryptEngine;
6
10
 
11
+ struct bc_salt_args {
12
+ const char * prefix;
13
+ unsigned long count;
14
+ const char * input;
15
+ int size;
16
+ };
17
+
18
+ static void * bc_salt_nogvl(void * ptr) {
19
+ struct bc_salt_args * args = ptr;
20
+
21
+ return crypt_gensalt_ra(args->prefix, args->count, args->input, args->size);
22
+ }
23
+
7
24
  /* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+.
8
25
  */
9
26
  static VALUE bc_salt(VALUE self, VALUE prefix, VALUE count, VALUE input) {
10
27
  char * salt;
11
28
  VALUE str_salt;
12
-
13
- salt = crypt_gensalt_ra(
14
- StringValuePtr(prefix),
15
- NUM2ULONG(count),
16
- NIL_P(input) ? NULL : StringValuePtr(input),
17
- NIL_P(input) ? 0 : RSTRING_LEN(input));
29
+ struct bc_salt_args args;
30
+
31
+ /* duplicate the parameters for thread safety. If another thread has a
32
+ * reference to the parameters and mutates them while we are working,
33
+ * that would be very bad. Duping the strings means that the reference
34
+ * isn't shared. */
35
+ prefix = rb_str_new_frozen(prefix);
36
+ input = rb_str_new_frozen(input);
37
+
38
+ args.prefix = StringValueCStr(prefix);
39
+ args.count = NUM2ULONG(count);
40
+ args.input = NIL_P(input) ? NULL : StringValuePtr(input);
41
+ args.size = NIL_P(input) ? 0 : RSTRING_LEN(input);
42
+
43
+ #ifdef HAVE_RUBY_THREAD_H
44
+ salt = rb_thread_call_without_gvl(bc_salt_nogvl, &args, NULL, NULL);
45
+ #else
46
+ salt = bc_salt_nogvl((void *)&args);
47
+ #endif
18
48
 
19
49
  if(!salt) return Qnil;
20
50
 
21
51
  str_salt = rb_str_new2(salt);
52
+
53
+ RB_GC_GUARD(prefix);
54
+ RB_GC_GUARD(input);
22
55
  free(salt);
23
56
 
24
57
  return str_salt;
25
58
  }
26
59
 
60
+ struct bc_crypt_args {
61
+ const char * key;
62
+ const char * setting;
63
+ void * data;
64
+ int size;
65
+ };
66
+
67
+ static void * bc_crypt_nogvl(void * ptr) {
68
+ struct bc_crypt_args * args = ptr;
69
+
70
+ return crypt_ra(args->key, args->setting, &args->data, &args->size);
71
+ }
72
+
27
73
  /* Given a secret and a salt, generates a salted hash (which you can then store safely).
28
74
  */
29
75
  static VALUE bc_crypt(VALUE self, VALUE key, VALUE setting) {
30
76
  char * value;
31
- void * data;
32
- int size;
33
77
  VALUE out;
34
78
 
35
- data = NULL;
36
- size = 0xDEADBEEF;
79
+ struct bc_crypt_args args;
37
80
 
38
81
  if(NIL_P(key) || NIL_P(setting)) return Qnil;
39
82
 
40
- value = crypt_ra(
41
- NIL_P(key) ? NULL : StringValuePtr(key),
42
- NIL_P(setting) ? NULL : StringValuePtr(setting),
43
- &data,
44
- &size);
83
+ /* duplicate the parameters for thread safety. If another thread has a
84
+ * reference to the parameters and mutates them while we are working,
85
+ * that would be very bad. Duping the strings means that the reference
86
+ * isn't shared. */
87
+ key = rb_str_new_frozen(key);
88
+ setting = rb_str_new_frozen(setting);
89
+
90
+ args.data = NULL;
91
+ args.size = 0xDEADBEEF;
92
+ args.key = NIL_P(key) ? NULL : StringValueCStr(key);
93
+ args.setting = NIL_P(setting) ? NULL : StringValueCStr(setting);
94
+
95
+ #ifdef HAVE_RUBY_THREAD_H
96
+ value = rb_thread_call_without_gvl(bc_crypt_nogvl, &args, NULL, NULL);
97
+ #else
98
+ value = bc_crypt_nogvl((void *)&args);
99
+ #endif
45
100
 
46
- if(!value || !data) return Qnil;
101
+ if(!value || !args.data) return Qnil;
47
102
 
48
103
  out = rb_str_new2(value);
49
104
 
50
- xfree(data);
105
+ RB_GC_GUARD(key);
106
+ RB_GC_GUARD(setting);
107
+ free(args.data);
51
108
 
52
109
  return out;
53
110
  }
data/lib/bcrypt/engine.rb CHANGED
@@ -53,6 +53,13 @@ module BCrypt
53
53
  # Given a secret and a valid salt (see BCrypt::Engine.generate_salt) calculates
54
54
  # a bcrypt() password hash. Secrets longer than 72 bytes are truncated.
55
55
  def self.hash_secret(secret, salt, _ = nil)
56
+ unless _.nil?
57
+ warn "[DEPRECATION] Passing the third argument to " \
58
+ "`BCrypt::Engine.hash_secret` is deprecated. " \
59
+ "Please do not pass the third argument which " \
60
+ "is currently not used."
61
+ end
62
+
56
63
  if valid_secret?(secret)
57
64
  if valid_salt?(salt)
58
65
  if RUBY_PLATFORM == "java"
@@ -31,6 +31,12 @@ describe "Creating a hashed password" do
31
31
  specify "should tolerate very long string secrets" do
32
32
  expect { BCrypt::Password.create("abcd"*1024) }.not_to raise_error
33
33
  end
34
+
35
+ specify "blows up when null bytes are in the string" do
36
+ # JRuby can handle the null bytes
37
+ skip if RUBY_ENGINE == 'jruby'
38
+ expect { BCrypt::Password.create( "foo\0bar".chop ) }.to raise_error
39
+ end
34
40
  end
35
41
 
36
42
  describe "Reading a hashed password" do
metadata CHANGED
@@ -1,38 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.17
4
+ version: 3.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coda Hale
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2023-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake-compiler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 0.9.2
20
- type: :development
18
+ version: 1.2.0
19
+ name: rake-compiler
21
20
  prerelease: false
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.2
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
32
  version: '3'
34
- type: :development
33
+ name: rspec
35
34
  prerelease: false
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
@@ -50,10 +50,10 @@ extra_rdoc_files:
50
50
  - README.md
51
51
  - COPYING
52
52
  - CHANGELOG
53
+ - lib/bcrypt.rb
53
54
  - lib/bcrypt/password.rb
54
55
  - lib/bcrypt/engine.rb
55
56
  - lib/bcrypt/error.rb
56
- - lib/bcrypt.rb
57
57
  files:
58
58
  - ".github/workflows/ruby.yml"
59
59
  - ".gitignore"
@@ -63,7 +63,6 @@ files:
63
63
  - Gemfile
64
64
  - README.md
65
65
  - Rakefile
66
- - appveyor.yml
67
66
  - bcrypt.gemspec
68
67
  - ext/jruby/bcrypt_jruby/BCrypt.java
69
68
  - ext/mri/bcrypt_ext.c
@@ -90,7 +89,7 @@ homepage: https://github.com/bcrypt-ruby/bcrypt-ruby
90
89
  licenses:
91
90
  - MIT
92
91
  metadata: {}
93
- post_install_message:
92
+ post_install_message:
94
93
  rdoc_options:
95
94
  - "--title"
96
95
  - bcrypt-ruby
@@ -111,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
110
  - !ruby/object:Gem::Version
112
111
  version: '0'
113
112
  requirements: []
114
- rubygems_version: 3.1.4
115
- signing_key:
113
+ rubygems_version: 3.2.29
114
+ signing_key:
116
115
  specification_version: 4
117
116
  summary: OpenBSD's bcrypt() password hashing algorithm.
118
117
  test_files: []
data/appveyor.yml DELETED
@@ -1,50 +0,0 @@
1
- version: "{branch}-{build}"
2
- build: off
3
- clone_depth: 1
4
-
5
- init:
6
- # Install Ruby head
7
- - if %RUBY_VERSION%==head (
8
- appveyor DownloadFile https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x86.exe -FileName C:\head_x86.exe &
9
- C:\head_x86.exe /verysilent /dir=C:\Ruby%RUBY_VERSION%
10
- )
11
- - if %RUBY_VERSION%==head-x64 (
12
- appveyor DownloadFile https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x64.exe -FileName C:\head_x64.exe &
13
- C:\head_x64.exe /verysilent /dir=C:\Ruby%RUBY_VERSION%
14
- )
15
-
16
- # Add Ruby to the path
17
- - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
18
-
19
- environment:
20
- matrix:
21
- - RUBY_VERSION: "head"
22
- - RUBY_VERSION: "head-x64"
23
- - RUBY_VERSION: "25"
24
- - RUBY_VERSION: "25-x64"
25
- - RUBY_VERSION: "24"
26
- - RUBY_VERSION: "24-x64"
27
- - RUBY_VERSION: "23"
28
- - RUBY_VERSION: "23-x64"
29
- - RUBY_VERSION: "22"
30
- - RUBY_VERSION: "22-x64"
31
- - RUBY_VERSION: "21"
32
- - RUBY_VERSION: "21-x64"
33
- - RUBY_VERSION: "200"
34
- - RUBY_VERSION: "200-x64"
35
-
36
- install:
37
- - ps: "Set-Content -Value 'gem: --no-ri --no-rdoc ' -Path C:\\ProgramData\\gemrc"
38
- - if %RUBY_VERSION%==head ( gem install bundler -v'< 2' )
39
- - if %RUBY_VERSION%==head-x64 ( gem install bundler -v'< 2' )
40
- - bundle install
41
-
42
- before_build:
43
- - ruby -v
44
- - gem -v
45
-
46
- build_script:
47
- - bundle exec rake compile -rdevkit
48
-
49
- test_script:
50
- - bundle exec rake spec