Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions tests/unit/security/test_mse_handshake_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ async def test_initiate_wrong_message_type_rkeye(
"""Test initiate when wrong message type received instead of RKEYE."""
handshake = MSEHandshake()

# Create valid SKEYE message instead of RKEYE
payload = b"peer_key_data"
wrong_message = handshake._encode_transcript_message(MSEHandshakeType.SKEYE, payload)
# Legacy SKEYE is type + DH key; short transcript frames are ignored.
dh_len = handshake._dh_public_key_length()
wrong_payload = bytes([int(MSEHandshakeType.SKEYE)]) + (b"\x01" * dh_len)
wrong_message = handshake._build_handshake_message(wrong_payload)

async def mock_readexactly(n):
if n == 4:
Expand Down Expand Up @@ -180,10 +181,12 @@ async def test_initiate_wrong_message_type_crypto(
"""Test initiate when wrong message type received instead of CRYPTO."""
handshake = MSEHandshake()

# Mock RKEYE success, but wrong message type for CRYPTO
# Mock RKEYE success, but wrong legacy message type for CRYPTO
rkeye_payload = b"peer_key" * 10
rkeye_msg = handshake._encode_transcript_message(MSEHandshakeType.RKEYE, rkeye_payload)
wrong_crypto = handshake._encode_transcript_message(MSEHandshakeType.SKEYE, b"\x01")
dh_len = handshake._dh_public_key_length()
wrong_payload = bytes([int(MSEHandshakeType.SKEYE)]) + (b"\x01" * dh_len)
wrong_crypto = handshake._build_handshake_message(wrong_payload)

call_count = 0

Expand Down Expand Up @@ -337,9 +340,10 @@ async def test_respond_wrong_message_type_skeye(
"""Test respond when wrong message type received instead of SKEYE."""
handshake = MSEHandshake()

# Create RKEYE message instead of SKEYE
payload = b"peer_key_data"
wrong_message = handshake._encode_transcript_message(MSEHandshakeType.RKEYE, payload)
# Legacy RKEYE is type + DH key; short transcript frames are ignored.
dh_len = handshake._dh_public_key_length()
wrong_payload = bytes([int(MSEHandshakeType.RKEYE)]) + (b"\x01" * dh_len)
wrong_message = handshake._build_handshake_message(wrong_payload)

async def mock_readexactly(n):
if n == 4:
Expand Down Expand Up @@ -427,7 +431,9 @@ async def test_respond_wrong_message_type_crypto(

skeye_payload = b"peer_key" * 10
skeye_msg = handshake._encode_transcript_message(MSEHandshakeType.SKEYE, skeye_payload)
wrong_crypto = handshake._encode_transcript_message(MSEHandshakeType.RKEYE, b"\x01")
dh_len = handshake._dh_public_key_length()
wrong_payload = bytes([int(MSEHandshakeType.RKEYE)]) + (b"\x01" * dh_len)
wrong_crypto = handshake._build_handshake_message(wrong_payload)

call_count = 0

Expand Down
Loading