diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2018-06-12 21:26:08 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2018-06-12 21:26:08 +0800 |
commit | 0255951587ef0eada5d162f3404bc481f70a2ce2 (patch) | |
tree | 6aa0c1c9405df6a88f4cbeb72e170e6e19cf55d5 /whisper | |
parent | 85cd64df0e3331e46f41ec86a647f1b8ff306eda (diff) | |
download | dexon-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.gz dexon-0255951587ef0eada5d162f3404bc481f70a2ce2.tar.zst dexon-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 'whisper')
-rw-r--r-- | whisper/whisperv5/api.go | 9 | ||||
-rw-r--r-- | whisper/whisperv6/api.go | 9 |
2 files changed, 6 insertions, 12 deletions
diff --git a/whisper/whisperv5/api.go b/whisper/whisperv5/api.go index c56d13949..2ce464220 100644 --- a/whisper/whisperv5/api.go +++ b/whisper/whisperv5/api.go @@ -252,8 +252,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er // Set asymmetric key that is used to encrypt the message if pubKeyGiven { - params.Dst = crypto.ToECDSAPub(req.PublicKey) - if !ValidatePublicKey(params.Dst) { + if params.Dst, err = crypto.UnmarshalPubkey(req.PublicKey); err != nil { return false, ErrInvalidPublicKey } } @@ -329,8 +328,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc. } if len(crit.Sig) > 0 { - filter.Src = crypto.ToECDSAPub(crit.Sig) - if !ValidatePublicKey(filter.Src) { + if filter.Src, err = crypto.UnmarshalPubkey(crit.Sig); err != nil { return nil, ErrInvalidSigningPubKey } } @@ -513,8 +511,7 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) { } if len(req.Sig) > 0 { - src = crypto.ToECDSAPub(req.Sig) - if !ValidatePublicKey(src) { + if src, err = crypto.UnmarshalPubkey(req.Sig); err != nil { return "", ErrInvalidSigningPubKey } } diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go index c60bc46a1..d729e79c3 100644 --- a/whisper/whisperv6/api.go +++ b/whisper/whisperv6/api.go @@ -272,8 +272,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil. // Set asymmetric key that is used to encrypt the message if pubKeyGiven { - params.Dst = crypto.ToECDSAPub(req.PublicKey) - if !ValidatePublicKey(params.Dst) { + if params.Dst, err = crypto.UnmarshalPubkey(req.PublicKey); err != nil { return nil, ErrInvalidPublicKey } } @@ -360,8 +359,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc. } if len(crit.Sig) > 0 { - filter.Src = crypto.ToECDSAPub(crit.Sig) - if !ValidatePublicKey(filter.Src) { + if filter.Src, err = crypto.UnmarshalPubkey(crit.Sig); err != nil { return nil, ErrInvalidSigningPubKey } } @@ -544,8 +542,7 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) { } if len(req.Sig) > 0 { - src = crypto.ToECDSAPub(req.Sig) - if !ValidatePublicKey(src) { + if src, err = crypto.UnmarshalPubkey(req.Sig); err != nil { return "", ErrInvalidSigningPubKey } } |