identity: SD-JWT interoperability measured in both directions with @sd-jwt/core 0.23.0 and jose 6.2.12 (ML-DSA-65 included), nested _sd_alg refused, the SD-JWT VC profile (draft-19, dc+sd-jwt, vct, Token Status List offline); conformance: SD-JWT and SD-JWT VC enrolled (213 rules, 13 verifiers, 553 vectors)
This commit is contained in:
1 parent
fab02f7952
commit
e1bb4e25d8
109 files changed
+9823
-175
No files matched your search
+38
-15
@@ -18,6 +18,10 @@
|
||||
// verify-sdjwt --sd-jwt f.txt --issuer-key k.json [--issuer-alg EdDSA|ML-DSA-65|ES256] --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 ...]
|
||||
// [--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)
|
||||
// Coduri de iesire: 0 VALID / COMPLIANT, 1 INVALID / NOT COMPLIANT, 2 intrare respinsa (motivul pe stderr, `error: ...`).
|
||||
// O valoare de --claim se citeste ca JSON daca e JSON (true, 42, {"a":1}), altfel ca text.
|
||||
import fs from 'node:fs';
|
||||
@@ -128,33 +132,52 @@ async function main() {
|
||||
else console.log(r.compliant ? `COMPLIANT with ${r.policyId} (${r.policyHash})` : `NOT COMPLIANT with ${r.policyId}:\n ` + r.reasons.join('\n '));
|
||||
return r.compliant ? 0 : 1;
|
||||
}
|
||||
if (cmd === 'verify-sdjwt') {
|
||||
if (cmd === 'verify-sdjwt' || cmd === 'verify-sdjwt-vc') {
|
||||
// 2026-09-30: SD-JWT (IETF RFC 9901) cu sdjwt.mjs; jetonul dintr-un fisier text (serializarea compacta, fara spatii)
|
||||
// 2026-10-18: verify-sdjwt-vc, profilul SD-JWT VC (sdjwt-vc.mjs): --expected-vct cerut, --status-list <fisier cu Status List Token-ul
|
||||
// adus de verificator> (altfel, cu `status` in jeton, INVALID: stare nejudecata; --status-not-required o lasa nejudecata si o spune)
|
||||
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}`); }
|
||||
const cheie = citeste(cere('--issuer-key'));
|
||||
const alg = get('--issuer-alg') ?? 'EdDSA';
|
||||
if (!['EdDSA', 'Ed25519', 'ES256', 'ML-DSA-65'].includes(alg)) throw new Folosire('--issuer-alg is EdDSA, ES256 or ML-DSA-65');
|
||||
// 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)
|
||||
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 cere2 = alg === 'ES256' ? k.asymmetricKeyType === 'ec' && k.asymmetricKeyDetails.namedCurve === 'prime256v1' : alg === 'ML-DSA-65' ? k.asymmetricKeyType === 'ml-dsa-65' : k.asymmetricKeyType === 'ed25519';
|
||||
if (!cere2) throw new Error(`the key is a ${k.asymmetricKeyType} key, not one for ${alg}`);
|
||||
} catch (e) { throw new Folosire('--issuer-key: ' + String(e.message || e).replace(/^sd-jwt: /, '').slice(0, 160)); }
|
||||
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)); }
|
||||
};
|
||||
const cheie = citeste(cere('--issuer-key'));
|
||||
const alg = get('--issuer-alg') ?? 'EdDSA';
|
||||
cheiePublicaBuna('--issuer-key', cheie, alg);
|
||||
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 r = verifySdJwt(jeton, { 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: alg, 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;
|
||||
if (statusListKey) cheiePublicaBuna('--status-list-key', statusListKey, statusListAlg);
|
||||
r = verifySdJwtVc(jeton, { ...comune, expectedVct: vcts, statusListJwt, statusListKey, statusListAlg, requireStatus: !are('--status-not-required') });
|
||||
}
|
||||
// JSON compact: cu indentare, iesirea creste cu patratul adancimii afirmatiilor (un jeton de 7 KB imbricat de 2.500 de ori dadea 6 MB)
|
||||
if (are('--json')) console.log(JSON.stringify(r));
|
||||
else console.log(r.valid ? `VALID: issued by ${r.issuer}${r.issuerChecked ? '' : ' (not checked against an expected issuer)'}; disclosed: ${r.disclosed.join(', ') || 'nothing'}` : 'INVALID: ' + r.reason);
|
||||
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}`);
|
||||
}
|
||||
return r.valid ? 0 : 1;
|
||||
}
|
||||
throw new Folosire('usage: identity-cli.mjs keygen|pub|id|issue|status-list|delegate|revoke|present|verify|comply|verify-sdjwt ... (see README.md)');
|
||||
throw new Folosire('usage: identity-cli.mjs keygen|pub|id|issue|status-list|delegate|revoke|present|verify|comply|verify-sdjwt|verify-sdjwt-vc ... (see README.md)');
|
||||
}
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
main().then((c) => { process.exitCode = c; }, (e) => { console.error('error: ' + (e.message || e)); process.exitCode = e instanceof Folosire ? 2 : 1; });
|
||||
|
||||
Reference in new issue
Block a user