2020-10-09 08:58:52 +00:00
|
|
|
import
|
2024-01-24 08:09:11 +00:00
|
|
|
std/net,
|
|
|
|
testutils/fuzzing,
|
2021-09-07 14:00:01 +00:00
|
|
|
../../../eth/p2p/discoveryv5/[encoding, enr, sessions, node]
|
2020-10-09 08:58:52 +00:00
|
|
|
|
|
|
|
init:
|
|
|
|
const
|
|
|
|
nodeAKey = "0xeef77acb6c6a6eebc5b363a475ac583ec7eccdb42b6481424c60f59aa326547f"
|
|
|
|
nodeBKey = "0x66fb62bfbd66b9177a138c1e5cddbe4f7c30c343e94e68df8769459cb1cde628"
|
|
|
|
let
|
|
|
|
rng = newRng()
|
|
|
|
privKeyA = PrivateKey.fromHex(nodeAKey)[] # sender -> encode
|
|
|
|
privKeyB = PrivateKey.fromHex(nodeBKey)[] # receive -> decode
|
|
|
|
|
|
|
|
enrRecA = enr.Record.init(1, privKeyA,
|
2024-06-18 16:09:27 +00:00
|
|
|
Opt.some(parseIpAddress("127.0.0.1")), Opt.some(Port(9000)),
|
|
|
|
Opt.some(Port(9000))).expect("Properly initialized private key")
|
2024-06-27 14:18:21 +00:00
|
|
|
nodeA = Node.fromRecord(enrRecA)
|
2020-10-09 08:58:52 +00:00
|
|
|
|
|
|
|
enrRecB = enr.Record.init(1, privKeyB,
|
2024-06-18 16:09:27 +00:00
|
|
|
Opt.some(parseIpAddress("127.0.0.1")), Opt.some(Port(9000)),
|
|
|
|
Opt.some(Port(9000))).expect("Properly initialized private key")
|
2024-06-27 14:18:21 +00:00
|
|
|
nodeB = Node.fromRecord(enrRecB)
|
2020-10-09 08:58:52 +00:00
|
|
|
|
|
|
|
var codecB = Codec(localNode: nodeB, privKey: privKeyB,
|
|
|
|
sessions: Sessions.init(5))
|
|
|
|
|
|
|
|
test:
|
|
|
|
# It is not the best idea to generate extra data and encrypt data but we do
|
|
|
|
# it like this as the decodeHeader proc does decrypt + decode + decrypt.
|
|
|
|
# There is no separate decrypt step that can be skipped because of this.
|
2022-06-17 20:45:37 +00:00
|
|
|
let
|
|
|
|
iv = rng[].generate(array[ivSize, byte])
|
|
|
|
maskedHeader = encryptHeader(nodeB.id, iv, payload)
|
2020-10-09 08:58:52 +00:00
|
|
|
|
|
|
|
let decoded = decodePacket(codecB, nodeA.address.get(), @iv & maskedHeader)
|
|
|
|
if decoded.isErr():
|
2022-11-16 16:44:00 +00:00
|
|
|
debug "Error occurred", error = decoded.error
|