2020-10-09 08:58:52 +00:00
|
|
|
import
|
2021-09-07 14:00:01 +00:00
|
|
|
testutils/fuzzing, stew/shims/net,
|
|
|
|
../../../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,
|
2021-01-26 13:11:22 +00:00
|
|
|
some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)),
|
|
|
|
some(Port(9000))).expect("Properly intialized private key")
|
2020-10-09 08:58:52 +00:00
|
|
|
nodeA = newNode(enrRecA).expect("Properly initialized record")
|
|
|
|
|
|
|
|
enrRecB = enr.Record.init(1, privKeyB,
|
2021-01-26 13:11:22 +00:00
|
|
|
some(ValidIpAddress.init("127.0.0.1")), some(Port(9000)),
|
|
|
|
some(Port(9000))).expect("Properly intialized private key")
|
2020-10-09 08:58:52 +00:00
|
|
|
nodeB = newNode(enrRecB).expect("Properly initialized record")
|
|
|
|
|
|
|
|
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.
|
|
|
|
var iv: array[ivSize, byte]
|
|
|
|
brHmacDrbgGenerate(rng[], iv)
|
|
|
|
let maskedHeader = encryptHeader(nodeB.id, iv, payload)
|
|
|
|
|
|
|
|
let decoded = decodePacket(codecB, nodeA.address.get(), @iv & maskedHeader)
|
|
|
|
if decoded.isErr():
|
|
|
|
debug "Error occured", error = decoded.error
|