Drop unencrypted messages on the encrypted control stream

This commit is contained in:
Cameron Gutman 2024-01-19 18:24:29 -06:00
parent c88fa655f5
commit a10ec3a98a

View File

@ -289,8 +289,15 @@ namespace stream {
void void
iterate(std::chrono::milliseconds timeout); iterate(std::chrono::milliseconds timeout);
/**
* @brief Calls the handler for a given control stream message.
* @param type The message type.
* @param session The session the message was received on.
* @param payload The payload of the message.
* @param reinjected `true` if this message is being reprocessed after decryption.
*/
void void
call(std::uint16_t type, session_t *session, const std::string_view &payload); call(std::uint16_t type, session_t *session, const std::string_view &payload, bool reinjected);
void void
map(uint16_t type, std::function<void(session_t *, const std::string_view &)> cb) { map(uint16_t type, std::function<void(session_t *, const std::string_view &)> cb) {
@ -537,8 +544,21 @@ namespace stream {
return nullptr; return nullptr;
} }
/**
* @brief Calls the handler for a given control stream message.
* @param type The message type.
* @param session The session the message was received on.
* @param payload The payload of the message.
* @param reinjected `true` if this message is being reprocessed after decryption.
*/
void void
control_server_t::call(std::uint16_t type, session_t *session, const std::string_view &payload) { control_server_t::call(std::uint16_t type, session_t *session, const std::string_view &payload, bool reinjected) {
// If we are using the encrypted control stream protocol, drop any messages that come off the wire unencrypted
if (session->config.controlProtocolType == 13 && !reinjected && type != packetTypes[IDX_ENCRYPTED]) {
BOOST_LOG(error) << "Dropping unencrypted message on encrypted control stream: "sv << util::hex(type).to_string_view();
return;
}
auto cb = _map_type_cb.find(type); auto cb = _map_type_cb.find(type);
if (cb == std::end(_map_type_cb)) { if (cb == std::end(_map_type_cb)) {
BOOST_LOG(debug) BOOST_LOG(debug)
@ -575,7 +595,7 @@ namespace stream {
auto type = *(std::uint16_t *) packet->data; auto type = *(std::uint16_t *) packet->data;
std::string_view payload { (char *) packet->data + sizeof(type), packet->dataLength - sizeof(type) }; std::string_view payload { (char *) packet->data + sizeof(type), packet->dataLength - sizeof(type) };
call(type, session, payload); call(type, session, payload, false);
} break; } break;
case ENET_EVENT_TYPE_CONNECT: case ENET_EVENT_TYPE_CONNECT:
BOOST_LOG(info) << "CLIENT CONNECTED"sv; BOOST_LOG(info) << "CLIENT CONNECTED"sv;
@ -1004,7 +1024,7 @@ namespace stream {
input::passthrough(session->input, std::move(plaintext)); input::passthrough(session->input, std::move(plaintext));
} }
else { else {
server->call(type, session, next_payload); server->call(type, session, next_payload, true);
} }
}); });