mirror of
https://github.com/status-im/nim-eth-p2p.git
synced 2025-01-14 17:04:19 +00:00
burnMem(secret)
This commit is contained in:
parent
5523cb44db
commit
e7959ee19d
@ -525,6 +525,12 @@ proc connectionEstablished(p: Peer, h: p2p.hello) =
|
|||||||
newSeq(p.protocolStates, gProtocols.len)
|
newSeq(p.protocolStates, gProtocols.len)
|
||||||
# XXX: initialize the sub-protocol states
|
# XXX: initialize the sub-protocol states
|
||||||
|
|
||||||
|
proc initSecretState(hs: var Handshake, authMsg, ackMsg: openarray[byte], p: Peer) =
|
||||||
|
var secrets: ConnectionSecret
|
||||||
|
check hs.getSecrets(authMsg, ackMsg, secrets)
|
||||||
|
initSecretState(secrets, p.secretsState)
|
||||||
|
burnMem(secrets)
|
||||||
|
|
||||||
proc rlpxConnect*(myKeys: KeyPair, listenPort: Port, remote: Node): Future[Peer] {.async.} =
|
proc rlpxConnect*(myKeys: KeyPair, listenPort: Port, remote: Node): Future[Peer] {.async.} =
|
||||||
# TODO: Make sure to close the socket in case of exception
|
# TODO: Make sure to close the socket in case of exception
|
||||||
new result
|
new result
|
||||||
@ -549,9 +555,7 @@ proc rlpxConnect*(myKeys: KeyPair, listenPort: Port, remote: Node): Future[Peer]
|
|||||||
await result.socket.fullRecvInto(addr ackMsg, ackMsgLen)
|
await result.socket.fullRecvInto(addr ackMsg, ackMsgLen)
|
||||||
|
|
||||||
check handshake.decodeAckMessage(^ackMsg)
|
check handshake.decodeAckMessage(^ackMsg)
|
||||||
var secrets: ConnectionSecret
|
initSecretState(handshake, ^authMsg, ^ackMsg, result)
|
||||||
check handshake.getSecrets(^authMsg, ^ackMsg, secrets)
|
|
||||||
initSecretState(secrets, result.secretsState)
|
|
||||||
|
|
||||||
if handshake.remoteHPubkey != remote.node.pubKey:
|
if handshake.remoteHPubkey != remote.node.pubKey:
|
||||||
raise newException(Exception, "Remote pubkey is wrong")
|
raise newException(Exception, "Remote pubkey is wrong")
|
||||||
@ -583,10 +587,7 @@ proc rlpxConnectIncoming*(myKeys: KeyPair, listenPort: Port, address: IpAddress,
|
|||||||
check handshake.ackMessage(ackMsg, ackMsgLen)
|
check handshake.ackMessage(ackMsg, ackMsgLen)
|
||||||
|
|
||||||
await s.send(addr ackMsg[0], ackMsgLen)
|
await s.send(addr ackMsg[0], ackMsgLen)
|
||||||
|
initSecretState(handshake, ^authMsg, ^ackMsg, result)
|
||||||
var secrets: ConnectionSecret
|
|
||||||
check handshake.getSecrets(^authMsg, ^ackMsg, secrets)
|
|
||||||
initSecretState(secrets, result.secretsState)
|
|
||||||
|
|
||||||
var response = await result.nextMsg(p2p.hello, discardOthers = true)
|
var response = await result.nextMsg(p2p.hello, discardOthers = true)
|
||||||
discard result.hello(baseProtocolVersion, clienId,
|
discard result.hello(baseProtocolVersion, clienId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user