Skip to content

fix(key): dont allow backup key to be named 'self' #7615

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

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ var keyRotateCmd = &cmds.Command{
Tagline: "Rotates the ipfs identity.",
ShortDescription: `
Generates a new ipfs identity and saves it to the ipfs config file.
Your existing identity key will be backed up in the Keystore.
The daemon must not be running when calling this command.

ipfs uses a repository in the local file system. By default, the repo is
Expand All @@ -453,7 +454,7 @@ environment variable:
},
Arguments: []cmds.Argument{},
Options: []cmds.Option{
cmds.StringOption(oldKeyOptionName, "o", "Keystore name for the old/rotated-out key."),
cmds.StringOption(oldKeyOptionName, "o", "Keystore name to use for backing up your existing identity"),
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault),
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
},
Expand Down Expand Up @@ -482,6 +483,9 @@ environment variable:
if !ok {
return fmt.Errorf("keystore name for backing up old key must be provided")
}
if oldKey == "self" {
return fmt.Errorf("keystore name for back up cannot be named 'self'")
}
return doRotate(os.Stdout, cctx.ConfigRoot, oldKey, algorithm, nBitsForKeypair, nBitsGiven)
},
}
Expand Down
6 changes: 6 additions & 0 deletions test/sharness/t0027-rotate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ test_rotate() {
esac
'

test_expect_success "'ipfs key rotate -o self' should fail" '
echo "Error: keystore name for back up cannot be named '\''self'\''" >expected-self
test_must_fail ipfs key rotate -o self 2>actual-self &&
test_cmp expected-self actual-self
'

test_expect_success "Compare second ID and key to first" '
ipfs id -f="<id>" > second_id &&
ipfs id -f="<pubkey>" > second_key &&
Expand Down