mirror of https://github.com/status-im/nim-eth.git
Add address to handshakes key
This commit is contained in:
parent
1fab56f894
commit
6b01ada194
|
@ -25,7 +25,7 @@ type
|
||||||
localNode*: Node
|
localNode*: Node
|
||||||
privKey*: PrivateKey
|
privKey*: PrivateKey
|
||||||
db*: Database
|
db*: Database
|
||||||
handshakes*: Table[string, Whoareyou] # TODO: Implement hash for NodeID
|
handshakes*: Table[string, Whoareyou] # TODO: Implement type & hash for NodeID + address
|
||||||
|
|
||||||
HandshakeSecrets = object
|
HandshakeSecrets = object
|
||||||
writeKey: AesKey
|
writeKey: AesKey
|
||||||
|
@ -247,7 +247,7 @@ proc decodeEncrypted*(c: var Codec,
|
||||||
auth = r.read(AuthHeader)
|
auth = r.read(AuthHeader)
|
||||||
authTag = auth.auth
|
authTag = auth.auth
|
||||||
|
|
||||||
let challenge = c.handshakes.getOrDefault($fromId)
|
let challenge = c.handshakes.getOrDefault($fromId & $fromAddr)
|
||||||
if challenge.isNil:
|
if challenge.isNil:
|
||||||
trace "Decoding failed (no challenge)"
|
trace "Decoding failed (no challenge)"
|
||||||
return HandshakeError
|
return HandshakeError
|
||||||
|
@ -260,7 +260,7 @@ proc decodeEncrypted*(c: var Codec,
|
||||||
if not c.decodeAuthResp(fromId, auth, challenge, sec, newNode):
|
if not c.decodeAuthResp(fromId, auth, challenge, sec, newNode):
|
||||||
trace "Decoding failed (bad auth)"
|
trace "Decoding failed (bad auth)"
|
||||||
return HandshakeError
|
return HandshakeError
|
||||||
c.handshakes.del($fromId)
|
c.handshakes.del($fromId & $fromAddr)
|
||||||
|
|
||||||
# Swap keys to match remote
|
# Swap keys to match remote
|
||||||
swap(sec.readKey, sec.writeKey)
|
swap(sec.readKey, sec.writeKey)
|
||||||
|
|
|
@ -100,11 +100,13 @@ proc sendWhoareyou(d: Protocol, address: Address, toNode: NodeId, authTag: AuthT
|
||||||
# will need to be canceled each time.
|
# will need to be canceled each time.
|
||||||
# TODO: could also clean up handshakes in a seperate call, e.g. triggered in
|
# TODO: could also clean up handshakes in a seperate call, e.g. triggered in
|
||||||
# a loop.
|
# a loop.
|
||||||
if not d.codec.handshakes.hasKeyOrPut($toNode, challenge):
|
# Use toNode + address to make it more difficult for an attacker to occupy
|
||||||
|
# the handshake of another node.
|
||||||
|
if not d.codec.handshakes.hasKeyOrPut($toNode & $address, challenge):
|
||||||
sleepAsync(handshakeTimeout).addCallback() do(data: pointer):
|
sleepAsync(handshakeTimeout).addCallback() do(data: pointer):
|
||||||
# TODO: should we still provide cancellation in case handshake completes
|
# TODO: should we still provide cancellation in case handshake completes
|
||||||
# correctly?
|
# correctly?
|
||||||
d.codec.handshakes.del($toNode)
|
d.codec.handshakes.del($toNode & $address)
|
||||||
|
|
||||||
var data = @(whoareyouMagic(toNode))
|
var data = @(whoareyouMagic(toNode))
|
||||||
data.add(rlp.encode(challenge[]))
|
data.add(rlp.encode(challenge[]))
|
||||||
|
|
Loading…
Reference in New Issue