Skip to content

Commit

Permalink
NETdecryptSecuredNetMessage: Additional validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 11, 2023
1 parent 58d10de commit 76e5d16
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/netplay/nettypes.cpp
Expand Up @@ -547,6 +547,12 @@ void NETclearSessionKeys(uint8_t player)
netSessionKeys[player].reset();
}

bool NETisExpectedSecuredMessageType(uint8_t type)
{
// currently there are no expected secured messages
return false;
}

// For encoding a secured net message, for a *specific player*
// Returns `false` on failure
// Notes:
Expand All @@ -558,6 +564,7 @@ bool NETbeginEncodeSecured(NETQUEUE queue, uint8_t type)
ASSERT_OR_RETURN(false, queue.index != realSelectedPlayer, "Secured messages are for other players, not ourselves.");
ASSERT_OR_RETURN(false, queue.index < MAX_PLAYERS, "Invalid recipient (queue.index == %u)", static_cast<unsigned>(queue.index));
ASSERT_OR_RETURN(false, netSessionKeys[queue.index] != nullptr, "Lacking session key for player: %u", static_cast<unsigned>(queue.index));
ASSERT(NETisExpectedSecuredMessageType(type), "Message type is not expected to be secured, and will be ignored on receipt");

NETbeginEncode(queue, type);
bSecretMessageWrap = true;
Expand Down Expand Up @@ -615,6 +622,13 @@ bool NETdecryptSecuredNetMessage(NETQUEUE queue, uint8_t& type)
return false;
}

if (!NETisExpectedSecuredMessageType(decryptedMessage.type))
{
// Ignore message types that aren't expected to be secured
debug(LOG_NET, "Not a message type that's expected to be secured: (type: %s) - ignoring", messageTypeToString(decryptedMessage.type));
return false;
}

NETlogPacket(NET_SECURED_NET_MESSAGE, static_cast<uint32_t>(encryptedMessage.rawLen()), true);

type = decryptedMessage.type; // must update type!
Expand Down

0 comments on commit 76e5d16

Please sign in to comment.