Skip to content

Commit 92fbcc3

Browse files
authored
Merge pull request #7615 from ipfs/fix/keystore-rotate
fix(key): dont allow backup key to be named 'self'
2 parents e80601b + edfd3c9 commit 92fbcc3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/commands/keystore.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ var keyRotateCmd = &cmds.Command{
442442
Tagline: "Rotates the ipfs identity.",
443443
ShortDescription: `
444444
Generates a new ipfs identity and saves it to the ipfs config file.
445+
Your existing identity key will be backed up in the Keystore.
445446
The daemon must not be running when calling this command.
446447
447448
ipfs uses a repository in the local file system. By default, the repo is
@@ -453,7 +454,7 @@ environment variable:
453454
},
454455
Arguments: []cmds.Argument{},
455456
Options: []cmds.Option{
456-
cmds.StringOption(oldKeyOptionName, "o", "Keystore name for the old/rotated-out key."),
457+
cmds.StringOption(oldKeyOptionName, "o", "Keystore name to use for backing up your existing identity"),
457458
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault),
458459
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
459460
},
@@ -482,6 +483,9 @@ environment variable:
482483
if !ok {
483484
return fmt.Errorf("keystore name for backing up old key must be provided")
484485
}
486+
if oldKey == "self" {
487+
return fmt.Errorf("keystore name for back up cannot be named 'self'")
488+
}
485489
return doRotate(os.Stdout, cctx.ConfigRoot, oldKey, algorithm, nBitsForKeypair, nBitsGiven)
486490
},
487491
}

test/sharness/t0027-rotate.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ test_rotate() {
4646
esac
4747
'
4848

49+
test_expect_success "'ipfs key rotate -o self' should fail" '
50+
echo "Error: keystore name for back up cannot be named '\''self'\''" >expected-self
51+
test_must_fail ipfs key rotate -o self 2>actual-self &&
52+
test_cmp expected-self actual-self
53+
'
54+
4955
test_expect_success "Compare second ID and key to first" '
5056
ipfs id -f="<id>" > second_id &&
5157
ipfs id -f="<pubkey>" > second_key &&

0 commit comments

Comments
 (0)