Skip to content

Conversation

levidurfee
Copy link
Contributor

Having the ability to determine the length of the password generated is something I would find helpful.

Thanks :)

Copy link
Contributor

@ignatk ignatk left a 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?

@@ -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)`)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

levidurfee added a commit to levidurfee/gokey that referenced this pull request Jul 30, 2019
Copy link
Contributor

@ignatk ignatk left a 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

@levidurfee
Copy link
Contributor Author

I believe I resolved all the issues you mentioned. :)

Copy link
Contributor

@ignatk ignatk left a 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

@levidurfee
Copy link
Contributor Author

I've squashed the commits and added one commit for docs.

@ignatk
Copy link
Contributor

ignatk commented Aug 5, 2019

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?

@levidurfee
Copy link
Contributor Author

@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.

@ignatk
Copy link
Contributor

ignatk commented Aug 14, 2019

This is great. Thank you for your time and contribution.

@ignatk ignatk merged commit c96dd73 into cloudflare:master Aug 14, 2019
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.

2 participants