@@ -23,10 +23,12 @@ class TestType(Enum):
23
23
consisting of network magic followed by "version\x00 \x00 \x00 \x00 \x00 " before sending out its ellswift + garbage bytes
24
24
2. EXCESS_GARBAGE - Disconnection happens when > MAX_GARBAGE_LEN bytes garbage is sent
25
25
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
26
+ 4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
26
27
"""
27
28
EARLY_KEY_RESPONSE = 0
28
29
EXCESS_GARBAGE = 1
29
30
WRONG_GARBAGE_TERMINATOR = 2
31
+ WRONG_GARBAGE = 3
30
32
31
33
32
34
class EarlyKeyResponseState (EncryptedP2PState ):
@@ -61,6 +63,15 @@ def complete_handshake(self, response):
61
63
return length , wrong_garbage_terminator + handshake_bytes [16 :]
62
64
63
65
66
+ class WrongGarbageState (EncryptedP2PState ):
67
+ """Generate tampered garbage bytes"""
68
+ def generate_keypair_and_garbage (self ):
69
+ garbage_len = random .randrange (1 , MAX_GARBAGE_LEN )
70
+ ellswift_garbage_bytes = super ().generate_keypair_and_garbage (garbage_len )
71
+ # assume that garbage bytes sent to TestNode were tampered with
72
+ return ellswift_garbage_bytes [:64 ] + random_bitflip (ellswift_garbage_bytes [64 :])
73
+
74
+
64
75
class MisbehavingV2Peer (P2PInterface ):
65
76
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
66
77
def __init__ (self , test_type ):
@@ -74,6 +85,8 @@ def connection_made(self, transport):
74
85
self .v2_state = ExcessGarbageState (initiating = True , net = 'regtest' )
75
86
elif self .test_type == TestType .WRONG_GARBAGE_TERMINATOR :
76
87
self .v2_state = WrongGarbageTerminatorState (initiating = True , net = 'regtest' )
88
+ elif self .test_type == TestType .WRONG_GARBAGE :
89
+ self .v2_state = WrongGarbageState (initiating = True , net = 'regtest' )
77
90
super ().connection_made (transport )
78
91
79
92
def data_received (self , t ):
@@ -116,6 +129,7 @@ def test_v2disconnection(self):
116
129
[], # EARLY_KEY_RESPONSE
117
130
["V2 transport error: missing garbage terminator, peer=1" ], # EXCESS_GARBAGE
118
131
["V2 handshake timeout peer=2" ], # WRONG_GARBAGE_TERMINATOR
132
+ ["V2 transport error: packet decryption failure" ], # WRONG_GARBAGE
119
133
]
120
134
for test_type in TestType :
121
135
if test_type == TestType .EARLY_KEY_RESPONSE :
0 commit comments