Skip to content

Commit 000a040

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 49eacca commit 000a040

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/functional/p2p_v2_misbehaving.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class TestType(Enum):
2626
2. EXCESS_GARBAGE - Disconnection happens when > MAX_GARBAGE_LEN bytes garbage is sent
2727
3. WRONG_GARBAGE_TERMINATOR - Disconnection happens when incorrect garbage terminator is sent
2828
4. WRONG_GARBAGE - Disconnection happens when garbage bytes that is sent is different from what the peer receives
29+
5. SEND_NO_AAD - Disconnection happens when AAD of first encrypted packet after the garbage terminator is not filled
2930
"""
3031
EARLY_KEY_RESPONSE = 0
3132
EXCESS_GARBAGE = 1
3233
WRONG_GARBAGE_TERMINATOR = 2
3334
WRONG_GARBAGE = 3
35+
SEND_NO_AAD = 4
3436

3537

3638
class TestEncryptedP2PState(EncryptedP2PState):
@@ -87,8 +89,9 @@ def initiate_v2_handshake(self):
8789
return super().initiate_v2_handshake()
8890

8991
def complete_handshake(self, response):
90-
"""Add option for sending wrong garbage terminator
91-
when TestType = (WRONG_GARBAGE_TERMINATOR)"""
92+
"""Add option for sending wrong garbage terminator, not filling first encrypted packet after garbage terminator
93+
with AAD
94+
when TestType = (WRONG_GARBAGE_TERMINATOR, SEND_NO_AAD)"""
9295
ellswift_theirs = self.received_prefix + response.read(64 - len(self.received_prefix))
9396
# return b"" if we need to receive more bytes
9497
if len(ellswift_theirs) != 64:
@@ -101,6 +104,8 @@ def complete_handshake(self, response):
101104

102105
if self.test_type == TestType.WRONG_GARBAGE_TERMINATOR:
103106
msg_to_send = random_bitflip(msg_to_send)
107+
elif self.test_type == TestType.SEND_NO_AAD:
108+
aad = b''
104109

105110
# Optionally send decoy packets after garbage terminator.
106111
for decoy_content_len in [random.randint(1, 100) for _ in range(random.randint(0, 10))]:
@@ -170,6 +175,7 @@ def test_v2disconnection(self):
170175
["V2 transport error: missing garbage terminator, peer=1"], # EXCESS_GARBAGE
171176
["version handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
172177
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
178+
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
173179
]
174180
for test_type in TestType:
175181
if test_type == TestType.EARLY_KEY_RESPONSE:

0 commit comments

Comments
 (0)