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

Add option to specify key type (RSA or Ed25519) #4076

Closed
wants to merge 3 commits into from

Conversation

JustinDrake
Copy link
Contributor

@JustinDrake JustinDrake commented Jul 17, 2017

See #3896 for context

License: MIT
Signed-off-by: Justin Drake drakefjustin@gmail.com

License: MIT
Signed-off-by: Justin Drake <drakefjustin@gmail.com>
@whyrusleeping whyrusleeping requested review from magik6k, Kubuxu and Stebalien and removed request for magik6k July 29, 2017 22:42
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Would be nice to get some sharness tests for this, something like https://github.com/ipfs/go-ipfs/pull/4001/files#diff-362467109e2261605f06379a54ce9703

Other than the lack of tests and the option nitpick LGTM

cmd/ipfs/init.go Outdated
@@ -90,6 +94,12 @@ environment variable:
return
}

keyType, _, err := req.Option("k").Int()
Copy link
Member

Choose a reason for hiding this comment

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

Use the longer option name here

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 used the short option name for consistency. See empty, _, err := req.Option("e").Bool() and nBitsForKeypair, _, err := req.Option("b").Int() right above.

Copy link
Member

Choose a reason for hiding this comment

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

Most other commands use long option names. Looks this one was not migrated.

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've used the long name for all the options that were using the short name in this file. 👍

cmd/ipfs/init.go Outdated
@@ -49,6 +52,7 @@ environment variable:
},
Options: []cmds.Option{
cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key.").Default(nBitsForKeypairDefault),
cmds.IntOption("key-type", "k", "Key type (RSA or Ed25519-id").Default(ci.RSA),
Copy link
Member

Choose a reason for hiding this comment

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

Use the default you defined in line 25.

cmd/ipfs/init.go Outdated
@@ -16,10 +16,13 @@ import (
namesys "github.com/ipfs/go-ipfs/namesys"
config "github.com/ipfs/go-ipfs/repo/config"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
Copy link
Member

Choose a reason for hiding this comment

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

Separate local and gx deps with a new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Member

@Kubuxu Kubuxu left a comment

Choose a reason for hiding this comment

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

^^^ (I miss clicked with approve).

License: MIT
Signed-off-by: Justin Drake <drakefjustin@gmail.com>
cmd/ipfs/init.go Outdated
@@ -49,6 +53,7 @@ environment variable:
},
Options: []cmds.Option{
cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key.").Default(nBitsForKeypairDefault),
cmds.IntOption("key-type", "k", "Key type (RSA or Ed25519-id").Default(keypairTypeDefault),
Copy link
Member

Choose a reason for hiding this comment

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

appears to be a typo here, missing paren

@whyrusleeping
Copy link
Member

One comment, then would be great to have a test that tests ipfs init with one of these keys, and verifies ipfs id returns a correct looking key.

License: MIT
Signed-off-by: Justin Drake <drakefjustin@gmail.com>
if nbits < 1024 {
return ident, errors.New("Bitsize less than 1024 is considered unsafe.")

switch keyType {
Copy link
Contributor

Choose a reason for hiding this comment

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

So what happens here if the user passed an incorrect key type?
I don't see the user option validated anywhere, it's just an int.

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically you need a default handler that errors out with something helpful for the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incorrect key type options will error out on line 113 with sk, pk, err := ci.GenerateKeyPair(keyType, nbits).

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little inconsistent with the intent of the switch, and, more importantly, there are other valid key types supported by libp2p-crypto that we don't use yet in ipfs (eg secp256k1 keys).

So I think it's better to tell the user we are not ready to handle this type of key rather than fallthrough and possibly succeed with surprising results.

@whyrusleeping whyrusleeping mentioned this pull request Sep 6, 2017
@richardschneider
Copy link

This has laying around for 1.5 years. Is it ever going to implemented?

@Stebalien
Copy link
Member

(this was implemented a while ago)

@Stebalien Stebalien closed this Sep 2, 2021
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.

7 participants