identity: the SD-JWT form of an AERE hybrid identity is judged on its ML-DSA-65 half by default, the Ed25519 half only on explicit request, and every verdict says postQuantum (rule sdjwt.hybrid-half); pq-pki: the signature algorithm a certificate or a revocation list declares must be its issuer key's (ALG_KEY, CRL_ALG_KEY); agents: an equivocation proof requires the agent's ML-DSA-65 key; pq-gateway: the status names the path to the backend and hybrid-only refuses a plain-HTTP backend; conformance 241 rules, 631 vectors

This commit is contained in:
Aere Network committed 2026-10-19 05:19:21 +03:00
1 parent 3ff21f7758
commit 0c8f1de3fd
122 files changed
+1205 -262

No files matched your search

+14 -1
View File
@@ -8,6 +8,12 @@
// PBKDF2 slab (A1), prima lista de revocare in loc de cea mai noua (A2), extensiile listei ignorate (A3), exceptie pe SPKI malformat si
// frunza cu cheie de 10 octeti admisa (A5), EKU pe autoritati neaplicat (A6), prima ancora cu acelasi nume la reinnoirea radacinii (A7),
// OID cu primul subidentificator pe mai multi octeti (A10, in der.mjs).
// 2026-10-19 (AIP-25 constatarea C3, D-537): algoritmul de semnatura DECLARAT de un certificat sau de o lista de revocare trebuie sa fie chiar
// algoritmul cheii emitentului (RFC 5280, campul signature din TBSCertificate si din TBSCertList: "the algorithm used by the CA to sign"; RFC 9881: ML-DSA-44, -65 si -87 sunt
// trei algoritmi). Pana atunci semnatura se verifica cu cheia emitentului oricare ar fi algoritmul declarat, deci o frunza care declara
// id-ml-dsa-87, semnata de o radacina ml-dsa-44, trecea (masurat de aips/aip25-inventar/masoara-constatari.mjs), iar o politica ce citeste
// algoritmul declarat era mintita. O nepotrivire e un refuz numit: ALG_KEY (certificat, si radacina fata de propria cheie), CRL_ALG_KEY (lista).
// OpenSSL 3.5 refuza aceleasi cazuri ("unable to get local issuer certificate", "CRL signature failure"; masurat in test/proba.mjs).
import crypto from 'node:crypto';
import * as D from './der.mjs';
@@ -441,6 +447,8 @@ function verifyChainInner({ leaf, intermediates = [], roots = [], at = new Date(
function judeca(path) {
const top = path[path.length - 1];
// AIP-25 C3: o radacina auto-semnata declara algoritmul propriei chei
if (!(top.alg === top.pkAlg)) return fail('ALG_KEY', `the trusted root "${cnOf(top)}" declares its signature as ${top.alg}, and its own key is ${top.pkAlg} (RFC 9881: the signature algorithm is the issuer key's)`);
if (!top.subjectRaw.equals(top.issuerRaw) || !verifySig(top.tbs, top.signature, top.spki, cnOf(top))) return fail('ROOT', 'the trusted root is not a valid self-signed certificate');
// 2. fiecare legatura
for (let k = 0; k < path.length; k++) {
@@ -456,6 +464,8 @@ function verifyChainInner({ leaf, intermediates = [], roots = [], at = new Date(
if (p.pathLen !== undefined && casBelow > p.pathLen) return fail('PATH_LEN', `"${cnOf(p)}" allows ${p.pathLen} CA(s) below it, the chain has ${casBelow}`);
// [A6] EKU pe o autoritate restrange tot ce e sub ea (OpenSSL, Chrome, Mozilla fac la fel); anyExtendedKeyUsage NU scuteste, ca la OpenSSL.
if (purpose && p.eku && !p.eku.has(OID[purpose])) return fail('EKU', `the issuer "${cnOf(p)}" is not valid for ${purpose} (its extended key usage does not allow it)`);
// AIP-25 C3: algoritmul declarat de c e cel al cheii lui p (altfel o politica ce citeste algoritmul declarat e mintita)
if (!(c.alg === p.pkAlg)) return fail('ALG_KEY', `"${cnOf(c)}" declares its signature as ${c.alg}, and the key of its issuer "${cnOf(p)}" is ${p.pkAlg} (RFC 5280, the signature field of TBSCertificate; RFC 9881: the signature algorithm is the issuer key's)`);
if (!verifySig(c.tbs, c.signature, p.spki, cnOf(c))) return fail('SIGNATURE', `the signature on "${cnOf(c)}" does not verify under "${cnOf(p)}"`);
const rv = revocare(c, p);
if (rv) return rv;
@@ -485,6 +495,9 @@ function verifyChainInner({ leaf, intermediates = [], roots = [], at = new Date(
if (!verificate.length) return fail('CRL_SIGNATURE', `the revocation list of "${cnOf(p)}" does not verify`);
const rea = verificate.find((l) => l.refusedExt);
if (rea) return fail('CRL_EXT', `the revocation list of "${cnOf(p)}" carries ${rea.refusedExt}`);
// AIP-25 C3: o lista care verifica sub cheia emitentului dar declara alt algoritm decat al ei e un verdict, ca CRL_EXT, nu e sarita
const altAlg = verificate.find((l) => !(l.alg === p.pkAlg));
if (altAlg) return fail('CRL_ALG_KEY', `the revocation list of "${cnOf(p)}" declares its signature as ${altAlg.alg}, and the key of "${cnOf(p)}" is ${p.pkAlg} (RFC 5280, the signature field of TBSCertList; RFC 9881)`);
const curente = verificate.filter((l) => at >= l.thisUpdate);
if (!curente.length) return fail('CRL_STALE', `the revocation list of "${cnOf(p)}" is dated in the future`);
curente.sort((a, b) => (b.thisUpdate - a.thisUpdate) || cmpBig(b.crlNumber, a.crlNumber));
@@ -498,7 +511,7 @@ function verifyChainInner({ leaf, intermediates = [], roots = [], at = new Date(
/** Semnatura unui certificat auto-semnat, verificata cu propria cheie (interoperabilitatea inversa: certificate facute de altii). */
export function selfSignatureValid(der) {
const c = parseCert(der);
return c.subjectRaw.equals(c.issuerRaw) && verifySig(c.tbs, c.signature, c.spki, cnOf(c));
return c.alg === c.pkAlg && c.subjectRaw.equals(c.issuerRaw) && verifySig(c.tbs, c.signature, c.spki, cnOf(c)); // AIP-25 C3: algoritmul declarat e al cheii
}
export function cnOf(c) {