aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2018-06-12 21:26:08 +0800
committerGuillaume Ballet <gballet@gmail.com>2018-06-12 21:26:08 +0800
commit0255951587ef0eada5d162f3404bc481f70a2ce2 (patch)
tree6aa0c1c9405df6a88f4cbeb72e170e6e19cf55d5 /cmd
parent85cd64df0e3331e46f41ec86a647f1b8ff306eda (diff)
downloadgo-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.tar
go-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.gz
go-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.bz2
go-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.lz
go-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.xz
go-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.zst
go-tangerine-0255951587ef0eada5d162f3404bc481f70a2ce2.zip
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.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/wnode/main.go13
1 files changed, 4 insertions, 9 deletions
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index 5031a088c..31b65c1da 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -140,8 +140,8 @@ func processArgs() {
}
if *asymmetricMode && len(*argPub) > 0 {
- pub = crypto.ToECDSAPub(common.FromHex(*argPub))
- if !isKeyValid(pub) {
+ var err error
+ if pub, err = crypto.UnmarshalPubkey(common.FromHex(*argPub)); err != nil {
utils.Fatalf("invalid public key")
}
}
@@ -321,10 +321,6 @@ func startServer() error {
return nil
}
-func isKeyValid(k *ecdsa.PublicKey) bool {
- return k.X != nil && k.Y != nil
-}
-
func configureNode() {
var err error
var p2pAccept bool
@@ -340,9 +336,8 @@ func configureNode() {
if b == nil {
utils.Fatalf("Error: can not convert hexadecimal string")
}
- pub = crypto.ToECDSAPub(b)
- if !isKeyValid(pub) {
- utils.Fatalf("Error: invalid public key")
+ if pub, err = crypto.UnmarshalPubkey(b); err != nil {
+ utils.Fatalf("Error: invalid peer public key")
}
}
}