From ac766bf7b3d26b6e7062a59f15d479a07bc5796f Mon Sep 17 00:00:00 2001 From: kdeme Date: Mon, 8 Apr 2019 13:06:33 +0200 Subject: [PATCH] Fix decoded dst bug + add tests --- eth/p2p/rlpx_protocols/whisper_protocol.nim | 4 ++-- tests/p2p/test_shh.nim | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/eth/p2p/rlpx_protocols/whisper_protocol.nim b/eth/p2p/rlpx_protocols/whisper_protocol.nim index dd715f8..339fa0e 100644 --- a/eth/p2p/rlpx_protocols/whisper_protocol.nim +++ b/eth/p2p/rlpx_protocols/whisper_protocol.nim @@ -607,6 +607,8 @@ proc notify*(filters: var Filters, msg: Message) {.gcsafe.} = if decoded.isNone(): decoded = decode(msg.env.data, dst = filter.privateKey, symKey = filter.symKey) + if decoded.isNone(): + continue if filter.privateKey.isSome(): keyHash = keccak256.digest(filter.privateKey.get().data) # TODO: Get rid of the hash and just use pubkey to compare? @@ -615,8 +617,6 @@ proc notify*(filters: var Filters, msg: Message) {.gcsafe.} = keyHash = keccak256.digest(filter.symKey.get()) # else: # NOTE: should we error on messages without encryption? - if decoded.isNone(): - continue else: if filter.privateKey.isSome(): if keyHash != keccak256.digest(filter.privateKey.get().data): diff --git a/tests/p2p/test_shh.nim b/tests/p2p/test_shh.nim index 8bbd4a3..0c89370 100644 --- a/tests/p2p/test_shh.nim +++ b/tests/p2p/test_shh.nim @@ -22,6 +22,7 @@ suite "Whisper payload": check: decoded.isSome() payload.payload == decoded.get().payload + decoded.get().src.isNone() decoded.get().padding.get().len == 251 # 256 -1 -1 -3 test "should roundtrip with symmetric encryption": @@ -33,6 +34,7 @@ suite "Whisper payload": check: decoded.isSome() payload.payload == decoded.get().payload + decoded.get().src.isNone() decoded.get().padding.get().len == 251 # 256 -1 -1 -3 test "should roundtrip with signature": @@ -59,6 +61,7 @@ suite "Whisper payload": check: decoded.isSome() payload.payload == decoded.get().payload + decoded.get().src.isNone() decoded.get().padding.get().len == 251 # 256 -1 -1 -3 test "should return specified bloom": @@ -299,7 +302,10 @@ suite "Whisper filter": notify(filters, msg) let messages = filters.getFilterMessages(filterId) - check messages.len == 1 + check: + messages.len == 1 + messages[0].decoded.src.isNone() + messages[0].dst.isNone() test "should notify filter on message with asymmetric encryption": let privKey = keys.newPrivateKey() @@ -314,7 +320,10 @@ suite "Whisper filter": notify(filters, msg) let messages = filters.getFilterMessages(filterId) - check messages.len == 1 + check: + messages.len == 1 + messages[0].decoded.src.isNone() + messages[0].dst.isSome() test "should notify filter on message with signature": let privKey = keys.newPrivateKey() @@ -329,7 +338,10 @@ suite "Whisper filter": notify(filters, msg) let messages = filters.getFilterMessages(filterId) - check messages.len == 1 + check: + messages.len == 1 + messages[0].decoded.src.isSome() + messages[0].dst.isNone() test "test notify of filter against PoW requirement": let topic = [byte 0, 0, 0, 0]