control-plane: the judgement of an organization (one evidence pack, 25 kinds in eight domains, each judged again by its published verifier with the relying party's own trust, revocations and clock; 74/74, 75/75 with --online on testnet 28001, view 48/48; negative controls 45/45 and 20/20); the compliance report is made again from its own findings

This commit is contained in:
Aere Network committed 2026-10-21 01:12:43 +03:00
1 parent 6ba33c477f
commit 82c5b261ac
10 files changed
+1902 -17

No files matched your search

+43
View File
@@ -178,3 +178,46 @@ export function verificaRaport(raport, plic) {
return h === String(e).toLowerCase() ? { ok: true } : { ok: false, reason: 'the report is NOT the one bound to the envelope', fingerprint: h, inEnvelope: e };
}
export { verificaRaport as verifyReport };
// DERIVAREA (revizia B2, 2026-10-21): legarea de plic spune numai CA raportul e cel legat, nu si ca e ce da generatorul. Plicul nu e semnat, deci
// cine tine raportul ii poate rescrie rezumatul ("no quantum-vulnerable public-key algorithm") peste constatari care spun altceva, il poate lega
// din nou, si legarea iese buna (masurat: judecata organizatiei dadea VALID si arata rezumatul rescris). Aici raportul se FACE INCA O DATA din
// propriile constatari, cu acelasi generator: fiecare constatare devine actiunea din care generatorul ar fi scris-o (natura ei, refacuta prin
// `natura`), iar rezumatul, termenele, zilele, expunerea, regimurile, limitele si declaratia plicului trebuie sa iasa EXACT cele primite.
// Ce nu se poate reface de aici: ca actiunile erau chiar cele ale planului real (asta e inventarul si scanarea, nu raportul).
const ACTIUNE_PE_NATURA = { 'key-exchange': { source: 'inventory', primitive: 'key-agree' }, signature: { source: 'inventory', primitive: 'signature' }, 'key-use-unknown': { source: 'inventory', primitive: '' } };
const json = (v) => JSON.parse(JSON.stringify(v === undefined ? null : v));
/** prima cale la care doua valori JSON difera, ca motivul sa spuna CE nu se reface */
function primaDiferenta(a, b, cale = '') {
if (canonicJson(a) === canonicJson(b)) return null;
if (a && b && typeof a === 'object' && typeof b === 'object' && Array.isArray(a) === Array.isArray(b)) {
const chei = [...new Set([...Object.keys(a), ...Object.keys(b)])].sort();
for (const k of chei) { const d = primaDiferenta(a[k], b[k], cale + (Array.isArray(a) ? `[${k}]` : (cale ? '.' : '') + k)); if (d) return d; }
}
return cale || '(the whole)';
}
/**
* Raportul e ce da generatorul acesta pentru propriile lui constatari, data, risc si CNSA? { ok: true } | { ok: false, reason } | { ok: null, reason }
* (null = alt generator: nu se poate reface de aici, deci nu se poate spune nici da, nici nu).
*/
export function verificaDerivarea(raport, plic) {
if (!raport || typeof raport !== 'object' || Array.isArray(raport)) return { ok: false, reason: 'the report is not an object' };
if (raport.version !== VERSIUNE) return { ok: null, reason: `the report says it was made by ${JSON.stringify(raport.version)}; this generator is ${VERSIUNE} and does not re-derive another` };
if (!Array.isArray(raport.findings) || !raport.findings.every((f) => f && typeof f === 'object' && !Array.isArray(f))) return { ok: false, reason: 'the report has no list of findings' };
const actiuni = [], cnsaCategories = Object.create(null);
for (const f of raport.findings) {
actiuni.push({ ref: f.ref, asset: f.asset, problem: f.problem, urgency: f.urgency, method: f.method, product: f.product, target: f.target, blocker: f.blocker, scope: f.scope,
...(Object.hasOwn(ACTIUNE_PE_NATURA, String(f.nature)) ? ACTIUNE_PE_NATURA[f.nature] : { source: null }) });
for (const r of Array.isArray(f.regimes) ? f.regimes : []) if (r && r.regime === 'cnsa-2.0' && r.assumed === false && typeof r.category === 'string') cnsaCategories[f.ref] = r.category;
}
const p = raport.plan && typeof raport.plan === 'object' ? raport.plan : {};
let d;
try { d = raportConformitate({ plan: { version: p.version, summary: p.summary, actions: actiuni }, organization: raport.organization, risk: raport.risk === null ? undefined : raport.risk, date: raport.date, cnsa: raport.cnsa === true, cnsaCategories }); }
catch (e) { return { ok: false, reason: 'the report cannot be made again from its own findings: ' + String(e.message).slice(0, 160) }; }
const unde = primaDiferenta(json(d.report), json(raport));
if (unde) return { ok: false, reason: `the report is not what the report generator gives for its own findings (it differs at ${unde})` };
const st = plic && plic.statement && typeof plic.statement === 'object' ? plic.statement : null;
const undeP = primaDiferenta(json(d.envelope.statement), json(st));
if (undeP) return { ok: false, reason: `the envelope's statement is not the one the generator writes for this report (it differs at statement.${undeP})` };
return { ok: true };
}