verify-layer: verify-consistency names the signer of each head (or unsigned); identity: Travel Rule requires a replay store

- verify-consistency without --signer now says whether each head is signed and by which key, and that no expected signer was
  checked (verify-inclusion already did; the README said the output does)
- openMessage opens nothing without a replay store (seen: an object with has/add that keeps the ids for at least maxAgeS);
  before, the same signed and sealed message could be opened any number of times when no store was given

Tests: verify-layer tree 20/20, negative control 14/14; sidecar 44/44, 9/9; travel rule 19/19, negative control 19/19.
This commit is contained in:
Aere Network committed 2026-09-30 10:31:23 +03:00
1 parent 082b862d78
commit 8f5f0bd00d
9 files changed
+57 -14

No files matched your search

+5 -3
View File
@@ -103,14 +103,16 @@ and can be notarized. An inclusion proof carries the entry itself: the verifier
envelope, so an internal node cannot be passed off as an entry. A proof names a tree by its size and root; bind it to a head you
received (`--head`), not to the numbers in the proof. Two heads of the same log with no consistency proof between them mean the
history was rewritten. What it does not prove, as for the chain: that the entries are true (the host writes them), or that no
other log with other heads was shown to someone else; whoever receives heads from both, or notarized heads, sees it.
other log with other heads was shown to someone else; whoever receives heads from both, or notarized heads, sees it. A head is
only as good as where you got it: without `--signer`, anyone can make two unsigned heads of an invented log that extend each
other, so both verify commands then say whether each head is signed and by which key, and that no expected signer was checked.
## Tests
node proba-sidecar.mjs # 44 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 # 19: 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 # 13 guards removed in a copy, each turns its named test red
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
`proba-sidecar.mjs` records runtime, deployment and envelope entries; checks that a modified entry breaks the chain at its
seq, a changed hash is caught, and nothing is appended to a broken chain; that a chain **rebuilt from genesis** passes
+2
View File
@@ -22,6 +22,8 @@ const PLANTARI = [
['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'],
['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'],
];
const FISIERE = [M, J, 'sidecar.mjs', 'proba-arbore.mjs'];
function copie() {
+3 -1
View File
@@ -84,6 +84,8 @@ export function verificaConsistenta(d, { vechi, nou, semnatar = null }) {
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` };
return { ok: true };
// 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 }; }
}
+21
View File
@@ -165,6 +165,27 @@ test('linia de comanda: tree-head, prove-inclusion, verify-inclusion (0; alt cap
const w2 = run('verify-consistency', '--proof', 'c.json', '--old', 'h20.json', '--new', 'h12.json'); cere(w2.cod === 1 && /NOT consistent/.test(w2.out), w2.out);
} finally { fs.rmSync(T, { recursive: true, force: true }); }
});
// B-25 (2026-09-30, revizuirea adversariala): fara --signer, doua capete NESEMNATE (pe care le poate fabrica oricine) care se continua
// ieseau "EXTENDS" fara niciun cuvant despre semnatura, desi README spunea ca iesirea o spune; verify-inclusion o spunea deja
test('B-25: verify-consistency fara --signer spune ca ambele capete sunt nesemnate si ca nu s-a cerut semnatarul; cu --signer, ca e cel asteptat', () => {
const T = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-arbore-b25-')); const S = path.join(AICI, 'sidecar.mjs');
const run = (...a) => { const r = spawnSync(process.execPath, [S, ...a], { cwd: T, encoding: 'utf8' }); return { cod: r.status, out: (r.stdout || '') + (r.stderr || '') }; };
try {
const lg = path.join(T, 'audit.log');
fs.writeFileSync(lg, L.slice(0, 12).map((e) => JSON.stringify(e)).join('\n') + '\n');
fs.writeFileSync(path.join(T, 'k.pem'), pem(k1)); fs.writeFileSync(path.join(T, 'p.pem'), pub(k1));
cere(run('tree-head', '--log', lg, '--out', 'u12.json').cod === 0 && run('tree-head', '--log', lg, '--sign-key', 'k.pem', '--out', 's12.json').cod === 0, 'capete 12');
fs.appendFileSync(lg, L.slice(12).map((e) => JSON.stringify(e)).join('\n') + '\n');
cere(run('tree-head', '--log', lg, '--out', 'u20.json').cod === 0 && run('tree-head', '--log', lg, '--sign-key', 'k.pem', '--out', 's20.json').cod === 0, 'capete 20');
cere(run('prove-consistency', '--log', lg, '--from', '12', '--out', 'c.json').cod === 0, 'prove-consistency');
const u = run('verify-consistency', '--proof', 'c.json', '--old', 'u12.json', '--new', 'u20.json');
cere(u.cod === 0 && /old head unsigned, new head unsigned/.test(u.out) && /no expected signer was checked/.test(u.out), 'nesemnate: ' + u.out);
const s = run('verify-consistency', '--proof', 'c.json', '--old', 's12.json', '--new', 's20.json', '--signer', 'p.pem');
cere(s.cod === 0 && /both heads signed by the expected signer/.test(s.out), 'cu --signer: ' + s.out);
const r = J.verificaConsistenta(J.dovadaConsistenta(L, 12), { vechi: JSON.parse(fs.readFileSync(path.join(T, 's12.json'))), nou: JSON.parse(fs.readFileSync(path.join(T, 'u20.json'))) });
cere(r.ok && r.semnatVechi && r.semnatNou === null, 'modulul intoarce cine a semnat fiecare cap: ' + JSON.stringify(r));
} finally { fs.rmSync(T, { recursive: true, force: true }); }
});
console.log(`\naere-arbore: ${treceri}/${treceri + esecuri.length} cum trebuia`);
process.exitCode = esecuri.length ? 1 : 0;
+5 -1
View File
@@ -402,7 +402,11 @@ async function main() {
return r.ok ? 0 : 1;
}
const r = A.verificaConsistenta(citeste(get('--proof'), '--proof'), { vechi: citeste(get('--old'), '--old'), nou: citeste(get('--new'), '--new'), semnatar });
console.log(r.ok ? 'the new head EXTENDS the old one (the history up to the old head was not rewritten)' : `NOT consistent: ${r.motiv}`);
// B-25 (2026-09-30): ca la verify-inclusion, iesirea spune cine a semnat capetele si daca s-a cerut semnatarul
const cine = (k) => (k ? `signed by key ${k.slice(0, 18)}` : 'unsigned');
const semn = !r.ok ? '' : semnatar ? `; both heads signed by the expected signer (${r.semnatNou.slice(0, 18)})`
: `; old head ${cine(r.semnatVechi)}, new head ${cine(r.semnatNou)}${r.semnatVechi && r.semnatNou && r.semnatVechi !== r.semnatNou ? ' (DIFFERENT keys)' : ''}; no expected signer was checked (--signer): this proves only that the second head you hold extends the first one you hold`;
console.log(r.ok ? `the new head EXTENDS the old one (the history up to the old head was not rewritten)${semn}` : `NOT consistent: ${r.motiv}`);
return r.ok ? 0 : 1;
} catch (e) { console.log(`${cmd}: ${String(e.message).replace(/[0-9a-fA-F]{32,}/g, '<hex>').slice(0, 200)}`); return 2; }
}