@@ -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 ):
@@ -72,6 +74,17 @@ def generate_keypair_and_garbage(self):
72
74
return ellswift_garbage_bytes [:64 ] + random_bitflip (ellswift_garbage_bytes [64 :])
73
75
74
76
77
+ class NoAADState (EncryptedP2PState ):
78
+ """Add option for not filling first encrypted packet after garbage terminator with AAD"""
79
+ def generate_keypair_and_garbage (self ):
80
+ garbage_len = random .randrange (1 , MAX_GARBAGE_LEN )
81
+ return super ().generate_keypair_and_garbage (garbage_len )
82
+
83
+ def complete_handshake (self , response ):
84
+ self .sent_garbage = b'' # do not authenticate the garbage which is sent
85
+ return super ().complete_handshake (response )
86
+
87
+
75
88
class MisbehavingV2Peer (P2PInterface ):
76
89
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
77
90
def __init__ (self , test_type ):
@@ -87,6 +100,8 @@ def connection_made(self, transport):
87
100
self .v2_state = WrongGarbageTerminatorState (initiating = True , net = 'regtest' )
88
101
elif self .test_type == TestType .WRONG_GARBAGE :
89
102
self .v2_state = WrongGarbageState (initiating = True , net = 'regtest' )
103
+ elif self .test_type == TestType .SEND_NO_AAD :
104
+ self .v2_state = NoAADState (initiating = True , net = 'regtest' )
90
105
super ().connection_made (transport )
91
106
92
107
def data_received (self , t ):
@@ -130,6 +145,7 @@ def test_v2disconnection(self):
130
145
["V2 transport error: missing garbage terminator, peer=1" ], # EXCESS_GARBAGE
131
146
["V2 handshake timeout peer=2" ], # WRONG_GARBAGE_TERMINATOR
132
147
["V2 transport error: packet decryption failure" ], # WRONG_GARBAGE
148
+ ["V2 transport error: packet decryption failure" ], # SEND_NO_AAD
133
149
]
134
150
for test_type in TestType :
135
151
if test_type == TestType .EARLY_KEY_RESPONSE :
0 commit comments