Security: console service account with a random password (SRP6 verified against a real server), rotated at install

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-09-30 10:09:54 +05:00
1 parent 903b999181
commit 6a550353b3
8 files changed
+129 -3

No files matched your search

+2
View File
@@ -19,6 +19,8 @@ base64 = "0.22"
zstd = { version = "0.13", features = ["zstdmt"] }
reqwest = { version = "0.12", default-features = false, features = ["blocking", "native-tls"] }
tar = "0.4"
num-bigint = "0.4"
sha1 = "0.10"
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "std"] }
[dev-dependencies]
+1 -1
View File
@@ -33,7 +33,7 @@ fn main() {
&Params { source: Source::Dir(out.clone()), dest: dest.clone(), trusted_key: coa_core::signing::EMBEDDED_PUBLIC_KEY, registry: &registry, cancel: Cancel::default() },
&|s| eprintln!(" install: {:>3}% {} {}", s.percent, s.step, s.detail.unwrap_or_default()),
)
.expect("install");
.unwrap_or_else(|e| panic!("install failed: {e:?}"));
println!("installed {} at {} in {:?}", installed.version, installed.path, t.elapsed());
assert!(!dest.with_file_name("coa-installtest.installing").exists());
+1 -1
View File
@@ -1,7 +1,7 @@
//! Create an account through the Manager's RA client on a RUNNING disposable fixture.
fn main() {
let a: Vec<String> = std::env::args().skip(1).collect();
assert!(a[0].to_lowercase().contains("fixture"), "refusing: not a fixture folder");
assert!(a[0].to_lowercase().contains("fixture") || a[0].to_lowercase().contains("installtest"), "refusing: not a disposable folder");
let root = std::path::Path::new(&a[0]);
let mut ra = coa_core::ra::Ra::connect(root).expect("connect");
ra.create_account(&a[1], &a[2]).expect("create");
+28
View File
@@ -247,6 +247,34 @@ impl Db {
}
}
/// Name of the service account the Manager uses for the server console (RA). Accounts are stored upper-case.
pub const SERVICE_ACCOUNT: &str = "COAMANAGER";
impl Db {
/// Create (or reset) the console service account with a fresh random password and administrator rights on
/// all realms, and return that password. The database must be running.
pub fn provision_service_account(&self) -> Result<String> {
let password = hex::encode(&crate::srp6::new_salt()[..8]); // 16 random hex characters
let salt = crate::srp6::new_salt();
let verifier = crate::srp6::verifier(SERVICE_ACCOUNT, &password, &salt);
let (s, v) = (hex::encode(salt), hex::encode(verifier));
self.query(&format!(
"INSERT INTO acore_auth.account (username, salt, verifier, email, reg_mail) VALUES ('{SERVICE_ACCOUNT}', UNHEX('{s}'), UNHEX('{v}'), '', '') ON DUPLICATE KEY UPDATE salt=UNHEX('{s}'), verifier=UNHEX('{v}'), failed_logins=0, locked=0; INSERT INTO acore_auth.account_access (id, gmlevel, RealmID, comment) SELECT id, 3, -1, 'CoA Server Manager console' FROM acore_auth.account WHERE username='{SERVICE_ACCOUNT}' ON DUPLICATE KEY UPDATE gmlevel=3;"
))?;
Ok(password)
}
}
/// Point `Settings/repack.json` at the service account (other keys are preserved).
pub fn write_console_credentials(root: &Path, password: &str) -> Result<()> {
let path = root.join("Settings/repack.json");
let mut v: serde_json::Value = fsx::read_json(&path)?;
let obj = v.as_object_mut().ok_or_else(|| Error::Invalid("repack.json is not an object".into()))?;
obj.insert("raUsername".into(), SERVICE_ACCOUNT.into());
obj.insert("raPassword".into(), password.into());
fsx::atomic_write_json(&path, &v)
}
pub fn valid_identifier(name: &str) -> bool {
ident_ok(name)
}
+4 -1
View File
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
use serde::Serialize;
use crate::db::{Account, Db};
use crate::db::{self, Account, Db};
use crate::download::Cancel;
use crate::driver::{self, Verb};
use crate::error::{Error, Result};
@@ -172,6 +172,9 @@ fn bootstrap_database(root: &Path) -> Result<()> {
sql.push_str("FLUSH PRIVILEGES;\n");
db.query(&sql)?;
fsx::atomic_write_json(&target, &serde_json::json!({ "rootPassword": root_pw, "appPassword": app_pw }))?;
// The server console gets its own account with a random password instead of a shared default.
let console_pw = Db::from_repack(root, Account::Admin)?.provision_service_account()?; // new root password
db::write_console_credentials(root, &console_pw)?;
// The new root password must actually work before we throw the old one away.
if !Db::from_repack(root, Account::Admin)?.ping() {
return Err(Error::Invalid("The new database password did not work.".into()));
+1
View File
@@ -20,6 +20,7 @@ pub mod ra;
pub mod registry;
pub mod update;
pub mod signing;
pub mod srp6;
pub use error::{Error, ErrorCode, Result};
+60
View File
@@ -0,0 +1,60 @@
//! AzerothCore's SRP6 account verifier (salt + verifier), so the Manager can create the service account it
//! needs for the server console without ever knowing a shared default password.
use num_bigint::BigUint;
use sha1::{Digest, Sha1};
const N_HEX: &str = "894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7";
fn n() -> BigUint {
BigUint::parse_bytes(N_HEX.as_bytes(), 16).expect("constant")
}
fn le32(v: &BigUint) -> [u8; 32] {
let mut b = v.to_bytes_le();
b.resize(32, 0);
b.try_into().expect("32 bytes")
}
/// Verifier for `username`/`password` under `salt` (both names are case-folded, as the server does).
pub fn verifier(username: &str, password: &str, salt: &[u8; 32]) -> [u8; 32] {
let h1 = Sha1::digest(format!("{}:{}", username.to_uppercase(), password.to_uppercase()).as_bytes());
let mut h2 = Sha1::new();
h2.update(salt);
h2.update(h1);
let x = BigUint::from_bytes_le(&h2.finalize());
le32(&BigUint::from(7u32).modpow(&x, &n()))
}
/// A fresh random salt.
pub fn new_salt() -> [u8; 32] {
let mut s = [0u8; 32];
for chunk in s.chunks_mut(16) {
chunk.copy_from_slice(uuid::Uuid::new_v4().as_bytes());
}
s
}
#[cfg(test)]
mod tests {
use super::*;
fn hex32(s: &str) -> [u8; 32] {
hex::decode(s).unwrap().try_into().unwrap()
}
#[test]
fn matches_a_verifier_created_by_a_real_worldserver() {
// Account created through the server's own `account create` command (RA) on a disposable fixture.
let salt = hex32("54A0DE1E331BB7D2E3964389DB5A443115ED3619BED86B501157DA93C4FC2CF6");
let expected = hex32("7C39E59C220E8D62CE4CAAB110D4BE8C2381B62E95825B0DC1A4640E57233A46");
assert_eq!(verifier("ManagerTest1", "hunter22", &salt), expected);
assert_eq!(verifier("MANAGERTEST1", "HUNTER22", &salt), expected, "case-insensitive like the server");
assert_ne!(verifier("ManagerTest1", "hunter23", &salt), expected);
}
#[test]
fn salts_are_random() {
assert_ne!(new_salt(), new_salt());
}
}