mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 09:59:13 +08:00
Fix ipns validator key parsing
License: MIT Signed-off-by: Dirk McCormick <dirkmdev@gmail.com>
This commit is contained in:

committed by
Steven Allen

parent
f6d507b203
commit
fdb0046a17
@ -8,6 +8,7 @@ import (
|
|||||||
path "github.com/ipfs/go-ipfs/path"
|
path "github.com/ipfs/go-ipfs/path"
|
||||||
u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
|
u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
|
||||||
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||||
|
peer "gx/ipfs/Qma7H6RW8wRrfZpNSXwxYGcd1E149s42FpWNpDNieSVrnU/go-libp2p-peer"
|
||||||
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
|
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
|
||||||
record "gx/ipfs/QmbsY8Pr6s3uZsKg7rzBtGDKeCtdoAhNaMTCXBUbvb1eCV/go-libp2p-record"
|
record "gx/ipfs/QmbsY8Pr6s3uZsKg7rzBtGDKeCtdoAhNaMTCXBUbvb1eCV/go-libp2p-record"
|
||||||
)
|
)
|
||||||
@ -45,7 +46,7 @@ func TestValidation(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create IPNS record path with a different key
|
// Create IPNS record path with a different private key
|
||||||
_, ipnsWrongAuthor := genKeys(t, r)
|
_, ipnsWrongAuthor := genKeys(t, r)
|
||||||
wrongAuthorRec, err := record.MakePutRecord(priv, ipnsWrongAuthor, val, true)
|
wrongAuthorRec, err := record.MakePutRecord(priv, ipnsWrongAuthor, val, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -118,14 +119,14 @@ func TestValidation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genKeys(t *testing.T, r io.Reader) (ci.PrivKey, string) {
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
pubkb, err := pubk.Bytes()
|
id, err := peer.IDFromPrivateKey(priv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
p := "/ipns/" + u.Hash(pubkb).B58String()
|
_, ipnsKey := IpnsKeysForID(id)
|
||||||
return priv, p
|
return priv, ipnsKey
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ func ValidateIpnsRecord(r *record.ValidationRecord) error {
|
|||||||
// need to do that here
|
// need to do that here
|
||||||
|
|
||||||
// Author in key must match author in record
|
// Author in key must match author in record
|
||||||
pid, err := peer.IDB58Decode(r.Key)
|
pid, err := peer.IDFromString(r.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrInvalidAuthor
|
return ErrInvalidAuthor
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user