mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-23 14:33:07 +00:00
fix: adapt the session key packets and the packet decoder to the 33 character key
SetSessionKey, SessionKeyResponse and NewSessionAlert carry the key as a 33 character string where the number was, which the auth, master and world servers now pass. The packet decoder blanks that string in a kept packet, and the packet tests write the string. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -92,7 +92,7 @@ namespace MasterPackets {
|
|||||||
|
|
||||||
// Auth -> master: an account logged in with this session key
|
// Auth -> master: an account logged in with this session key
|
||||||
struct SetSessionKey : public LUBitStream {
|
struct SetSessionKey : public LUBitStream {
|
||||||
uint32_t sessionKey{};
|
LUString sessionKey{}; // 32 hex characters
|
||||||
LUString username{};
|
LUString username{};
|
||||||
|
|
||||||
SetSessionKey() : LUBitStream(ServiceType::MASTER, MessageType::Master::SET_SESSION_KEY) {}
|
SetSessionKey() : LUBitStream(ServiceType::MASTER, MessageType::Master::SET_SESSION_KEY) {}
|
||||||
@@ -102,7 +102,7 @@ namespace MasterPackets {
|
|||||||
|
|
||||||
// Master -> world: answer to RequestSessionKey
|
// Master -> world: answer to RequestSessionKey
|
||||||
struct SessionKeyResponse : public LUBitStream {
|
struct SessionKeyResponse : public LUBitStream {
|
||||||
uint32_t sessionKey{};
|
LUString sessionKey{};
|
||||||
LUWString username{};
|
LUWString username{};
|
||||||
|
|
||||||
SessionKeyResponse() : LUBitStream(ServiceType::MASTER, MessageType::Master::SESSION_KEY_RESPONSE) {}
|
SessionKeyResponse() : LUBitStream(ServiceType::MASTER, MessageType::Master::SESSION_KEY_RESPONSE) {}
|
||||||
@@ -112,7 +112,7 @@ namespace MasterPackets {
|
|||||||
|
|
||||||
// Master -> every server: the account logged in again with a new session key
|
// Master -> every server: the account logged in again with a new session key
|
||||||
struct NewSessionAlert : public LUBitStream {
|
struct NewSessionAlert : public LUBitStream {
|
||||||
uint32_t sessionKey{};
|
LUString sessionKey{};
|
||||||
LUString username{};
|
LUString username{};
|
||||||
|
|
||||||
NewSessionAlert() : LUBitStream(ServiceType::MASTER, MessageType::Master::NEW_SESSION_ALERT) {}
|
NewSessionAlert() : LUBitStream(ServiceType::MASTER, MessageType::Master::NEW_SESSION_ALERT) {}
|
||||||
|
|||||||
@@ -245,9 +245,9 @@ namespace {
|
|||||||
{ K(S::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE), { nullptr, Scrub<ChatPackets::GeneralChatMessage>(nullptr, [](auto& p) { X(p.senderName); X(p.message); }) } },
|
{ K(S::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE), { nullptr, Scrub<ChatPackets::GeneralChatMessage>(nullptr, [](auto& p) { X(p.senderName); X(p.message); }) } },
|
||||||
{ K(S::CHAT, MessageType::Chat::PRIVATE_CHAT_MESSAGE), { nullptr, Scrub<ChatPackets::PrivateChatMessage>(nullptr, [](auto& p) { X(p.senderName); X(p.receiverName); X(p.message); }) } },
|
{ K(S::CHAT, MessageType::Chat::PRIVATE_CHAT_MESSAGE), { nullptr, Scrub<ChatPackets::PrivateChatMessage>(nullptr, [](auto& p) { X(p.senderName); X(p.receiverName); X(p.message); }) } },
|
||||||
{ K(S::MASTER, MessageType::Master::REQUEST_SESSION_KEY), { nullptr, Scrub<MasterPackets::RequestSessionKey>([](auto& p) { X(p.username); }) } },
|
{ K(S::MASTER, MessageType::Master::REQUEST_SESSION_KEY), { nullptr, Scrub<MasterPackets::RequestSessionKey>([](auto& p) { X(p.username); }) } },
|
||||||
{ K(S::MASTER, MessageType::Master::SESSION_KEY_RESPONSE), { Blank<MasterPackets::SessionKeyResponse>([](auto& p) { p.sessionKey = 0; }), Scrub<MasterPackets::SessionKeyResponse>([](auto& p) { X(p.username); }) } },
|
{ K(S::MASTER, MessageType::Master::SESSION_KEY_RESPONSE), { Blank<MasterPackets::SessionKeyResponse>([](auto& p) { p.sessionKey.string.clear(); }), Scrub<MasterPackets::SessionKeyResponse>([](auto& p) { X(p.username); }) } },
|
||||||
{ K(S::MASTER, MessageType::Master::SET_SESSION_KEY), { Blank<MasterPackets::SetSessionKey>([](auto& p) { p.sessionKey = 0; }), Scrub<MasterPackets::SetSessionKey>([](auto& p) { X(p.username); }) } },
|
{ K(S::MASTER, MessageType::Master::SET_SESSION_KEY), { Blank<MasterPackets::SetSessionKey>([](auto& p) { p.sessionKey.string.clear(); }), Scrub<MasterPackets::SetSessionKey>([](auto& p) { X(p.username); }) } },
|
||||||
{ K(S::MASTER, MessageType::Master::NEW_SESSION_ALERT), { Blank<MasterPackets::NewSessionAlert>([](auto& p) { p.sessionKey = 0; }), Scrub<MasterPackets::NewSessionAlert>([](auto& p) { X(p.username); }) } },
|
{ K(S::MASTER, MessageType::Master::NEW_SESSION_ALERT), { Blank<MasterPackets::NewSessionAlert>([](auto& p) { p.sessionKey.string.clear(); }), Scrub<MasterPackets::NewSessionAlert>([](auto& p) { X(p.username); }) } },
|
||||||
};
|
};
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,14 +119,14 @@ namespace LegacyMaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dMasterServer/MasterServer.cpp SET_SESSION_KEY, and dNet/AuthPackets.cpp
|
// dMasterServer/MasterServer.cpp SET_SESSION_KEY, and dNet/AuthPackets.cpp
|
||||||
inline void WriteSessionKey(RakNet::BitStream& bitStream, MessageType::Master type, uint32_t sessionKey, const LUString& username) {
|
inline void WriteSessionKey(RakNet::BitStream& bitStream, MessageType::Master type, const LUString& sessionKey, const LUString& username) {
|
||||||
BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, type);
|
BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, type);
|
||||||
bitStream.Write(sessionKey);
|
bitStream.Write(sessionKey);
|
||||||
bitStream.Write(username);
|
bitStream.Write(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dMasterServer/MasterServer.cpp REQUEST_SESSION_KEY
|
// dMasterServer/MasterServer.cpp REQUEST_SESSION_KEY
|
||||||
inline void WriteSessionKeyResponse(RakNet::BitStream& bitStream, uint32_t sessionKey, const LUWString& username) {
|
inline void WriteSessionKeyResponse(RakNet::BitStream& bitStream, const LUString& sessionKey, const LUWString& username) {
|
||||||
BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SESSION_KEY_RESPONSE);
|
BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SESSION_KEY_RESPONSE);
|
||||||
bitStream.Write(sessionKey);
|
bitStream.Write(sessionKey);
|
||||||
bitStream.Write(username);
|
bitStream.Write(username);
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ TEST(MasterPacketsTests, ServerInfoMatchesLegacy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(MasterPacketsTests, SessionKeysMatchLegacy) {
|
TEST(MasterPacketsTests, SessionKeysMatchLegacy) {
|
||||||
for (const uint32_t key : { 0u, 12345u, 0xFFFFFFFFu }) {
|
for (const auto& key : { LUString(""), LUString("0123456789abcdef0123456789abcdef"), LUString("ffffffffffffffffffffffffffffffff") }) {
|
||||||
for (const auto& name : g_Strings) {
|
for (const auto& name : g_Strings) {
|
||||||
if (name.size() > 33) continue;
|
if (name.size() > 33) continue;
|
||||||
MasterPackets::SetSessionKey set;
|
MasterPackets::SetSessionKey set;
|
||||||
|
|||||||
@@ -351,14 +351,14 @@ TEST(PacketDecoderTests, NamesEveryService) {
|
|||||||
|
|
||||||
TEST(PacketDecoderTests, SessionKeysBetweenServersAreBlanked) {
|
TEST(PacketDecoderTests, SessionKeysBetweenServersAreBlanked) {
|
||||||
MasterPackets::SetSessionKey key;
|
MasterPackets::SetSessionKey key;
|
||||||
key.sessionKey = 0xDEADBEEF;
|
const std::string secret = "0123456789abcdef0123456789abcdef";
|
||||||
|
key.sessionKey = LUString(secret);
|
||||||
key.username = LUString("alice");
|
key.username = LUString("alice");
|
||||||
RakNet::BitStream stream;
|
RakNet::BitStream stream;
|
||||||
key.WritePacket(stream);
|
key.WritePacket(stream);
|
||||||
std::string bytes(reinterpret_cast<const char*>(stream.GetData()), stream.GetNumberOfBytesUsed());
|
std::string bytes(reinterpret_cast<const char*>(stream.GetData()), stream.GetNumberOfBytesUsed());
|
||||||
ASSERT_TRUE(PacketDecoder::Redact(bytes));
|
ASSERT_TRUE(PacketDecoder::Redact(bytes));
|
||||||
const uint32_t secret = 0xDEADBEEF;
|
EXPECT_EQ(bytes.find(secret), std::string::npos);
|
||||||
EXPECT_EQ(bytes.find(std::string(reinterpret_cast<const char*>(&secret), 4)), std::string::npos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
Reference in New Issue
Block a user