mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 19:25:56 +00:00
feat(phase15): release and security hardening, DPAPI key store, probe & protocol hardening, secret redaction, audit and readiness report
This commit is contained in:
1 parent
b69fa6b867
commit
51e0f136d6
207 files changed
+38235
-7770
No files matched your search
@@ -1,22 +1,65 @@
|
||||
//! Read-only database structure checks. A release can ship a contract captured from its clean database.
|
||||
use crate::{db::Db, error::Result, fsx};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::Path;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::{db::Db, error::Result, fsx};
|
||||
|
||||
pub const CONTRACT: &str = "Scripts/database-schema.json";
|
||||
pub const WILDCARD_TABLES: &[(&str, &[&str])] = &[
|
||||
("world", &["ascension_wildcard_boss_marks", "ascension_wildcard_tooltip_links"]),
|
||||
("characters", &["coa_wildcard_skill_card", "coa_wildcard_skill_card_pending", "coa_wildcard_skill_card_account", "coa_wildcard_skill_card_purchase", "coa_wildcard_specialization_cache"]),
|
||||
(
|
||||
"world",
|
||||
&[
|
||||
"ascension_wildcard_boss_marks",
|
||||
"ascension_wildcard_tooltip_links",
|
||||
],
|
||||
),
|
||||
(
|
||||
"characters",
|
||||
&[
|
||||
"coa_wildcard_skill_card",
|
||||
"coa_wildcard_skill_card_pending",
|
||||
"coa_wildcard_skill_card_account",
|
||||
"coa_wildcard_skill_card_purchase",
|
||||
"coa_wildcard_specialization_cache",
|
||||
],
|
||||
),
|
||||
];
|
||||
const WILDCARD_COLUMNS: &[(&str, &str, &[&str])] = &[
|
||||
("world", "ascension_wildcard_boss_marks", &["CreatureEntry", "Amount"]),
|
||||
("world", "ascension_wildcard_tooltip_links", &["Talent", "Ability"]),
|
||||
("characters", "coa_wildcard_skill_card", &["account", "card", "progress"]),
|
||||
("characters", "coa_wildcard_skill_card_pending", &["account", "id", "card"]),
|
||||
("characters", "coa_wildcard_skill_card_account", &["account", "bonus_progress"]),
|
||||
("characters", "coa_wildcard_skill_card_purchase", &["account", "type", "count"]),
|
||||
("characters", "coa_wildcard_specialization_cache", &["account", "claimed_at"]),
|
||||
(
|
||||
"world",
|
||||
"ascension_wildcard_boss_marks",
|
||||
&["CreatureEntry", "Amount"],
|
||||
),
|
||||
(
|
||||
"world",
|
||||
"ascension_wildcard_tooltip_links",
|
||||
&["Talent", "Ability"],
|
||||
),
|
||||
(
|
||||
"characters",
|
||||
"coa_wildcard_skill_card",
|
||||
&["account", "card", "progress"],
|
||||
),
|
||||
(
|
||||
"characters",
|
||||
"coa_wildcard_skill_card_pending",
|
||||
&["account", "id", "card"],
|
||||
),
|
||||
(
|
||||
"characters",
|
||||
"coa_wildcard_skill_card_account",
|
||||
&["account", "bonus_progress"],
|
||||
),
|
||||
(
|
||||
"characters",
|
||||
"coa_wildcard_skill_card_purchase",
|
||||
&["account", "type", "count"],
|
||||
),
|
||||
(
|
||||
"characters",
|
||||
"coa_wildcard_specialization_cache",
|
||||
&["account", "claimed_at"],
|
||||
),
|
||||
];
|
||||
type Columns = BTreeMap<String, BTreeMap<String, BTreeMap<String, String>>>;
|
||||
|
||||
@@ -28,16 +71,27 @@ pub struct Contract {
|
||||
|
||||
pub fn require_release_contract(root: &Path) -> Result<Contract> {
|
||||
let contract: Contract = fsx::read_json(&root.join(CONTRACT))?;
|
||||
if contract.schema != 1 || ["auth", "characters", "world"].iter().any(|kind| {
|
||||
contract.columns.get(*kind).is_none_or(|tables| tables.is_empty() || tables.values().any(|columns| columns.is_empty()))
|
||||
}) {
|
||||
return Err(crate::Error::Invalid("The release must include a complete supported database schema contract.".into()));
|
||||
if contract.schema != 1
|
||||
|| ["auth", "characters", "world"].iter().any(|kind| {
|
||||
contract.columns.get(*kind).is_none_or(|tables| {
|
||||
tables.is_empty() || tables.values().any(|columns| columns.is_empty())
|
||||
})
|
||||
})
|
||||
{
|
||||
return Err(crate::Error::Invalid(
|
||||
"The release must include a complete supported database schema contract.".into(),
|
||||
));
|
||||
}
|
||||
Ok(contract)
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Problem { pub database: String, pub table: String, pub column: String, pub detail: String }
|
||||
pub struct Problem {
|
||||
pub database: String,
|
||||
pub table: String,
|
||||
pub column: String,
|
||||
pub detail: String,
|
||||
}
|
||||
|
||||
fn read_columns(db: &Db, kind: &str) -> Result<BTreeMap<String, BTreeMap<String, String>>> {
|
||||
let schema = db.realm_schema(crate::db::schema_of(kind)?);
|
||||
@@ -45,41 +99,74 @@ fn read_columns(db: &Db, kind: &str) -> Result<BTreeMap<String, BTreeMap<String,
|
||||
let mut tables: BTreeMap<String, BTreeMap<String, String>> = BTreeMap::new();
|
||||
for line in text.lines() {
|
||||
let fields: Vec<_> = line.split('\t').collect();
|
||||
if fields.len() == 3 { tables.entry(fields[0].into()).or_default().insert(fields[1].into(), fields[2].into()); }
|
||||
if fields.len() == 3 {
|
||||
tables
|
||||
.entry(fields[0].into())
|
||||
.or_default()
|
||||
.insert(fields[1].into(), fields[2].into());
|
||||
}
|
||||
}
|
||||
Ok(tables)
|
||||
}
|
||||
|
||||
pub fn capture(db: &Db, root: &Path) -> Result<()> {
|
||||
let mut columns = Columns::new();
|
||||
for kind in ["auth", "characters", "world"] { columns.insert(kind.into(), read_columns(db, kind)?); }
|
||||
for kind in ["auth", "characters", "world"] {
|
||||
columns.insert(kind.into(), read_columns(db, kind)?);
|
||||
}
|
||||
fsx::atomic_write_json(&root.join(CONTRACT), &Contract { schema: 1, columns })
|
||||
}
|
||||
|
||||
pub fn check(db: &Db, root: &Path) -> Result<Vec<Problem>> {
|
||||
let contract = if root.join(CONTRACT).is_file() {
|
||||
let contract: Contract = fsx::read_json(&root.join(CONTRACT))?;
|
||||
if contract.schema != 1 { return Err(crate::Error::Invalid("Unsupported database schema contract.".into())); }
|
||||
if contract.schema != 1 {
|
||||
return Err(crate::Error::Invalid(
|
||||
"Unsupported database schema contract.".into(),
|
||||
));
|
||||
}
|
||||
contract
|
||||
} else {
|
||||
// Older packages have no full contract. Check the columns used by initial character saves.
|
||||
let tables: BTreeMap<String, Vec<String>> = serde_json::from_str(include_str!("character-save-columns.json"))?;
|
||||
Contract { schema: 1, columns: BTreeMap::from([("characters".into(), tables.into_iter().map(|(t, cols)| (t, cols.into_iter().map(|c| (c, String::new())).collect())).collect())]) }
|
||||
let tables: BTreeMap<String, Vec<String>> =
|
||||
serde_json::from_str(include_str!("character-save-columns.json"))?;
|
||||
Contract {
|
||||
schema: 1,
|
||||
columns: BTreeMap::from([(
|
||||
"characters".into(),
|
||||
tables
|
||||
.into_iter()
|
||||
.map(|(t, cols)| (t, cols.into_iter().map(|c| (c, String::new())).collect()))
|
||||
.collect(),
|
||||
)]),
|
||||
}
|
||||
};
|
||||
let mut problems = Vec::new();
|
||||
// Older releases omit a schema contract. Still verify the feature's actual tables,
|
||||
// independently of its migration history, before declaring an update healthy.
|
||||
if std::fs::read(root.join("Core/worldserver.exe")).is_ok_and(|bytes| bytes.windows(b"Wildcard synergy settings".len()).any(|w| w == b"Wildcard synergy settings")) {
|
||||
if std::fs::read(root.join("Core/worldserver.exe")).is_ok_and(|bytes| {
|
||||
bytes
|
||||
.windows(b"Wildcard synergy settings".len())
|
||||
.any(|w| w == b"Wildcard synergy settings")
|
||||
}) {
|
||||
for (kind, tables) in WILDCARD_TABLES {
|
||||
let actual = read_columns(db, kind)?;
|
||||
for table in *tables {
|
||||
if !actual.contains_key(*table) {
|
||||
problems.push(Problem { database: (*kind).into(), table: (*table).into(), column: String::new(), detail: "Missing required Wildcard table; migration history is not proof of its presence".into() });
|
||||
} else {
|
||||
for (_, _, columns) in WILDCARD_COLUMNS.iter().filter(|(k, t, _)| k == kind && t == table) {
|
||||
for (_, _, columns) in WILDCARD_COLUMNS
|
||||
.iter()
|
||||
.filter(|(k, t, _)| k == kind && t == table)
|
||||
{
|
||||
for column in *columns {
|
||||
if !actual[*table].contains_key(*column) {
|
||||
problems.push(Problem { database: (*kind).into(), table: (*table).into(), column: (*column).into(), detail: "Missing required Wildcard column".into() });
|
||||
problems.push(Problem {
|
||||
database: (*kind).into(),
|
||||
table: (*table).into(),
|
||||
column: (*column).into(),
|
||||
detail: "Missing required Wildcard column".into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,26 +177,53 @@ pub fn check(db: &Db, root: &Path) -> Result<Vec<Problem>> {
|
||||
for (kind, expected) in &contract.columns {
|
||||
let actual = read_columns(db, kind)?;
|
||||
for (table, cols) in expected {
|
||||
if matches!(table.as_str(), "updates" | "updates_include" | "coa_manager_migrations") { continue; }
|
||||
if matches!(
|
||||
table.as_str(),
|
||||
"updates" | "updates_include" | "coa_manager_migrations"
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if !actual.contains_key(table) {
|
||||
problems.push(Problem { database: kind.clone(), table: table.clone(), column: String::new(), detail: "Missing table".into() });
|
||||
problems.push(Problem {
|
||||
database: kind.clone(),
|
||||
table: table.clone(),
|
||||
column: String::new(),
|
||||
detail: "Missing table".into(),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
for (column, want) in cols {
|
||||
let found = actual[table].get(column);
|
||||
if found.is_none() || (!want.is_empty() && found != Some(want)) {
|
||||
problems.push(Problem { database: kind.clone(), table: table.clone(), column: column.clone(), detail: found.map(|s| format!("Expected {want}, found {s}")).unwrap_or_else(|| "Missing column".into()) });
|
||||
problems.push(Problem {
|
||||
database: kind.clone(),
|
||||
table: table.clone(),
|
||||
column: column.clone(),
|
||||
detail: found
|
||||
.map(|s| format!("Expected {want}, found {s}"))
|
||||
.unwrap_or_else(|| "Missing column".into()),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// A custom NOT NULL column without a default can reject every INSERT even when all standard columns exist.
|
||||
let supplied: BTreeMap<String, Vec<String>> = serde_json::from_str(include_str!("character-save-columns.json"))?;
|
||||
let supplied: BTreeMap<String, Vec<String>> =
|
||||
serde_json::from_str(include_str!("character-save-columns.json"))?;
|
||||
let schema = db.realm_schema("acore_characters");
|
||||
let required = db.query(&format!("SELECT TABLE_NAME,COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='{schema}' AND IS_NULLABLE='NO' AND COLUMN_DEFAULT IS NULL AND EXTRA NOT LIKE '%auto_increment%' AND EXTRA NOT LIKE '%GENERATED%';"))?;
|
||||
for (table, column) in required.lines().filter_map(|l| l.split_once('\t')) {
|
||||
if supplied.get(table).is_some_and(|cols| !cols.iter().any(|c| c == column)) {
|
||||
problems.push(Problem { database: "characters".into(), table: table.into(), column: column.into(), detail: "Required column has no default and is not supplied by character creation".into() });
|
||||
if supplied
|
||||
.get(table)
|
||||
.is_some_and(|cols| !cols.iter().any(|c| c == column))
|
||||
{
|
||||
problems.push(Problem {
|
||||
database: "characters".into(),
|
||||
table: table.into(),
|
||||
column: column.into(),
|
||||
detail: "Required column has no default and is not supplied by character creation"
|
||||
.into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
// The any-race/class migration supports every standard playable race for all CoA classes.
|
||||
@@ -131,12 +245,21 @@ pub fn check(db: &Db, root: &Path) -> Result<Vec<Problem>> {
|
||||
}
|
||||
|
||||
fn missing_coa_starts(rows: &str) -> Vec<Problem> {
|
||||
let pairs: BTreeSet<_> = rows.lines().filter_map(|l| l.split_once('\t')).map(|(a,b)| (a.to_owned(),b.to_owned())).collect();
|
||||
let pairs: BTreeSet<_> = rows
|
||||
.lines()
|
||||
.filter_map(|l| l.split_once('\t'))
|
||||
.map(|(a, b)| (a.to_owned(), b.to_owned()))
|
||||
.collect();
|
||||
let mut problems = Vec::new();
|
||||
for race in [1, 2, 3, 4, 5, 6, 7, 8, 10, 11] {
|
||||
for class in 12..=32 {
|
||||
if !pairs.contains(&(race.to_string(), class.to_string())) {
|
||||
problems.push(Problem { database: "world".into(), table: "playercreateinfo".into(), column: String::new(), detail: format!("No starting data for CoA race {race} / class {class}") });
|
||||
problems.push(Problem {
|
||||
database: "world".into(),
|
||||
table: "playercreateinfo".into(),
|
||||
column: String::new(),
|
||||
detail: format!("No starting data for CoA race {race} / class {class}"),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,13 +274,27 @@ mod tests {
|
||||
fn a_release_cannot_use_a_partial_or_empty_schema_contract() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
assert!(require_release_contract(dir.path()).is_err());
|
||||
fsx::atomic_write_json(&dir.path().join(CONTRACT), &Contract { schema: 1, columns: Columns::new() }).unwrap();
|
||||
fsx::atomic_write_json(
|
||||
&dir.path().join(CONTRACT),
|
||||
&Contract {
|
||||
schema: 1,
|
||||
columns: Columns::new(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
assert!(require_release_contract(dir.path()).is_err());
|
||||
let mut columns = Columns::new();
|
||||
for kind in ["auth", "characters", "world"] {
|
||||
columns.insert(kind.into(), BTreeMap::from([("table".into(), BTreeMap::from([("id".into(), "int|NO|<NULL>|<NONE>".into())]))]));
|
||||
columns.insert(
|
||||
kind.into(),
|
||||
BTreeMap::from([(
|
||||
"table".into(),
|
||||
BTreeMap::from([("id".into(), "int|NO|<NULL>|<NONE>".into())]),
|
||||
)]),
|
||||
);
|
||||
}
|
||||
fsx::atomic_write_json(&dir.path().join(CONTRACT), &Contract { schema: 1, columns }).unwrap();
|
||||
fsx::atomic_write_json(&dir.path().join(CONTRACT), &Contract { schema: 1, columns })
|
||||
.unwrap();
|
||||
assert!(require_release_contract(dir.path()).is_ok());
|
||||
}
|
||||
|
||||
@@ -165,10 +302,16 @@ mod tests {
|
||||
fn detects_a_missing_orc_class_pair_even_when_the_class_exists_for_other_races() {
|
||||
let mut rows = String::new();
|
||||
for race in [1, 2, 3, 4, 5, 6, 7, 8, 10, 11] {
|
||||
for class in 12..=32 { rows.push_str(&format!("{race}\t{class}\n")); }
|
||||
for class in 12..=32 {
|
||||
rows.push_str(&format!("{race}\t{class}\n"));
|
||||
}
|
||||
}
|
||||
assert!(missing_coa_starts(&rows).is_empty());
|
||||
let incomplete = rows.lines().filter(|line| *line != "2\t30").collect::<Vec<_>>().join("\n");
|
||||
let incomplete = rows
|
||||
.lines()
|
||||
.filter(|line| *line != "2\t30")
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let problems = missing_coa_starts(&incomplete);
|
||||
assert_eq!(problems.len(), 1);
|
||||
assert!(problems[0].detail.contains("race 2 / class 30"));
|
||||
|
||||
Reference in new issue
Block a user