mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-16 08:45:27 +00:00
fix: generate session keys from the system entropy source
The key came from the shared game random engine, which is seeded from the start time. It now comes from std::random_device through a small helper. The key stays a 32 bit number, so the packets do not change. The master and world servers no longer write the key or its hash to the log. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
35
tests/dCommonTests/TestGeneralUtils.cpp
Normal file
35
tests/dCommonTests/TestGeneralUtils.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <random>
|
||||
#include <set>
|
||||
|
||||
#include "Game.h"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
TEST(GeneralUtilsTest, UnpredictableNumberLeavesTheGameEngineAlone) {
|
||||
Game::randomEngine = std::mt19937(1234);
|
||||
std::mt19937 expected(1234);
|
||||
|
||||
GeneralUtils::GenerateUnpredictableNumber<uint32_t>();
|
||||
GeneralUtils::GenerateUnpredictableNumber<uint64_t>();
|
||||
|
||||
EXPECT_EQ(Game::randomEngine(), expected());
|
||||
}
|
||||
|
||||
TEST(GeneralUtilsTest, UnpredictableNumberDoesNotFollowTheGameEngineSeed) {
|
||||
std::set<uint64_t> seen;
|
||||
for (uint32_t i = 0; i < 16; i++) {
|
||||
// The same seed every time would give the same number every time from the game engine
|
||||
Game::randomEngine = std::mt19937(1234);
|
||||
seen.insert(GeneralUtils::GenerateUnpredictableNumber<uint64_t>());
|
||||
}
|
||||
|
||||
EXPECT_EQ(seen.size(), 16);
|
||||
}
|
||||
|
||||
TEST(GeneralUtilsTest, UnpredictableNumberFillsEveryByte) {
|
||||
uint64_t seenBits = 0;
|
||||
for (uint32_t i = 0; i < 64; i++) seenBits |= GeneralUtils::GenerateUnpredictableNumber<uint64_t>();
|
||||
|
||||
EXPECT_EQ(seenBits, 0xFFFFFFFFFFFFFFFFULL);
|
||||
}
|
||||
Reference in New Issue
Block a user