@cryptotaxi247 / kubo / commits / 6b63de8a5

fix: check repo version before key export

https://github.com/ipfs/go-ipfs/pull/8113#discussion_r628314443

Marcin Rataj committed May 11, 2021 at 19:39 UTC 6b63de8a5ad6b9063bd1b65a41f355543ead0511
2 files changed +11 -1
core/commands/keystore.go
+10
@@ -18,6 +18,7 @@ import (
18 "github.com/ipfs/go-ipfs/core/commands/e"
19 ke "github.com/ipfs/go-ipfs/core/commands/keyencode"
20 fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
21 + migrations "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
22 options "github.com/ipfs/interface-go-ipfs-core/options"
23 "github.com/libp2p/go-libp2p-core/crypto"
24 peer "github.com/libp2p/go-libp2p-core/peer"
@@ -163,6 +164,15 @@ path can be specified with '--output=<path>' or '-o=<path>'.
164 return err
165 }
166
167 + // Check repo version, and error out if not matching
168 + ver, err := migrations.RepoVersion(cfgRoot)
169 + if err != nil {
170 + return err
171 + }
172 + if ver > fsrepo.RepoVersion {
173 + return fmt.Errorf("key export expects repo version (%d) but found (%d)", fsrepo.RepoVersion, ver)
174 + }
175 +
176 // Export is read-only: safe to read it without acquiring repo lock
177 // (this makes export work when ipfs daemon is already running)
178 ksp := filepath.Join(cfgRoot, "keystore")
test/sharness/t0165-keystore.sh
+1 -1
@@ -187,7 +187,7 @@ ipfs key rm key_ed25519
187
188 test_expect_success "key export over HTTP /api/v0/key/export is not possible" '
189 ipfs key gen nohttpexporttest_key --type=ed25519 &&
190 - test_curl_resp_http_code "http://127.0.0.1:$API_PORT/api/v0/key/export&arg=nohttpexporttest_key" "HTTP/1.1 404 Not Found"
190 + curl -X POST -sI "http://$API_ADDR/api/v0/key/export&arg=nohttpexporttest_key" | grep -q "^HTTP/1.1 404 Not Found"
191 '
192
193 test_expect_success "online rotate rsa key" '