Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove bcrypt code from code-base (#4844) #4845

Merged
merged 1 commit into from Aug 23, 2017
Merged

Conversation

aead
Copy link
Member

@aead aead commented Aug 22, 2017

Bcrypt is not neccessary and not used properly. This change
replace the whole bcrypt hash computation through a constant time
compare and removes bcrypt from the code base.

Fixes #4844

How Has This Been Tested?

Manually

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@harshavardhana
Copy link
Member

hole bcrypt hash computation

what is a hole bcrypt hash ? do you mean whole ?

@codecov-io
Copy link

codecov-io commented Aug 22, 2017

Codecov Report

Merging #4845 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4845      +/-   ##
==========================================
- Coverage   63.02%   63.02%   -0.01%     
==========================================
  Files         191      191              
  Lines       27452    27440      -12     
==========================================
- Hits        17302    17294       -8     
+ Misses       8975     8972       -3     
+ Partials     1175     1174       -1
Impacted Files Coverage Δ
cmd/credential.go 87.5% <100%> (+4.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a73c67...bbc52f2. Read the comment docs.

@aead
Copy link
Member Author

aead commented Aug 22, 2017

Ahm, yes xD - I fix it!

Copy link
Member

@balamurugana balamurugana left a comment

Choose a reason for hiding this comment

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

LGTM for removing codes

One question.
Does subtle.ConstantTimeCompare() prevent timing attack?

@aead
Copy link
Member Author

aead commented Aug 22, 2017

Yes, that's exactly the function used in bcrypt for comparing the computed hash values. It compares two byte slices in constant time. This prevents timing attacks.

@aead
Copy link
Member Author

aead commented Aug 22, 2017

Closed until we decide what to do...

@aead aead closed this Aug 22, 2017
@aead
Copy link
Member Author

aead commented Aug 22, 2017

This PR should fulfill the requirements - reopened


return (cred.AccessKey == ccred.AccessKey &&
bcrypt.CompareHashAndPassword(cred.secretKeyHash, []byte(ccred.SecretKey)) == nil)
return subtle.ConstantTimeCompare([]byte(cred.SecretKey), []byte(ccred.SecretKey)) == 1
Copy link
Member

Choose a reason for hiding this comment

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

How about doing below?

return (cred.AccessKey == ccred.AccessKey && subtle.ConstantTimeCompare([]byte(cred.SecretKey), []byte(ccred.SecretKey)) == 1)

Copy link
Member Author

Choose a reason for hiding this comment

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

The access key is public information so this is fine. However for me it looks a lite bit wired when credentials are compared and some parts are constant time and some aren't. It's just easier to miss something in the future - but the decision is up to you...

Copy link
Member

Choose a reason for hiding this comment

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

I think you can do the change.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

_, err = rand.Read(keyBytes)
if err != nil {
return cred, err
// Generate access key - the access key consits only of alpha-numeric digits.
Copy link
Member

Choose a reason for hiding this comment

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

I think you can keep function unchanged to minimize this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR also cleans up the code a bit - like unnecessary if-else. aso.

Copy link
Member

Choose a reason for hiding this comment

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

Yep. Its better to send different PR doing cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@harshavardhana
Copy link
Member

Can you squash your commits? @aead

@aead
Copy link
Member Author

aead commented Aug 23, 2017

Squashed

Bcrypt is not neccessary and not used properly. This change
replace the whole bcrypt hash computation through a constant time
compare and removes bcrypt from the code base.
@deekoder deekoder merged commit b233345 into minio:master Aug 23, 2017
@aead aead deleted the remove-bcrypt branch September 1, 2017 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

do not compare credentials using bcrypt
5 participants