aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-10-12 09:21:39 +0200
committerfanquake <fanquake@gmail.com>2023-10-12 09:35:07 +0200
commit4a5aae9330780c3740e27cc511f7cba1fab745b9 (patch)
treee79205446a8bc837c05f960ce38c98d544bb7f39 /test/functional
parentccf7895e179f6b35ad09788b57563057703ccb53 (diff)
parent3bb51c29df596aab2c1fde184667cee435597715 (diff)
downloadbitcoin-4a5aae9330780c3740e27cc511f7cba1fab745b9.tar.xz
Merge bitcoin/bitcoin#28634: test: BIP324: add check for detection of missing garbage terminator
3bb51c29df596aab2c1fde184667cee435597715 test: BIP324: add check for missing garbage terminator detection (Sebastian Falbesoner) Pull request description: This PR adds test coverage for the "missing garbage terminator" detection on incoming v2 transport (BIP324) connections: https://github.com/bitcoin/bitcoin/blob/04265ba9378efbd4c35b33390b1e5cf246d420a9/src/net.cpp#L1205-L1209 Note that this always happens at the same exact amount of bytes sent in (after 64 + 4095 + 16 = 4175 bytes), if at no point, the last 16 bytes of potential authentication data match the garbage, i.e. all the previous bytes after the ellswift pubkey. To keep it simple, we just send in zero-value bytes here and verify that the detection hits exactly after the last bytes is sent. AFAICT, with this PR all the v2 transport errors that can be triggered in this simple way of "just open a socket and send in a fixed byte-string" are covered. For more advanced test, we need BIP324 cryptography in the test framework in order to perform a v2 handshake etc. (PRs #28374, #24748). ACKs for top commit: sipa: utACK 3bb51c29df596aab2c1fde184667cee435597715 laanwj: ACK 3bb51c29df596aab2c1fde184667cee435597715 Tree-SHA512: f88275061c7c377a3d9f2608452671afc26deb6d5bd5be596de987c7e5042555153ffe681760c33bce2b921ae04e50f349ea0128a677e6443a95a079e52cdc5f
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/p2p_v2_transport.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/functional/p2p_v2_transport.py b/test/functional/p2p_v2_transport.py
index dd564fed88..99417a17a9 100755
--- a/test/functional/p2p_v2_transport.py
+++ b/test/functional/p2p_v2_transport.py
@@ -148,6 +148,19 @@ class V2TransportTest(BitcoinTestFramework):
with self.nodes[0].assert_debug_log("V2 transport error: V1 peer with wrong MessageStart"):
s.sendall(wrong_network_magic_prefix + b"somepayload")
+ # Check detection of missing garbage terminator (hits after fixed amount of data if terminator never matches garbage)
+ MAX_KEY_GARB_AND_GARBTERM_LEN = 64 + 4095 + 16
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+ num_peers = len(self.nodes[0].getpeerinfo())
+ s.connect(("127.0.0.1", p2p_port(0)))
+ self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == num_peers + 1)
+ s.sendall(b'\x00' * (MAX_KEY_GARB_AND_GARBTERM_LEN - 1))
+ self.wait_until(lambda: self.nodes[0].getpeerinfo()[-1]["bytesrecv"] == MAX_KEY_GARB_AND_GARBTERM_LEN - 1)
+ with self.nodes[0].assert_debug_log("V2 transport error: missing garbage terminator"):
+ s.sendall(b'\x00') # send out last byte
+ # should disconnect immediately
+ self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == num_peers)
+
if __name__ == '__main__':
V2TransportTest().main()