@@ -24,11 +24,13 @@ class TestType(Enum):
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
26
4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
27
+ 5. SEND_NO_AAD - Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled
27
28
"""
28
29
EARLY_KEY_RESPONSE = 0
29
30
EXCESS_GARBAGE = 1
30
31
WRONG_GARBAGE_TERMINATOR = 2
31
32
WRONG_GARBAGE = 3
33
+ SEND_NO_AAD = 4
32
34
33
35
34
36
class EarlyKeyResponseState (EncryptedP2PState ):
@@ -77,6 +79,13 @@ def generate_keypair_and_garbage(self):
77
79
return ellswift_garbage_bytes [:64 ] + random_bitflip (ellswift_garbage_bytes [64 :])
78
80
79
81
82
+ class NoAADState (EncryptedP2PState ):
83
+ """Add option for not filling first encrypted packet after garbage terminator with AAD"""
84
+ def complete_handshake (self , response ):
85
+ self .sent_garbage = b'' # do not authenticate the garbage which is sent
86
+ return super ().complete_handshake (response )
87
+
88
+
80
89
class MisbehavingV2Peer (P2PInterface ):
81
90
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
82
91
def __init__ (self , test_type ):
@@ -92,6 +101,8 @@ def connection_made(self, transport):
92
101
self .v2_state = WrongGarbageTerminatorState (initiating = True , net = 'regtest' )
93
102
elif self .test_type == TestType .WRONG_GARBAGE :
94
103
self .v2_state = WrongGarbageState (initiating = True , net = 'regtest' )
104
+ elif self .test_type == TestType .SEND_NO_AAD :
105
+ self .v2_state = NoAADState (initiating = True , net = 'regtest' )
95
106
super ().connection_made (transport )
96
107
97
108
def data_received (self , t ):
@@ -136,6 +147,7 @@ def test_v2disconnection(self):
136
147
["V2 transport error: missing garbage terminator, peer=1" ], # EXCESS_GARBAGE
137
148
["V2 handshake timeout peer=2" ], # WRONG_GARBAGE_TERMINATOR
138
149
["V2 transport error: packet decryption failure" ], # WRONG_GARBAGE
150
+ ["V2 transport error: packet decryption failure" ], # SEND_NO_AAD
139
151
]
140
152
for test_type in TestType :
141
153
if test_type == TestType .EARLY_KEY_RESPONSE :
0 commit comments