From 2bc1ff0ec1df1bf2e31d5957418d954590129a99 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Tue, 14 Jul 2020 10:51:29 -0700 Subject: [PATCH] test all key types --- cmd/ipfs/rotate.go | 4 +- test/sharness/t0027-rotate.sh | 106 ++++++++++++++++++++-------------- 2 files changed, 64 insertions(+), 46 deletions(-) diff --git a/cmd/ipfs/rotate.go b/cmd/ipfs/rotate.go index 77831af5a5c0..11a00a8af89e 100644 --- a/cmd/ipfs/rotate.go +++ b/cmd/ipfs/rotate.go @@ -13,7 +13,7 @@ import ( ) const ( - algorithmDefault = options.Ed25519Key + algorithmDefault = options.RSAKey algorithmOptionName = "algorithm" oldKeyOptionName = "oldkey" ) @@ -36,7 +36,7 @@ environment variable: Options: []cmds.Option{ cmds.StringOption(oldKeyOptionName, "o", "Keystore name for the old/rotated-out key."), cmds.StringOption(algorithmOptionName, "a", "Cryptographic algorithm to use for key generation.").WithDefault(algorithmDefault), - cmds.IntOption(bitsOptionName, "b", "Number of bits to use in the generated RSA private key.").WithDefault(nBitsForKeypairDefault), + cmds.IntOption(bitsOptionName, "b", "Number of bits to use in the generated RSA private key."), }, PreRun: func(req *cmds.Request, env cmds.Environment) error { cctx := env.(*oldcmds.Context) diff --git a/test/sharness/t0027-rotate.sh b/test/sharness/t0027-rotate.sh index e14ad3530d4d..caef0d477ce3 100755 --- a/test/sharness/t0027-rotate.sh +++ b/test/sharness/t0027-rotate.sh @@ -4,47 +4,65 @@ test_description="Test rotate command" . lib/test-lib.sh -test_init_ipfs - -test_expect_success "Save first ID and key" ' -ipfs id -f="" > first_id && -ipfs id -f="" > first_key -' - -test_launch_ipfs_daemon - -test_kill_ipfs_daemon - -test_expect_success "rotating keys" ' -ipfs rotate --oldkey=oldkey -' - -test_expect_success "Compare second ID and key to first" ' -ipfs id -f="" > second_id && -ipfs id -f="" > second_key && -! test_cmp first_id second_id && -! test_cmp first_key second_key -' - -test_expect_success "checking ID" ' -ipfs config Identity.PeerID > expected-id && -ipfs id -f "\n" > actual-id && -ipfs key list -l | grep self | cut -d " " -f1 > keystore-id && -ipfs key list -l | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && -test_cmp expected-id actual-id && -test_cmp expected-id keystore-id && -test_cmp old-keystore-id first_id -' - -test_launch_ipfs_daemon - -test_expect_success "publish name with new and old keys" ' -echo "hello world" > msg && -ipfs add msg | cut -d " " -f2 | tr -d "\n" > msg_hash && -ipfs name publish --offline --allow-offline --key=self $(cat msg_hash) && -ipfs name publish --offline --allow-offline --key=oldkey $(cat msg_hash) -' - -test_kill_ipfs_daemon - -test_done +# $1 must be one of 'rsa', 'ed25519' or '' (for default key algorithm). +test_rotate() { + TEST_ALG=$1 + + test_init_ipfs + + test_expect_success "Save first ID and key" ' + ipfs id -f="" > first_id && + ipfs id -f="" > first_key + ' + + test_launch_ipfs_daemon + + test_kill_ipfs_daemon + + test_expect_success "rotating keys" ' + case $TEST_ALG in + rsa) + ipfs rotate -a=rsa -b=2048 --oldkey=oldkey + ;; + ed25519) + ipfs rotate -a=ed25519 --oldkey=oldkey + ;; + *) + ipfs rotate --oldkey=oldkey + ;; + esac + ' + + test_expect_success "Compare second ID and key to first" ' + ipfs id -f="" > second_id && + ipfs id -f="" > second_key && + ! test_cmp first_id second_id && + ! test_cmp first_key second_key + ' + + test_expect_success "checking ID" ' + ipfs config Identity.PeerID > expected-id && + ipfs id -f "\n" > actual-id && + ipfs key list -l | grep self | cut -d " " -f1 > keystore-id && + ipfs key list -l | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && + test_cmp expected-id actual-id && + test_cmp expected-id keystore-id && + test_cmp old-keystore-id first_id + ' + + test_launch_ipfs_daemon + + test_expect_success "publish name with new and old keys" ' + echo "hello world" > msg && + ipfs add msg | cut -d " " -f2 | tr -d "\n" > msg_hash && + ipfs name publish --offline --allow-offline --key=self $(cat msg_hash) && + ipfs name publish --offline --allow-offline --key=oldkey $(cat msg_hash) + ' + + test_kill_ipfs_daemon + + test_done +} +test_rotate 'rsa' +test_rotate 'ed25519' +test_rotate ''