Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 18584 dev #4

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion test/functional/p2p_leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from test_framework.messages import msg_getaddr, msg_ping, msg_verack
from test_framework.mininode import mininode_lock, P2PInterface
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import wait_until
from test_framework.util import (
assert_equal,
assert_greater_than_or_equal,
wait_until,
)

banscore = 10

Expand Down Expand Up @@ -88,11 +92,24 @@ def on_version(self, message):
self.send_message(msg_ping())
self.send_message(msg_getaddr())


class P2PVersionStore(P2PInterface):
version_received = None

def on_version(self, msg):
super().on_version(msg)
self.version_received = msg


class P2PLeakTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [['-banscore=' + str(banscore)]]

def setup_network(self):
self.disable_mocktime()
self.setup_nodes()

def run_test(self):
no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False)
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
Expand Down Expand Up @@ -121,6 +138,18 @@ def run_test(self):
assert(no_version_idlenode.unexpected_msg == False)
assert(no_verack_idlenode.unexpected_msg == False)

self.log.info('Check that the version message does not leak the local address of the node')
time_begin = int(time.time())
p2p_version_store = self.nodes[0].add_p2p_connection(P2PVersionStore())
time_end = time.time()
ver = p2p_version_store.version_received
assert_greater_than_or_equal(ver.nTime, time_begin)
assert_greater_than_or_equal(time_end, ver.nTime)
assert_equal(ver.addrFrom.port, 0)
assert_equal(ver.addrFrom.ip, '0.0.0.0')
assert_equal(ver.nStartingHeight, 201)
assert_equal(ver.nRelay, 1)


if __name__ == '__main__':
P2PLeakTest().main()