-
Notifications
You must be signed in to change notification settings - Fork 93
Add ability to set password length #29
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
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 actually have a TODO
in the code to add length (to both passwords and raw outputs): https://github.com/cloudflare/gokey/blob/master/cmd/gokey/main.go#L82-L83
Can you make it just length
and apply to both passwords and raw symmetric keys?
cmd/gokey/main.go
Outdated
@@ -30,6 +31,7 @@ func init() { | |||
flag.StringVar(&realm, "r", "", "password/key realm (most probably purpose of the password/key)") | |||
flag.StringVar(&output, "o", "", "output path to store generated key/password (default stdout)") | |||
flag.BoolVar(&unsafe, "u", false, "UNSAFE: allow key generation without a seed") | |||
flag.IntVar(&passwordLength, "l", 10, `password length (only used for "pass" type)`) |
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.
this probably needs some input validation - what if the user puts 0
or -1
or 1234567890
?
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.
Just pushed some changes. Length now works on both passwords and raw symmetric keys.
I wanted to keep the defaults for each output type for backward compatibility. So, genRaw
checks if length
was passed, if it wasn't then it sets length to 32
. Passwords still use the default of 10
characters.
It also does some input validation, but it may need to be tweaked.
cmd/gokey/main.go
Outdated
@@ -54,7 +56,16 @@ func genSeed(w io.Writer) { | |||
} | |||
|
|||
func genPass(seed []byte, w io.Writer) { | |||
password, err := gokey.GetPass(pass, realm, seed, &gokey.PasswordSpec{10, 3, 3, 1, 1, ""}) | |||
upperLower := math.Ceil(float64(passwordLength) * 3.0 / 10.0) |
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 suggest not to hardcode this logic - what if there would be a weird website which will require "all uppercase"? It is not supported now, but I think all of them should be cmd line parameters.
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.
Excellent point - I'll work on that
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 wasn't sure how to do this with only the standard library since these cmd line parameters wouldn't always be used.
Check for invalid lengths [cloudflare#29]
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.
As stated inline, I think we should do most parameter validation inline inside the main function before calling the helpers-generators. The reason is - we want to have slightly different validation logic (like not enforcing 1024
limit on the raw
type) as well as additional logic: we should probably throw an error if the "l" flag is explicitly defined for key types, which do not support it, like ec256
, rsa2048
etc
I believe I resolved all the issues you mentioned. :) |
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.
Looks good. Beside the one last inline comment can you squash the work now and update the documentation in a separate commit?
Thanks
c9c1ff3
to
a581bb1
Compare
I've squashed the commits and added one commit for docs. |
Sorry not to mention it: there are two doc files - the one you modified and https://github.com/cloudflare/gokey/blob/master/gokey.1.md (for Debian packaging). Can you modify it as well and squash with your doc commit? |
07bd14c
to
fe6ffa0
Compare
@ignatk I appreciate your help with this pull request. Please let me know if there is anything else I need to do before it is accepted. |
This is great. Thank you for your time and contribution. |
Having the ability to determine the length of the password generated is something I would find helpful.
Thanks :)