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

+3 -2
View File
@@ -48,12 +48,13 @@ A Node TLS server loads the key in process, without ever writing it in clear: `t
- **Revocation**, for each issuer in the chain: among that issuer's lists that verify under its key and are not dated in the future, **the one with the newest `thisUpdate` is used** (ties broken by the larger `crlNumber`); the order of the input does not matter. That list must be current (`CRL_STALE` after `nextUpdate`), and a listed serial is `REVOKED`. `requireCrl` makes a missing list `CRL_MISSING`. A list whose signature does not verify is `CRL_SIGNATURE`.
- **CRL extensions**: `authorityKeyIdentifier` and `crlNumber` are understood; `issuingDistributionPoint` and `deltaCRLIndicator` are refused however they are marked, and so is any other critical extension of the list or of an entry (`certificateIssuer` of an indirect list, for instance): verdict `CRL_EXT`, naming the extension. Non-critical unknown extensions (a `reasonCode` on an entry, for instance) are ignored.
- **End entity**: not a CA, `digitalSignature`, the extended key usage of the purpose, and the host name or IPv4 address in the subject alternative name.
- **The declared algorithm is the issuer key's** (since 2026-10-19; AIP-25, finding C3): the signature algorithm a certificate declares must be the algorithm of its issuer's public key, and a trusted root's must be that of its own key (verdict `ALG_KEY`); a revocation list that verifies under its issuer's key but declares another algorithm is `CRL_ALG_KEY` (RFC 5280 Sections 4.1.2.3 and 5.1.2.2; RFC 9881). Until then a certificate declaring `id-ml-dsa-87`, signed with an ML-DSA-44 key, passed: the signature was verified with whatever key the issuer has, so a policy that reads the declared algorithm was misled. OpenSSL 3.5 refuses the same cases (`unable to get local issuer certificate`, `CRL signature failure`), measured in `test/proba.mjs`.
Every refusal carries a code: `SIGNATURE`, `UNTRUSTED`, `ROOT`, `EXPIRED`, `NOT_YET_VALID`, `NOT_CA`, `KEY_USAGE`, `PATH_LEN`, `EKU`, `SPKI`, `REVOKED`, `CRL_MISSING`, `CRL_SIGNATURE`, `CRL_STALE`, `CRL_EXT`, `LEAF_IS_CA`, `HOSTNAME`, `CRITICAL_EXT`, `ALG`, `ALG_MISMATCH`, `ALG_PARAMS`, `VERSION`, `EXT_DUP`, `DER`. The DER parser is strict: no indefinite lengths, no non-minimal lengths, no trailing bytes, no non-canonical integers or object identifiers; object identifiers with a multi-byte first subidentifier (`2.999` is `06 02 88 37`) encode and decode as OpenSSL does.
Every refusal carries a code: `SIGNATURE`, `UNTRUSTED`, `ROOT`, `EXPIRED`, `NOT_YET_VALID`, `NOT_CA`, `KEY_USAGE`, `PATH_LEN`, `EKU`, `SPKI`, `REVOKED`, `CRL_MISSING`, `CRL_SIGNATURE`, `CRL_STALE`, `CRL_EXT`, `CRL_ALG_KEY`, `ALG_KEY`, `LEAF_IS_CA`, `HOSTNAME`, `CRITICAL_EXT`, `ALG`, `ALG_MISMATCH`, `ALG_PARAMS`, `VERSION`, `EXT_DUP`, `DER`. The DER parser is strict: no indefinite lengths, no non-minimal lengths, no trailing bytes, no non-canonical integers or object identifiers; object identifiers with a multi-byte first subidentifier (`2.999` is `06 02 88 37`) encode and decode as OpenSSL does.
## How it is proven
`node test/proba.mjs` (27 probes, about 25 s) compares every verdict with a foreign implementation, the OpenSSL 3.5 command line in `-x509_strict` mode: the valid chain, revocation, the newest of several lists (both orders), lists made by `openssl ca -gencrl` (plain, with a revoked entry and a reason code, with a critical issuing distribution point, with an unknown critical extension), a delta list (OpenSSL refuses it only with `-extended_crl`), a changed byte, another root, expiry and not-yet-valid, a path-length violation, a non-CA issuer (a chain made by OpenSSL), host and IP names, purpose on the leaf and on authorities (`unsuitable certificate purpose` at depth 1), a renewed root (both anchors in one `CAfile`), malformed public keys (`decode error`), an unknown critical extension (made by OpenSSL), object identifier bytes (`asn1parse -genstr`). It also reads and verifies certificates made by OpenSSL, runs the real TLS handshake, measures the cost of a passphrase guess, exercises the passphrase policy, and drives the command line end to end. `node test/control-negativ.mjs` (about 3 minutes, four plantings in parallel) breaks each check in a copy of the code (22 plantings, at least one per finding of the review) and requires the named probe to turn red, the original to stay byte-identical, and the untouched suite to stay green; the number of probes is taken from the untouched run, not written down.
`node test/proba.mjs` (28 probes, about 25 s) compares every verdict with a foreign implementation, the OpenSSL 3.5 command line in `-x509_strict` mode: the valid chain, revocation, the newest of several lists (both orders), lists made by `openssl ca -gencrl` (plain, with a revoked entry and a reason code, with a critical issuing distribution point, with an unknown critical extension), a delta list (OpenSSL refuses it only with `-extended_crl`), a changed byte, another root, expiry and not-yet-valid, a path-length violation, a non-CA issuer (a chain made by OpenSSL), host and IP names, purpose on the leaf and on authorities (`unsuitable certificate purpose` at depth 1), a renewed root (both anchors in one `CAfile`), malformed public keys (`decode error`), an unknown critical extension (made by OpenSSL), object identifier bytes (`asn1parse -genstr`). It also reads and verifies certificates made by OpenSSL, runs the real TLS handshake, measures the cost of a passphrase guess, exercises the passphrase policy, and drives the command line end to end. `node test/control-negativ.mjs` (about 3 minutes, four plantings in parallel) breaks each check in a copy of the code (26 plantings, at least one per finding of the review and four for C3) and requires the named probe to turn red, the original to stay byte-identical, and the untouched suite to stay green; the number of probes is taken from the untouched run, not written down.
## What it does not do, and where it differs from OpenSSL
+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) {
+5
View File
@@ -45,6 +45,11 @@ const PLANTARI = [
['[A7] numai primul intermediar candidat', 'pki.mjs', 'certs.inter.filter((c) => c !== cur && !stiva.includes(c) && emite(c, cur)) : [];', 'certs.inter.filter((c) => c !== cur && !stiva.includes(c) && emite(c, cur)).slice(0, 1) : [];', 'reinnoirea radacinii'],
['[A10] primul subidentificator OID scris pe un singur octet', 'der.mjs', ' const out = base128(p[0] * 40n + p[1]);', ' const out = [Number((p[0] * 40n + p[1]) & 0x7fn)];', 'OID'],
['[A10] arcul OID dedus fara regula de 80', 'der.mjs', ' const arc = first < 80n ? first / 40n : 2n;', ' const arc = first / 40n;', 'OID'],
// 2026-10-19 (AIP-25 C3, D-537): algoritmul declarat e al cheii emitentului; fiecare paznic nou scos pe rand
['[AIP-25 C3] algoritmul declarat de un certificat nu mai e legat de cheia emitentului', 'pki.mjs', "if (!(c.alg === p.pkAlg)) return fail('ALG_KEY'", "if (!(c.alg === p.pkAlg) && Boolean(Number('0'))) return fail('ALG_KEY'", 'algoritmul declarat e al cheii emitentului'],
['[AIP-25 C3] radacina declara alt algoritm decat propria cheie', 'pki.mjs', "if (!(top.alg === top.pkAlg)) return fail('ALG_KEY'", "if (!(top.alg === top.pkAlg) && Boolean(Number('0'))) return fail('ALG_KEY'", 'algoritmul declarat e al cheii emitentului'],
['[AIP-25 C3] lista de revocare declara alt algoritm decat cheia emitentului', 'pki.mjs', 'const altAlg = verificate.find((l) => !(l.alg === p.pkAlg));', "const altAlg = verificate.find((l) => !(l.alg === p.pkAlg) && Boolean(Number('0')));", 'algoritmul declarat e al cheii emitentului'],
['[AIP-25 C3] selfSignatureValid nu mai cere algoritmul cheii', 'pki.mjs', 'return c.alg === c.pkAlg && c.subjectRaw.equals(c.issuerRaw)', 'return c.subjectRaw.equals(c.issuerRaw)', 'algoritmul declarat e al cheii emitentului'],
];
// 1. martorul: originalul trebuie sa fie verde, si din el se ia numarul de probe
+41
View File
@@ -268,6 +268,47 @@ await test('forma: algoritm exterior diferit de cel interior (ALG_MISMATCH), par
e = null; try { P.parseCert(Buffer.concat([leaf, Buffer.from([0])])); } catch (x) { e = x; } has(e && e.message, 'bytes after the structure', 'coada');
const nc = Buffer.from([0x30, 0x81, 0x03, 0x02, 0x01, 0x05]); e = null; try { P.parseCert(nc); } catch (x) { e = x; } has(e && e.message, 'non-canonical', 'lungime lunga pentru una scurta');
});
// AIP-25 C3 (D-537, 2026-10-19): algoritmul de semnatura pe care il declara un certificat (si o lista de revocare) e cel al CHEII emitentului
// (RFC 5280 s.4.1.2.3 si 5.1.2.2: algoritmul cu care a semnat CA-ul; RFC 9881: ML-DSA-44/65/87 sunt trei algoritmi). Pana atunci semnatura se
// verifica cu cheia emitentului oricare ar fi algoritmul declarat, deci o politica ce citeste algoritmul declarat era mintita. Cazurile sunt
// facute aici: TBS-ul cu OID-ul de semnatura schimbat, RESEMNAT cu cheia adevarata a emitentului (semnatura e buna, numai declaratia minte).
const OIDS = { 'ml-dsa-44': '0609608648016503040311', 'ml-dsa-65': '0609608648016503040312', 'ml-dsa-87': '0609608648016503040313' };
function declara(der, din, cu, cheie) {
const [tbsEl] = Dm.children(Dm.parse(der)); const tbs = Buffer.from(tbsEl.raw);
const a = Buffer.from(OIDS[din], 'hex'), p = tbs.indexOf(a); if (p < 0) throw new Error('fixtura: OID-ul ' + din + ' nu e in TBS');
const t2 = Buffer.from(tbs); Buffer.from(OIDS[cu], 'hex').copy(t2, p);
return Dm.seq(t2, Dm.seq(Dm.oid(P.ALG[cu])), Dm.bits(crypto.sign(null, t2, cheie)));
}
await test('algoritmul declarat e al cheii emitentului [AIP-25 C3]: o frunza care declara ml-dsa-87, semnata de o radacina ml-dsa-44: ALG_KEY la noi, "unable to get local issuer" la OpenSSL; o radacina care declara alt algoritm decat cheia ei: ALG_KEY, si la OpenSSL nu e auto-semnata; o lista de revocare care declara alt algoritm: CRL_ALG_KEY la noi, "CRL signature failure" la OpenSSL; martorul aceleiasi forme, cu algoritmul adevarat: OK la amandoi', () => {
const k44 = P.generateKey('ml-dsa-44'), k65 = P.generateKey('ml-dsa-65');
const r44 = P.issue({ issuer: null, signingKey: k44.privateKey, subject: { cn: 'C3 Root 44' }, publicKey: k44.publicKey, ca: true, pathLen: 0, days: 2 });
const fr = P.issue({ issuer: r44, signingKey: k44.privateKey, subject: { cn: 'localhost' }, publicKey: k65.publicKey, days: 1, dns: ['localhost'], eku: ['serverAuth'] });
const fr87 = declara(fr, 'ml-dsa-44', 'ml-dsa-87', k44.privateKey);
eq(P.parseCert(fr87).alg, 'ml-dsa-87', 'fixtura: frunza declara ml-dsa-87');
const martor = declara(fr, 'ml-dsa-44', 'ml-dsa-44', k44.privateKey); // aceeasi constructie, algoritmul adevarat: trebuie sa treaca
eq(P.verifyChain({ leaf: martor, roots: [r44], host: 'localhost' }).ok, true, 'martorul resemnat cu algoritmul adevarat');
const v = P.verifyChain({ leaf: fr87, roots: [r44], host: 'localhost' }); eq(v.code, 'ALG_KEY', 'noi, frunza ' + v.reason); has(v.reason, 'ml-dsa-87', 'motivul numeste algoritmul declarat'); has(v.reason, 'ml-dsa-44', 'motivul numeste cheia emitentului');
const fR = w('c3-r44.pem', r44), fM = w('c3-martor.pem', martor), fF = w('c3-fr87.pem', fr87);
eq(ossl(['verify', '-x509_strict', '-purpose', 'sslserver', '-CAfile', fR, fM]).code, 0, 'openssl martorul');
const of = ossl(['verify', '-x509_strict', '-purpose', 'sslserver', '-CAfile', fR, fF]); eq(of.code === 0, false, 'openssl frunza ' + of.out); has(of.out, 'unable to get local issuer', 'openssl frunza');
// radacina auto-semnata cu cheia ml-dsa-44 care declara ml-dsa-87
const r87 = declara(r44, 'ml-dsa-44', 'ml-dsa-87', k44.privateKey);
const vr = P.verifyChain({ leaf: fr, roots: [r87], host: 'localhost' }); eq(vr.code, 'ALG_KEY', 'noi, radacina ' + vr.reason);
eq(P.selfSignatureValid(r87), false, 'selfSignatureValid pe radacina care minte'); eq(P.selfSignatureValid(r44), true, 'selfSignatureValid pe radacina buna');
has(ossl(['verify', '-x509_strict', '-CAfile', w('c3-r87.pem', r87), f('c3-r87.pem')]).out, 'unable to get local issuer', 'openssl radacina');
// lista de revocare a radacinii, semnata cu cheia ml-dsa-44, care declara ml-dsa-87; martorul: aceeasi lista cu algoritmul adevarat
const l = P.crl({ issuer: r44, signingKey: k44.privateKey, revoked: [], days: 7, number: 1 });
const l87 = declara(l, 'ml-dsa-44', 'ml-dsa-87', k44.privateKey), lm = declara(l, 'ml-dsa-44', 'ml-dsa-44', k44.privateKey);
eq(P.verifyChain({ leaf: fr, roots: [r44], host: 'localhost', crls: [lm], requireCrl: true }).ok, true, 'martorul listei');
const vl = P.verifyChain({ leaf: fr, roots: [r44], host: 'localhost', crls: [l87], requireCrl: true }); eq(vl.code, 'CRL_ALG_KEY', 'noi, lista ' + vl.reason);
const ol = ossl(['verify', '-x509_strict', '-purpose', 'sslserver', '-crl_check', '-CAfile', fR, '-CRLfile', w('c3-l87.pem', l87, 'X509 CRL'), w('c3-fr.pem', fr)]);
eq(ol.code === 0, false, 'openssl lista ' + ol.out); has(ol.out, 'CRL signature failure', 'openssl lista');
// o cheie ml-dsa-44 (1312 octeti) declarata ml-dsa-87 in SPKI e refuzata la citire (lungimea FIPS 204), inainte de orice semnatura
const sp = Buffer.from(P.parseCert(fr).spki); const s87 = Buffer.from(sp); const po = s87.indexOf(Buffer.from(OIDS['ml-dsa-65'], 'hex')); Buffer.from(OIDS['ml-dsa-87'], 'hex').copy(s87, po);
const tbsS = Dm.seq(...Dm.children(Dm.parse(P.parseCert(fr).tbs)).map((x) => (x.raw.equals(sp) ? s87 : x.raw)));
let e = null; try { P.parseCert(Dm.seq(tbsS, Dm.seq(Dm.oid(P.ALG['ml-dsa-44'])), Dm.bits(crypto.sign(null, tbsS, k44.privateKey)))); } catch (x) { e = x; } eq(e && e.code, 'SPKI', 'cheia 65 declarata 87 in SPKI');
return 'OpenSSL: frunza "' + (of.out.split('\n').find((x) => /error \d+/.test(x)) || '').trim() + '"; lista "' + (ol.out.split('\n').find((x) => /error \d+/.test(x)) || '').trim() + '"';
});
// [A5] SPKI
const cuSpkiRau = (der) => { const c = P.parseCert(der); const [algEl] = Dm.children(Dm.parse(c.spki)); const s = Dm.seq(algEl.raw, Dm.bits(Buffer.alloc(10, 7))); return { c, tbs: Dm.seq(...Dm.children(Dm.parse(c.tbs)).map((k) => (k.raw.equals(c.spki) ? s : k.raw))) }; };
await test('cheie publica malformata [A5]: SPKI de 10 octeti sub id-ml-dsa pe frunza, pe intermediar si pe radacina: verdict SPKI (cu lungimea) la noi, fara exceptie; "decode error" la OpenSSL; o cheie de 1312 octeti sub id-ml-dsa-65 e tot SPKI', () => {