Skip to content

Commit dc2137a

Browse files
committed
test: Check that disconnection happens when AAD isn't filled
This test type is represented using SEND_NO_AAD. If AAD of the first encrypted packet sent after the garbage terminator (optional decoy packet/version packet) hasn't been filled, disconnection happens.
1 parent 3abe42a commit dc2137a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/functional/p2p_v2_misbehaving.py

+12
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ class TestType(Enum):
2424
2. EXCESS_GARBAGE - Disconnection happens when > MAX_GARBAGE_LEN bytes garbage is sent
2525
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
2626
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
2728
"""
2829
EARLY_KEY_RESPONSE = 0
2930
EXCESS_GARBAGE = 1
3031
WRONG_GARBAGE_TERMINATOR = 2
3132
WRONG_GARBAGE = 3
33+
SEND_NO_AAD = 4
3234

3335

3436
class EarlyKeyResponseState(EncryptedP2PState):
@@ -77,6 +79,13 @@ def generate_keypair_and_garbage(self):
7779
return ellswift_garbage_bytes[:64] + random_bitflip(ellswift_garbage_bytes[64:])
7880

7981

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+
8089
class MisbehavingV2Peer(P2PInterface):
8190
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
8291
def __init__(self, test_type):
@@ -92,6 +101,8 @@ def connection_made(self, transport):
92101
self.v2_state = WrongGarbageTerminatorState(initiating=True, net='regtest')
93102
elif self.test_type == TestType.WRONG_GARBAGE:
94103
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')
95106
super().connection_made(transport)
96107

97108
def data_received(self, t):
@@ -136,6 +147,7 @@ def test_v2disconnection(self):
136147
["V2 transport error: missing garbage terminator, peer=1"], # EXCESS_GARBAGE
137148
["V2 handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
138149
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
150+
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
139151
]
140152
for test_type in TestType:
141153
if test_type == TestType.EARLY_KEY_RESPONSE:

0 commit comments

Comments
 (0)