Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/shared/revision_data.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

#define WORLD_DB_VERSION_NR "22"
#define WORLD_DB_STRUCTURE_NR "6"
#define WORLD_DB_CONTENT_NR "3"
#define WORLD_DB_UPDATE_DESCRIPT "Warden_Checks"
#define WORLD_DB_CONTENT_NR "4"
#define WORLD_DB_UPDATE_DESCRIPT "Warden_Locale_Hardening"

#define VER_COMPANY_NAME_STR "MaNGOS Developers"
#define VER_LEGALCOPYRIGHT_STR "(c)2005-@rev_year@ MaNGOS"
Expand Down
5 changes: 3 additions & 2 deletions src/tests/DatabaseVersionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ TEST(CoreDatabaseVersion_requires_database_backed_warden_catalogue)

CHECK_STR(GitRevision::GetWorldDBVersion(), "22");
CHECK_STR(GitRevision::GetWorldDBStructure(), "6");
CHECK_STR(GitRevision::GetWorldDBContent(), "3");
CHECK_STR(GitRevision::GetWorldDBUpdateDescription(), "Warden_Checks");
CHECK_STR(GitRevision::GetWorldDBContent(), "4");
CHECK_STR(GitRevision::GetWorldDBUpdateDescription(),
"Warden_Locale_Hardening");
}
118 changes: 93 additions & 25 deletions src/tests/WardenCheckCatalogTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ std::vector<warden::WardenCheckRowInput> FirstProfileRows()
{
std::vector<warden::WardenCheckRowInput> rows =
warden::test::InitialWardenRows();
rows.resize(7);
rows.resize(9);
return rows;
}
}

TEST(WardenCheckCatalog_decodes_and_selects_three_exact_profiles)
TEST(WardenCheckCatalog_decodes_and_selects_eight_exact_profiles)
{
warden::WardenCheckCatalogBuilder builder;
warden::WardenCheckDiagnostic diagnostic;
Expand All @@ -86,21 +86,94 @@ TEST(WardenCheckCatalog_decodes_and_selects_three_exact_profiles)
warden::WardenCheckCatalog catalog;
REQUIRE(builder.Build(catalog, diagnostic) ==
warden::CheckCatalogValidation::Valid);
CHECK_EQ(catalog.TotalRows(), uint32(21));
CHECK_EQ(catalog.EnabledRows(), uint32(21));
CHECK_EQ(catalog.Profiles().size(), size_t(3));
CHECK_EQ(catalog.TotalRows(), uint32(72));
CHECK_EQ(catalog.EnabledRows(), uint32(72));
CHECK_EQ(catalog.Profiles().size(), size_t(8));

struct ProfileExpectation
{
uint32 build;
char const* locale;
char const* mpqSha1;
char const* luaText;
uint32 frameDispatchAddress;
char const* frameDispatchBytes;
};
ProfileExpectation const profiles[] =
{
{5875, "enUS", "7d88154d3411811985f5d81177c5453248133443",
"4f6b6179", 4784584,
"5eff48006bff480078ff480095ff4800"},
{5875, "koKR", "755d6d7f49bb34114433386d559261ed3aa23f00",
"ed9995ec9db8", 4784584,
"5eff48006bff480078ff480095ff4800"},
{5875, "zhTW", "2a70e6402a40a4f9e9960ced419dba5e6deb8536",
"e7a2bae5ae9a", 4784584,
"5eff48006bff480078ff480095ff4800"},
{5875, "frFR", "af2d81af013a9ba6bb92ce171e43fa903c9e8c09",
"4f4b", 4784584,
"5eff48006bff480078ff480095ff4800"},
{5875, "esES", "1ecec2c6596b8411fa5fe153edfb9a6ee43360e9",
"41636570746172", 4784584,
"5eff48006bff480078ff480095ff4800"},
{6005, "enGB", "7d88154d3411811985f5d81177c5453248133443",
"4f6b6179", 4784584,
"5eff48006bff480078ff480095ff4800"},
{6005, "deDE", "a0b3dc2d78ad892f2436bcd937be51b4989d64c1",
"4f4b", 4784584,
"5eff48006bff480078ff480095ff4800"},
{6141, "zhCN", "c5a1de4c1cd412eb4d2e02afab6131b737efcaf0",
"e7a1aee5ae9a", 4788152,
"4e0d49005b0d4900680d4900850d4900"}
};
uint32 const expectedIds[] =
{65536, 1, 2, 1107, 827, 1566, 1135, 65537, 65538};

for (ProfileExpectation const& expected : profiles)
{
warden::WardenCheckProfile const* profile =
catalog.Find(expected.build, "Win", expected.locale);
REQUIRE(profile != nullptr);
REQUIRE(profile->checks.size() == 9u);
CHECK(profile->hasActionableChecks);
CHECK_EQ(profile->totalRows, uint32(9));
for (size_t index = 0; index < 9u; ++index)
{
CHECK_EQ(warden::GetWardenCheckId(profile->checks[index]),
expectedIds[index]);
}

CHECK(warden::GetWardenCheckType(profile->checks[0]) ==
warden::WardenCheckType::Timing);
CHECK(!warden::IsConfirmationEligible(profile->checks[0]));
CHECK(warden::IsConfirmationEligible(profile->checks[1]));

warden::MpqCheckProfile const& mpq =
std::get<warden::MpqCheckProfile>(profile->checks[1].payload);
CHECK_HEX(mpq.expectedSha1.data(), mpq.expectedSha1.size(),
expected.mpqSha1);
warden::LuaCheckProfile const& lua =
std::get<warden::LuaCheckProfile>(profile->checks[2].payload);
CHECK_HEX(reinterpret_cast<uint8 const*>(lua.expectedText.data()),
lua.expectedText.size(), expected.luaText);

warden::MemCheckProfile const& glue =
std::get<warden::MemCheckProfile>(profile->checks[7].payload);
CHECK_EQ(glue.addressOrRva, uint32(4631212));
CHECK_HEX(glue.expectedBytes.data(), glue.expectedBytes.size(),
"1ca9460029a9460036a946009ea94600");
CHECK(profile->checks[7].evidenceClass ==
warden::WardenEvidenceClass::IntegrityInvariant);

warden::MemCheckProfile const& frame =
std::get<warden::MemCheckProfile>(profile->checks[8].payload);
CHECK_EQ(frame.addressOrRva, expected.frameDispatchAddress);
CHECK_HEX(frame.expectedBytes.data(), frame.expectedBytes.size(),
expected.frameDispatchBytes);
CHECK(profile->checks[8].evidenceClass ==
warden::WardenEvidenceClass::IntegrityInvariant);
}

warden::WardenCheckProfile const* profile =
catalog.Find(6141, "Win", "zhCN");
REQUIRE(profile != nullptr);
REQUIRE(profile->checks.size() == 7u);
CHECK(profile->hasActionableChecks);
CHECK_EQ(profile->totalRows, uint32(7));
CHECK_EQ(warden::GetWardenCheckId(profile->checks[0]), uint32(65536));
CHECK(warden::GetWardenCheckType(profile->checks[0]) ==
warden::WardenCheckType::Timing);
CHECK(!warden::IsConfirmationEligible(profile->checks[0]));
CHECK(warden::IsConfirmationEligible(profile->checks[1]));
CHECK(warden::IsActionableEvidenceClass(
warden::WardenEvidenceClass::IntegrityInvariant));
CHECK(warden::IsActionableEvidenceClass(
Expand All @@ -110,12 +183,7 @@ TEST(WardenCheckCatalog_decodes_and_selects_three_exact_profiles)
CHECK(!warden::IsActionableEvidenceClass(
warden::WardenEvidenceClass::Corroboration));

warden::LuaCheckProfile const& lua =
std::get<warden::LuaCheckProfile>(profile->checks[2].payload);
CHECK_HEX(reinterpret_cast<uint8 const*>(lua.expectedText.data()),
lua.expectedText.size(), "e7a1aee5ae9a");
CHECK(catalog.Find(5875, "Win", "enUS") != nullptr);
CHECK(catalog.Find(6005, "Win", "enGB") != nullptr);
CHECK(catalog.Find(5875, "Win", "itIT") == nullptr);
CHECK(catalog.Find(6005, "Win", "enUS") == nullptr);
CHECK(catalog.Find(6141, "OSX", "zhCN") == nullptr);
}
Expand Down Expand Up @@ -239,7 +307,7 @@ TEST(WardenCheckCatalog_enforces_timing_contract_and_cardinality)
CHECK(BuildRows(rows) == warden::CheckCatalogValidation::DisabledTiming);
rows = FirstProfileRows();
warden::WardenCheckRowInput secondTiming = rows[0];
secondTiming.checkId = 65537;
secondTiming.checkId = 65539;
secondTiming.sortOrder = 11;
rows.push_back(secondTiming);
CHECK(BuildRows(rows) == warden::CheckCatalogValidation::MultipleTiming);
Expand Down Expand Up @@ -523,12 +591,12 @@ TEST(WardenCheckCatalog_enforces_complete_profiles_and_atomic_build)

warden::WardenCheckCatalog unchanged =
warden::test::BuildInitialWardenCatalog();
REQUIRE(unchanged.TotalRows() == 21u);
REQUIRE(unchanged.TotalRows() == 72u);
rows = FirstProfileRows();
rows[2].checkId = rows[1].checkId;
CHECK(BuildRows(rows, unchanged) ==
warden::CheckCatalogValidation::DuplicateId);
CHECK_EQ(unchanged.TotalRows(), uint32(21));
CHECK_EQ(unchanged.TotalRows(), uint32(72));
CHECK(unchanged.Find(6141, "Win", "zhCN") != nullptr);
}

Expand Down
62 changes: 56 additions & 6 deletions src/tests/WardenCheckFixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ inline void AppendInitialProfile(std::vector<WardenCheckRowInput>& rows,
std::string const& mpqExpectedHex, std::string const& luaExpectedHex,
uint32 functionAddress, std::string const& functionExpectedHex,
uint32 flagsAddress, uint32 luaProtectionAddress,
std::string const& luaProtectionExpectedHex, uint32 wallClimbAddress)
std::string const& luaProtectionExpectedHex, uint32 wallClimbAddress,
uint32 frameDispatchAddress, std::string const& frameDispatchExpectedHex)
{
rows.push_back(MakeRow(build, localeHex, 65536,
WardenCheckType::Timing, 10, WardenEvidenceClass::ProtocolHealth));
Expand Down Expand Up @@ -98,28 +99,77 @@ inline void AppendInitialProfile(std::vector<WardenCheckRowInput>& rows,
wallClimb.length = 4;
wallClimb.expectedHex = "BB8D243F";
rows.push_back(wallClimb);

// Both tables dispatch the client interface-signature result. A patched
// table can turn all outcomes into success without changing Warden code.
WardenCheckRowInput glueDispatch = MakeRow(build, localeHex, 65537,
WardenCheckType::Mem, 80, WardenEvidenceClass::IntegrityInvariant);
glueDispatch.address = 4631212;
glueDispatch.length = 16;
glueDispatch.expectedHex = "1CA9460029A9460036A946009EA94600";
rows.push_back(glueDispatch);

WardenCheckRowInput frameDispatch = MakeRow(build, localeHex, 65538,
WardenCheckType::Mem, 90, WardenEvidenceClass::IntegrityInvariant);
frameDispatch.address = frameDispatchAddress;
frameDispatch.length = 16;
frameDispatch.expectedHex = frameDispatchExpectedHex;
rows.push_back(frameDispatch);
}

/** Exact database rows intended for the first three supported profiles. */
/** Exact database rows intended for all supported Classic Windows profiles. */
inline std::vector<WardenCheckRowInput> InitialWardenRows()
{
std::vector<WardenCheckRowInput> rows;
rows.reserve(21);
rows.reserve(72);
AppendInitialProfile(rows, 5875, "656E5553",
"7D88154D3411811985F5D81177C5453248133443", "4F6B6179",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E824DA1A005DC20800",
8151558, 4803152, "A1C0EACE00", 8445948);
8151558, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 5875, "6B6F4B52",
"755D6D7F49BB34114433386D559261ED3AA23F00", "ED9995EC9DB8",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E824DA1A005DC20800",
8151558, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 5875, "7A685457",
"2A70E6402A40A4F9E9960CED419DBA5E6DEB8536", "E7A2BAE5AE9A",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E824DA1A005DC20800",
8151558, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 5875, "66724652",
"AF2D81AF013A9BA6BB92CE171E43FA903C9E8C09", "4F4B",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E824DA1A005DC20800",
8151558, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 5875, "65734553",
"1ECEC2C6596B8411FA5FE153EDFB9A6EE43360E9", "41636570746172",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E824DA1A005DC20800",
8151558, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 6005, "656E4742",
"7D88154D3411811985F5D81177C5453248133443", "4F6B6179",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E864DA1A005DC20800",
8151622, 4803152, "A1C0EACE00", 8445948);
8151622, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 6005, "64654445",
"A0B3DC2D78AD892F2436BCD937BE51B4989D64C1", "4F4B",
6392064,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E864DA1A005DC20800",
8151622, 4803152, "A1C0EACE00", 8445948, 4784584,
"5EFF48006BFF480078FF480095FF4800");
AppendInitialProfile(rows, 6141, "7A68434E",
"C5A1DE4C1CD412EB4D2E02AFAB6131B737EFCAF0", "E7A1AEE5AE9A",
6401184,
"558BEC8B51408B450C81E2FF7DA075508950108B450850E864EB1A005DC20800",
8165094, 4806720, "A1E031CF00", 8462780);
8165094, 4806720, "A1E031CF00", 8462780, 4788152,
"4E0D49005B0D4900680D4900850D4900");
return rows;
}

Expand Down
22 changes: 11 additions & 11 deletions src/tests/WardenCheckPlannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ TEST(WardenCheckPlanner_profileless_planner_remains_inert)
TEST(WardenCheckPlanner_initial_plan_waits_and_preserves_catalogue_order)
{
std::vector<warden::WardenCheckDefinition> const checks = ExactChecks();
REQUIRE(checks.size() == 7u);
REQUIRE(checks.size() == 9u);
warden::WardenCheckPlanner planner(warden::WardenConfiguration{}, 1000,
checks);

Expand All @@ -169,11 +169,11 @@ TEST(WardenCheckPlanner_initial_plan_waits_and_preserves_catalogue_order)
REQUIRE(plan.has_value());
CHECK_EQ(plan->requestId, uint32(1));
CHECK(plan->purpose == warden::CheckPlanPurpose::Initial);
REQUIRE(plan->checks.size() == 7u);
REQUIRE(plan->checks.size() == 9u);
for (size_t index = 1; index < plan->checks.size(); ++index)
CHECK(plan->checks[index - 1].sortOrder < plan->checks[index].sortOrder);
CHECK_EQ(warden::GetWardenCheckId(plan->checks.front()), uint32(65536));
CHECK_EQ(warden::GetWardenCheckId(plan->checks.back()), uint32(1135));
CHECK_EQ(warden::GetWardenCheckId(plan->checks.back()), uint32(65538));
CHECK(!planner.Update(true, 60000).has_value());
}

Expand All @@ -189,15 +189,15 @@ TEST(WardenCheckPlanner_resets_partial_initial_delay_when_ineligible)

TEST(WardenCheckPlanner_normal_rotation_covers_every_nonhealth_check_once)
{
ScriptedRandom random{{30, 30, 30, 30}, {}, {}};
ScriptedRandom random{{30, 30, 30, 30, 30}, {}, {}};
warden::WardenCheckPlanner planner(warden::WardenConfiguration{}, 1000,
ExactChecks(), random.Callback());
std::optional<warden::CheckPlan> initial = planner.Update(true, 1000);
REQUIRE(initial.has_value());
planner.Complete(*initial);

std::map<uint32, uint32> counts;
for (uint32 batch = 0; batch < 3; ++batch)
for (uint32 batch = 0; batch < 4; ++batch)
{
std::optional<warden::CheckPlan> recurring =
planner.Update(true, 30000);
Expand All @@ -216,9 +216,9 @@ TEST(WardenCheckPlanner_normal_rotation_covers_every_nonhealth_check_once)
planner.Complete(*recurring);
}

CHECK_EQ(counts.size(), size_t(6));
CHECK_EQ(counts.size(), size_t(8));
for (uint32 id : {uint32(1), uint32(2), uint32(1107), uint32(827),
uint32(1566), uint32(1135)})
uint32(1566), uint32(1135), uint32(65537), uint32(65538)})
CHECK_EQ(counts[id], uint32(1));
}

Expand Down Expand Up @@ -275,7 +275,7 @@ TEST(WardenCheckPlanner_aggressive_plans_include_only_actionable_checks)
CHECK(immediate->purpose ==
warden::CheckPlanPurpose::AggressiveImmediate);
CHECK(CheckIds(*immediate) ==
std::vector<uint32>({1107, 827, 1566}));
std::vector<uint32>({1107, 827, 1566, 65537, 65538}));
planner.Complete(*immediate);

std::optional<warden::CheckPlan> initial = planner.Update(true, 1000);
Expand All @@ -287,7 +287,7 @@ TEST(WardenCheckPlanner_aggressive_plans_include_only_actionable_checks)
CHECK(recurring->purpose ==
warden::CheckPlanPurpose::AggressiveRecurring);
CHECK(CheckIds(*recurring) ==
std::vector<uint32>({1107, 827, 1566}));
std::vector<uint32>({1107, 827, 1566, 65537, 65538}));
}

TEST(WardenCheckPlanner_observation_only_aggressive_mode_uses_normal_checks)
Expand Down Expand Up @@ -354,10 +354,10 @@ TEST(WardenCheckPlanner_preflight_is_linear_and_uses_exact_purposes)
REQUIRE(exact != nullptr);
std::vector<warden::CheckPlan> plans =
warden::BuildWardenPreflightPlans(*exact);
REQUIRE(plans.size() == 7u);
REQUIRE(plans.size() == 9u);
CHECK(plans[0].purpose == warden::CheckPlanPurpose::Initial);
CHECK_EQ(plans[0].requestId, uint32(1));
CHECK_EQ(plans[0].checks.size(), size_t(7));
CHECK_EQ(plans[0].checks.size(), size_t(9));
for (size_t index = 1; index < plans.size(); ++index)
{
CHECK(plans[index].purpose ==
Expand Down
2 changes: 1 addition & 1 deletion src/tests/WardenModuleCatalogTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST(WardenCatalog_coverage_requires_profiles_and_modules_both_directions)

std::vector<warden::WardenCheckRowInput> rows =
warden::test::InitialWardenRows();
rows.resize(7);
rows.resize(9);
warden::WardenCheckCatalog missingModule = BuildCheckCatalog(rows);
CHECK(warden::ValidateWardenCatalogCoverage(missingModule, modules) ==
warden::WardenCheckCatalogLoadFailure::ModuleWithoutProfile);
Expand Down
Loading
Loading