@@ -27,12 +27,14 @@ class TestType(Enum):
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
29
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
30
31
"""
31
32
EARLY_KEY_RESPONSE = 0
32
33
EXCESS_GARBAGE = 1
33
34
WRONG_GARBAGE_TERMINATOR = 2
34
35
WRONG_GARBAGE = 3
35
36
SEND_NO_AAD = 4
37
+ SEND_NON_EMPTY_VERSION_PACKET = 5
36
38
37
39
38
40
class TestEncryptedP2PState (EncryptedP2PState ):
@@ -90,8 +92,8 @@ def initiate_v2_handshake(self):
90
92
91
93
def complete_handshake (self , response ):
92
94
"""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 )"""
95
97
ellswift_theirs = self .received_prefix + response .read (64 - len (self .received_prefix ))
96
98
# return b"" if we need to receive more bytes
97
99
if len (ellswift_theirs ) != 64 :
@@ -111,8 +113,13 @@ def complete_handshake(self, response):
111
113
for decoy_content_len in [random .randint (1 , 100 ) for _ in range (random .randint (0 , 10 ))]:
112
114
msg_to_send += self .v2_enc_packet (decoy_content_len * b'\x00 ' , aad = aad , ignore = True )
113
115
aad = b''
116
+
114
117
# 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
+
116
123
return 64 - len (self .received_prefix ), msg_to_send
117
124
118
125
@@ -176,14 +183,19 @@ def test_v2disconnection(self):
176
183
["version handshake timeout peer=2" ], # WRONG_GARBAGE_TERMINATOR
177
184
["V2 transport error: packet decryption failure" ], # WRONG_GARBAGE
178
185
["V2 transport error: packet decryption failure" ], # SEND_NO_AAD
186
+ [], # SEND_NON_EMPTY_VERSION_PACKET
179
187
]
180
188
for test_type in TestType :
181
189
if test_type == TestType .EARLY_KEY_RESPONSE :
182
190
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 } " )
187
199
188
200
189
201
if __name__ == '__main__' :
0 commit comments