identity: the Travel Rule and compliance-policy verifiers name their rules; a missing originator id or nonce is now a refusal in acceptBeneficiary; conformance: Travel Rule and compliance presentations enrolled (239 rules, 15 verifiers, 21 kinds, 619 vectors), nothing of identity left out
This commit is contained in:
1 parent
e1bb4e25d8
commit
ea695dcf32
81 files changed
+17246
-127
No files matched your search
+19
-1
@@ -304,7 +304,25 @@ SD-JWT verifier and the SD-JWT VC profile are enrolled there too: `verifySdJwt`
|
||||
first refusal. The suite holds 54 vectors of the kind `sdjwt-presentation` (the RFC 9901 example, the tokens of `@sd-jwt/core` from the
|
||||
interop fixtures, and tokens issued with AERE keys) and 32 of `sdjwt-vc-presentation` (ours with their status lists, and the credentials
|
||||
and lists of `@sd-jwt/sd-jwt-vc` and `@owf/token-status-list`); a VC whose status was waived and not judged is `PARTIAL` there, never
|
||||
`VALID`. Travel Rule and compliance are not enrolled.
|
||||
`VALID`.
|
||||
|
||||
Since the same day the Travel Rule and the compliance verifiers are enrolled too, the last two of this folder. `acceptBeneficiary`,
|
||||
`openMessage` and `verifyReceipt` return, beside `ok` and `motive` (unchanged), `rules` (the ids that refused, sorted) and `rows`
|
||||
(every check, `{ rule, pass, detail }`); the 23 rules are in `REGULI` of `travel-rule.mjs` (`binding-form`, `binding-id`,
|
||||
`binding-signature`, `binding-window`, `vasp-presentation`, `vasp-status`, `vasp-identity`, `vasp-claim`, `message-form`,
|
||||
`message-id`, `message-signature`, `message-recipient`, `message-kem-keys`, `message-freshness`, `replay-store`, `replay`, `kem-alg`,
|
||||
`kem-open`, `ciphertext`, `receipt-form`, `receipt-from`, `receipt-signature`, `receipt-message`), and `OPRIRI` names the three after
|
||||
which the verifier stopped reading. The VASP presentation inside is judged by `verifyPresentation`; its refusals are reported under
|
||||
`vasp-presentation`. The header checks of a message are all made; at any refusal the message is not opened. Two behaviours changed:
|
||||
a verifier clock that cannot be read refuses the message's freshness (before, it compared with NaN and passed that check; the
|
||||
presentation inside still refused); and `acceptBeneficiary` called without `originatorId` or without `nonce` refuses the VASP
|
||||
presentation (before, the identity verifier left its audience or nonce unjudged and the beneficiary came out accepted, with a
|
||||
presentation that could be replayed to any originator; found by the malformed-input row of the conformance suite on 2026-10-18, now a
|
||||
test of `proba-travel-rule.mjs`, a planting of its negative control and two vectors of the suite). `checkCompliance` returns, beside `compliant` and `reasons` (unchanged), `rules` (`presentation`,
|
||||
`status`, `rule`; `REGULI` of `conformitate.mjs`), `rows` and `unjudged` (the causes `verifyPresentation` left unjudged). The suite
|
||||
holds 19 vectors of the kind `travel-rule-binding`, 26 of `travel-rule-message` (judged with the beneficiary's KEM key pair, test
|
||||
material made for those vectors and declared so at the scene), 9 of `travel-rule-receipt` and 12 of `compliance-presentation`; a
|
||||
compliance judgement under a policy that waives the status, with no list read, is `PARTIAL` there.
|
||||
|
||||
Two things changed in behaviour that day, both measured by `proba-identity.mjs`, each with its planting in the negative control:
|
||||
|
||||
|
||||
@@ -11,12 +11,21 @@
|
||||
// O politica e { v:1, kind:'aere-compliance-policy', id, trustedIssuers:[id], requireStatus, maxAgeS, require:[regula] }, cu regula
|
||||
// { claim, equals } | { claim, in:[...] } | { claim, notIn:[...] } | { claim, atLeast:number } | { claim, present:true }. Hash-ul ei
|
||||
// se recalculeaza din forma canonica, deci o politica mai laxa nu poate trece sub hash-ul uneia stricte.
|
||||
//
|
||||
// REGULILE NUMITE (2026-10-18, pentru suita de conformitate tools/aere-conformance): fiecare motiv al lui `checkCompliance` numeste regula
|
||||
// lui, din REGULI (`presentation`: prezentarea e valida pentru acest verificator, judecata de identity.mjs cu emitentii politicii; `status`:
|
||||
// starea credentialului e judecata cand politica o cere; `rule`: fiecare regula a politicii tine pe afirmatiile aratate); fiecare verificare
|
||||
// e un rand { rule, pass, detail } si poarta /*PAZA:<regula>*/ pe conditia ei buna. Rezultatul poarta, pe langa `compliant` si `reasons`
|
||||
// (neschimbate), `rules` (id-urile refuzate, sortate), `rows` si `unjudged` (cauzele lasate nejudecate de verificatorul de identitate).
|
||||
// O prezentare invalida nu stabileste nicio afirmatie, deci si fiecare regula a politicii iese "not met" (asa spunea si ieri).
|
||||
import crypto from 'node:crypto';
|
||||
import { verifyPresentation, canonical, idOf } from './identity.mjs';
|
||||
|
||||
const sha = (s) => '0x' + crypto.createHash('sha256').update(Buffer.from(s, 'utf8')).digest('hex');
|
||||
const ID = /^aere-id:[0-9a-f]{40}$/;
|
||||
const OPERATORI = ['equals', 'in', 'notIn', 'atLeast', 'present'];
|
||||
/** regulile pe care le poate numi un motiv al lui checkCompliance */
|
||||
export const REGULI = ['presentation', 'status', 'rule'];
|
||||
|
||||
/** Forma normala a unei politici si hash-ul ei; refuza campuri necunoscute si reguli fara inteles. */
|
||||
export function definePolicy(p) {
|
||||
@@ -65,19 +74,20 @@ export function checkCompliance(p, politica, { audience, nonce, now = new Date()
|
||||
const { policy, policyHash } = definePolicy(politica);
|
||||
if (typeof audience !== 'string' || !audience || typeof nonce !== 'string' || !nonce) throw new Error('compliance: the verifier\'s audience and nonce are required (without them a presentation can be replayed)');
|
||||
const v = verifyPresentation(p, { audience, nonce, now, trustedIssuers: policy.trustedIssuers, statusLists, revocations, maxAgeS: policy.maxAgeS });
|
||||
const motive = [];
|
||||
if (!v.valid) motive.push('the presentation is not valid: ' + v.rows.filter((r) => r.pass === false).map((r) => r.name + (r.detail ? ' (' + r.detail + ')' : '')).join('; '));
|
||||
const rows = []; const ok = (rule, pass, detail) => { if (!REGULI.includes(rule)) throw new Error('compliance: undeclared rule ' + rule); rows.push({ rule, pass: !!pass, detail: pass ? '' : detail }); };
|
||||
ok('presentation', v.valid /*PAZA:presentation*/, 'the presentation is not valid: ' + v.rows.filter((r) => r.pass === false).map((r) => r.name + (r.detail ? ' (' + r.detail + ')' : '')).join('; '));
|
||||
const status = v.rows.find((r) => /^credential: (not revoked|status)/.test(r.name));
|
||||
if (policy.requireStatus && !(status && status.pass === true)) motive.push('the policy requires the credential status to be judged: ' + (status ? status.detail || 'not judged' : 'no status row'));
|
||||
ok('status', !policy.requireStatus || !!(status && status.pass === true) /*PAZA:status*/, 'the policy requires the credential status to be judged: ' + (status ? status.detail || 'not judged' : 'no status row'));
|
||||
const claims = v.claims || {};
|
||||
for (const r of policy.require) if (!regula(r, claims)) motive.push(`rule not met: ${canonical(r)}`);
|
||||
for (const r of policy.require) ok('rule', regula(r, claims) /*PAZA:rule*/, `rule not met: ${canonical(r)}`);
|
||||
const motive = rows.filter((r) => !r.pass).map((r) => r.detail);
|
||||
const holder = p && p.credential && p.credential.statement && p.credential.statement.holder ? p.credential.statement.holder.id : null;
|
||||
// B-29 (2026-09-30, revizuirea API-ului): digestul e al LEGATURII semnate de cel care prezinta (ea numeste prin hash credentialul intreg,
|
||||
// dezvaluirile, lantul de delegare, publicul, nonce-ul si momentul), nu al obiectului intreg: un camp de sus nesemnat, adaugat de
|
||||
// oricine, schimba obiectul fara sa schimbe nimic semnat, deci digestul vechi nu numea unic prezentarea. Semnatura nu intra: ML-DSA
|
||||
// semneaza aleator, deci aceeasi legatura poate avea oricate semnaturi valide. Fara legatura (prezentare stricata), obiectul intreg.
|
||||
const legatura = p && typeof p === 'object' && p.binding && typeof p.binding === 'object' && !Array.isArray(p.binding) ? p.binding : null;
|
||||
return { compliant: !motive.length, reasons: motive, policyHash, policyId: policy.id, holder, notJudged: v.notJudged,
|
||||
return { compliant: !motive.length, reasons: motive, rules: [...new Set(rows.filter((r) => !r.pass).map((r) => r.rule))].sort(), rows, unjudged: v.unjudged, policyHash, policyId: policy.id, holder, notJudged: v.notJudged,
|
||||
presentationHash: sha(canonical(legatura || p || null)), ...(keepClaims && !motive.length ? { claims } : {}) };
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ const PLANTARI = [
|
||||
['notIn nu mai compara', "if (Object.hasOwn(r, 'notIn')) return !r.notIn.some((x) => canonical(x) === canonical(v));", "if (Object.hasOwn(r, 'notIn')) return true;", 'neconform: jurisdictie interzisa'],
|
||||
['atLeast nu mai compara', "if (Object.hasOwn(r, 'atLeast')) return typeof v === 'number' && Number.isFinite(v) && v >= r.atLeast;", "if (Object.hasOwn(r, 'atLeast')) return true;", 'neconform: jurisdictie interzisa'],
|
||||
['o afirmatie ceruta si nearatata trece', 'if (!are) return false;', 'if (!are) return true;', 'neconform: o afirmatie ceruta nearatata'],
|
||||
['starea nejudecata trece drept nerevocata', 'if (policy.requireStatus && !(status && status.pass === true))', 'if (false)', 'neconform: starea ceruta'],
|
||||
['o prezentare invalida judecata conforma', 'if (!v.valid) motive.push(', 'if (false) motive.push(', 'neconform: emitent in afara'],
|
||||
// 2026-10-18: forma cu reguli numite (`ok('<regula>', <conditia buna> /*PAZA:<regula>*/, ...)`); paznicul se scoate facand conditia `true`
|
||||
['starea nejudecata trece drept nerevocata', "ok('status', !policy.requireStatus || !!(status && status.pass === true) /*PAZA:status*/,", "ok('status', true /*PAZA:status*/,", 'neconform: starea ceruta'],
|
||||
['o prezentare invalida judecata conforma', "ok('presentation', v.valid /*PAZA:presentation*/,", "ok('presentation', true /*PAZA:presentation*/,", 'neconform: emitent in afara'],
|
||||
['emitentii politicii nu mai ajung la verificare', 'trustedIssuers: policy.trustedIssuers,', 'trustedIssuers: null,', 'neconform: emitent in afara'],
|
||||
['judecata fara publicul si nonce-ul verificatorului', "if (typeof audience !== 'string' || !audience || typeof nonce !== 'string' || !nonce) throw new Error('compliance: the verifier", "if (false) throw new Error('compliance: the verifier", 'neconform: prezentare facuta pentru alt verificator'],
|
||||
['regulile nu mai sunt in forma normala', '}).sort((a, b) => (canonical(a) < canonical(b) ? -1 : 1));', '});', 'politica: forma normala'],
|
||||
|
||||
@@ -10,26 +10,30 @@ const AICI = path.dirname(fileURLToPath(import.meta.url));
|
||||
const DEV_VERIFY = path.resolve(AICI, '..', 'aere-proof-protocol', 'verify.mjs');
|
||||
const VERIFY = process.env.AERE_VERIFY_PROOF || (fs.existsSync(DEV_VERIFY) ? DEV_VERIFY : '');
|
||||
const T = 'travel-rule.mjs';
|
||||
// 2026-10-18: tiparele sunt pe forma cu reguli numite (fiecare verificare e `C.ok('<regula>', <conditia buna> /*PAZA:<regula>*/, ...)`;
|
||||
// un paznic se scoate facand conditia buna `true`, cu marcajul pastrat)
|
||||
const PLANTARI = [
|
||||
// [nume, [[tipar, inlocuire], ...], proba (inceputul numelui ei)]
|
||||
['legarea KEM nesemnata de VASP-ul ei primita', [["if (!verifyText('kem-binding', canonical(S), binding.signature, S.vasp.keys)) motive.push(", 'if (false) motive.push(']], 'ATAC: legarea KEM semnata de alt VASP'],
|
||||
['credentialul altei identitati primit', [['if (!holder || holder.id !== id) motive.push(', 'if (false) motive.push(']], 'ATAC: legarea KEM a lui C cu prezentarea'],
|
||||
['un credential fara vasp:true primit', [['if (v.valid && (!v.claims || v.claims.vasp !== true)) motive.push(', 'if (false) motive.push(']], 'ATAC: credential de VASP de la un registru'],
|
||||
['legarea KEM nesemnata de VASP-ul ei primita', [["C.ok('binding-signature', verifyText('kem-binding', canonical(S), binding.signature, S.vasp.keys) /*PAZA:binding-signature*/,", "C.ok('binding-signature', true /*PAZA:binding-signature*/,"]], 'ATAC: legarea KEM semnata de alt VASP'],
|
||||
['credentialul altei identitati primit', [["ok('vasp-identity', !!(holder && holder.id === id) /*PAZA:vasp-identity*/,", "ok('vasp-identity', true /*PAZA:vasp-identity*/,"]], 'ATAC: legarea KEM a lui C cu prezentarea'],
|
||||
['un credential fara vasp:true primit', [["ok('vasp-claim', (!v.valid || !!(v.claims && v.claims.vasp === true)) /*PAZA:vasp-claim*/,", "ok('vasp-claim', true /*PAZA:vasp-claim*/,"]], 'ATAC: credential de VASP de la un registru'],
|
||||
['registrele de incredere nu mai ajung la verificare', [['trustedIssuers: registries,', 'trustedIssuers: null,']], 'ATAC: credential de VASP de la un registru'],
|
||||
['starea nejudecata a VASP-ului primita', [['if (!(stare && stare.pass === true)) motive.push(', 'if (false) motive.push(']], 'ATAC: un VASP revocat'],
|
||||
['legarea expirata primita', [["if (!(timp(S.validFrom, 'validFrom') <= acum && acum <= timp(S.validUntil, 'validUntil'))) motive.push(", 'if (false) motive.push(']], 'ATAC: prezentarea beneficiarului facuta pentru alt initiator'],
|
||||
['semnatura mesajului nu se mai verifica', [["if (!verifyText('travel-rule', canonical(semnat), m.signature, m.from.keys)) motive.push(", 'if (false) motive.push(']], 'ATAC: mesaj semnat de un strain'],
|
||||
['destinatarul nu se mai compara', [['if (m.to.id !== me) motive.push(', 'if (false) motive.push(']], 'ATAC: alt VASP (C)'],
|
||||
['cheile KEM ale destinatarului nu se mai compara', [['if (canonical(m.to.kem) !== canonical(kem.public)) motive.push(', 'if (false) motive.push(']], 'ATAC: alt VASP (C)'],
|
||||
['prospetimea nu se mai cere', [["if (Math.abs(acum - timp(m.createdAt, 'createdAt')) > maxAgeS * 1000) motive.push(", 'if (false) motive.push(']], 'ATAC: acelasi mesaj primit a doua oara'],
|
||||
['reluarea nu se mai opreste', [[' else if (seen.has(m.id)) motive.push(', ' else if (false) motive.push(']], 'ATAC: acelasi mesaj primit a doua oara'],
|
||||
// 2026-10-18: forma de dinainte, in care publicul si nonce-ul lasate nejudecate de verificatorul de identitate nu refuzau prezentarea
|
||||
['publicul si nonce-ul nejudecate iar acceptate', [["const nejudecate = v.rows.filter((r) => r.pass === null && (r.unjudged === 'audience' || r.unjudged === 'nonce'));", 'const nejudecate = [];']], 'ATAC: acceptBeneficiary fara originatorId'],
|
||||
['starea nejudecata a VASP-ului primita', [["ok('vasp-status', !!(stare && stare.pass === true) /*PAZA:vasp-status*/,", "ok('vasp-status', true /*PAZA:vasp-status*/,"]], 'ATAC: un VASP revocat'],
|
||||
['legarea expirata primita', [["C.ok('binding-window', (timp(S.validFrom, 'validFrom') <= acum && acum <= timp(S.validUntil, 'validUntil')) /*PAZA:binding-window*/,", "C.ok('binding-window', true /*PAZA:binding-window*/,"]], 'ATAC: prezentarea beneficiarului facuta pentru alt initiator'],
|
||||
['semnatura mesajului nu se mai verifica', [["C.ok('message-signature', verifyText('travel-rule', canonical(semnat), m.signature, m.from.keys) /*PAZA:message-signature*/,", "C.ok('message-signature', true /*PAZA:message-signature*/,"]], 'ATAC: mesaj semnat de un strain'],
|
||||
['destinatarul nu se mai compara', [["C.ok('message-recipient', m.to.id === me /*PAZA:message-recipient*/,", "C.ok('message-recipient', true /*PAZA:message-recipient*/,"]], 'ATAC: alt VASP (C)'],
|
||||
['cheile KEM ale destinatarului nu se mai compara', [["C.ok('message-kem-keys', canonical(m.to.kem) === canonical(kem.public) /*PAZA:message-kem-keys*/,", "C.ok('message-kem-keys', true /*PAZA:message-kem-keys*/,"]], 'ATAC: alt VASP (C)'],
|
||||
['prospetimea nu se mai cere', [["C.ok('message-freshness', (Number.isFinite(acum) && Math.abs(acum - timp(m.createdAt, 'createdAt')) <= maxAgeS * 1000) /*PAZA:message-freshness*/,", "C.ok('message-freshness', true /*PAZA:message-freshness*/,"]], 'ATAC: acelasi mesaj primit a doua oara'],
|
||||
['reluarea nu se mai opreste', [["C.ok('replay', !seen.has(m.id) /*PAZA:replay*/,", "C.ok('replay', true /*PAZA:replay*/,"]], 'ATAC: acelasi mesaj primit a doua oara'],
|
||||
// B-26: forma publicata in f75c334 (seen optional: fara el, orice reluare trecea)
|
||||
['magazia de reluare iar optionala (B-26)', [[" if (!seen || typeof seen.has !== 'function' || typeof seen.add !== 'function') motive.push(", " if (false) motive.push("], [" else if (seen.has(m.id)) motive.push(", " else if (seen && seen.has && seen.has(m.id)) motive.push("], [' seen.add(m.id);', ' if (seen && seen.add) seen.add(m.id);']], 'B-26'],
|
||||
['initiatorul nu mai trebuie dovedit VASP', [["motive.push(...v.motive.map((x) => 'originator VASP: ' + x));", '']], 'ATAC: initiatorul nedovedit ca VASP'],
|
||||
['magazia de reluare iar optionala (B-26)', [["C.ok('replay-store', (!!seen && typeof seen.has === 'function' && typeof seen.add === 'function') /*PAZA:replay-store*/,", "C.ok('replay-store', true /*PAZA:replay-store*/,"], ["C.ok('replay', !seen.has(m.id) /*PAZA:replay*/,", "C.ok('replay', !(seen && seen.has && seen.has(m.id)) /*PAZA:replay*/,"], [' seen.add(m.id);', ' if (seen && seen.add) seen.add(m.id);']], 'B-26'],
|
||||
['initiatorul nu mai trebuie dovedit VASP', [["const v = eVasp(m.fromPresentation, { registries, audience: me, nonce: m.id, id: m.from.id, now, statusLists, maxAgeS }, C.ok, 'originator VASP: ');", 'const v = { claims: null };']], 'ATAC: initiatorul nedovedit ca VASP'],
|
||||
['antetul nu mai e legat de cifru (nici AAD, nici derivarea)', [["const c = crypto.createCipheriv('aes-256-gcm', d.key, d.iv); c.setAAD(aad);", "const c = crypto.createCipheriv('aes-256-gcm', d.key, d.iv);"], ['dc.setAAD(aad); dc.setAuthTag', 'dc.setAuthTag'], ["crypto.createHash('sha256').update(transcript).digest()", 'Buffer.alloc(32)']], 'ATAC: suma din antet schimbata'],
|
||||
['numai secretul X25519 intra in cheie', [['const ikm = Buffer.concat([ssK, ssX]);', 'const ikm = Buffer.concat([ssX]);']], 'KEM hibrid'],
|
||||
['confirmarea altui VASP primita', [['if (S.from.id !== beneficiaryId || idOf(S.from.keys) !== S.from.id) motive.push(', 'if (false) motive.push(']], 'ATAC: confirmare semnata de C'],
|
||||
['confirmarea altui mesaj primita', [["if (S.messageId !== message.id || S.messageHash !== sha(Buffer.from(canonical(semnat), 'utf8'))) motive.push(", 'if (false) motive.push(']], 'ATAC: confirmare semnata de C'],
|
||||
['confirmarea altui VASP primita', [["C.ok('receipt-from', (S.from.id === beneficiaryId && idOf(S.from.keys) === S.from.id) /*PAZA:receipt-from*/,", "C.ok('receipt-from', true /*PAZA:receipt-from*/,"]], 'ATAC: confirmare semnata de C'],
|
||||
['confirmarea altui mesaj primita', [["C.ok('receipt-message', (S.messageId === message.id && S.messageHash === sha(Buffer.from(canonical(semnat), 'utf8'))) /*PAZA:receipt-message*/,", "C.ok('receipt-message', true /*PAZA:receipt-message*/,"]], 'ATAC: confirmare semnata de C'],
|
||||
['id-ul initiatorului scris in inregistrare', [["const subject = 'transfer:' + sha(", 'const subject = message.from.id + sha(']], 'inregistrarea (plic AIP-23 compliance)'],
|
||||
['un fisier de chei KEM cu partea publica a altcuiva primit', [['if (canonical(pub) !== canonical(j.public)) throw', 'if (false) throw']], 'cheile KEM'],
|
||||
];
|
||||
|
||||
@@ -67,6 +67,14 @@ test('ATAC: un VASP revocat de registru nu mai primeste date; fara lista de star
|
||||
const r2 = TR.acceptBeneficiary({ binding: bindB, presentation: pres(credB, B, A.id, 'n'), registries: [reg.id], originatorId: A.id, nonce: 'n', now: NOW, statusLists: [] });
|
||||
cere(are(r2, /status is not judged/), r2.motive.join(' | '));
|
||||
});
|
||||
// 2026-10-18, gasit de randul intrarilor malformate al suitei de conformitate (tools/aere-conformance): fara originatorId sau fara nonce (lipsa, nu
|
||||
// gresite) verificatorul de identitate lasa publicul si nonce-ul NEJUDECATE, si acceptBeneficiary iesea ok:true cu o prezentare reluabila
|
||||
test('ATAC: acceptBeneficiary fara originatorId sau fara nonce (publicul si nonce-ul prezentarii nejudecate) -> refuzat, nu acceptat pe incredere', () => {
|
||||
const r1 = TR.acceptBeneficiary({ binding: bindB, presentation: pres(credB, B, A.id, 'n-acc'), registries: [reg.id], originatorId: undefined, nonce: 'n-acc', now: NOW, statusLists: [LISTA] });
|
||||
cere(are(r1, /audience .*not judged|not judged: without the verifier/), 'fara originatorId a trecut: ' + r1.motive.join(' | '));
|
||||
const r2 = TR.acceptBeneficiary({ binding: bindB, presentation: pres(credB, B, A.id, 'n-acc'), registries: [reg.id], originatorId: A.id, nonce: undefined, now: NOW, statusLists: [LISTA] });
|
||||
cere(are(r2, /nonce .*not judged|not judged: without the verifier/), 'fara nonce a trecut: ' + r2.motive.join(' | '));
|
||||
});
|
||||
test('ATAC: prezentarea beneficiarului facuta pentru alt initiator (reluata) -> refuzata; legarea expirata -> refuzata', () => {
|
||||
const r = TR.acceptBeneficiary({ binding: bindB, presentation: pres(credB, B, C.id, 'n'), registries: [reg.id], originatorId: A.id, nonce: 'n', now: NOW, statusLists: [LISTA] });
|
||||
cere(are(r, /made for/), r.motive.join(' | '));
|
||||
@@ -80,7 +88,8 @@ const M = sigileaza();
|
||||
test('drumul intreg: beneficiarul deschide mesajul; datele IVMS101 si transferul sunt cele trimise; nimic din ele nu e in clar in mesaj', () => {
|
||||
const o = deschide(M);
|
||||
cere(o.ok && I.canonical(o.ivms101) === I.canonical(IVMS) && o.transfer.amount === TRANSFER.amount && o.from.id === A.id, o.motive.join(' | '));
|
||||
const s = JSON.stringify(M); cere(!s.includes('Ionescu') && !s.includes('Pop') && !s.includes('0xAAAA000000000000000000000000000000000001'), 'date personale in clar in mesaj');
|
||||
// 2026-10-18: valorile se cauta ca text JSON ("Pop", cu ghilimele): trei litere goale apar din intamplare intr-un base64 de semnatura ML-DSA (masurat: 18/19 o data din trei rulari)
|
||||
const s = JSON.stringify(M); cere(!s.includes('"Ionescu"') && !s.includes('"Pop"') && !s.includes('0xAAAA000000000000000000000000000000000001'), 'date personale in clar in mesaj');
|
||||
});
|
||||
test('ATAC: un octet al cifrului schimbat -> refuzat (semnatura; si fara ea, GCM)', () => {
|
||||
const m = clon(M); const b = Buffer.from(m.ciphertext, 'base64'); b[5] ^= 1; m.ciphertext = b.toString('base64');
|
||||
|
||||
+70
-43
@@ -13,10 +13,30 @@
|
||||
// Ce NU face: nu valideaza schema IVMS101 (poarta obiectul asa cum e dat, cere doar `originator` si `beneficiary`); nu descopera VASP-ul
|
||||
// beneficiarului dupa o adresa (asta e treaba unui protocol de descoperire); nu spune ca un transfer e legal, ci ca datele au ajuns,
|
||||
// cifrate, la VASP-ul numit si ca acesta a confirmat. Momentele sunt ale celor care semneaza, judecate pe ceasul celui care verifica.
|
||||
//
|
||||
// REGULILE NUMITE (2026-10-18, pentru suita de conformitate tools/aere-conformance): fiecare refuz al celor trei verificatoare
|
||||
// (`acceptBeneficiary`, `openMessage`, `verifyReceipt`) numeste regula lui, din REGULI; fiecare verificare e un rand { rule, pass, detail }
|
||||
// si poarta marcajul /*PAZA:<regula>*/ pe conditia ei BUNA (controlul negativ al suitei o face adevarata intr-o copie). Rezultatul poarta,
|
||||
// pe langa `ok` si `motive` (textele de ieri, neschimbate), `rules` (id-urile refuzate, sortate) si `rows`. Prezentarea de VASP e judecata
|
||||
// de verificatorul de identitate (identity.mjs, inrolat cu regulile lui); aici refuzurile ei poarta o singura regula, `vasp-presentation`.
|
||||
// Verificarile antetului unui mesaj se fac toate; la orice refuz al lor mesajul NU se mai deschide (incapsularea si cifrul nu se judeca).
|
||||
import crypto from 'node:crypto';
|
||||
import { canonical, signText, verifyText, verifyPresentation, idOf, publicKeyObjects } from './identity.mjs';
|
||||
|
||||
export const KEM_ALG = 'x25519+ml-kem-768';
|
||||
/** regulile pe care le poate numi un refuz (binding-*: acceptBeneficiary; vasp-*: prezentarea de VASP, in amandoua; message-*, replay*, kem-*, ciphertext: openMessage; receipt-*: verifyReceipt) */
|
||||
export const REGULI = ['binding-form', 'binding-id', 'binding-signature', 'binding-window', 'vasp-presentation', 'vasp-status', 'vasp-identity', 'vasp-claim',
|
||||
'message-form', 'message-id', 'message-signature', 'message-recipient', 'message-kem-keys', 'message-freshness', 'replay-store', 'replay', 'kem-alg', 'kem-open', 'ciphertext',
|
||||
'receipt-form', 'receipt-from', 'receipt-signature', 'receipt-message'];
|
||||
/** regulile dupa al caror refuz verificatorul s-a oprit (ce nu poate citi): celelalte verificari nu s-au mai facut */
|
||||
export const OPRIRI = ['binding-form', 'message-form', 'receipt-form'];
|
||||
// randurile unei verificari: ok(regula, conditia buna, motivul) -> conditia; gata() -> { ok, motive, rules, rows }
|
||||
function colector() {
|
||||
const rows = [];
|
||||
const ok = (rule, pass, detail = '') => { if (!REGULI.includes(rule)) throw new Error('travel rule: undeclared rule ' + rule); rows.push({ rule, pass: !!pass, detail: pass ? '' : detail }); return !!pass; };
|
||||
const gata = (extra = {}) => { const rele = rows.filter((r) => !r.pass); return { ok: !rele.length, motive: rele.map((r) => r.detail), rules: [...new Set(rele.map((r) => r.rule))].sort(), rows, ...extra }; };
|
||||
return { ok, gata, rows };
|
||||
}
|
||||
const sha = (b) => '0x' + crypto.createHash('sha256').update(b).digest('hex');
|
||||
const b64 = (b) => Buffer.from(b).toString('base64');
|
||||
const SPKI_X25519 = Buffer.from('302a300506032b656e032100', 'hex');
|
||||
@@ -62,36 +82,41 @@ export function bindKemKeys({ vasp, kem, validUntil, now = new Date() }) {
|
||||
}
|
||||
|
||||
// prezentarea credentialului de VASP: valida, de la un registru de incredere, facuta pentru `audience`, cu `nonce`, a detinatorului `id`,
|
||||
// cu afirmatia vasp:true si starea judecata (un VASP revocat nu mai primeste date)
|
||||
function eVasp(pres, { registries, audience, nonce, id, now, statusLists, maxAgeS }) {
|
||||
// cu afirmatia vasp:true si starea judecata (un VASP revocat nu mai primeste date). `ok` e colectorul celui care cheama; `prefix` sta in
|
||||
// fata fiecarui motiv (openMessage scrie 'originator VASP: ')
|
||||
function eVasp(pres, { registries, audience, nonce, id, now, statusLists, maxAgeS }, ok, prefix = '') {
|
||||
const v = verifyPresentation(pres, { audience, nonce, now, trustedIssuers: registries, statusLists, maxAgeS });
|
||||
const motive = v.rows.filter((r) => r.pass === false).map((r) => r.name + (r.detail ? ' (' + r.detail + ')' : ''));
|
||||
// 2026-10-18, gasit de randul intrarilor malformate al suitei de conformitate: fara publicul sau nonce-ul verificatorului (originatorId,
|
||||
// nonce lipsa) verifyPresentation le lasa NEJUDECATE si ramane valid, iar beneficiarul iesea acceptat cu o prezentare reluabila; aici
|
||||
// o prezentare al carei public sau nonce nu a fost judecat e refuzata, nu primita pe incredere
|
||||
const nejudecate = v.rows.filter((r) => r.pass === null && (r.unjudged === 'audience' || r.unjudged === 'nonce'));
|
||||
if (!((v.valid && nejudecate.length === 0) /*PAZA:vasp-presentation*/)) { for (const r of [...v.rows.filter((r) => r.pass === false), ...nejudecate]) ok('vasp-presentation', false, prefix + r.name + (r.detail ? ' (' + r.detail + ')' : '')); }
|
||||
else ok('vasp-presentation', true);
|
||||
const stare = v.rows.find((r) => /^credential: (not revoked|status)/.test(r.name));
|
||||
if (!(stare && stare.pass === true)) motive.push('the VASP credential status is not judged: ' + (stare ? stare.detail || 'not judged' : 'no status row'));
|
||||
ok('vasp-status', !!(stare && stare.pass === true) /*PAZA:vasp-status*/, prefix + 'the VASP credential status is not judged: ' + (stare ? stare.detail || 'not judged' : 'no status row'));
|
||||
const holder = pres && pres.credential && pres.credential.statement && pres.credential.statement.holder;
|
||||
if (!holder || holder.id !== id) motive.push(`the VASP credential belongs to ${holder && holder.id}, not to ${id}`);
|
||||
if (v.valid && (!v.claims || v.claims.vasp !== true)) motive.push('the credential does not say vasp: true');
|
||||
return { ok: !motive.length, motive, claims: v.valid ? v.claims : null };
|
||||
ok('vasp-identity', !!(holder && holder.id === id) /*PAZA:vasp-identity*/, prefix + `the VASP credential belongs to ${holder && holder.id}, not to ${id}`);
|
||||
ok('vasp-claim', (!v.valid || !!(v.claims && v.claims.vasp === true)) /*PAZA:vasp-claim*/, prefix + 'the credential does not say vasp: true');
|
||||
return { claims: v.valid ? v.claims : null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiatorul accepta un beneficiar: legarea cheilor KEM semnata de identitatea lui, valabila acum, si prezentarea credentialului lui
|
||||
* de VASP de la un registru de incredere, facuta pentru initiator (`audience` = id-ul initiatorului) cu nonce-ul lui, a ACELEIASI
|
||||
* identitati. Intoarce { ok, motive, beneficiary: { id, keys, kem, claims } }.
|
||||
* identitati. Intoarce { ok, motive, rules, rows, beneficiary: { id, keys, kem, claims } }.
|
||||
*/
|
||||
export function acceptBeneficiary({ binding, presentation, registries, originatorId, nonce, now = new Date(), statusLists = [], maxAgeS = 300 }) {
|
||||
const motive = []; const acum = new Date(now).getTime();
|
||||
const C = colector(); const acum = new Date(now).getTime();
|
||||
const S = binding && binding.statement;
|
||||
try {
|
||||
if (!S || S.kind !== 'aere-travel-rule-kem-binding') throw new Error('not an aere-travel-rule-kem-binding');
|
||||
if (idOf(S.vasp.keys) !== S.vasp.id) motive.push('the binding names an id not derived from its keys');
|
||||
if (!verifyText('kem-binding', canonical(S), binding.signature, S.vasp.keys)) motive.push('the binding is not signed by the VASP it names');
|
||||
if (!((!!S && S.kind === 'aere-travel-rule-kem-binding') /*PAZA:binding-form*/)) throw new Error('not an aere-travel-rule-kem-binding');
|
||||
C.ok('binding-id', idOf(S.vasp.keys) === S.vasp.id /*PAZA:binding-id*/, 'the binding names an id not derived from its keys');
|
||||
C.ok('binding-signature', verifyText('kem-binding', canonical(S), binding.signature, S.vasp.keys) /*PAZA:binding-signature*/, 'the binding is not signed by the VASP it names');
|
||||
kemPublicObjects(S.kem);
|
||||
if (!(timp(S.validFrom, 'validFrom') <= acum && acum <= timp(S.validUntil, 'validUntil'))) motive.push(`the binding is valid from ${S.validFrom} until ${S.validUntil}`);
|
||||
} catch (e) { motive.push('the binding cannot be read: ' + e.message); return { ok: false, motive }; }
|
||||
const v = eVasp(presentation, { registries, audience: originatorId, nonce, id: S.vasp.id, now, statusLists, maxAgeS });
|
||||
motive.push(...v.motive);
|
||||
return { ok: !motive.length, motive, beneficiary: { id: S.vasp.id, keys: S.vasp.keys, kem: S.kem, claims: v.claims } };
|
||||
C.ok('binding-window', (timp(S.validFrom, 'validFrom') <= acum && acum <= timp(S.validUntil, 'validUntil')) /*PAZA:binding-window*/, `the binding is valid from ${S.validFrom} until ${S.validUntil}`);
|
||||
} catch (e) { if (!(false /*PAZA:binding-form*/)) C.ok('binding-form', false, 'the binding cannot be read: ' + e.message); return C.gata(); }
|
||||
const v = eVasp(presentation, { registries, audience: originatorId, nonce, id: S.vasp.id, now, statusLists, maxAgeS }, C.ok);
|
||||
return C.gata({ beneficiary: { id: S.vasp.id, keys: S.vasp.keys, kem: S.kem, claims: v.claims } });
|
||||
}
|
||||
|
||||
const TRANSFER = ['chainId', 'asset', 'amount', 'beneficiaryAddress'];
|
||||
@@ -139,41 +164,42 @@ export function sealMessage({ from, beneficiary, ivms101, transfer, presentation
|
||||
* 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 }.
|
||||
* Intoarce { ok, motive, rules, rows, ivms101, transfer, from, messageHash }. Un ceas al verificatorului care nu se poate citi e refuz
|
||||
* (`message-freshness`), nu un NaN care trece.
|
||||
*/
|
||||
export function openMessage(m, { me, kem, registries, now = new Date(), statusLists = [], seen = null, maxAgeS = 300 }) {
|
||||
const motive = []; const acum = new Date(now).getTime();
|
||||
const C = colector(); const acum = new Date(now).getTime();
|
||||
try {
|
||||
if (!m || m.kind !== 'aere-travel-rule-message' || m.v !== 1) throw new Error('not an aere-travel-rule-message');
|
||||
if (!((!!m && m.kind === 'aere-travel-rule-message' && m.v === 1) /*PAZA:message-form*/)) throw new Error('not an aere-travel-rule-message');
|
||||
const semnat = { ...antet(m), ciphertext: m.ciphertext };
|
||||
if (idOf(m.from.keys) !== m.from.id) motive.push('the message names an originator id not derived from its keys');
|
||||
if (!verifyText('travel-rule', canonical(semnat), m.signature, m.from.keys)) motive.push('the message is not signed by the originator it names');
|
||||
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 || 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 };
|
||||
C.ok('message-id', idOf(m.from.keys) === m.from.id /*PAZA:message-id*/, 'the message names an originator id not derived from its keys');
|
||||
C.ok('message-signature', verifyText('travel-rule', canonical(semnat), m.signature, m.from.keys) /*PAZA:message-signature*/, 'the message is not signed by the originator it names');
|
||||
C.ok('message-recipient', m.to.id === me /*PAZA:message-recipient*/, `the message is for ${m.to.id}, not for ${me}`);
|
||||
C.ok('message-kem-keys', canonical(m.to.kem) === canonical(kem.public) /*PAZA:message-kem-keys*/, 'the message is sealed to other KEM keys');
|
||||
C.ok('message-freshness', (Number.isFinite(acum) && Math.abs(acum - timp(m.createdAt, 'createdAt')) <= maxAgeS * 1000) /*PAZA:message-freshness*/, `the message was made at ${m.createdAt}, outside ${maxAgeS} s of this clock`);
|
||||
if (C.ok('replay-store', (!!seen && typeof seen.has === 'function' && typeof seen.add === 'function') /*PAZA:replay-store*/, 'no replay store was given (seen: a set of the message ids already received, kept at least maxAgeS)'))
|
||||
C.ok('replay', !seen.has(m.id) /*PAZA:replay*/, '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 }, C.ok, 'originator VASP: ');
|
||||
if (!C.gata().ok) return C.gata();
|
||||
const ePub = Buffer.from(m.kem.ephemeralX25519, 'base64'), ctK = Buffer.from(m.kem.mlkemCiphertext, 'base64');
|
||||
if (m.kem.alg !== KEM_ALG || ePub.length !== 32) return { ok: false, motive: ['the key encapsulation is not ' + KEM_ALG] };
|
||||
if (!C.ok('kem-alg', (m.kem.alg === KEM_ALG && ePub.length === 32) /*PAZA:kem-alg*/, 'the key encapsulation is not ' + KEM_ALG)) return C.gata();
|
||||
let ssX, ssK;
|
||||
try {
|
||||
const { x25519: skX, mlkem768: skK } = kem.privat;
|
||||
ssX = crypto.diffieHellman({ privateKey: skX, publicKey: crypto.createPublicKey({ key: Buffer.concat([SPKI_X25519, ePub]), format: 'der', type: 'spki' }) });
|
||||
ssK = crypto.decapsulate(skK, ctK);
|
||||
} catch { return { ok: false, motive: ['the key encapsulation does not open with these keys'] }; }
|
||||
} catch { if (!(false /*PAZA:kem-open*/)) { C.ok('kem-open', false, 'the key encapsulation does not open with these keys'); return C.gata(); } }
|
||||
const aad = Buffer.from(canonical(antet(m)), 'utf8');
|
||||
const d = derive(ssK, ssX, aad); ssX.fill(0); ssK.fill(0);
|
||||
const ct = Buffer.from(m.ciphertext, 'base64');
|
||||
let pt;
|
||||
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'] }; }
|
||||
catch { if (!(false /*PAZA:ciphertext*/)) { C.ok('ciphertext', false, 'the ciphertext or its header was modified, or it is not for these keys'); return C.gata(); } }
|
||||
finally { d.key.fill(0); }
|
||||
C.ok('kem-open', true); C.ok('ciphertext', true);
|
||||
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] }; }
|
||||
return C.gata({ 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) { if (!(false /*PAZA:message-form*/)) C.ok('message-form', false, 'the message cannot be read: ' + e.message); return C.gata(); }
|
||||
}
|
||||
|
||||
/** Confirmarea semnata a beneficiarului: ce mesaj (hash), ce continut (hash-ul textului clar), acceptat sau nu si de ce. */
|
||||
@@ -182,17 +208,18 @@ export function acknowledge({ opened, message, me, accepted = true, reason = nul
|
||||
from: { id: me.id, keys: me.public }, to: message.from.id, accepted: !!accepted, ...(reason ? { reason: String(reason) } : {}), at: new Date(now).toISOString() };
|
||||
return { statement, signature: signText('travel-rule-receipt', canonical(statement), me) };
|
||||
}
|
||||
/** Initiatorul verifica o confirmare: semnata de beneficiarul acceptat, pentru ACEST mesaj (hash-ul celui trimis). */
|
||||
/** Initiatorul verifica o confirmare: semnata de beneficiarul acceptat, pentru ACEST mesaj (hash-ul celui trimis). Intoarce { ok, accepted, motive, rules, rows }. */
|
||||
export function verifyReceipt(r, { message, beneficiaryId }) {
|
||||
const S = r && r.statement; const motive = [];
|
||||
const S = r && r.statement; const C = colector();
|
||||
try {
|
||||
if (!S || S.kind !== 'aere-travel-rule-receipt') throw new Error('not an aere-travel-rule-receipt');
|
||||
if (S.from.id !== beneficiaryId || idOf(S.from.keys) !== S.from.id) motive.push(`the receipt is from ${S.from.id}, not from the accepted beneficiary`);
|
||||
if (!verifyText('travel-rule-receipt', canonical(S), r.signature, S.from.keys)) motive.push('the receipt is not signed by the beneficiary');
|
||||
if (!((!!S && S.kind === 'aere-travel-rule-receipt') /*PAZA:receipt-form*/)) throw new Error('not an aere-travel-rule-receipt');
|
||||
C.ok('receipt-from', (S.from.id === beneficiaryId && idOf(S.from.keys) === S.from.id) /*PAZA:receipt-from*/, `the receipt is from ${S.from.id}, not from the accepted beneficiary`);
|
||||
C.ok('receipt-signature', verifyText('travel-rule-receipt', canonical(S), r.signature, S.from.keys) /*PAZA:receipt-signature*/, 'the receipt is not signed by the beneficiary');
|
||||
const semnat = { ...antet(message), ciphertext: message.ciphertext };
|
||||
if (S.messageId !== message.id || S.messageHash !== sha(Buffer.from(canonical(semnat), 'utf8'))) motive.push('the receipt is for another message');
|
||||
} catch (e) { motive.push('the receipt cannot be read: ' + e.message); }
|
||||
return { ok: !motive.length, accepted: !motive.length && !!S.accepted, motive };
|
||||
C.ok('receipt-message', (S.messageId === message.id && S.messageHash === sha(Buffer.from(canonical(semnat), 'utf8'))) /*PAZA:receipt-message*/, 'the receipt is for another message');
|
||||
} catch (e) { if (!(false /*PAZA:receipt-form*/)) C.ok('receipt-form', false, 'the receipt cannot be read: ' + e.message); }
|
||||
const g = C.gata();
|
||||
return { ...g, accepted: g.ok && !!(S && S.accepted) };
|
||||
}
|
||||
|
||||
/** Inregistrarea schimbului fara date personale (plic AIP-23 `compliance`): transferul prin hash, rezultatul, digestul mesajului. */
|
||||
|
||||
Reference in new issue
Block a user