2019-06-18 15:28:55 +00:00
|
|
|
import
|
2020-06-12 14:19:58 +00:00
|
|
|
testutils/fuzzing, chronicles,
|
|
|
|
eth/p2p/[discovery, enode], eth/[keys, rlp],
|
|
|
|
../../p2p/p2p_test_helper
|
2019-06-18 15:28:55 +00:00
|
|
|
|
|
|
|
const DefaultListeningPort = 30303
|
2019-09-03 13:45:26 +00:00
|
|
|
var targetNode: DiscoveryProtocol
|
|
|
|
|
2019-09-25 15:02:43 +00:00
|
|
|
init:
|
2019-09-03 13:45:26 +00:00
|
|
|
# Set up a discovery node, this is the node we target when fuzzing
|
|
|
|
var
|
2020-06-12 14:19:58 +00:00
|
|
|
targetNodeKey = PrivateKey.fromHex("a2b50376a79b1a8c8a3296485572bdfbf54708bb46d3c25d73d2723aaaf6a617")[]
|
2019-09-03 13:45:26 +00:00
|
|
|
targetNodeAddr = localAddress(DefaultListeningPort)
|
|
|
|
targetNode = newDiscoveryProtocol(targetNodeKey, targetNodeAddr, @[])
|
|
|
|
# Create the transport as else replies on the messages send will fail.
|
|
|
|
targetNode.open()
|
2019-06-18 15:28:55 +00:00
|
|
|
|
2019-09-25 15:02:43 +00:00
|
|
|
test:
|
2019-06-18 15:28:55 +00:00
|
|
|
var
|
|
|
|
msg: seq[byte]
|
|
|
|
address: Address
|
|
|
|
|
2019-09-25 15:02:43 +00:00
|
|
|
# Sending raw payload is possible but won't find us much. We need a hash and
|
|
|
|
# a signature, and without it there is a big chance it will always result in
|
|
|
|
# "Wrong msg mac from" error.
|
2020-06-12 14:19:58 +00:00
|
|
|
let nodeKey = PrivateKey.fromHex("a2b50376a79b1a8c8a3296485572bdfbf54708bb46d3c25d73d2723aaaf6a618")[]
|
2019-09-25 15:02:43 +00:00
|
|
|
msg = packData(payload, nodeKey)
|
|
|
|
address = localAddress(DefaultListeningPort + 1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
targetNode.receive(address, msg)
|
|
|
|
# These errors are also catched in `processClient` in discovery.nim
|
|
|
|
# TODO: move them a layer down in discovery so we can do a cleaner test there?
|
2020-06-12 14:19:58 +00:00
|
|
|
except RlpError as e:
|
|
|
|
debug "Receive failed", err = e.msg
|
|
|
|
except DiscProtocolError as e:
|
2020-04-06 16:24:15 +00:00
|
|
|
debug "Receive failed", err = e.msg
|