From fdb0046a1712e20ad107980b9667d65048b4660f Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Tue, 23 Jan 2018 08:25:40 -0500 Subject: [PATCH] Fix ipns validator key parsing License: MIT Signed-off-by: Dirk McCormick --- namesys/ipns_validate_test.go | 11 ++++++----- namesys/publisher.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/namesys/ipns_validate_test.go b/namesys/ipns_validate_test.go index 2d46c7a82..fa7888103 100644 --- a/namesys/ipns_validate_test.go +++ b/namesys/ipns_validate_test.go @@ -8,6 +8,7 @@ import ( path "github.com/ipfs/go-ipfs/path" u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" + peer "gx/ipfs/Qma7H6RW8wRrfZpNSXwxYGcd1E149s42FpWNpDNieSVrnU/go-libp2p-peer" ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" record "gx/ipfs/QmbsY8Pr6s3uZsKg7rzBtGDKeCtdoAhNaMTCXBUbvb1eCV/go-libp2p-record" ) @@ -45,7 +46,7 @@ func TestValidation(t *testing.T) { t.Fatal(err) } - // Create IPNS record path with a different key + // Create IPNS record path with a different private key _, ipnsWrongAuthor := genKeys(t, r) wrongAuthorRec, err := record.MakePutRecord(priv, ipnsWrongAuthor, val, true) if err != nil { @@ -118,14 +119,14 @@ func TestValidation(t *testing.T) { } func genKeys(t *testing.T, r io.Reader) (ci.PrivKey, string) { - priv, pubk, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, r) + priv, _, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, r) if err != nil { t.Fatal(err) } - pubkb, err := pubk.Bytes() + id, err := peer.IDFromPrivateKey(priv) if err != nil { t.Fatal(err) } - p := "/ipns/" + u.Hash(pubkb).B58String() - return priv, p + _, ipnsKey := IpnsKeysForID(id) + return priv, ipnsKey } diff --git a/namesys/publisher.go b/namesys/publisher.go index 48d32bcc1..3dc38c4d1 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -318,7 +318,7 @@ func ValidateIpnsRecord(r *record.ValidationRecord) error { // need to do that here // Author in key must match author in record - pid, err := peer.IDB58Decode(r.Key) + pid, err := peer.IDFromString(r.Key) if err != nil { return ErrInvalidAuthor }