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 -2
View File
@@ -137,6 +137,8 @@ export function sealMessage({ from, beneficiary, ivms101, transfer, presentation
/**
* Beneficiarul deschide un mesaj: semnatura initiatorului, VASP-ul lui (prezentare pentru beneficiar, nonce = id-ul mesajului),
* destinatarul (cheile KEM ale beneficiarului), prospetimea, reluarea (`seen`: id-urile deja primite), apoi descifrarea.
* B-26 (2026-09-30, revizuirea adversariala): `seen` e OBLIGATORIU (un Set sau orice obiect cu has/add care tine id-urile cel putin
* maxAgeS); fara el, acelasi mesaj semnat si sigilat se deschidea de oricate ori, deci reluarea era prinsa numai de cine stia sa ceara.
* Intoarce { ok, motive, ivms101, transfer, from, messageHash }.
*/
export function openMessage(m, { me, kem, registries, now = new Date(), statusLists = [], seen = null, maxAgeS = 300 }) {
@@ -149,7 +151,8 @@ export function openMessage(m, { me, kem, registries, now = new Date(), statusLi
if (m.to.id !== me) motive.push(`the message is for ${m.to.id}, not for ${me}`);
if (canonical(m.to.kem) !== canonical(kem.public)) motive.push('the message is sealed to other KEM keys');
if (Math.abs(acum - timp(m.createdAt, 'createdAt')) > maxAgeS * 1000) motive.push(`the message was made at ${m.createdAt}, outside ${maxAgeS} s of this clock`);
if (seen && seen.has(m.id)) motive.push('replay: this message id was received before');
if (!seen || typeof seen.has !== 'function' || typeof seen.add !== 'function') motive.push('no replay store was given (seen: a set of the message ids already received, kept at least maxAgeS)');
else if (seen.has(m.id)) motive.push('replay: this message id was received before');
const v = eVasp(m.fromPresentation, { registries, audience: me, nonce: m.id, id: m.from.id, now, statusLists, maxAgeS });
motive.push(...v.motive.map((x) => 'originator VASP: ' + x));
if (motive.length) return { ok: false, motive };
@@ -168,7 +171,7 @@ export function openMessage(m, { me, kem, registries, now = new Date(), statusLi
try { const dc = crypto.createDecipheriv('aes-256-gcm', d.key, d.iv); dc.setAAD(aad); dc.setAuthTag(ct.subarray(ct.length - 16)); pt = Buffer.concat([dc.update(ct.subarray(0, ct.length - 16)), dc.final()]); }
catch { return { ok: false, motive: ['the ciphertext or its header was modified, or it is not for these keys'] }; }
finally { d.key.fill(0); }
if (seen) seen.add(m.id);
seen.add(m.id);
return { ok: true, motive: [], ivms101: JSON.parse(pt.toString('utf8')), transfer: m.transfer, from: { id: m.from.id, claims: v.claims }, messageHash: sha(Buffer.from(canonical(semnat), 'utf8')), payloadHash: sha(pt) };
} catch (e) { return { ok: false, motive: [...motive, 'the message cannot be read: ' + e.message] }; }
}