mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-02 06:47:51 +08:00
Merge pull request #7582 from ipfs/petar/keys
use b36 keys by default for keys and IPNS
This commit is contained in:
commit
c7a24a3e9b
37
core/commands/keyencode/keyencode.go
Normal file
37
core/commands/keyencode/keyencode.go
Normal file
@ -0,0 +1,37 @@
|
||||
package keyencode
|
||||
|
||||
import (
|
||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||
mbase "github.com/multiformats/go-multibase"
|
||||
)
|
||||
|
||||
const IPNSKeyFormatOptionName = "ipns-base"
|
||||
|
||||
type KeyEncoder struct {
|
||||
baseEnc *mbase.Encoder
|
||||
}
|
||||
|
||||
func KeyEncoderFromString(formatLabel string) (KeyEncoder, error) {
|
||||
switch formatLabel {
|
||||
case "b58mh", "v0":
|
||||
return KeyEncoder{}, nil
|
||||
default:
|
||||
if enc, err := mbase.EncoderByName(formatLabel); err != nil {
|
||||
return KeyEncoder{}, err
|
||||
} else {
|
||||
return KeyEncoder{&enc}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (enc KeyEncoder) FormatID(id peer.ID) string {
|
||||
if enc.baseEnc == nil {
|
||||
//nolint deprecated
|
||||
return peer.IDB58Encode(id)
|
||||
}
|
||||
if s, err := peer.ToCid(id).StringOfBase(enc.baseEnc.Encoding()); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return s
|
||||
}
|
||||
}
|
||||
@ -15,11 +15,11 @@ import (
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core/commands/e"
|
||||
ke "github.com/ipfs/go-ipfs/core/commands/keyencode"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
options "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||
mbase "github.com/multiformats/go-multibase"
|
||||
)
|
||||
|
||||
var KeyCmd = &cmds.Command{
|
||||
@ -68,11 +68,10 @@ type KeyRenameOutput struct {
|
||||
}
|
||||
|
||||
const (
|
||||
keyStoreAlgorithmDefault = options.RSAKey
|
||||
keyStoreTypeOptionName = "type"
|
||||
keyStoreSizeOptionName = "size"
|
||||
keyFormatOptionName = "format"
|
||||
oldKeyOptionName = "oldkey"
|
||||
keyStoreAlgorithmDefault = options.RSAKey
|
||||
keyStoreTypeOptionName = "type"
|
||||
keyStoreSizeOptionName = "size"
|
||||
oldKeyOptionName = "oldkey"
|
||||
)
|
||||
|
||||
var keyGenCmd = &cmds.Command{
|
||||
@ -82,7 +81,7 @@ var keyGenCmd = &cmds.Command{
|
||||
Options: []cmds.Option{
|
||||
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault),
|
||||
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
|
||||
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Arguments: []cmds.Argument{
|
||||
cmds.StringArg("name", true, false, "name of key to create"),
|
||||
@ -109,7 +108,8 @@ var keyGenCmd = &cmds.Command{
|
||||
if sizefound {
|
||||
opts = append(opts, options.Key.Size(size))
|
||||
}
|
||||
if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ var keyGenCmd = &cmds.Command{
|
||||
|
||||
return cmds.EmitOnce(res, &KeyOutput{
|
||||
Name: name,
|
||||
Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)),
|
||||
Id: keyEnc.FormatID(key.ID()),
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
@ -223,7 +223,7 @@ var keyImportCmd = &cmds.Command{
|
||||
Tagline: "Import a key and prints imported key id",
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Arguments: []cmds.Argument{
|
||||
cmds.StringArg("name", true, false, "name to associate with key in keychain"),
|
||||
@ -236,6 +236,11 @@ var keyImportCmd = &cmds.Command{
|
||||
return fmt.Errorf("cannot import key with name 'self'")
|
||||
}
|
||||
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
@ -280,7 +285,7 @@ var keyImportCmd = &cmds.Command{
|
||||
|
||||
return cmds.EmitOnce(res, &KeyOutput{
|
||||
Name: name,
|
||||
Id: formatID(pid, req.Options[keyFormatOptionName].(string)),
|
||||
Id: keyEnc.FormatID(pid),
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
@ -298,10 +303,11 @@ var keyListCmd = &cmds.Command{
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption("l", "Show extra information about keys."),
|
||||
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -320,7 +326,7 @@ var keyListCmd = &cmds.Command{
|
||||
for _, key := range keys {
|
||||
list = append(list, KeyOutput{
|
||||
Name: key.Name(),
|
||||
Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)),
|
||||
Id: keyEnc.FormatID(key.ID()),
|
||||
})
|
||||
}
|
||||
|
||||
@ -346,12 +352,17 @@ var keyRenameCmd = &cmds.Command{
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."),
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
api, err := cmdenv.GetApi(env, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := req.Arguments[0]
|
||||
newName := req.Arguments[1]
|
||||
@ -365,7 +376,7 @@ var keyRenameCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, &KeyRenameOutput{
|
||||
Was: name,
|
||||
Now: newName,
|
||||
Id: key.ID().Pretty(),
|
||||
Id: keyEnc.FormatID(key.ID()),
|
||||
Overwrite: overwritten,
|
||||
})
|
||||
},
|
||||
@ -391,12 +402,17 @@ var keyRmCmd = &cmds.Command{
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption("l", "Show extra information about keys."),
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
api, err := cmdenv.GetApi(env, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
names := req.Arguments
|
||||
|
||||
@ -407,7 +423,10 @@ var keyRmCmd = &cmds.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
list = append(list, KeyOutput{Name: name, Id: key.ID().Pretty()})
|
||||
list = append(list, KeyOutput{
|
||||
Name: name,
|
||||
Id: keyEnc.FormatID(key.ID()),
|
||||
})
|
||||
}
|
||||
|
||||
return cmds.EmitOnce(res, &KeyOutputList{list})
|
||||
@ -517,31 +536,6 @@ func doRotate(out io.Writer, repoRoot string, oldKey string, algorithm string, n
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifyIDFormatLabel(formatLabel string) error {
|
||||
switch formatLabel {
|
||||
case "b58mh":
|
||||
return nil
|
||||
case "b36cid":
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid output format option")
|
||||
}
|
||||
|
||||
func formatID(id peer.ID, formatLabel string) string {
|
||||
switch formatLabel {
|
||||
case "b58mh":
|
||||
return id.Pretty()
|
||||
case "b36cid":
|
||||
if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return s
|
||||
}
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
|
||||
func keyOutputListEncoders() cmds.EncoderFunc {
|
||||
return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *KeyOutputList) error {
|
||||
withID, _ := req.Options["l"].(bool)
|
||||
|
||||
@ -5,10 +5,11 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/ipfs/go-ipfs-cmds"
|
||||
cmds "github.com/ipfs/go-ipfs-cmds"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
ke "github.com/ipfs/go-ipfs/core/commands/keyencode"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-record"
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
)
|
||||
|
||||
type ipnsPubsubState struct {
|
||||
@ -72,7 +73,15 @@ var ipnspsSubsCmd = &cmds.Command{
|
||||
Helptext: cmds.HelpText{
|
||||
Tagline: "Show current name subscriptions",
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n, err := cmdenv.GetNode(env)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -93,7 +102,7 @@ var ipnspsSubsCmd = &cmds.Command{
|
||||
log.Errorf("ipns key not a valid peer ID: %s", err)
|
||||
continue
|
||||
}
|
||||
paths = append(paths, "/ipns/"+peer.Encode(pid))
|
||||
paths = append(paths, "/ipns/"+keyEnc.FormatID(pid))
|
||||
}
|
||||
|
||||
return cmds.EmitOnce(res, &stringList{paths})
|
||||
|
||||
@ -9,9 +9,11 @@ import (
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs-cmds"
|
||||
ke "github.com/ipfs/go-ipfs/core/commands/keyencode"
|
||||
iface "github.com/ipfs/interface-go-ipfs-core"
|
||||
options "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
path "github.com/ipfs/interface-go-ipfs-core/path"
|
||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -81,12 +83,17 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
|
||||
cmds.StringOption(ttlOptionName, "Time duration this record should be cached for. Uses the same syntax as the lifetime option. (caution: experimental)"),
|
||||
cmds.StringOption(keyOptionName, "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'.").WithDefault("self"),
|
||||
cmds.BoolOption(quieterOptionName, "Q", "Write only final hash."),
|
||||
cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
api, err := cmdenv.GetApi(env, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allowOffline, _ := req.Options[allowOfflineOptionName].(bool)
|
||||
kname, _ := req.Options[keyOptionName].(string)
|
||||
@ -129,8 +136,14 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
|
||||
return err
|
||||
}
|
||||
|
||||
// parse path, extract cid, re-base cid, reconstruct path
|
||||
pid, err := peer.Decode(out.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cmds.EmitOnce(res, &IpnsEntry{
|
||||
Name: out.Name(),
|
||||
Name: keyEnc.FormatID(pid),
|
||||
Value: out.Value().String(),
|
||||
})
|
||||
},
|
||||
|
||||
@ -82,23 +82,6 @@ Resolve the value of an IPFS DAG path:
|
||||
name := req.Arguments[0]
|
||||
recursive, _ := req.Options[resolveRecursiveOptionName].(bool)
|
||||
|
||||
var enc cidenc.Encoder
|
||||
switch {
|
||||
case !cmdenv.CidBaseDefined(req):
|
||||
// Not specified, check the path.
|
||||
enc, err = cmdenv.CidEncoderFromPath(name)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
// Nope, fallback on the default.
|
||||
fallthrough
|
||||
default:
|
||||
enc, err = cmdenv.GetCidEncoder(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// the case when ipns is resolved step by step
|
||||
if strings.HasPrefix(name, "/ipns/") && !recursive {
|
||||
rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
|
||||
@ -128,6 +111,23 @@ Resolve the value of an IPFS DAG path:
|
||||
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: ipfspath.Path(p.String())})
|
||||
}
|
||||
|
||||
var enc cidenc.Encoder
|
||||
switch {
|
||||
case !cmdenv.CidBaseDefined(req) && !strings.HasPrefix(name, "/ipns/"):
|
||||
// Not specified, check the path.
|
||||
enc, err = cmdenv.CidEncoderFromPath(name)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
// Nope, fallback on the default.
|
||||
fallthrough
|
||||
default:
|
||||
enc, err = cmdenv.GetCidEncoder(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// else, ipfs path or ipns with recursive flag
|
||||
rp, err := api.ResolvePath(req.Context, path.New(name))
|
||||
if err != nil {
|
||||
|
||||
@ -122,24 +122,13 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
|
||||
|
||||
key := segments[2]
|
||||
|
||||
if p, ok := ns.cacheGet(key); ok {
|
||||
var err error
|
||||
if len(segments) > 3 {
|
||||
p, err = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
|
||||
}
|
||||
|
||||
out <- onceResult{value: p, err: err}
|
||||
close(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// Resolver selection:
|
||||
// 1. if it is a PeerID/CID/multihash resolve through "ipns".
|
||||
// 2. if it is a domain name, resolve through "dns"
|
||||
// 3. otherwise resolve through the "proquint" resolver
|
||||
|
||||
var res resolver
|
||||
_, err := peer.Decode(key)
|
||||
ipnsKey, err := peer.Decode(key)
|
||||
|
||||
// CIDs in IPNS are expected to have libp2p-key multicodec
|
||||
// We ease the transition by returning a more meaningful error with a valid CID
|
||||
@ -155,6 +144,22 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
|
||||
}
|
||||
}
|
||||
|
||||
cacheKey := key
|
||||
if err == nil {
|
||||
cacheKey = string(ipnsKey)
|
||||
}
|
||||
|
||||
if p, ok := ns.cacheGet(cacheKey); ok {
|
||||
var err error
|
||||
if len(segments) > 3 {
|
||||
p, err = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
|
||||
}
|
||||
|
||||
out <- onceResult{value: p, err: err}
|
||||
close(out)
|
||||
return out
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
res = ns.ipnsResolver
|
||||
} else if isd.IsDomain(key) {
|
||||
@ -172,7 +177,7 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
|
||||
case res, ok := <-resCh:
|
||||
if !ok {
|
||||
if best != (onceResult{}) {
|
||||
ns.cacheSet(key, best.value, best.ttl)
|
||||
ns.cacheSet(cacheKey, best.value, best.ttl)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -218,7 +223,7 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
|
||||
if err := ns.ipnsPublisher.PublishWithEOL(ctx, name, value, eol); err != nil {
|
||||
// Invalidate the cache. Publishing may _partially_ succeed but
|
||||
// still return an error.
|
||||
ns.cacheInvalidate(peer.Encode(id))
|
||||
ns.cacheInvalidate(string(id))
|
||||
return err
|
||||
}
|
||||
ttl := DefaultResolverCacheTTL
|
||||
@ -228,6 +233,6 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
|
||||
if ttEol := time.Until(eol); ttEol < ttl {
|
||||
ttl = ttEol
|
||||
}
|
||||
ns.cacheSet(peer.Encode(id), value, ttl)
|
||||
ns.cacheSet(string(id), value, ttl)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func TestPublishWithTTL(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ientry, ok := nsys.(*mpns).cache.Get(pid.Pretty())
|
||||
ientry, ok := nsys.(*mpns).cache.Get(string(pid))
|
||||
if !ok {
|
||||
t.Fatal("cache get failed")
|
||||
}
|
||||
|
||||
@ -445,8 +445,8 @@ file_size() {
|
||||
|
||||
# len 46: 2048-bit RSA keys, b58mh-encoded
|
||||
# len 52: ED25519 keys, b58mh-encoded
|
||||
# len 56: 2048-bit RSA keys, b36cid-encoded
|
||||
# len 62: ED25519 keys, b36cid-encoded
|
||||
# len 56: 2048-bit RSA keys, base36-encoded
|
||||
# len 62: ED25519 keys, base36-encoded
|
||||
test_check_peerid() {
|
||||
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
|
||||
test "$peeridlen" = "46" -o "$peeridlen" = "52" -o "$peeridlen" = "56" -o "$peeridlen" = "62" || {
|
||||
@ -471,7 +471,7 @@ test_check_ed25519_b58mh_peerid() {
|
||||
}
|
||||
}
|
||||
|
||||
test_check_rsa2048_b36cid_peerid() {
|
||||
test_check_rsa2048_base36_peerid() {
|
||||
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
|
||||
test "$peeridlen" = "56" || {
|
||||
echo "Bad RSA2048 B36CID peerid '$1' with len '$peeridlen'"
|
||||
@ -479,7 +479,7 @@ test_check_rsa2048_b36cid_peerid() {
|
||||
}
|
||||
}
|
||||
|
||||
test_check_ed25519_b36cid_peerid() {
|
||||
test_check_ed25519_base36_peerid() {
|
||||
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
|
||||
test "$peeridlen" = "62" || {
|
||||
echo "Bad ED25519 B36CID peerid '$1' with len '$peeridlen'"
|
||||
|
||||
@ -56,8 +56,8 @@ test_rotate() {
|
||||
test_expect_success "checking ID" '
|
||||
ipfs config Identity.PeerID > expected-id &&
|
||||
ipfs id -f "<id>\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 &&
|
||||
ipfs key list -l --ipns-base=b58mh | grep self | cut -d " " -f1 > keystore-id &&
|
||||
ipfs key list -l --ipns-base=b58mh | 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
|
||||
|
||||
@ -24,7 +24,7 @@ test_name_with_self() {
|
||||
ipfs init --profile=test -a=ed25519 > /dev/null
|
||||
;;
|
||||
esac &&
|
||||
export PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
|
||||
export PEERID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` &&
|
||||
test_check_peerid "${PEERID}"
|
||||
'
|
||||
|
||||
@ -109,21 +109,26 @@ test_name_with_self() {
|
||||
# test publishing with B36CID and B58MH resolve to the same B36CID
|
||||
|
||||
test_expect_success "verify self key output" '
|
||||
B58MH_ID=`ipfs key list -f=b58mh -l | grep self | cut -d " " -f1` &&
|
||||
B36CID_ID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
|
||||
B58MH_ID=`ipfs key list --ipns-base=b58mh -l | grep self | cut -d " " -f1` &&
|
||||
B36CID_ID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` &&
|
||||
test_check_peerid "${B58MH_ID}" &&
|
||||
test_check_peerid "${B36CID_ID}"
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name publish --allow-offline --key=<peer-id> <hash>' succeeds" '
|
||||
ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id &&
|
||||
ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >b36cid_published_id
|
||||
ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id_base36 &&
|
||||
ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >base36_published_id_base36 &&
|
||||
ipfs name publish --allow-offline --key=${B58MH_ID} --ipns-base=b58mh "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id_b58mh &&
|
||||
ipfs name publish --allow-offline --key=${B36CID_ID} --ipns-base=b58mh "/ipfs/$HASH_WELCOME_DOCS" >base36_published_id_b58mh
|
||||
'
|
||||
|
||||
test_expect_success "publish an explicit node ID as two key in B58MH and B36CID, name looks good" '
|
||||
echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id &&
|
||||
test_cmp expected_published_id b58mh_published_id &&
|
||||
test_cmp expected_published_id b36cid_published_id
|
||||
echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id_base36 &&
|
||||
echo "Published to ${B58MH_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id_b58mh &&
|
||||
test_cmp expected_published_id_base36 b58mh_published_id_base36 &&
|
||||
test_cmp expected_published_id_base36 base36_published_id_base36 &&
|
||||
test_cmp expected_published_id_b58mh b58mh_published_id_b58mh &&
|
||||
test_cmp expected_published_id_b58mh base36_published_id_b58mh
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
@ -250,15 +255,15 @@ test_name_with_key() {
|
||||
test_expect_success "'prepare keys" '
|
||||
case $GEN_ALG in
|
||||
rsa)
|
||||
export KEY=`ipfs key gen -f=b58mh --type=rsa --size=2048 key` &&
|
||||
export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1`
|
||||
export KEY=`ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key` &&
|
||||
export KEY_B36CID=`ipfs key list --ipns-base=base36 -l | grep key | cut -d " " -f1`
|
||||
;;
|
||||
ed25519_b58)
|
||||
export KEY=`ipfs key gen -f=b58mh --type=ed25519 key`
|
||||
export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1`
|
||||
export KEY=`ipfs key gen --ipns-base=b58mh --type=ed25519 key`
|
||||
export KEY_B36CID=`ipfs key list --ipns-base=base36 -l | grep key | cut -d " " -f1`
|
||||
;;
|
||||
ed25519_b36)
|
||||
export KEY=`ipfs key gen -f=b36cid --type=ed25519 key`
|
||||
export KEY=`ipfs key gen --ipns-base=base36 --type=ed25519 key`
|
||||
export KEY_B36CID=$KEY
|
||||
;;
|
||||
esac &&
|
||||
|
||||
@ -113,7 +113,7 @@ test_expect_success "Add the test directory" '
|
||||
'
|
||||
|
||||
test_expect_success "Publish test text file to IPNS using RSA keys" '
|
||||
RSA_KEY=$(ipfs key gen -f=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n")
|
||||
RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n")
|
||||
RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0)
|
||||
RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --codec libp2p-key -b base36)
|
||||
RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36)
|
||||
@ -125,9 +125,9 @@ test_expect_success "Publish test text file to IPNS using RSA keys" '
|
||||
'
|
||||
|
||||
test_expect_success "Publish test text file to IPNS using ED25519 keys" '
|
||||
ED25519_KEY=$(ipfs key gen -f=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n")
|
||||
ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n")
|
||||
ED25519_IPNS_IDv0=$ED25519_KEY
|
||||
ED25519_IPNS_IDv1=$(ipfs key list -l -f b36cid | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n")
|
||||
ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=base36 | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n")
|
||||
ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --codec protobuf)
|
||||
test_check_peerid "${ED25519_KEY}" &&
|
||||
ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out &&
|
||||
|
||||
@ -22,8 +22,8 @@ test_expect_success "resolve: prepare dag" '
|
||||
'
|
||||
|
||||
test_expect_success "resolve: prepare keys" '
|
||||
self_hash=$(ipfs id -f="<id>") &&
|
||||
alt_hash=$(ipfs key gen -f=b58mh -t rsa alt)
|
||||
self_hash=$(ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1) &&
|
||||
alt_hash=$(ipfs key gen --ipns-base=base36 -t rsa alt)
|
||||
'
|
||||
|
||||
test_resolve_setup_name() {
|
||||
@ -60,6 +60,7 @@ test_resolve() {
|
||||
}
|
||||
|
||||
test_resolve_cmd() {
|
||||
echo '-- starting test_resolve_cmd'
|
||||
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
|
||||
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
|
||||
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
|
||||
@ -96,6 +97,7 @@ test_resolve_cmd() {
|
||||
}
|
||||
|
||||
test_resolve_cmd_b32() {
|
||||
echo '-- starting test_resolve_cmd_b32'
|
||||
# no flags needed, base should be preserved
|
||||
|
||||
test_resolve "/ipfs/$a_hash_b32" "/ipfs/$a_hash_b32"
|
||||
|
||||
@ -13,11 +13,11 @@ test_init_ipfs
|
||||
test_key_cmd() {
|
||||
# test key output format
|
||||
test_expect_success "create an RSA key and test B58MH/B36CID output formats" '
|
||||
PEERID=$(ipfs key gen -f=b58mh --type=rsa --size=2048 key_rsa) &&
|
||||
PEERID=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key_rsa) &&
|
||||
test_check_rsa2048_b58mh_peerid $PEERID &&
|
||||
ipfs key rm key_rsa &&
|
||||
PEERID=$(ipfs key gen -f=b36cid --type=rsa --size=2048 key_rsa) &&
|
||||
test_check_rsa2048_b36cid_peerid $PEERID
|
||||
PEERID=$(ipfs key gen --ipns-base=base36 --type=rsa --size=2048 key_rsa) &&
|
||||
test_check_rsa2048_base36_peerid $PEERID
|
||||
'
|
||||
|
||||
test_expect_success "test RSA key sk export format" '
|
||||
@ -27,19 +27,19 @@ rm key_rsa.key
|
||||
'
|
||||
|
||||
test_expect_success "test RSA key B58MH/B36CID multihash format" '
|
||||
PEERID=$(ipfs key list -f=b58mh -l | grep key_rsa | head -n 1 | cut -d " " -f1) &&
|
||||
PEERID=$(ipfs key list --ipns-base=b58mh -l | grep key_rsa | head -n 1 | cut -d " " -f1) &&
|
||||
test_check_rsa2048_b58mh_peerid $PEERID &&
|
||||
PEERID=$(ipfs key list -f=b36cid -l | grep key_rsa | head -n 1 | cut -d " " -f1) &&
|
||||
test_check_rsa2048_b36cid_peerid $PEERID &&
|
||||
PEERID=$(ipfs key list --ipns-base=base36 -l | grep key_rsa | head -n 1 | cut -d " " -f1) &&
|
||||
test_check_rsa2048_base36_peerid $PEERID &&
|
||||
ipfs key rm key_rsa
|
||||
'
|
||||
|
||||
test_expect_success "create an ED25519 key and test B58MH/B36CID output formats" '
|
||||
PEERID=$(ipfs key gen -f=b58mh --type=ed25519 key_ed25519) &&
|
||||
PEERID=$(ipfs key gen --ipns-base=b58mh --type=ed25519 key_ed25519) &&
|
||||
test_check_ed25519_b58mh_peerid $PEERID &&
|
||||
ipfs key rm key_ed25519 &&
|
||||
PEERID=$(ipfs key gen -f=b36cid --type=ed25519 key_ed25519) &&
|
||||
test_check_ed25519_b36cid_peerid $PEERID
|
||||
PEERID=$(ipfs key gen --ipns-base=base36 --type=ed25519 key_ed25519) &&
|
||||
test_check_ed25519_base36_peerid $PEERID
|
||||
'
|
||||
|
||||
test_expect_success "test ED25519 key sk export format" '
|
||||
@ -49,10 +49,10 @@ rm key_ed25519.key
|
||||
'
|
||||
|
||||
test_expect_success "test ED25519 key B58MH/B36CID multihash format" '
|
||||
PEERID=$(ipfs key list -f=b58mh -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) &&
|
||||
PEERID=$(ipfs key list --ipns-base=b58mh -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) &&
|
||||
test_check_ed25519_b58mh_peerid $PEERID &&
|
||||
PEERID=$(ipfs key list -f=b36cid -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) &&
|
||||
test_check_ed25519_b36cid_peerid $PEERID &&
|
||||
PEERID=$(ipfs key list --ipns-base=base36 -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) &&
|
||||
test_check_ed25519_base36_peerid $PEERID &&
|
||||
ipfs key rm key_ed25519
|
||||
'
|
||||
# end of format test
|
||||
@ -125,7 +125,7 @@ ipfs key rm key_ed25519
|
||||
|
||||
test_expect_success "key list -l contains self key with peerID" '
|
||||
PeerID="$(ipfs config Identity.PeerID)"
|
||||
ipfs key list -l | grep "$PeerID\s\+self"
|
||||
ipfs key list -l --ipns-base=b58mh | grep "$PeerID\s\+self"
|
||||
'
|
||||
|
||||
test_expect_success "key rm remove a key" '
|
||||
|
||||
@ -13,7 +13,8 @@ test_expect_success 'init iptb' '
|
||||
startup_cluster $NUM_NODES --enable-namesys-pubsub
|
||||
|
||||
test_expect_success 'peer ids' '
|
||||
PEERID_0=$(iptb attr get 0 id)
|
||||
PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) &&
|
||||
PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1)
|
||||
'
|
||||
|
||||
test_expect_success 'check namesys pubsub state' '
|
||||
@ -28,17 +29,22 @@ test_expect_success 'check namesys pubsub state' '
|
||||
|
||||
# These commands are *expected* to fail. We haven't published anything yet.
|
||||
test_expect_success 'subscribe nodes to the publisher topic' '
|
||||
ipfsi 1 name resolve /ipns/$PEERID_0 --timeout=1s;
|
||||
ipfsi 2 name resolve /ipns/$PEERID_0 --timeout=1s;
|
||||
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
|
||||
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
|
||||
true
|
||||
'
|
||||
|
||||
test_expect_success 'check subscriptions' '
|
||||
echo /ipns/$PEERID_0 > expected &&
|
||||
echo /ipns/$PEERID_0_BASE36 > expected_base36 &&
|
||||
echo /ipns/$PEERID_0_B58MH > expected_b58mh &&
|
||||
ipfsi 1 name pubsub subs > subs1 &&
|
||||
ipfsi 2 name pubsub subs > subs2 &&
|
||||
test_cmp expected subs1 &&
|
||||
test_cmp expected subs2
|
||||
ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh &&
|
||||
ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh &&
|
||||
test_cmp expected_base36 subs1 &&
|
||||
test_cmp expected_base36 subs2 &&
|
||||
test_cmp expected_b58mh subs1_b58mh &&
|
||||
test_cmp expected_b58mh subs2_b58mh
|
||||
'
|
||||
|
||||
test_expect_success 'add an object on publisher node' '
|
||||
@ -56,15 +62,15 @@ test_expect_success 'wait for the flood' '
|
||||
|
||||
test_expect_success 'resolve name in subscriber nodes' '
|
||||
echo "/ipfs/$HASH_FILE" > expected &&
|
||||
ipfsi 1 name resolve /ipns/$PEERID_0 > name1 &&
|
||||
ipfsi 2 name resolve /ipns/$PEERID_0 > name2 &&
|
||||
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 > name1 &&
|
||||
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > name2 &&
|
||||
test_cmp expected name1 &&
|
||||
test_cmp expected name2
|
||||
'
|
||||
|
||||
test_expect_success 'cancel subscriptions to the publisher topic' '
|
||||
ipfsi 1 name pubsub cancel /ipns/$PEERID_0 &&
|
||||
ipfsi 2 name pubsub cancel /ipns/$PEERID_0
|
||||
ipfsi 1 name pubsub cancel /ipns/$PEERID_0_BASE36 &&
|
||||
ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36
|
||||
'
|
||||
|
||||
test_expect_success 'check subscriptions' '
|
||||
|
||||
@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" '
|
||||
test_launch_ipfs_daemon --offline
|
||||
|
||||
test_expect_success "'ipfs name resolve' succeeds after ipfs id when daemon offline" '
|
||||
PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
|
||||
PEERID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
|
||||
'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user