-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix handling of dht records and local fixups #2943
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,13 +73,19 @@ func (v Validator) IsSigned(k key.Key) (bool, error) { | |
// verifies that the passed in record value is the PublicKey | ||
// that matches the passed in key. | ||
func ValidatePublicKeyRecord(k key.Key, val []byte) error { | ||
keyparts := bytes.Split([]byte(k), []byte("/")) | ||
if len(keyparts) < 3 { | ||
return errors.New("invalid key") | ||
if len(k) != 38 { | ||
return errors.New("invalid public key record key") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this length check will cause trouble when changing multihashes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't want to do that we can do: bytes.SplitN([]byte(k). []byte("/"), 2) then the second part should contain the rest of the key (even if it contains more slashes). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true... I guess i could switch to chopping off the prefix and checking that its a valid multihash |
||
} | ||
|
||
prefix := string(k[:4]) | ||
if prefix != "/pk/" { | ||
return errors.New("key was not prefixed with /pk/") | ||
} | ||
|
||
keyhash := []byte(k[4:]) | ||
|
||
pkh := u.Hash(val) | ||
if !bytes.Equal(keyparts[2], pkh) { | ||
if !bytes.Equal(keyhash, pkh) { | ||
return errors.New("public key does not match storage key") | ||
} | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package record | ||
|
||
import ( | ||
"encoding/base64" | ||
"testing" | ||
|
||
key "github.com/ipfs/go-ipfs/blocks/key" | ||
ci "gx/ipfs/QmUWER4r4qMvaCnX5zREcfyiWN7cXN9g3a7fkRqNz8qWPP/go-libp2p-crypto" | ||
) | ||
|
||
var OffensiveKey = "CAASXjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDjXAQQMal4SB2tSnX6NJIPmC69/BT8A8jc7/gDUZNkEhdhYHvc7k7S4vntV/c92nJGxNdop9fKJyevuNMuXhhHAgMBAAE=" | ||
|
||
func TestValidatePublicKey(t *testing.T) { | ||
pkb, err := base64.StdEncoding.DecodeString(OffensiveKey) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
pubk, err := ci.UnmarshalPublicKey(pkb) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
pkh, err := pubk.Hash() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
k := key.Key("/pk/" + string(pkh)) | ||
|
||
err = ValidatePublicKeyRecord(k, pkb) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is what the self-dials where from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, that was indeed the source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have been lowercase.