@@ -26,11 +26,13 @@ class TestType(Enum):
26
26
2. EXCESS_GARBAGE - Disconnection happens when > MAX_GARBAGE_LEN bytes garbage is sent
27
27
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
28
28
4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
29
+ 5. SEND_NON_EMPTY_VERSION_PACKET - non-empty version packet is simply ignored
29
30
"""
30
31
EARLY_KEY_RESPONSE = 0
31
32
EXCESS_GARBAGE = 1
32
33
WRONG_GARBAGE_TERMINATOR = 2
33
34
WRONG_GARBAGE = 3
35
+ SEND_NON_EMPTY_VERSION_PACKET = 4
34
36
35
37
36
38
class TestEncryptedP2PState (EncryptedP2PState ):
@@ -79,9 +81,9 @@ def initiate_v2_handshake(self):
79
81
return super ().initiate_v2_handshake ()
80
82
81
83
def complete_handshake (self , response ):
82
- """Add option for sending wrong garbage terminator. Also option for when
84
+ """Add option for sending wrong garbage terminator or a non-empty transport version packet . Also option for when
83
85
there's a mismatch between garbage bytes used here vs garbage bytes which were sent out.
84
- For TestType = (WRONG_GARBAGE_TERMINATOR, WRONG_GARBAGE)
86
+ For TestType = (WRONG_GARBAGE_TERMINATOR, WRONG_GARBAGE, SEND_NON_EMPTY_VERSION_PACKET )
85
87
"""
86
88
ellswift_theirs = self .received_prefix + response .read (64 - len (self .received_prefix ))
87
89
# return b"" if we need to receive more bytes
@@ -102,7 +104,10 @@ def complete_handshake(self, response):
102
104
msg_to_send += self .v2_enc_packet (decoy_content_len * b'\x00 ' , aad = aad , ignore = True )
103
105
aad = b''
104
106
# Send version packet.
105
- msg_to_send += self .v2_enc_packet (TRANSPORT_VERSION , aad = aad )
107
+ if self .test_type == TestType .SEND_NON_EMPTY_VERSION_PACKET :
108
+ msg_to_send += self .v2_enc_packet (random .randbytes (5 ), aad = aad )
109
+ else :
110
+ msg_to_send += self .v2_enc_packet (TRANSPORT_VERSION , aad = aad )
106
111
return 64 - len (self .received_prefix ), msg_to_send
107
112
108
113
@@ -165,13 +170,18 @@ def test_v2disconnection(self):
165
170
["V2 transport error: missing garbage terminator, peer=1" ], # EXCESS_GARBAGE
166
171
["version handshake timeout peer=2" ], # WRONG_GARBAGE_TERMINATOR
167
172
["V2 transport error: packet decryption failure" ], # WRONG_GARBAGE
173
+ [], # SEND_NON_EMPTY_VERSION_PACKET
168
174
]
169
175
for test_type in TestType :
170
176
if test_type == TestType .EARLY_KEY_RESPONSE :
171
177
continue
172
- with self .nodes [0 ].assert_debug_log (expected_debug_message [test_type .value ], timeout = 5 ):
173
- node0 .add_p2p_connection (MisbehavingV2Peer (test_type ), wait_for_verack = False , send_version = False , supports_v2_p2p = True , wait_for_disconnect = True )
174
- self .log .info (f"Expected disconnection for { test_type .name } " )
178
+ elif test_type == TestType .SEND_NON_EMPTY_VERSION_PACKET :
179
+ node0 .add_p2p_connection (MisbehavingV2Peer (test_type ), wait_for_verack = True , send_version = True , supports_v2_p2p = True )
180
+ self .log .info (f"No disconnection for { test_type .name } " )
181
+ else :
182
+ with self .nodes [0 ].assert_debug_log (expected_debug_message [test_type .value ], timeout = 5 ):
183
+ node0 .add_p2p_connection (MisbehavingV2Peer (test_type ), wait_for_verack = False , send_version = False , supports_v2_p2p = True , wait_for_disconnect = True )
184
+ self .log .info (f"Expected disconnection for { test_type .name } " )
175
185
176
186
177
187
if __name__ == '__main__' :
0 commit comments