@@ -25,12 +25,14 @@ class TestType(Enum):
25
25
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
26
26
4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
27
27
5. SEND_NO_AAD - Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled
28
+ 6. SEND_NON_EMPTY_VERSION_PACKET - non-empty version packet is simply ignored
28
29
"""
29
30
EARLY_KEY_RESPONSE = 0
30
31
EXCESS_GARBAGE = 1
31
32
WRONG_GARBAGE_TERMINATOR = 2
32
33
WRONG_GARBAGE = 3
33
34
SEND_NO_AAD = 4
35
+ SEND_NON_EMPTY_VERSION_PACKET = 5
34
36
35
37
36
38
class EarlyKeyResponseState (EncryptedP2PState ):
@@ -86,6 +88,13 @@ def complete_handshake(self, response):
86
88
return super ().complete_handshake (response )
87
89
88
90
91
+ class NonEmptyVersionPacketState (EncryptedP2PState ):
92
+ """"Add option for sending non-empty transport version packet."""
93
+ def complete_handshake (self , response ):
94
+ self .transport_version = random .randbytes (5 )
95
+ return super ().complete_handshake (response )
96
+
97
+
89
98
class MisbehavingV2Peer (P2PInterface ):
90
99
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
91
100
def __init__ (self , test_type ):
@@ -103,6 +112,8 @@ def connection_made(self, transport):
103
112
self .v2_state = WrongGarbageState (initiating = True , net = 'regtest' )
104
113
elif self .test_type == TestType .SEND_NO_AAD :
105
114
self .v2_state = NoAADState (initiating = True , net = 'regtest' )
115
+ elif TestType .SEND_NON_EMPTY_VERSION_PACKET :
116
+ self .v2_state = NonEmptyVersionPacketState (initiating = True , net = 'regtest' )
106
117
super ().connection_made (transport )
107
118
108
119
def data_received (self , t ):
@@ -147,14 +158,19 @@ def test_v2disconnection(self):
147
158
["V2 handshake timeout peer=2" ], # WRONG_GARBAGE_TERMINATOR
148
159
["V2 transport error: packet decryption failure" ], # WRONG_GARBAGE
149
160
["V2 transport error: packet decryption failure" ], # SEND_NO_AAD
161
+ [], # SEND_NON_EMPTY_VERSION_PACKET
150
162
]
151
163
for test_type in TestType :
152
164
if test_type == TestType .EARLY_KEY_RESPONSE :
153
165
continue
154
- with node0 .assert_debug_log (expected_debug_message [test_type .value ], timeout = 5 ):
155
- peer = node0 .add_p2p_connection (MisbehavingV2Peer (test_type ), wait_for_verack = False , send_version = False , supports_v2_p2p = True , expect_success = False )
156
- peer .wait_for_disconnect ()
157
- self .log .info (f"Expected disconnection for { test_type .name } " )
166
+ elif test_type == TestType .SEND_NON_EMPTY_VERSION_PACKET :
167
+ node0 .add_p2p_connection (MisbehavingV2Peer (test_type ), wait_for_verack = True , send_version = True , supports_v2_p2p = True )
168
+ self .log .info (f"No disconnection for { test_type .name } " )
169
+ else :
170
+ with node0 .assert_debug_log (expected_debug_message [test_type .value ], timeout = 5 ):
171
+ peer = node0 .add_p2p_connection (MisbehavingV2Peer (test_type ), wait_for_verack = False , send_version = False , supports_v2_p2p = True , expect_success = False )
172
+ peer .wait_for_disconnect ()
173
+ self .log .info (f"Expected disconnection for { test_type .name } " )
158
174
159
175
160
176
if __name__ == '__main__' :
0 commit comments