From 0255951587ef0eada5d162f3404bc481f70a2ce2 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 12 Jun 2018 15:26:08 +0200 Subject: crypto: replace ToECDSAPub with error-checking func UnmarshalPubkey (#16932) ToECDSAPub was unsafe because it returned a non-nil key with nil X, Y in case of invalid input. This change replaces ToECDSAPub with UnmarshalPubkey across the codebase. --- p2p/rlpx.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'p2p') diff --git a/p2p/rlpx.go b/p2p/rlpx.go index a320e81e7..149eda689 100644 --- a/p2p/rlpx.go +++ b/p2p/rlpx.go @@ -528,9 +528,9 @@ func importPublicKey(pubKey []byte) (*ecies.PublicKey, error) { return nil, fmt.Errorf("invalid public key length %v (expect 64/65)", len(pubKey)) } // TODO: fewer pointless conversions - pub := crypto.ToECDSAPub(pubKey65) - if pub.X == nil { - return nil, fmt.Errorf("invalid public key") + pub, err := crypto.UnmarshalPubkey(pubKey65) + if err != nil { + return nil, err } return ecies.ImportECDSAPublic(pub), nil } -- cgit v1.2.3