Skip to content

Commit a9e4a90

Browse files
gluk256karalabe
authored andcommitted
whisper: change the whisper message format so as to add the payload size (#15870)
* whisper: message format changed * whisper: tests fixed * whisper: style fixes * whisper: fixed names, fixed failing tests * whisper: fix merge issue in #15870 Occured while using the github online merge tool. Lesson learned. * whisper: fix a gofmt error for #15870
1 parent 59a852e commit a9e4a90

8 files changed

Lines changed: 193 additions & 183 deletions

File tree

‎whisper/whisperv6/api.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
278278
if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
279279
return false, err
280280
}
281-
if !validateSymmetricKey(params.KeySym) {
281+
if !validateDataIntegrity(params.KeySym, aesKeyLength) {
282282
return false, ErrInvalidSymmetricKey
283283
}
284284
}
@@ -384,7 +384,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.
384384
if err != nil {
385385
return nil, err
386386
}
387-
if !validateSymmetricKey(key) {
387+
if !validateDataIntegrity(key, aesKeyLength) {
388388
return nil, ErrInvalidSymmetricKey
389389
}
390390
filter.KeySym = key
@@ -556,7 +556,7 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) {
556556
if keySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
557557
return "", err
558558
}
559-
if !validateSymmetricKey(keySym) {
559+
if !validateDataIntegrity(keySym, aesKeyLength) {
560560
return "", ErrInvalidSymmetricKey
561561
}
562562
}

‎whisper/whisperv6/doc.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@ const (
5252
p2pMessageCode = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
5353
NumberOfMessageCodes = 128
5454

55-
paddingMask = byte(3)
55+
SizeMask = byte(3) // mask used to extract the size of payload size field from the flags
5656
signatureFlag = byte(4)
5757

5858
TopicLength = 4 // in bytes
5959
signatureLength = 65 // in bytes
6060
aesKeyLength = 32 // in bytes
61-
AESNonceLength = 12 // in bytes
61+
aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize()
6262
keyIDSize = 32 // in bytes
6363
bloomFilterSize = 64 // in bytes
64+
flagsLength = 1
6465

6566
EnvelopeHeaderLength = 20
6667

6768
MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
6869
DefaultMaxMessageSize = uint32(1024 * 1024)
6970
DefaultMinimumPoW = 0.2
7071

71-
padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol (must not exceed 2^24)
72+
padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol
7273
messageQueueLimit = 1024
7374

7475
expirationCycle = time.Second

‎whisper/whisperv6/envelope.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error) {
200200

201201
// Open tries to decrypt an envelope, and populates the message fields in case of success.
202202
func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
203-
// The API interface forbids filters doing both symmetric and
204-
// asymmetric encryption.
203+
// The API interface forbids filters doing both symmetric and asymmetric encryption.
205204
if watcher.expectsAsymmetricEncryption() && watcher.expectsSymmetricEncryption() {
206205
return nil
207206
}
@@ -219,7 +218,7 @@ func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
219218
}
220219

221220
if msg != nil {
222-
ok := msg.Validate()
221+
ok := msg.ValidateAndParse()
223222
if !ok {
224223
return nil
225224
}

0 commit comments

Comments
 (0)