mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Merge bitcoin/bitcoin#29431: test/BIP324: disconnection scenarios during v2 handshake
c9dacd958dtest: Check that non empty version packet is ignored and no disconnection happens (stratospher)997cc00b95test: Check that disconnection happens when AAD isn't filled (stratospher)b5e6238fdbtest: Check that disconnection happens when garbage sent/received are different (stratospher)ad1482d5a2test: Check that disconnection happens when wrong garbage terminator is sent (stratospher)e351576862test: Check that disconnection happens when >4095 garbage bytes is sent (stratospher)e075fd131dtest: Introduce test types and modify v2 handshake function accordingly (stratospher)7d07daa623log: Add V2 handshake timeout (stratospher)d4a1da8543test: Make global TRANSPORT_VERSION variable an instance variable (stratospher)c642b08c4etest: Log when the garbage is actually sent to transport layer (stratospher)86cca2cba2test: Support disconnect waiting for add_p2p_connection (stratospher)bf9669af9ctest: Rename early key response test and move random_bitflip to util (stratospher) Pull request description: Add tests for the following v2 handshake scenarios: 1. Disconnection happens when > `MAX_GARBAGE_LEN` bytes garbage is sent 2. Disconnection happens when incorrect garbage terminator is sent 3. Disconnection happens when garbage bytes are tampered with 4. Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled 5. bitcoind ignores non-empty version packet and no disconnection happens All these tests require a modified v2 P2P class (different from `EncryptedP2PState` used in `v2_p2p.py`) to implement our custom handshake behaviour based on different scenarios and have been kept in a single test file (`test/functional/p2p_v2_misbehaving.py`). Shifted the test in `test/functional/p2p_v2_earlykeyresponse.py` which is of the same pattern to this file too. ACKs for top commit: achow101: ACKc9dacd958dmzumsande: ACKc9dacd958dtheStack: Code-review ACKc9dacd958dTree-SHA512: 90df81f0c7f4ecf0a47762d290a618ded92cde9f83d3ef3cc70e1b005ecb16125ec39a9d80ce95f99e695d29abd63443240cb5490aa57c5bc8fa2e52149a0672
This commit is contained in:
@@ -223,6 +223,7 @@ class P2PConnection(asyncio.Protocol):
|
||||
# send the initial handshake immediately
|
||||
if self.supports_v2_p2p and self.v2_state.initiating and not self.v2_state.tried_v2_handshake:
|
||||
send_handshake_bytes = self.v2_state.initiate_v2_handshake()
|
||||
logger.debug(f"sending {len(self.v2_state.sent_garbage)} bytes of garbage data")
|
||||
self.send_raw_message(send_handshake_bytes)
|
||||
# for v1 outbound connections, send version message immediately after opening
|
||||
# (for v2 outbound connections, send it after the initial v2 handshake)
|
||||
@@ -262,6 +263,7 @@ class P2PConnection(asyncio.Protocol):
|
||||
self.v2_state = None
|
||||
return
|
||||
elif send_handshake_bytes:
|
||||
logger.debug(f"sending {len(self.v2_state.sent_garbage)} bytes of garbage data")
|
||||
self.send_raw_message(send_handshake_bytes)
|
||||
elif send_handshake_bytes == b"":
|
||||
return # only after send_handshake_bytes are sent can `complete_handshake()` be done
|
||||
|
||||
Reference in New Issue
Block a user