conformance: 97 rules of 9 verifiers, 206 vectors; verify-layer and agents refuse a classical key under an ML-DSA-65 name; market-settlement reads the notarization time from the certified read; proof-of-ai README in English
This commit is contained in:
1 parent
c9f2932e04
commit
c9798a0013
111 files changed
+15871
-292
No files matched your search
+12
-4
@@ -110,7 +110,7 @@ other, so both verify commands then say whether each head is signed and by which
|
||||
|
||||
## Tests
|
||||
|
||||
node proba-sidecar.mjs # 44 checks
|
||||
node proba-sidecar.mjs # 45 checks
|
||||
node control-negativ-sidecar.mjs # puts each guard back to its absent form and requires the named check to fail
|
||||
node proba-arbore.mjs # 20: the tree (the reference roots of Certificate Transparency for 1..8 leaves, every proof up to 64 leaves, each attack)
|
||||
node control-negativ-arbore.mjs # 14 guards removed in a copy, each turns its named test red
|
||||
@@ -119,18 +119,26 @@ other, so both verify commands then say whether each head is signed and by which
|
||||
seq, a changed hash is caught, and nothing is appended to a broken chain; that a chain **rebuilt from genesis** passes
|
||||
`verify-log` alone (the stated limit) but fails against the attested head, as do a shortened log and a modified attestation,
|
||||
while a log that only grew passes; that a signed head passes the verifier's signature level and `--signer`, while a head
|
||||
signed by another key, an unsigned head with `--signer`, and a damaged signature are refused; that two writers appending 150 entries each at the same time leave an intact chain of 300;
|
||||
signed by another key, an unsigned head with `--signer`, a damaged signature, and a head signed with a classical key that
|
||||
declares `ml-dsa-65` are refused; that two writers appending 150 entries each at the same time leave an intact chain of 300;
|
||||
that a line that is not JSON is reported as broken at its seq; that the Docker and Kubernetes adapters record only running
|
||||
containers and no secret value; and that every envelope is `VALID` for the AIP-23 reference verifier. The verifier is looked
|
||||
for at `AERE_VERIFY_PROOF` (for example `verify-proof.mjs` from the `aere-node` repository, after `npm install` there); without
|
||||
it, the five checks that need it are reported as skipped and the exit code is 2, not 0.
|
||||
|
||||
`control-negativ-sidecar.mjs` measured 10 of 10 on 2026-09-29: the version before the review (taken from the development
|
||||
history, skipped where that history is absent) and nine plantings, each disabling one guard (the writer lock, the head
|
||||
`control-negativ-sidecar.mjs` measured 11 of 11 on 2026-10-05: the version before the review (taken from the development
|
||||
history, skipped where that history is absent) and ten plantings, each disabling one guard (the requirement that the key of a
|
||||
head signature be an ML-DSA-65 key, the writer lock, the head
|
||||
comparison, the length check, the attestation hash check, the handling of an unreadable line, the digest check of `--attested`,
|
||||
the head signature check, the comparison with `--signer`, the refusal of an unsigned head when `--signer` is given).
|
||||
`proba-notarizare-testnet.mjs --key-file <testnet key>` repeats the on-chain run above (9 checks, it needs a funded testnet key).
|
||||
|
||||
**Corrected on 2026-10-03.** Until then the check of a head's signature required the DECLARED scheme to be `ml-dsa-65` but not
|
||||
the key to be an ML-DSA-65 key: a head signed with an Ed25519, RSA or P-256 key that declared `ml-dsa-65` was reported as a head
|
||||
signed with ML-DSA-65. Found while this verifier was enrolled in the conformance suite (`conformance/`), where it is now a vector.
|
||||
The key must be an ML-DSA-65 key, or the head is refused by name. Every refusal of `verify-log`, of the inclusion check and of the
|
||||
consistency check now also carries a rule id from a declared list (`REGULI` in `sidecar.mjs` and `jurnal-arbore.mjs`).
|
||||
|
||||
## What it is not (yet)
|
||||
|
||||
It does not report to a live console over the network, and it has no per-cloud adapters that read deployments from the AWS,
|
||||
|
||||
@@ -15,12 +15,12 @@ const PLANTARI = [
|
||||
['consistenta nu mai cere radacina veche', M, [["return sn === 0 && hx(fr) === firstRoot && hx(sr) === secondRoot;", 'return sn === 0 && hx(sr) === secondRoot;']], 'ATAC: istoria rescrisa'],
|
||||
['consistenta fara radacina veche pusa in fata la o putere a lui 2', M, [["if ((firstSize & (firstSize - 1)) === 0) pc.unshift(dinHex(firstRoot, 'first root'));", '']], 'fiecare dovada de consistenta'],
|
||||
['marimi egale acceptate cu orice drum', M, [['if (firstSize === secondSize) return path.length === 0 && firstRoot === secondRoot;', 'if (firstSize === secondSize) return true;']], 'CONTROL: marimi egale'],
|
||||
['intrarea din dovada nu isi mai reface hash-ul', J, [["if (hashIntrare(e.seq, e.prev, e.proof) !== e.hash) return", 'if (false) return']], 'ATAC: intrarea din dovada schimbata'],
|
||||
['plicul intrarii nu mai trebuie sa fie intreg', J, [["if (!e.proof || !e.proof.statement || sha256(Buffer.from(JSON.stringify(e.proof.statement), 'utf8')) !== String(e.proof.statementHash).toLowerCase()) return", 'if (false) return']], 'ATAC: un plic stricat scris de gazda'],
|
||||
['marimea si radacina capului nu se mai compara cu dovada', J, [['if (cap.statement.treeSize !== d.treeSize || cap.statement.rootHash !== d.rootHash) return', 'if (false) return']], 'ATAC: dovada de includere pentru un arbore de alta marime'],
|
||||
['capul atins primit (statementHash nerefacut)', J, [["if (!H.test(String(cap.statementHash)) || sha256(Buffer.from(JSON.stringify(st), 'utf8')) !== cap.statementHash) return", 'if (false) return']], 'ATAC: capul de arbore atins'],
|
||||
['intrarea din dovada nu isi mai reface hash-ul', J, [["if (!(hashIntrare(e.seq, e.prev, e.proof) === e.hash /*PAZA:includere-intrare*/)) return", 'if (false) return']], 'ATAC: intrarea din dovada schimbata'],
|
||||
['plicul intrarii nu mai trebuie sa fie intreg', J, [["=== String(e.proof.statementHash).toLowerCase() /*PAZA:includere-plic*/)) return", "=== String(e.proof.statementHash).toLowerCase() /*PAZA:includere-plic*/) && Boolean(Number('0'))) return"]], 'ATAC: un plic stricat scris de gazda'],
|
||||
['marimea si radacina capului nu se mai compara cu dovada', J, [['if (!(cap.statement.treeSize === d.treeSize && cap.statement.rootHash === d.rootHash /*PAZA:includere-cap*/)) return', 'if (false) return']], 'ATAC: dovada de includere pentru un arbore de alta marime'],
|
||||
['capul atins primit (statementHash nerefacut)', J, [["=== cap.statementHash /*PAZA:arbore-hash*/)) return", "=== cap.statementHash /*PAZA:arbore-hash*/) && Boolean(Number('0'))) return"]], 'ATAC: capul de arbore atins'],
|
||||
['semnatarul cerut nu mai trece in verificare', J, [['const s = verificaSemnaturaCap(cap, semnatar);', 'const s = verificaSemnaturaCap(cap, null);']], 'includere: intrarea 7'],
|
||||
['dovada de consistenta nu mai trebuie sa porneasca de la capul vechi', J, [['if (vechi.statement.treeSize !== d.firstSize || vechi.statement.rootHash !== d.firstRoot) return', 'if (false) return']], 'ATAC: capetele inversate'],
|
||||
['dovada de consistenta nu mai trebuie sa porneasca de la capul vechi', J, [['if (!(vechi.statement.treeSize === d.firstSize && vechi.statement.rootHash === d.firstRoot /*PAZA:consistenta-inceput*/)) return', 'if (false) return']], 'ATAC: capetele inversate'],
|
||||
['un jurnal rupt primeste cap', J, [['if (!v.ok) throw new Error(`tree: the log is broken', 'if (false) throw new Error(`tree: the log is broken']], 'un jurnal rupt'],
|
||||
// B-25: forma publicata in 082b862 (iesirea tace despre semnatura capetelor)
|
||||
['verify-consistency tace despre semnatura capetelor', 'sidecar.mjs', [['the history up to the old head was not rewritten)${semn}', 'the history up to the old head was not rewritten)']], 'B-25'],
|
||||
|
||||
@@ -37,6 +37,7 @@ const T = {
|
||||
semnStricata: 'S CONTROL: o semnatura de cap stricata',
|
||||
altaCheie: 'S CONTROL: capul semnat de alta cheie',
|
||||
nesemnat: 'S CONTROL: un cap nesemnat',
|
||||
cheieClasica: 'S CONTROL: un cap semnat cu o cheie clasica',
|
||||
};
|
||||
|
||||
function caz(id, text, tinte) {
|
||||
@@ -66,14 +67,15 @@ const nou = fs.readFileSync(SRC, 'utf8');
|
||||
const NU = "process.env.AERE_PLANTA_NICIODATA === 'da'";
|
||||
const P = [
|
||||
['P1', " try { return fn(); } finally { try { fs.unlinkSync(lacat); } catch { /* deja ridicat */ } }\n}", ` try { return fn(); } finally { try { fs.unlinkSync(lacat); } catch { /* deja ridicat */ } }\n}\nconst cuLacatAdevarat = cuLacat;\ncuLacat = (p, fn) => (${NU} ? cuLacatAdevarat(p, fn) : fn());`, [T.concurent]],
|
||||
['P2', 'if (h !== st.head.toLowerCase()) return', `if (h !== st.head.toLowerCase() && ${NU}) return`, [T.refacut]],
|
||||
['P3', 'if (intrari.length < st.count) return', `if (intrari.length < st.count && ${NU}) return`, [T.taiat]],
|
||||
['P4', "if (!eDigest(cap.statementHash) || sha256(Buffer.from(JSON.stringify(st), 'utf8')) !== cap.statementHash.toLowerCase()) return", `if (!eDigest(cap.statementHash) || (sha256(Buffer.from(JSON.stringify(st), 'utf8')) !== cap.statementHash.toLowerCase() && ${NU})) return`, [T.capMan]],
|
||||
['P2', 'if (!(h === String(st.head).toLowerCase() /*PAZA:cap-rescris*/)) return', `if (!(h === String(st.head).toLowerCase() /*PAZA:cap-rescris*/) && ${NU}) return`, [T.refacut]],
|
||||
['P3', 'if (!(intrari.length >= st.count /*PAZA:cap-scurt*/)) return', `if (!(intrari.length >= st.count /*PAZA:cap-scurt*/) && ${NU}) return`, [T.taiat]],
|
||||
['P4', "=== cap.statementHash.toLowerCase() /*PAZA:cap-hash*/)) return", `=== cap.statementHash.toLowerCase() /*PAZA:cap-hash*/) && ${NU}) return`, [T.capMan]],
|
||||
['P5', "try { return JSON.parse(l); } catch { return { necitibil: true }; }", `try { return JSON.parse(l); } catch (e) { if (${NU}) return { necitibil: true }; throw e; }`, [T.necitibil]],
|
||||
['P6', 'if (!eDigest(attested)) {', `if (!eDigest(attested) && ${NU}) {`, [T.digest]],
|
||||
['P7', "if (!ok) return { ok: false, semnat: true, keyId: idCheie(pub), motiv: 'the head signature does not verify over the statement' };", `if (!ok && ${NU}) return { ok: false, semnat: true, keyId: idCheie(pub), motiv: 'the head signature does not verify over the statement' };`, [T.semnStricata]],
|
||||
['P8', 'if (idCheie(asteptat) !== idCheie(pub)) return', `if (idCheie(asteptat) !== idCheie(pub) && ${NU}) return`, [T.altaCheie]],
|
||||
['P9', 'if (!s) return semnatarPem ? { ok: false,', `if (!s) return (semnatarPem && ${NU}) ? { ok: false,`, [T.nesemnat]],
|
||||
['P7', 'if (!(ok /*PAZA:cap-semnatura*/)) return', `if (!(ok /*PAZA:cap-semnatura*/) && ${NU}) return`, [T.semnStricata]],
|
||||
['P8', 'if (!(asteptat !== null && idCheie(asteptat) === id /*PAZA:cap-semnatar*/)) return', `if (!(asteptat !== null && idCheie(asteptat) === id /*PAZA:cap-semnatar*/) && ${NU}) return`, [T.altaCheie]],
|
||||
['P9', 'if (!(!semnatarPem /*PAZA:cap-nesemnat*/)) return', `if (!(!semnatarPem /*PAZA:cap-nesemnat*/) && ${NU}) return`, [T.nesemnat]],
|
||||
['P10', "if (!(!!pub && pub.asymmetricKeyType === 'ml-dsa-65' /*PAZA:cap-schema*/)) return", `if (!(!!pub && pub.asymmetricKeyType === 'ml-dsa-65' /*PAZA:cap-schema*/) && ${NU}) return`, [T.cheieClasica]],
|
||||
];
|
||||
for (const [id, a, b, tinte] of P) {
|
||||
let t = planta(nou, a, b);
|
||||
|
||||
@@ -33,14 +33,18 @@ export function capDeArbore(intrari, { host = 'sidecar', createdAt = new Date().
|
||||
const plic = { v: 1, kind: TREE_HEAD + '-attestation', statement, statementHash: sha256(Buffer.from(JSON.stringify(statement), 'utf8')) };
|
||||
return signKeyPem ? semneazaCap(plic, signKeyPem) : plic;
|
||||
}
|
||||
// Every refusal of the checks below NAMES its rule (`regula`); the refusals of a head's signature carry the rules of the sidecar
|
||||
// (cap-*). Each check of a rule carries its marker (see sidecar.mjs).
|
||||
export const REGULI = ['dovada-forma', 'arbore-forma', 'arbore-hash', 'includere-index', 'includere-intrare', 'includere-plic', 'includere-frunza', 'includere-drum', 'includere-cap', 'consistenta-inceput', 'consistenta-sfarsit', 'consistenta'];
|
||||
const refuz = (regula, motiv) => { if (!REGULI.includes(regula)) throw new Error('tree: undeclared rule ' + regula); return { ok: false, regula, motiv }; };
|
||||
// un cap de arbore intreg (statementHash se reface), semnat de cine se cere (daca se cere)
|
||||
function capBun(cap, semnatar) {
|
||||
const st = cap && cap.statement;
|
||||
if (!cap || cap.kind !== TREE_HEAD + '-attestation' || !st || st.kind !== TREE_HEAD) return { ok: false, motiv: `not an ${TREE_HEAD} attestation` };
|
||||
if (!H.test(String(cap.statementHash)) || sha256(Buffer.from(JSON.stringify(st), 'utf8')) !== cap.statementHash) return { ok: false, motiv: 'the tree head statementHash does not match its statement (modified head)' };
|
||||
if (!Number.isInteger(st.treeSize) || st.treeSize < 1 || !H.test(String(st.rootHash))) return { ok: false, motiv: 'the tree head has no valid size and root' };
|
||||
if (!(!!cap && cap.kind === TREE_HEAD + '-attestation' && !!st && st.kind === TREE_HEAD /*PAZA:arbore-forma*/)) return refuz('arbore-forma', `not an ${TREE_HEAD} attestation`);
|
||||
if (!(!!cap && H.test(String(cap.statementHash)) && sha256(Buffer.from(String(JSON.stringify(st)), 'utf8')) === cap.statementHash /*PAZA:arbore-hash*/)) return refuz('arbore-hash', 'the tree head statementHash does not match its statement (modified head)');
|
||||
if (!(!!st && Number.isInteger(st.treeSize) && st.treeSize >= 1 && H.test(String(st.rootHash)) /*PAZA:arbore-forma*/)) return refuz('arbore-forma', 'the tree head has no valid size and root');
|
||||
const s = verificaSemnaturaCap(cap, semnatar);
|
||||
if (!s.ok) return { ok: false, motiv: s.motiv };
|
||||
if (!s.ok) return { ok: false, regula: s.regula, motiv: s.motiv };
|
||||
return { ok: true, semnatDe: s.semnat ? s.keyId : null };
|
||||
}
|
||||
|
||||
@@ -55,20 +59,20 @@ export function dovadaIncludere(intrari, seq, treeSize = intrari.length) {
|
||||
*/
|
||||
export function verificaIncludere(d, { cap = null, semnatar = null } = {}) {
|
||||
try {
|
||||
if (!d || d.kind !== 'aere-audit-inclusion-proof' || !d.entry) return { ok: false, motiv: 'not an aere-audit-inclusion-proof' };
|
||||
if (!(!!d && d.kind === 'aere-audit-inclusion-proof' && !!d.entry && typeof d.entry === 'object' /*PAZA:dovada-forma*/)) return refuz('dovada-forma', 'not an aere-audit-inclusion-proof');
|
||||
const e = d.entry;
|
||||
if (e.seq !== d.index) return { ok: false, motiv: `the entry is seq ${e.seq}, the proof is for index ${d.index}` };
|
||||
if (hashIntrare(e.seq, e.prev, e.proof) !== e.hash) return { ok: false, motiv: 'the entry hash does not match its content (modified entry)' };
|
||||
if (!e.proof || !e.proof.statement || sha256(Buffer.from(JSON.stringify(e.proof.statement), 'utf8')) !== String(e.proof.statementHash).toLowerCase()) return { ok: false, motiv: 'the entry\'s envelope statementHash does not match its statement' };
|
||||
if (d.leafHash !== frunza(e.hash)) return { ok: false, motiv: 'the leaf is not this entry' };
|
||||
if (!verifyInclusion(d)) return { ok: false, motiv: `the path does not lead from the entry to root ${String(d.rootHash).slice(0, 18)}.. of a tree of ${d.treeSize}` };
|
||||
if (!(e.seq === d.index /*PAZA:includere-index*/)) return refuz('includere-index', `the entry is seq ${e.seq}, the proof is for index ${d.index}`);
|
||||
if (!(hashIntrare(e.seq, e.prev, e.proof) === e.hash /*PAZA:includere-intrare*/)) return refuz('includere-intrare', 'the entry hash does not match its content (modified entry)');
|
||||
if (!(!!e.proof && !!e.proof.statement && sha256(Buffer.from(JSON.stringify(e.proof.statement), 'utf8')) === String(e.proof.statementHash).toLowerCase() /*PAZA:includere-plic*/)) return refuz('includere-plic', 'the entry\'s envelope statementHash does not match its statement');
|
||||
if (!(d.leafHash === frunza(e.hash) /*PAZA:includere-frunza*/)) return refuz('includere-frunza', 'the leaf is not this entry');
|
||||
if (!(verifyInclusion(d) /*PAZA:includere-drum*/)) return refuz('includere-drum', `the path does not lead from the entry to root ${String(d.rootHash).slice(0, 18)}.. of a tree of ${d.treeSize}`);
|
||||
if (cap) {
|
||||
const c = capBun(cap, semnatar); if (!c.ok) return c;
|
||||
if (cap.statement.treeSize !== d.treeSize || cap.statement.rootHash !== d.rootHash) return { ok: false, motiv: `the proof is for a tree of ${d.treeSize} with another root than the head's (${cap.statement.treeSize})` };
|
||||
if (!(cap.statement.treeSize === d.treeSize && cap.statement.rootHash === d.rootHash /*PAZA:includere-cap*/)) return refuz('includere-cap', `the proof is for a tree of ${d.treeSize} with another root than the head's (${cap.statement.treeSize})`);
|
||||
return { ok: true, semnatDe: c.semnatDe };
|
||||
}
|
||||
return { ok: true, semnatDe: null };
|
||||
} catch (x) { return { ok: false, motiv: 'the proof cannot be read: ' + x.message }; }
|
||||
} catch (x) { return refuz('dovada-forma', 'the proof cannot be read: ' + x.message); }
|
||||
}
|
||||
|
||||
/** Dovada ca arborele de marime `firstSize` e un prefix al celui de marime `secondSize` (implicit tot jurnalul). */
|
||||
@@ -78,14 +82,14 @@ export function dovadaConsistenta(intrari, firstSize, secondSize = intrari.lengt
|
||||
/** Verifica, FARA jurnal, ca un cap nou continua unul vechi: ambele capete intregi (si semnate de `semnatar`), dovada intre ele. */
|
||||
export function verificaConsistenta(d, { vechi, nou, semnatar = null }) {
|
||||
try {
|
||||
if (!d || d.kind !== 'aere-audit-consistency-proof') return { ok: false, motiv: 'not an aere-audit-consistency-proof' };
|
||||
const a = capBun(vechi, semnatar); if (!a.ok) return { ok: false, motiv: 'old head: ' + a.motiv };
|
||||
const b = capBun(nou, semnatar); if (!b.ok) return { ok: false, motiv: 'new head: ' + b.motiv };
|
||||
if (vechi.statement.treeSize !== d.firstSize || vechi.statement.rootHash !== d.firstRoot) return { ok: false, motiv: 'the proof does not start at the old head' };
|
||||
if (nou.statement.treeSize !== d.secondSize || nou.statement.rootHash !== d.secondRoot) return { ok: false, motiv: 'the proof does not end at the new head' };
|
||||
if (!verifyConsistency(d)) return { ok: false, motiv: `the new head (${d.secondSize}) does not extend the old one (${d.firstSize}): the history was rewritten` };
|
||||
if (!(!!d && d.kind === 'aere-audit-consistency-proof' /*PAZA:dovada-forma*/)) return refuz('dovada-forma', 'not an aere-audit-consistency-proof');
|
||||
const a = capBun(vechi, semnatar); if (!a.ok) return { ok: false, regula: a.regula, motiv: 'old head: ' + a.motiv };
|
||||
const b = capBun(nou, semnatar); if (!b.ok) return { ok: false, regula: b.regula, motiv: 'new head: ' + b.motiv };
|
||||
if (!(vechi.statement.treeSize === d.firstSize && vechi.statement.rootHash === d.firstRoot /*PAZA:consistenta-inceput*/)) return refuz('consistenta-inceput', 'the proof does not start at the old head');
|
||||
if (!(nou.statement.treeSize === d.secondSize && nou.statement.rootHash === d.secondRoot /*PAZA:consistenta-sfarsit*/)) return refuz('consistenta-sfarsit', 'the proof does not end at the new head');
|
||||
if (!(verifyConsistency(d) /*PAZA:consistenta*/)) return refuz('consistenta', `the new head (${d.secondSize}) does not extend the old one (${d.firstSize}): the history was rewritten`);
|
||||
// B-25 (2026-09-30): cine semneaza fiecare cap se intoarce si se spune; fara `semnatar`, doua capete nesemnate (sau semnate de
|
||||
// oricine) care se continua trec, si cititorul trebuie sa vada asta, nu doar "EXTENDS"
|
||||
return { ok: true, semnatVechi: a.semnatDe, semnatNou: b.semnatDe };
|
||||
} catch (x) { return { ok: false, motiv: 'the proof cannot be read: ' + x.message }; }
|
||||
} catch (x) { return refuz('dovada-forma', 'the proof cannot be read: ' + x.message); }
|
||||
}
|
||||
@@ -126,6 +126,11 @@ try {
|
||||
const hsr = path.join(T, 'head-semnat-rau.json'); fs.writeFileSync(hsr, JSON.stringify(cs));
|
||||
const rSr = side(['verify-log', '--log', log, '--attested', hsr]);
|
||||
cer('S CONTROL: o semnatura de cap stricata -> refuzat chiar fara --signer (cod 1)', rSr.cod === 1 && /does not verify/.test(rSr.out));
|
||||
// 2026-10-03: o cheie CLASICA (Ed25519) care semneaza capul si declara schema ml-dsa-65: pana azi trecea drept cap semnat ML-DSA-65
|
||||
{ const cc = jr(hs); const { publicKey, privateKey } = crypto.generateKeyPairSync('ed25519');
|
||||
cc.signature = { scheme: 'ml-dsa-65', publicKey: publicKey.export({ type: 'spki', format: 'der' }).toString('base64'), signature: crypto.sign(null, Buffer.from(JSON.stringify(cc.statement), 'utf8'), privateKey).toString('base64') };
|
||||
const hcc = path.join(T, 'head-cheie-clasica.json'); fs.writeFileSync(hcc, JSON.stringify(cc)); const rCc = side(['verify-log', '--log', log, '--attested', hcc]);
|
||||
cer('S CONTROL: un cap semnat cu o cheie clasica (Ed25519) care declara ml-dsa-65 -> refuzat (cod 1)', rCc.cod === 1 && /public key is ed25519/.test(rCc.out)); }
|
||||
|
||||
// ---- N: intrari nevalide -------------------------------------------------------------------------------------------------
|
||||
const logN = path.join(T, 'necitibil.log'); fs.writeFileSync(logN, JSON.stringify(intrari[0]) + '\n{nu e json\n');
|
||||
|
||||
+32
-22
@@ -57,14 +57,19 @@ function citesteJurnal(p) {
|
||||
* Verifica lantul de hash-uri end-to-end. Returneaza {ok, count, head, rupt, motiv} - rupt = primul seq stricat sau null.
|
||||
* NU spune nimic despre un lant refacut in intregime: pentru asta, verificaFataDeCap.
|
||||
*/
|
||||
// Every refusal of the checks below NAMES its rule (`regula`); a rule that is not declared cannot be named. Each check of a rule carries
|
||||
// its marker, so that a conformance suite can take the rule out, in a copy, and see which of its vectors then pass.
|
||||
export const REGULI = ['intrare', 'seq', 'lant', 'hash', 'cap-forma', 'cap-hash', 'cap-nesemnat', 'cap-schema', 'cap-cheie', 'cap-semnatura', 'cap-semnatar', 'cap-scurt', 'cap-rescris'];
|
||||
const refuz = (regula, motiv, extra = {}) => { if (!REGULI.includes(regula)) throw new Error('sidecar: undeclared rule ' + regula); return { ok: false, regula, motiv, ...extra }; };
|
||||
export function verificaJurnal(intrari) {
|
||||
if (!(Array.isArray(intrari) /*PAZA:intrare*/)) return refuz('intrare', 'the log is not a list of entries', { count: 0, head: null, rupt: 0 });
|
||||
let prev = GENEZA;
|
||||
for (let i = 0; i < intrari.length; i++) {
|
||||
const e = intrari[i];
|
||||
if (!e || typeof e !== 'object' || e.necitibil) return { ok: false, count: intrari.length, head: null, rupt: i, motiv: `entry ${i} is not a JSON log entry` };
|
||||
if (e.seq !== i) return { ok: false, count: intrari.length, head: null, rupt: i, motiv: `wrong seq: ${e.seq} instead of ${i}` };
|
||||
if (e.prev !== prev) return { ok: false, count: intrari.length, head: null, rupt: i, motiv: `prev does not link entry ${i - 1}` };
|
||||
if (hashIntrare(e.seq, e.prev, e.proof) !== e.hash) return { ok: false, count: intrari.length, head: null, rupt: i, motiv: `the hash of entry ${i} does not match its content (modified)` };
|
||||
const e = intrari[i]; const la = { count: intrari.length, head: null, rupt: i };
|
||||
if (!(!!e && typeof e === 'object' && !e.necitibil /*PAZA:intrare*/)) return refuz('intrare', `entry ${i} is not a JSON log entry`, la);
|
||||
if (!(e.seq === i /*PAZA:seq*/)) return refuz('seq', `wrong seq: ${e.seq} instead of ${i}`, la);
|
||||
if (!(e.prev === prev /*PAZA:lant*/)) return refuz('lant', `prev does not link entry ${i - 1}`, la);
|
||||
if (!(hashIntrare(e.seq, e.prev, e.proof) === e.hash /*PAZA:hash*/)) return refuz('hash', `the hash of entry ${i} does not match its content (modified)`, la);
|
||||
prev = e.hash;
|
||||
}
|
||||
return { ok: true, count: intrari.length, head: prev, rupt: null };
|
||||
@@ -77,16 +82,16 @@ export function verificaJurnal(intrari) {
|
||||
*/
|
||||
export function verificaFataDeCap(intrari, cap, { semnatar = null } = {}) {
|
||||
const st = cap && cap.statement;
|
||||
if (!cap || cap.kind !== 'aere-audit-head-attestation' || !st || st.kind !== 'aere-audit-head') return { ok: false, motiv: 'the file is not an aere-audit-head attestation' };
|
||||
if (!eDigest(cap.statementHash) || sha256(Buffer.from(JSON.stringify(st), 'utf8')) !== cap.statementHash.toLowerCase()) return { ok: false, motiv: 'the attestation statementHash does not match its statement (modified attestation)' };
|
||||
if (!(!!cap && cap.kind === 'aere-audit-head-attestation' && !!st && st.kind === 'aere-audit-head' /*PAZA:cap-forma*/)) return refuz('cap-forma', 'the file is not an aere-audit-head attestation');
|
||||
if (!(!!cap && eDigest(cap.statementHash) && sha256(Buffer.from(String(JSON.stringify(st)), 'utf8')) === cap.statementHash.toLowerCase() /*PAZA:cap-hash*/)) return refuz('cap-hash', 'the attestation statementHash does not match its statement (modified attestation)');
|
||||
const sg = verificaSemnaturaCap(cap, semnatar);
|
||||
if (!sg.ok) return { ok: false, motiv: sg.motiv };
|
||||
if (!Number.isInteger(st.count) || st.count < 0 || !eDigest(st.head)) return { ok: false, motiv: 'the attestation has no valid count and head' };
|
||||
if (!sg.ok) return sg;
|
||||
if (!(!!st && Number.isInteger(st.count) && st.count >= 0 && eDigest(st.head) /*PAZA:cap-forma*/)) return refuz('cap-forma', 'the attestation has no valid count and head');
|
||||
const v = verificaJurnal(intrari);
|
||||
if (!v.ok) return { ok: false, motiv: `the log is broken at seq ${v.rupt}: ${v.motiv}` };
|
||||
if (intrari.length < st.count) return { ok: false, motiv: `the log has ${intrari.length} entries and the attested head covers ${st.count}: entries were removed` };
|
||||
const h = st.count === 0 ? GENEZA : intrari[st.count - 1].hash;
|
||||
if (h !== st.head.toLowerCase()) return { ok: false, motiv: `entry ${st.count - 1} is not the attested head: the history before the attested point was rewritten` };
|
||||
if (!v.ok) return refuz(v.regula, `the log is broken at seq ${v.rupt}: ${v.motiv}`);
|
||||
if (!(intrari.length >= st.count /*PAZA:cap-scurt*/)) return refuz('cap-scurt', `the log has ${intrari.length} entries and the attested head covers ${st.count}: entries were removed`);
|
||||
const ultima = intrari[st.count - 1]; const h = st.count === 0 ? GENEZA : (ultima ? ultima.hash : null);
|
||||
if (!(h === String(st.head).toLowerCase() /*PAZA:cap-rescris*/)) return refuz('cap-rescris', `entry ${st.count - 1} is not the attested head: the history before the attested point was rewritten`);
|
||||
return { ok: true, count: st.count, extra: intrari.length - st.count, semnatDe: sg.semnat ? sg.keyId : null };
|
||||
}
|
||||
|
||||
@@ -103,19 +108,24 @@ export function semneazaCap(plic, cheiePem) {
|
||||
const sig = crypto.sign(null, Buffer.from(JSON.stringify(plic.statement), 'utf8'), priv);
|
||||
return { ...plic, signature: { scheme: 'ml-dsa-65', publicKey: pub.export({ type: 'spki', format: 'der' }).toString('base64'), signature: sig.toString('base64') } };
|
||||
}
|
||||
/** @returns {{ok:boolean, semnat:boolean, keyId?:string, motiv?:string}} semnatarPem: cheia publica asteptata (optional) */
|
||||
/** @returns {{ok:boolean, semnat:boolean, keyId?:string, motiv?:string, regula?:string}} semnatarPem: cheia publica asteptata (optional) */
|
||||
export function verificaSemnaturaCap(plic, semnatarPem = null) {
|
||||
const s = plic && plic.signature;
|
||||
if (!s) return semnatarPem ? { ok: false, semnat: false, motiv: 'the head is not signed, and a signer was required' } : { ok: true, semnat: false };
|
||||
if (String(s.scheme).toLowerCase() !== 'ml-dsa-65' || !s.publicKey || !s.signature) return { ok: false, semnat: true, motiv: 'the head signature is not an ml-dsa-65 signature' };
|
||||
let pub; try { pub = crypto.createPublicKey({ key: Buffer.from(String(s.publicKey), 'base64'), format: 'der', type: 'spki' }); } catch { return { ok: false, semnat: true, motiv: 'the head signature public key cannot be read' }; }
|
||||
let ok = false; try { ok = crypto.verify(null, Buffer.from(JSON.stringify(plic.statement), 'utf8'), pub, Buffer.from(String(s.signature), 'base64')); } catch { ok = false; }
|
||||
if (!ok) return { ok: false, semnat: true, keyId: idCheie(pub), motiv: 'the head signature does not verify over the statement' };
|
||||
if (!s) { if (!(!semnatarPem /*PAZA:cap-nesemnat*/)) return refuz('cap-nesemnat', 'the head is not signed, and a signer was required', { semnat: false }); return { ok: true, semnat: false }; }
|
||||
if (!(String(s.scheme).toLowerCase() === 'ml-dsa-65' && !!s.publicKey && !!s.signature /*PAZA:cap-schema*/)) return refuz('cap-schema', 'the head signature is not an ml-dsa-65 signature', { semnat: true });
|
||||
let pub = null; try { pub = crypto.createPublicKey({ key: Buffer.from(String(s.publicKey), 'base64'), format: 'der', type: 'spki' }); } catch { pub = null; }
|
||||
if (!(pub !== null /*PAZA:cap-cheie*/)) return refuz('cap-cheie', 'the head signature public key cannot be read', { semnat: true });
|
||||
// The key must BE an ML-DSA-65 key. crypto.verify(null, ...) verifies with whatever key it is handed: until 2026-10-03 a head
|
||||
// "signed" with an Ed25519 (or RSA, or P-256) key that declared the scheme ml-dsa-65 verified here as an ML-DSA-65 signed head.
|
||||
if (!(!!pub && pub.asymmetricKeyType === 'ml-dsa-65' /*PAZA:cap-schema*/)) return refuz('cap-schema', `the head declares an ml-dsa-65 signature and its public key is ${pub ? pub.asymmetricKeyType : 'unreadable'}`, { semnat: true });
|
||||
const id = pub ? idCheie(pub) : null;
|
||||
let ok = false; try { ok = crypto.verify(null, Buffer.from(String(JSON.stringify(plic.statement)), 'utf8'), pub, Buffer.from(String(s.signature), 'base64')); } catch { ok = false; }
|
||||
if (!(ok /*PAZA:cap-semnatura*/)) return refuz('cap-semnatura', 'the head signature does not verify over the statement', { semnat: true, keyId: id });
|
||||
if (semnatarPem) {
|
||||
let asteptat; try { asteptat = crypto.createPublicKey(semnatarPem); } catch { return { ok: false, semnat: true, motiv: 'the expected signer key cannot be read' }; }
|
||||
if (idCheie(asteptat) !== idCheie(pub)) return { ok: false, semnat: true, keyId: idCheie(pub), motiv: `the head is signed by another key (${idCheie(pub).slice(0, 18)}), not the expected signer` };
|
||||
let asteptat = null; try { asteptat = crypto.createPublicKey(semnatarPem); } catch { asteptat = null; }
|
||||
if (!(asteptat !== null && idCheie(asteptat) === id /*PAZA:cap-semnatar*/)) return refuz('cap-semnatar', asteptat ? `the head is signed by another key (${String(id).slice(0, 18)}), not the expected signer` : 'the expected signer key cannot be read', { semnat: true, keyId: id });
|
||||
}
|
||||
return { ok: true, semnat: true, keyId: idCheie(pub) };
|
||||
return { ok: true, semnat: true, keyId: id };
|
||||
}
|
||||
|
||||
// ---- adaptorul de runtime: exportul pe care operatorul il face el insusi, fara acreditari de cloud ------------------------------
|
||||
|
||||
Reference in new issue
Block a user