-
Notifications
You must be signed in to change notification settings - Fork 583
(MODULES-1737) Add pw_hash() function #408
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
Conversation
25dcef9
to
3a75f94
Compare
Tests added. |
3a75f94
to
b20ee53
Compare
Rebased onto master, so tests should pass soon. |
Please update to have graceful failure on unsupported platforms for this function. They way it is currently written if attempted on Windows it will fail hard. |
|
||
# work around JRuby bug in String::crypt for JRuby < 1.7.17 | ||
if RUBY_PLATFORM == 'java' and 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' | ||
def password.crypt(salt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not just module String def crypt ...
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could change it to that. It was based on some code I found elsewhere to work around this issue.
@cyberious I'm not sure what you mean. Ruby provides a basic implementation of |
b20ee53
to
3906d21
Compare
return nil if password.empty? | ||
|
||
# work around JRuby bug in String#crypt for JRuby < 1.7.17 | ||
if RUBY_PLATFORM == 'java' and 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we only salting on the JVM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We salt everywhere. See line 42. This just checks for a faulty String#crypt
implementation that doesn't support extended hashes, which is known to exist in older versions of JRuby, and overrides it with a proper Java implementation of crypt()
. This weak implementation also exists on MRI on Windows, but we don't have a proper Java implementation under that scenario. I could change this to fail if the implementation is weak and we're not on Java, though. That seems like it would probably be a good idea.
Documentation and checking for unsupported platforms has been added. Working on a spec test for unsupported platforms now. |
7070f18
to
865d815
Compare
Spec test is in. Pinging @daenney, @cyberious, and @hunner for review. If the review is positive, I'll squash the commits together. |
|---------|---------------------| | ||
|1 |MD5 | | ||
|5 |SHA-256 | | ||
|6 |SHA-512 (recommended)| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we even implement hashes which we don't recommend?
why not make this the third, optional argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a difference between "you shouldn't use this" and "we recommend you to use the strongest one".
865d815
to
b46be2d
Compare
b46be2d
to
d1b6dfa
Compare
Rebased onto master and squashed. |
are compatible before using this function.") do |args| | ||
raise ArgumentError, "pw_hash(): wrong number of arguments (#{args.size} for 3)" if args.size != 3 | ||
raise ArgumentError, "pw_hash(): first argument must be a string" unless args[0].is_a? String | ||
raise ArgumentError, "pw_hash(): #{args[1]} is not a valid hash type" unless ['1', '5', '6'].include? args[1].to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this the other way around?
User-understanding wise I much prefer: pw_hash('lalalala', 'sha-256', 'oseatnoirsentaiore')
over pw_hash('lalalala', '5', 'oseatnoirsentaiore')
.
The first case I can immediately see what's going on. The second case I need to look up some implementation detail around specifiers to understand what type of hash this function call will be computing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Give me a few minutes to make the change.
d1b6dfa
to
e20b978
Compare
@daenney How's it look now? |
Much better but the tests are red.
|
101a48b
to
23be402
Compare
@daenney I knew I forgot to do something! Fixed. |
@hunner @cyberious I'm okay with this. Up to you now. |
(MODULES-1737) Add pw_hash() function
As per MODULES-1737, this PR provides a method of generating password hashes. Tests coming.