Issue #14915 has been updated by jeremyevans0 (Jeremy Evans).


shyouhei (Shyouhei Urabe) wrote:
> Off topic but,
> 
> jeremyevans0 (Jeremy Evans) wrote:
> > Apache htpasswd generates passwords using `$2y$`, but the hashes are the same as `$2a$` format, and Apache handles `$2a$` format just fine.  The bcrypt gem does not consider `$2y$` to match, but will work correctly if `$2y$` is changed to `$2a$`.   According to Wikipedia (https://en.wikipedia.org/wiki/Bcrypt#Versioning_history), `$2y$` instead of `$2a$` was just to note that the hash was not generated by a bad version of the crypt_blowfish PHP library, otherwise the formats are identical.
> 
> Is `$2a$` okay? The wikipedia entry you linked says that OpenBSD people abandoned `$2a$` to move to `$2b$`.  Sounds very much like it has flaw(s).

There is only a difference between `$2a$` and `$2b$` on OpenBSD if the password length is 256 characters or longer.  Such passwords are very rare.  The `bcrypt` gem currently only supports and generates `$2a` hashes, but much like `$2y$`, if you change `$2b$` to `$2a$`, the hash will match.

> I hope this is not an issue.  But at least `sub(/\A\$2y\$/, '$2a$')` seems something we should not.

`sub(/\A\$2y\$/, '$2b$')` is only fine after the bcrypt gem is modified to recognize `$2b$`.  I tested the bcrypt gem, and the algorithm it uses is compatible with OpenBSD's `$2b$` format:

~~~ ruby
pass = 'a'*500
s = `encrypt #{pass}`.chomp
# => "$2b$08$2iobD98d6MzMpS6/ViH8euWUmKGBgp4D8txRHAmCeIcfAS7ZtKPxW"
BCrypt::Password.new(s) == pass
# => false
BCrypt::Password.new(s.sub(/\A\$2b\$/, '$2a$')) == pass
# => true
~~~

So there are no security issues in the `sub(/\A\$2y\$/, '$2a$')`.  I would say that until the bcrypt gem is modified to recognize `$2b$` and `$2y$`, that we use `sub(/\A\$2[yb]\$/, '$2a$')` for maximum compatibility.

----------------------------------------
Feature #14915: Deprecate String#crypt, move implementation to string/crypt
https://bugs.ruby-lang.org/issues/14915#change-73118

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
This method is system and implementation dependent, and the
portable usage mentioned in the documentation is not truly
portable (doesn't work on OpenBSD) and insecure as it uses DES.
For systems that lack a crypt(3) implementation, Ruby will
happily substitute a version that only supports DES.  It's 2018,
using DES should be avoided if at all possible.

The only internal usage of String#crypt in Ruby is in Webrick,
where it uses DES for basic authentication with an htpasswd file.
That could and should be changed to use a more secure hash by
default (bcrypt since that's the most secure htpasswd format),
or at least allow the user to customize Webrick's authentication.
I expect there are few if any users actively using Webrick's
htpasswd support.

This moves the String#crypt implementation to the string/crypt
extension, but leaves the String#crypt core method.  The core
method prints a deprecation warning, then loads the string/crypt
extension. The string/crypt extension undefines the String#crypt
core method, then defines the previous implementation.

Because extensions use extconf.rb instead of configure for their
configuration, this ports the related configure.ac code to
extconf.rb.  I'm not sure that is done correctly and works on
all platforms, it will need testing.

For systems that lack a crypt(3) implementation, this modifies the
fallback code to only define crypt_r, since that is the only
function that String#crypt will call in that case.

While the patch just deprecates String#crypt, I think
we should plan to remove support from ruby:

2.6: core method deprecated
2.7: core method removed, string/crypt extension ships with ruby
2.8: string/crypt extension moves to external gem, not shipped

---Files--------------------------------
0001-Deprecate-String-crypt-move-implementation-to-string.patch (20.5 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>