Skip to content

Commit 67708b6

Browse files
committed
test: Check that non empty version packet is ignored and no disconnection happens
This test type is represented using SEND_NON_EMPTY_VERSION_PACKET.
1 parent ac802db commit 67708b6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

test/functional/p2p_v2_misbehaving.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ class TestType(Enum):
2727
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
2828
4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
2929
5. SEND_NO_AAD - Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled
30+
6. SEND_NON_EMPTY_VERSION_PACKET - non-empty version packet is simply ignored
3031
"""
3132
EARLY_KEY_RESPONSE = 0
3233
EXCESS_GARBAGE = 1
3334
WRONG_GARBAGE_TERMINATOR = 2
3435
WRONG_GARBAGE = 3
3536
SEND_NO_AAD = 4
37+
SEND_NON_EMPTY_VERSION_PACKET = 5
3638

3739

3840
class TestEncryptedP2PState(EncryptedP2PState):
@@ -90,8 +92,8 @@ def initiate_v2_handshake(self):
9092

9193
def complete_handshake(self, response):
9294
"""Add option for sending wrong garbage terminator, not filling first encrypted packet after garbage terminator
93-
with AAD
94-
when TestType = (WRONG_GARBAGE_TERMINATOR, SEND_NO_AAD)"""
95+
with AAD, sending non-empty transport version packet.
96+
when TestType = (WRONG_GARBAGE_TERMINATOR, SEND_NO_AAD, SEND_NON_EMPTY_VERSION_PACKET)"""
9597
ellswift_theirs = self.received_prefix + response.read(64 - len(self.received_prefix))
9698
# return b"" if we need to receive more bytes
9799
if len(ellswift_theirs) != 64:
@@ -111,8 +113,13 @@ def complete_handshake(self, response):
111113
for decoy_content_len in [random.randint(1, 100) for _ in range(random.randint(0, 10))]:
112114
msg_to_send += self.v2_enc_packet(decoy_content_len * b'\x00', aad=aad, ignore=True)
113115
aad = b''
116+
114117
# Send version packet.
115-
msg_to_send += self.v2_enc_packet(TRANSPORT_VERSION, aad=aad)
118+
if self.test_type == TestType.SEND_NON_EMPTY_VERSION_PACKET:
119+
msg_to_send += self.v2_enc_packet(random.randbytes(5), aad=aad)
120+
else:
121+
msg_to_send += self.v2_enc_packet(TRANSPORT_VERSION, aad=aad)
122+
116123
return 64 - len(self.received_prefix), msg_to_send
117124

118125

@@ -176,14 +183,19 @@ def test_v2disconnection(self):
176183
["version handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
177184
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
178185
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
186+
[], # SEND_NON_EMPTY_VERSION_PACKET
179187
]
180188
for test_type in TestType:
181189
if test_type == TestType.EARLY_KEY_RESPONSE:
182190
continue
183-
with node0.assert_debug_log(expected_debug_message[test_type.value], timeout=5):
184-
peer = node0.add_p2p_connection(MisbehavingV2Peer(test_type), wait_for_verack=False, send_version=False, supports_v2_p2p=True, expect_success=False)
185-
peer.wait_for_disconnect()
186-
self.log.info(f"Expected disconnection for {test_type.name}")
191+
elif test_type == TestType.SEND_NON_EMPTY_VERSION_PACKET:
192+
node0.add_p2p_connection(MisbehavingV2Peer(test_type), wait_for_verack=True, send_version=True, supports_v2_p2p=True)
193+
self.log.info(f"No disconnection for {test_type.name}")
194+
else:
195+
with node0.assert_debug_log(expected_debug_message[test_type.value], timeout=5):
196+
peer = node0.add_p2p_connection(MisbehavingV2Peer(test_type), wait_for_verack=False, send_version=False, supports_v2_p2p=True, expect_success=False)
197+
peer.wait_for_disconnect()
198+
self.log.info(f"Expected disconnection for {test_type.name}")
187199

188200

189201
if __name__ == '__main__':

0 commit comments

Comments
 (0)