whsiper: updated envelope validation

This commit is contained in:
Vlad 2016-10-06 10:57:36 +02:00
parent 54925b8374
commit 5abb7463ad
2 changed files with 17 additions and 2 deletions

View file

@ -28,6 +28,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
mrand "math/rand"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
@ -106,7 +107,7 @@ func DeriveOneTimeKey(key []byte, salt []byte, version uint64) ([]byte, error) {
func NewSentMessage(params *MessageParams) *SentMessage {
// Construct an initial flag set: no signature, no padding, other bits random
buf := make([]byte, 1)
crand.Read(buf)
mrand.Read(buf)
flags := buf[0]
flags &= ^paddingMask
flags &= ^signatureFlag
@ -140,7 +141,7 @@ func (msg *SentMessage) appendPadding(params *MessageParams) {
panic("please fix the padding algorithm before releasing new version")
}
buf := make([]byte, padSize)
crand.Read(buf[1:])
mrand.Read(buf[1:])
buf[0] = byte(padSize)
if params.Padding != nil {
copy(buf[1:], params.Padding)

View file

@ -385,6 +385,20 @@ func (wh *Whisper) add(envelope *Envelope) error {
return fmt.Errorf("huge messages are not allowed")
}
if len(envelope.Version) > 4 {
return fmt.Errorf("oversized Version")
}
if len(envelope.AESNonce) > 12 {
// the standard AES GSM nonce size is 12,
// but const gcmStandardNonceSize cannot be accessed directly
return fmt.Errorf("oversized AESNonce")
}
if len(envelope.Salt) > saltLength {
return fmt.Errorf("oversized Salt")
}
if envelope.PoW() < MinimumPoW {
glog.V(logger.Debug).Infof("envelope with low PoW dropped: %f", envelope.PoW())
return nil // drop envelope without error