"use strict"; // Signed asset root (docs/security-audit U2). The corpus root asset-manifest.json names every shard, pack, // install plan and delta by sha256, and the client's loader checks each object against it; the root itself was taken // from the CDN as is, so whoever controlled R2 could swap any asset, scripts the renderer runs included. // client/release/corpus.mjs publish signs the root with the release key (asset-manifest.json.sig, base64 Ed25519 // over the exact bytes); an installed client whose build says so (environments.json assetRootSigned) accepts only // roots with a valid signature (launcher/main.cjs serveFromAssetBase). const crypto = require("crypto"); /** The root's own path inside the corpus URL space (`.../assets/asset-manifest.json`, any query). */ function isAssetRootPath(pathname) { return /\/assets\/asset-manifest\.json$/.test(String(pathname)); } /** * Khaos (asset-verify 2026-10-15): the corpus paths the launcher fetches past Chromium's HTTP disk cache. These are * the ca/ blobs, the packs, and the asset-* metadata (root, shards, pack catalog, install plans, deltas). `relative` * is the path after `.../assets/`. The client checks these objects against the root and keeps them in its own store. * A copy in the HTTP cache (ca/ is served with max-age=31536000) was replayed at every request for a year. A beta * tester's data/items.bin failed "Asset verification failed" at every start while the CDN served good bytes. The * other paths (the login screen's look warm-up) keep the HTTP cache. */ function bypassesHttpCache(relative) { return /^(?:ca\/|packs\/|asset-)/.test(String(relative)); } /** * The release public keys of a build: a PEM string holding one or several `PUBLIC KEY` blocks, or an array of them. * Builds carry two (owner question 7): the hot key that signs releases and a cold one kept offline, so a lost or * leaked hot key is replaced by a release signed with the cold key instead of a reinstall for every player. */ function publicKeys(keys) { const list = Array.isArray(keys) ? keys : [keys]; return list.flatMap((k) => String(k || "").match(/-----BEGIN PUBLIC KEY-----[\s\S]+?-----END PUBLIC KEY-----/g) ?? []); } /** True only for a well-formed Ed25519 signature of exactly these bytes by one of these public keys. */ function verifySigned(bytes, signatureText, keys) { if (!bytes || typeof signatureText !== "string") return false; const sig = Buffer.from(signatureText.trim(), "base64"); if (sig.length !== 64) return false; for (const pem of publicKeys(keys)) { try { if (crypto.verify(null, Buffer.from(bytes), crypto.createPublicKey(pem), sig)) return true; } catch { /* malformed key: try the next */ } } return false; } /** The asset root's check (one or several public keys, see publicKeys). */ function verifyAssetRoot(bytes, signatureText, publicKeyPem) { return verifySigned(bytes, signatureText, publicKeyPem); } module.exports = { isAssetRootPath, bypassesHttpCache, verifyAssetRoot, verifySigned, publicKeys };