Skip to content

Add BCrypt Revision Support - #5992

Closed
lin199231 wants to merge 5 commits into
spring-projects:masterfrom
lin199231:fix_issue#3320
Closed

lin199231 wants to merge 5 commits into
spring-projects:masterfrom
lin199231:fix_issue#3320

Conversation

@lin199231

Copy link
Copy Markdown
Contributor

From issue #3320
I find that jBCrypt are already support
https://code.google.com/archive/p/jbcrypt/issues/9
So I try to add bcrypt revision support for BCryptPasswordEncoder, and compatible with old version.
Please merge my request, thanks.

@rwinch rwinch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I provided feedback inline.

I've also noticed that the checkstyle is failing. You can run checkstyle using ./gradlew checkstyleMain checkstyleTest. I don't mind fixing that up if it is too much trouble for you. However, you are able to clean it up it would be appreciated. Here is what the report states:

File /home/rwinch/code/spring-projects/spring-security/crypto/src/main/java/org/springframework/security/crypto/bcrypt/BCryptPasswordEncoder.java

Error Description | Line
-- | --
'if' is not followed by whitespace. | 105

File /home/rwinch/code/spring-projects/spring-security/crypto/src/main/java/org/springframework/security/crypto/bcrypt/BCrypt.java

Error Description | Line
-- | --
'typecast' is not followed by whitespace. | 426
'typecast' is not followed by whitespace. | 426
'typecast' is not followed by whitespace. | 428
Line has leading space characters; indentation should be performed with tabs only. | 440
'typecast' is not followed by whitespace. | 455
'typecast' is not followed by whitespace. | 457
'typecast' is not followed by whitespace. | 463
'typecast' is not followed by whitespace. | 465
'typecast' is not followed by whitespace. | 469
'typecast' is not followed by whitespace. | 471
'typecast' is not followed by whitespace. | 477
'typecast' is not followed by whitespace. | 527
'typecast' is not followed by whitespace. | 565
'typecast' is not followed by whitespace. | 566
Line has leading space characters; indentation should be performed with tabs only. | 690
'typecast' is not followed by whitespace. | 692
'typecast' is not followed by whitespace. | 716
'typecast' is not followed by whitespace. | 717
'typecast' is not followed by whitespace. | 718
'typecast' is not followed by whitespace. | 719
'typecast' is not followed by whitespace. | 754


/**
* @param version the version of bcrypt, can be 2a,2b,2y
*/
public BCryptPasswordEncoder(String version) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change version inputs from the user to be a inner nested enum named BCryptVersion so that an invalid version cannot be provided.

if (random != null) {
salt = BCrypt.gensalt(version, strength, random);
} else {
System.out.println(version);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the println statement

if (strength > 0) {
if (random != null) {
salt = BCrypt.gensalt(strength, random);
if(version != null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having this check and two different code paths, let's make it so that version is final and always non-null with a default of $2y

@lin199231

lin199231 commented Oct 19, 2018 via email

Copy link
Copy Markdown
Contributor Author

@lin199231

Copy link
Copy Markdown
Contributor Author

I have a question, if use $2y as default version. The old version of Spring Security's default version is $2a. Is this OK to change BCryptPasswordEncoder 's default version from $2a to $2y?

@rwinch

rwinch commented Oct 19, 2018

Copy link
Copy Markdown
Member

@lin199231 Thanks for pointing that out. Please use $2a as the default version.

@lin199231

Copy link
Copy Markdown
Contributor Author

OK,the default version is $2a now.

@rwinch rwinch self-assigned this Oct 22, 2018
@rwinch rwinch changed the title fix issue#3320 Support for bcrypt revision Add BCrypt Revision Support Oct 22, 2018
@rwinch rwinch added this to the 5.2.0.M1 milestone Oct 22, 2018
@rwinch rwinch added in: crypto An issue in spring-security-crypto type: enhancement A general enhancement labels Oct 22, 2018
@rwinch

rwinch commented Oct 22, 2018

Copy link
Copy Markdown
Member

Thanks for the updates @lin199231! The feature is merged into master and will be available in 5.2.0.M1 Note I applied a polish commit to fix the last checkstyle error f56f55d

@rwinch rwinch closed this Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: crypto An issue in spring-security-crypto type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants