identity: verify-sdjwt on the command line (an SD-JWT+KB checked with the issuer key you give; Aere Cloud runs it behind POST /v1/identity/sd-jwt/verify)

The issuer key (a public JWK, or the public keys of an AERE identity) is checked first: one that cannot be read, is private, or is not
a key for the algorithm asked exits 2 with the reason, instead of reporting the token INVALID. --json prints compact JSON (indented
output grew with the square of the claims' nesting depth). --at judges at a given time, as for verify. Test on the RFC 9901 example
presentation: valid at its own time, invalid now, a private key refused. Tests: SD-JWT 23/23, negative control 28/28; identity 44/44,
negative control 49/49.
This commit is contained in:
Aere Network committed 2026-09-30 13:17:07 +03:00
1 parent 4ffec8d7e3
commit 5f1e60b8d2
6 files changed
+54 -6

No files matched your search

+4 -1
View File
@@ -163,6 +163,9 @@ const shown = presentSdJwt({ sdJwt, reveal: ['age_over_18', { element: 'RO', in:
const r = verifySdJwt(shown, { issuerKey, audience, nonce, expectedIssuer: 'https://issuer.example' }); // { valid, reason, payload, disclosed, keyBinding }
```
From the command line (the issuer key a public JWK, or the output of `pub`): `node identity-cli.mjs verify-sdjwt --sd-jwt token.txt --issuer-key issuer.pub.json
--issuer-alg EdDSA --audience A --nonce N [--expected-issuer I] [--at T] [--json]`; Aere Cloud runs it behind `POST /v1/identity/sd-jwt/verify`.
Checked against the standard's own vectors (`fixturi-rfc9901.json`, extracted from RFC 9901 Section 5 and Appendix A.5; IETF code
components, Revised BSD License): the digest of each of the ten example disclosures; the example SD-JWT, signed ES256 by someone
else with the key in A.5, verifies and rebuilds every input claim; the example presentation with its Key Binding JWT verifies and
@@ -195,7 +198,7 @@ node proba-conformitate.mjs # 15: compliance policies judged on real pr
node control-negativ-conformitate.mjs # on a copy, each of 14 guards removed -> its own named test turns red
node proba-travel-rule.mjs # 19: two VASPs with registry credentials, the whole exchange, and each attack of the review
node control-negativ-travel-rule.mjs # on a copy, each of 19 guards removed -> its own named test turns red
node proba-sdjwt.mjs # 22: the RFC 9901 vectors, SD-JWTs issued with AERE keys (EdDSA and ML-DSA-65), each attack
node proba-sdjwt.mjs # 23: the RFC 9901 vectors, SD-JWTs issued with AERE keys (EdDSA and ML-DSA-65), each attack
node control-negativ-sdjwt.mjs # on a copy, each of 28 guards removed -> its own named test turns red
```
+2 -1
View File
@@ -63,7 +63,8 @@ const PLANTARI = [
['o lista stricata acuza credentialul', L, "verifyText('status-list', canonical(l.statement), l.signature, S.issuer.keys); } catch { return false; } });", "verifyText('status-list', canonical(l.statement), l.signature, S.issuer.keys); } catch (e) { throw e; } });", 'intrari stricate date verificatorului'],
['o revocare stricata acuza prezentarea', L, "try { canonical(R); } catch { nejudecat(`${et}: a revocation`, 'ignored: not readable'); continue; }", '', 'intrari stricate date verificatorului'],
['linia de comanda suprascrie o cheie', C, 'if (privat && fs.existsSync(f)) throw new Folosire(', 'if (false) throw new Folosire(', 'linia de comanda'],
['verify din linia de comanda iese 0 si pe INVALID', C, 'return r.valid ? 0 : 1;', 'return 0;', 'linia de comanda'],
// 2026-09-30: tiparul poarta randul de dinainte, fiindca verify-sdjwt are si el `return r.valid ? 0 : 1;`
['verify din linia de comanda iese 0 si pe INVALID', C, "JSON.stringify(r.claims));\n }\n return r.valid ? 0 : 1;", "JSON.stringify(r.claims));\n }\n return 0;", 'linia de comanda'],
];
const FISIERE = [L, C, 'proba-identity.mjs'];
function copie() {
+1 -1
View File
@@ -44,7 +44,7 @@ const PLANTARI = [
];
function copie() {
const t = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-sdjwt-ctl-'));
for (const f of [S, 'identity.mjs', 'proba-sdjwt.mjs', 'fixturi-rfc9901.json']) fs.copyFileSync(path.join(AICI, f), path.join(t, f));
for (const f of [S, 'identity.mjs', 'identity-cli.mjs', 'proba-sdjwt.mjs', 'fixturi-rfc9901.json']) fs.copyFileSync(path.join(AICI, f), path.join(t, f));
return t;
}
function ruleaza(t) {
+31 -1
View File
@@ -15,9 +15,13 @@
// 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
// [--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)
// 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';
import crypto from 'node:crypto';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as I from './identity.mjs';
@@ -124,7 +128,33 @@ 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;
}
throw new Folosire('usage: identity-cli.mjs keygen|pub|id|issue|status-list|delegate|revoke|present|verify|comply ... (see README.md)');
if (cmd === 'verify-sdjwt') {
// 2026-09-30: SD-JWT (IETF RFC 9901) cu sdjwt.mjs; jetonul dintr-un fisier text (serializarea compacta, fara spatii)
const { verifySdJwt, publicJwk } = await import('./sdjwt.mjs');
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 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 } : {}) });
// 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);
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)');
}
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; });
+14
View File
@@ -4,6 +4,8 @@
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
import os from 'node:os';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import * as I from './identity.mjs';
import * as J from './sdjwt.mjs';
@@ -193,5 +195,17 @@ test('REVIZUIRE: crit (orice forma), base64url necanonic al semnaturii, KB expir
cere(refuz(judeca(baza + kbExp), /key binding: expired/), 'KB expirat a trecut');
});
test('linia de comanda: verify-sdjwt pe prezentarea RFC 9901 s.5.2 -> 0 VALID la momentul ei (--at), 1 INVALID acum (KB vechi); o cheie privata -> 2', () => {
const T = fs.mkdtempSync(path.join(os.tmpdir(), 'aere-sdjwt-cli-'));
try {
fs.writeFileSync(path.join(T, 'p.txt'), F.presentation); fs.writeFileSync(path.join(T, 'k.json'), JSON.stringify(F.issuerJwk));
const run = (...a) => spawnSync(process.execPath, [path.join(AICI, 'identity-cli.mjs'), 'verify-sdjwt', '--sd-jwt', 'p.txt', '--issuer-key', 'k.json', '--issuer-alg', 'ES256', '--audience', KB.aud, '--nonce', KB.nonce, ...a], { cwd: T, encoding: 'utf8' });
const a = run('--at', new Date(KB.iat * 1000).toISOString(), '--json'); cere(a.status === 0 && JSON.parse(a.stdout).valid === true, 'la iat: ' + a.status + ' ' + a.stderr);
const b = run(); cere(b.status === 1 && /outside 300 s/.test(b.stdout), 'acum: ' + b.status + ' ' + b.stdout);
fs.writeFileSync(path.join(T, 'k.json'), JSON.stringify(crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' }).privateKey.export({ format: 'jwk' })));
const c = run(); cere(c.status === 2 && /private JWK/.test(c.stderr), 'cheia privata: ' + c.status + ' ' + c.stderr);
} finally { fs.rmSync(T, { recursive: true, force: true }); }
});
console.log(`\naere-sd-jwt: ${treceri}/${treceri + esecuri.length} cum trebuia`);
process.exitCode = esecuri.length ? 1 : 0;