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

+30 -17
View File
@@ -15,10 +15,11 @@
// comply --presentation p.json --policy policy.json --audience A --nonce N [--status-list l.json ...] [--revocation r.json ...]
// [--record record.json] [--pseudonym-key-file k] a compliance policy judged; the record carries no personal data
// [--json [--with-record]] [--at T] the whole result as one JSON object (with the record inside)
// verify-sdjwt --sd-jwt f.txt --issuer-key k.json [--issuer-alg EdDSA|ML-DSA-65|ES256] --audience A --nonce N
// verify-sdjwt --sd-jwt f.txt --issuer-key k.json [--issuer-alg EdDSA|ML-DSA-65|ES256] [--classical-half] --audience A --nonce N
// [--expected-issuer I] [--expected-typ T] [--max-age S] [--at T] [--json] an SD-JWT+KB (IETF RFC 9901), sdjwt.mjs;
// the issuer key is a public JWK or the public keys of an AERE identity (the output of pub)
// verify-sdjwt-vc --sd-jwt f.txt --issuer-key k.json [--issuer-alg A] --audience A --nonce N --expected-vct V [--expected-vct V2 ...]
// the issuer key is a public JWK or the public keys of an AERE identity (the output of pub). With AERE keys the ML-DSA-65
// half is judged; the Ed25519 half only with --classical-half (2026-10-19, AIP-25 C1), and then the verdict says postQuantum false
// verify-sdjwt-vc --sd-jwt f.txt --issuer-key k.json [--issuer-alg A] [--classical-half] --audience A --nonce N --expected-vct V [--expected-vct V2 ...]
// [--status-list f.txt [--status-list-key k.json] [--status-list-alg A]] [--status-not-required] [--expected-issuer I]
// [--max-age S] [--at T] [--json] an SD-JWT VC (draft-ietf-oauth-sd-jwt-vc), sdjwt-vc.mjs; the status list is the Token
// Status List JWT the verifier fetched from the uri the credential names (without it a credential with `status` is INVALID)
@@ -139,32 +140,42 @@ async function main() {
const { verifySdJwt, publicJwk } = await import('./sdjwt.mjs');
const vc = cmd === 'verify-sdjwt-vc';
let jeton; try { jeton = fs.readFileSync(cere('--sd-jwt'), 'utf8').trim(); } catch (e) { throw new Folosire(`cannot read --sd-jwt: ${e.message}`); }
// 2026-10-19 (AIP-25 C1, D-535): cu cheile publice ale unei identitati AERE (iesirea lui `pub`), fara --issuer-alg se judeca jumatatea
// ML-DSA-65; jumatatea Ed25519 numai cu --classical-half (si verdictul spune postQuantum false). Pana atunci implicitul era EdDSA, deci
// jumatatea clasica singura. Pentru un JWK simplu, --issuer-alg ramane cum era (implicit EdDSA, verificat contra cheii).
const classicalHalf = are('--classical-half');
const aere = (k) => !!k && typeof k === 'object' && k.alg === I.ALG;
// revizuirea din 30 sept: cheia emitentului e intrarea VERIFICATORULUI; una care nu se citeste, e privata sau nu e a algoritmului cerut e o
// greseala a lui (cod 2, cu motivul), nu un credential INVALID (cheile stricate ieseau INVALID cu mesajul Node)
// greseala a lui (cod 2, cu motivul), nu un credential INVALID (cheile stricate ieseau INVALID cu mesajul Node). Pentru chei AERE se
// citesc jumatatile pe care verificarea le poate folosi; cererea jumatatii Ed25519 fara --classical-half nu e o greseala de intrare, ci
// un refuz al verificatorului (INVALID, regula hybrid-half), ca jetonul doar-Ed25519
const cheiePublicaBuna = (optiune, cheie, alg) => {
if (!['EdDSA', 'Ed25519', 'ES256', 'ML-DSA-65'].includes(alg)) throw new Folosire(`${optiune}-alg is EdDSA, ES256 or ML-DSA-65`);
try {
const jwk = publicJwk(cheie, alg);
if ('d' in jwk || 'priv' in jwk) throw new Error('a private JWK was given where a public key belongs');
const k = crypto.createPublicKey({ key: jwk, format: 'jwk' });
const buna = alg === 'ES256' ? k.asymmetricKeyType === 'ec' && k.asymmetricKeyDetails.namedCurve === 'prime256v1' : alg === 'ML-DSA-65' ? k.asymmetricKeyType === 'ml-dsa-65' : k.asymmetricKeyType === 'ed25519';
if (!buna) throw new Error(`the key is a ${k.asymmetricKeyType} key, not one for ${alg}`);
} catch (e) { if (e instanceof Folosire) throw e; throw new Folosire(`${optiune}: ` + String(e.message || e).replace(/^sd-jwt: /, '').slice(0, 160)); }
if (alg != null && !['EdDSA', 'Ed25519', 'ES256', 'ML-DSA-65'].includes(alg)) throw new Folosire(`${optiune}-alg is EdDSA, ES256 or ML-DSA-65`);
const deCitit = !aere(cheie) ? [alg ?? 'EdDSA'] : alg != null ? (['EdDSA', 'Ed25519'].includes(alg) && !classicalHalf ? [] : [alg]) : (classicalHalf ? ['ML-DSA-65', 'EdDSA'] : ['ML-DSA-65']);
for (const a of deCitit) {
try {
const jwk = publicJwk(cheie, a, { classicalHalf: true });
if ('d' in jwk || 'priv' in jwk) throw new Error('a private JWK was given where a public key belongs');
const k = crypto.createPublicKey({ key: jwk, format: 'jwk' });
const buna = a === 'ES256' ? k.asymmetricKeyType === 'ec' && k.asymmetricKeyDetails.namedCurve === 'prime256v1' : a === 'ML-DSA-65' ? k.asymmetricKeyType === 'ml-dsa-65' : k.asymmetricKeyType === 'ed25519';
if (!buna) throw new Error(`the key is a ${k.asymmetricKeyType} key, not one for ${a}`);
} catch (e) { if (e instanceof Folosire) throw e; throw new Folosire(`${optiune}: ` + String(e.message || e).replace(/^sd-jwt: /, '').slice(0, 160)); }
}
};
const cheie = citeste(cere('--issuer-key'));
const alg = get('--issuer-alg') ?? 'EdDSA';
cheiePublicaBuna('--issuer-key', cheie, alg);
const algDat = get('--issuer-alg');
cheiePublicaBuna('--issuer-key', cheie, algDat);
const maxAgeS = Number(get('--max-age') ?? 300);
if (!Number.isInteger(maxAgeS) || maxAgeS < 1 || maxAgeS > 3600) throw new Folosire('--max-age is a number of seconds, 1..3600');
const tip = get('--expected-typ');
const comune = { issuerKey: cheie, issuerAlg: alg, audience: cere('--audience'), nonce: cere('--nonce'), expectedIssuer: get('--expected-issuer'), maxAgeS, now: momentul(), ...(tip != null ? { expectedTyp: tip } : {}) };
const comune = { issuerKey: cheie, issuerAlg: algDat ?? (aere(cheie) ? undefined : 'EdDSA'), classicalHalf, audience: cere('--audience'), nonce: cere('--nonce'), expectedIssuer: get('--expected-issuer'), maxAgeS, now: momentul(), ...(tip != null ? { expectedTyp: tip } : {}) };
let r;
if (!vc) r = verifySdJwt(jeton, comune);
else {
const { verifySdJwtVc } = await import('./sdjwt-vc.mjs');
const vcts = toate('--expected-vct'); if (!vcts.length) throw new Folosire('verify-sdjwt-vc needs --expected-vct <vct> (the credential type the verifier expects; may be repeated)');
let statusListJwt = null; if (get('--status-list')) { try { statusListJwt = fs.readFileSync(get('--status-list'), 'utf8').trim(); } catch (e) { throw new Folosire(`cannot read --status-list: ${e.message}`); } }
const statusListKey = get('--status-list-key') ? citeste(get('--status-list-key')) : null, statusListAlg = get('--status-list-alg') ?? alg;
const statusListKey = get('--status-list-key') ? citeste(get('--status-list-key')) : null, statusListAlg = get('--status-list-alg') ?? algDat ?? undefined;
if (statusListKey) cheiePublicaBuna('--status-list-key', statusListKey, statusListAlg);
r = verifySdJwtVc(jeton, { ...comune, expectedVct: vcts, statusListJwt, statusListKey, statusListAlg, requireStatus: !are('--status-not-required') });
}
@@ -173,7 +184,9 @@ async function main() {
else if (!r.valid) console.log('INVALID: ' + r.reason);
else {
const stare = !vc ? '' : '; status ' + (r.status.judged ? `${r.status.value} (${r.status.name}) in ${r.status.uri} at ${r.status.idx}` : r.status.present ? `not judged (${r.status.uri ?? r.status.mechanism})` : 'none');
console.log(`VALID: issued by ${r.issuer}${r.issuerChecked ? '' : ' (not checked against an expected issuer)'}${vc ? `; vct ${r.vct}` : ''}; disclosed: ${r.disclosed.join(', ') || 'nothing'}${stare}`);
// AIP-25 C1: textul spune si daca fiecare semnatura judecata e post-cuantica (in --json: postQuantum)
const pq = r.postQuantum ? '; post-quantum: every signature judged is ML-DSA-65' : `; NOT post-quantum: the issuer signed ${r.alg}${r.keyBinding ? ', the key binding ' + r.keyBinding.alg : ''}${vc && r.status && r.status.judged ? ' (or the status list is not ML-DSA-65)' : ''}`;
console.log(`VALID: issued by ${r.issuer}${r.issuerChecked ? '' : ' (not checked against an expected issuer)'}${vc ? `; vct ${r.vct}` : ''}; disclosed: ${r.disclosed.join(', ') || 'nothing'}${stare}${pq}`);
}
return r.valid ? 0 : 1;
}