Bug 2611 - Add support for $2b$ prefixed hashes
Summary: Add support for $2b$ prefixed hashes
Status: CLOSED INVALID
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: Miscellaneous (show other bugs)
Version: -current
Hardware: All All
: P3 enhancement
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-07 03:19 AEST by David Carlson
Modified: 2021-04-23 15:10 AEST (History)
1 user (show)

See Also:


Attachments
patch to add support (6.07 KB, patch)
2016-09-07 03:19 AEST, David Carlson
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Carlson 2016-09-07 03:19:03 AEST
Created attachment 2870 [details]
patch to add support

NOTE: refers to jbcrypt 0.4.0, but product is not selectable.

We have run into a problem with the prefix of bcrypt-hashed passwords. Our generated hash values include the prefix $2b$, but our crypt library rejects these, only accepting hash formats with the prefix $2a$.
Our current bcrypt java library (http://www.mindrot.org/projects/jBCrypt also https://github.com/jeremyh/jBCrypt) uses the modular crypt format (http://pythonhosted.org/passlib/modular_crypt_format.html) to store both the salt and the hash of the password.
The python library we have selected uses bcrypt.c. In (http://www.openwall.com/lists/oss-security/2012/01/02/4), 'Alexander' describes that Christos Zoulas discovered a wrap-around error. This is also described in https://en.wikipedia.org/wiki/Crypt_(C). Either way, the actual behavior in the c libarary is not truncation, but wrapping in a way that can eliminate significant (all) entropy in the overflow case (overflow is of the len variable which is uint8).
As a mitigation, some implementations use the $2b$ prefix which clarifies the behavior regarding long passwords (e.g. the actual behavior is now truncation). Implementations generally have addressed both the overflow and used the version bump to identify this change.
The jbcrypt library uses "minor >= 'a'" comparisons in many positions, but the critical section seems to be a check:
	if (salt.charAt(0) != '$' || salt.charAt(1) != '2') {
	    throw new IllegalArgumentException("Invalid salt version");
	}
	if (salt.charAt(2) == '$') {
	    off = 3;
	} else {
	    minor = salt.charAt(2);
	    if (minor != 'a' || salt.charAt(3) != '$') {
	        throw new IllegalArgumentException("Invalid salt revision");
	    }
	    off = 4;
	}
This code only supports prefixes $2a$ and $2$. It appears that the java implementation does not have the wrapping problem from the C implementation, but for compatibility, we would prefer that the java implementation include support for both.
Comment 1 Darren Tucker 2016-10-18 05:05:47 AEDT
I don't know if Damien is accepting bug reports for this nowadays, but he's the only one that can do anything about it so reassiging for either actioning or closing.
Comment 2 Damien Miller 2020-01-25 22:17:58 AEDT
jbcrypt bugs are not tracked here
Comment 3 Damien Miller 2021-04-23 15:10:46 AEST
closing resolved bugs as of 8.6p1 release