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

Support PBKDF2 using SHA512 #21

Closed
wants to merge 1 commit into from

Conversation

jefftrudeau
Copy link

No description provided.

@dblessing
Copy link

@carlosantoniodasilva Is this something you're open to accepting? Happy to help move it forward if it's agreeable.

@dblessing
Copy link

I tested these changes in our own project and provided feedback on what we experienced. Thanks for your contribution @jefftrudeau. I hope the maintainers will accept this.

end

def self.digest(password, stretches, salt, pepper)
hash = OpenSSL::Digest::SHA512.new

Choose a reason for hiding this comment

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

Suggested change
hash = OpenSSL::Digest::SHA512.new
hash = OpenSSL::Digest.new('SHA512').new

class Pbkdf2 < Base
def self.compare(encrypted_password, password, stretches, salt, pepper)
value_to_test = self.digest(password, stretches, salt, pepper)
ActiveSupport::SecurityUtils.fixed_length_secure_compare(encrypted_password, value_to_test)

Choose a reason for hiding this comment

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

If comparing unmatching values of differing length, this fails with mismatch length error. This should use Devise.secure_compare instead, which should also do a fixed length comparison, but also does an initial byte size/length check.

Suggested change
ActiveSupport::SecurityUtils.fixed_length_secure_compare(encrypted_password, value_to_test)
Devise.secure_compare(encrypted_password, value_to_test)

iterations: stretches,
hash: hash,
length: hash.digest_length,
).unpack('H*')[0]

Choose a reason for hiding this comment

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

Suggested change
).unpack('H*')[0]
).unpack1('H*')

def self.digest(password, stretches, salt, pepper)
hash = OpenSSL::Digest::SHA512.new
OpenSSL::KDF.pbkdf2_hmac(
password,

Choose a reason for hiding this comment

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

If a password is entirely numeric this function will fail trying due to implicit conversion of integer to string.

Suggested change
password,
password.to_s,

@jefftrudeau jefftrudeau deleted the master branch June 16, 2022 18:59
jefftrudeau added a commit to braeburntech/devise-encryptable that referenced this pull request Jun 16, 2022
@jefftrudeau
Copy link
Author

@dblessing @carlosantoniodasilva I rebased our branch against main and created a new PR: #25

29decibel pushed a commit to betterup/devise-encryptable that referenced this pull request Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants