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

PBKDF2 hash generation using base64, not raw bytes for salt #298

Open
coldfire84 opened this issue Jan 14, 2020 · 1 comment
Open

PBKDF2 hash generation using base64, not raw bytes for salt #298

coldfire84 opened this issue Jan 14, 2020 · 1 comment

Comments

@coldfire84
Copy link

coldfire84 commented Jan 14, 2020

I've been struggling with the use of passport-local-mongoose generated hashes in both EMQX4 and the mosquitto-go-auth plugin to enable MQTT login. You're thinking, what does this have to do with Passport Local Mongoose... right? :)

Having reviewed the code, and tracked the pbkdf2 hash generation, I can see that the 'setPassword' method converts generated salt bytes to base64/ hex (as per options.ecoding), saves this to MongoDB (desirable) but then uses the base64/ hex encoded salt against the pbkdf2 library (not desirable).

The issue here, from what I can tell, is that the pbkdf2 library expects salt in raw bytes format. If salt is not raw bytes the library will generate raw bytes, but using the default encoding which is defined within the module itself as either utf-8 or binary. Irrespective of utf-8 or binary formats, this creates a hash that is only usable within the confines of the application itself, where the hash generation and comparison uses the same process.

I'm unsure whether this is intentional behavior. If not, and accepting remedying this would be a breaking change, I wonder if a potential solution would be to create an option that is along the lines of 'useRawSalt : true/ false (with false the default, to ensure no impact for existing users)' that would then send/ use raw bytes instead of base64/ hex salt for pbkdf2 hash generation.

An example here of the difference in resulting hash: https://repl.it/repls/MeagerStandardDrivers

@coldfire84
Copy link
Author

I'll put together a pull request with proposed changes.

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

No branches or pull requests

1 participant