Skip to content

Commit 997cc00

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 b5e6238 commit 997cc00

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/functional/p2p_v2_misbehaving.py

+16
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):
@@ -72,6 +74,17 @@ def generate_keypair_and_garbage(self):
7274
return ellswift_garbage_bytes[:64] + random_bitflip(ellswift_garbage_bytes[64:])
7375

7476

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+
7588
class MisbehavingV2Peer(P2PInterface):
7689
"""Custom implementation of P2PInterface which uses modified v2 P2P protocol functions for testing purposes."""
7790
def __init__(self, test_type):
@@ -87,6 +100,8 @@ def connection_made(self, transport):
87100
self.v2_state = WrongGarbageTerminatorState(initiating=True, net='regtest')
88101
elif self.test_type == TestType.WRONG_GARBAGE:
89102
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')
90105
super().connection_made(transport)
91106

92107
def data_received(self, t):
@@ -130,6 +145,7 @@ def test_v2disconnection(self):
130145
["V2 transport error: missing garbage terminator, peer=1"], # EXCESS_GARBAGE
131146
["V2 handshake timeout peer=2"], # WRONG_GARBAGE_TERMINATOR
132147
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
148+
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
133149
]
134150
for test_type in TestType:
135151
if test_type == TestType.EARLY_KEY_RESPONSE:

0 commit comments

Comments
 (0)