pq-secrets: a zero-trust secrets service on top of pq-kms (each request authorized by an Aere Identity presentation signed for that exact request, per-secret policy whose non-admin grants can only narrow, the same refusal for every unauthorized caller, every operation a signed AIP-23 secret-access envelope); identity: a presentation optionally signed for one exact request; proof-kinds: secret-access with requestHash; conformance 240 rules, 626 vectors

This commit is contained in:
Aere Network committed 2026-10-19 00:30:58 +03:00
1 parent 8c7d72c1a7
commit ad16b1f69b
97 files changed
+4258 -133

No files matched your search

+25 -6
View File
@@ -259,20 +259,30 @@ export function statusBit(list, index) {
}
// ---------------------------------------------------------------- prezentarea
// CEREREA (2026-10-18, B8, revizuirea adversariala a lui pq-secrets): fara ea, semnatura prezentatorului acopera verificatorul, nonce-ul
// si momentul, dar NU ce i se cere verificatorului; o prezentare facuta pentru "citeste db" a fost depusa ca "revoca grantul" pe db.
// `request` e digestul cererii pe care detinatorul o face (0x + 64 hex, calculat de verificator intr-un singur loc, din cerere), pus in
// legatura INAINTE de semnare; verificatorul care il da cere ca legatura sa poarte exact acel digest. Modelul, citit 2026-10-18: OpenID
// for Verifiable Presentations 1.0 (Final, 9 iulie 2025), sectiunea 5.1 (parametrul `transaction_data` al cererii), 8.4 (datele
// tranzactiei semnate cu aceeasi cheie ca dovada de posesie a credentialului) si anexa B.3.3 (in Key Binding JWT-ul unui SD-JWT VC:
// `transaction_data_hashes`, sha-256 implicit, peste sirul primit, fara decodare).
const DIGEST = /^0x[0-9a-f]{64}$/;
/**
* Prezinta un credential: arata numai afirmatiile din `reveal` si leaga totul de publicul si nonce-ul verificatorului.
* `presenter` e detinatorul, sau, cu `delegations` (lantul de la detinator la el), delegatul.
* `presenter` e detinatorul, sau, cu `delegations` (lantul de la detinator la el), delegatul. `request` (optional): digestul cererii
* catre verificator (0x + 64 hex), semnat in legatura; fara el legatura e exact cea de pana acum.
*/
export function present({ credential, disclosures = [], reveal = [], presenter, delegations = [], audience, nonce, now = new Date() }) {
export function present({ credential, disclosures = [], reveal = [], presenter, delegations = [], audience, nonce, now = new Date(), request = null }) {
if (!presenter || !presenter.privat) throw new Error('aere-identity: presenting needs the presenter\'s private keys');
if (typeof audience !== 'string' || !audience || typeof nonce !== 'string' || !nonce) throw new Error('aere-identity: a presentation needs the verifier\'s audience and nonce');
if (request != null && (typeof request !== 'string' || !DIGEST.test(request))) throw new Error('aere-identity: request is the digest of the request (0x + 64 lowercase hex)');
const dupa = new Map(disclosures.map((e) => [decodeDisclosure(e).name, e]));
const alese = [];
// o afirmatie in clar se vede oricum: numele ei in `reveal` nu cere nimic
const inClar = (credential && credential.statement && credential.statement.claims) || {};
for (const n of [...new Set(reveal)].sort()) { if (Object.hasOwn(inClar, n)) continue; if (!dupa.has(n)) throw new Error('aere-identity: no disclosure for ' + n); alese.push(dupa.get(n)); }
const binding = { v: VERSION, kind: 'aere-presentation-binding', credentialHash: credentialHash(credential), disclosuresHash: hashOf(alese),
delegations: delegations.map(delegationHash), audience, nonce, createdAt: iso(now), presenter: { id: presenter.id, keys: presenter.public } };
delegations: delegations.map(delegationHash), audience, nonce, createdAt: iso(now), presenter: { id: presenter.id, keys: presenter.public }, ...(request != null ? { request } : {}) };
return { v: VERSION, kind: 'aere-presentation', credential, disclosures: alese, delegations, binding, signature: signText('presentation', canonical(binding), presenter) };
}
@@ -293,11 +303,15 @@ export const CLOCK_SKEW_S = 60;
export const REGULI = ['form', 'issuer-id', 'holder-id', 'credential-signature', 'issuer-trusted', 'credential-window', 'status-list', 'credential-revoked', 'sd-distinct',
'disclosure-readable', 'disclosure-signed', 'disclosure-once', 'disclosure-plain', 'claim-name', 'binding-credential', 'binding-disclosures', 'binding-delegations', 'presenter',
'presentation-signature', 'audience', 'nonce', 'freshness', 'chain-length', 'delegation-form', 'delegation-ids', 'delegation-from', 'delegation-parent', 'delegation-signature',
'delegation-scope', 'delegation-window', 'delegation-depth', 'delegation-narrows', 'delegation-credential', 'delegation-claims', 'delegation-audience', 'delegation-revoked', 'unreadable'];
export const NEJUDECATE = ['issuer-trust', 'status-none', 'status-unread', 'audience', 'nonce', 'revocation-ignored', 'revocations-none'];
'delegation-scope', 'delegation-window', 'delegation-depth', 'delegation-narrows', 'delegation-credential', 'delegation-claims', 'delegation-audience', 'delegation-revoked', 'unreadable',
// 2026-10-18: the presentation commits to the request the verifier received (OpenID4VP transaction_data, SD-JWT transaction_data_hashes)
'request'];
// `request` as a cause: the binding commits to a request and the verifier gave none to compare. A binding with no request, judged by a
// verifier that gives none, has NO request row at all (the rows of every presentation made before the field existed are unchanged).
export const NEJUDECATE = ['issuer-trust', 'status-none', 'status-unread', 'audience', 'nonce', 'revocation-ignored', 'revocations-none', 'request'];
export const OPRIRI = ['form', 'chain-length', 'delegation-form', 'unreadable'];
class Nedeclarata extends Error {}
export function verifyPresentation(p, { audience = null, nonce = null, now = new Date(), trustedIssuers = null, statusLists = [], revocations = [], maxAgeS = 300, clockSkewS = CLOCK_SKEW_S } = {}) {
export function verifyPresentation(p, { audience = null, nonce = null, now = new Date(), trustedIssuers = null, statusLists = [], revocations = [], maxAgeS = 300, clockSkewS = CLOCK_SKEW_S, request = null } = {}) {
const rows = [];
const ok = (rule, name, pass, detail = '') => { if (!REGULI.includes(rule)) throw new Nedeclarata('aere-identity: undeclared rule ' + rule); rows.push({ name, pass: !!pass, detail: pass ? '' : detail, rule }); return !!pass; };
const nejudecat = (cauza, name, detail) => { if (!NEJUDECATE.includes(cauza)) throw new Nedeclarata('aere-identity: undeclared cause ' + cauza); rows.push({ name, pass: null, detail, unjudged: cauza }); };
@@ -313,6 +327,7 @@ export function verifyPresentation(p, { audience = null, nonce = null, now = new
if (trustedIssuers != null && !Array.isArray(trustedIssuers)) throw new Error('verifyPresentation: trustedIssuers is a list of ids or public keys');
const idsIncredere = trustedIssuers == null ? null : trustedIssuers.map((x) => (typeof x === 'string' && ID.test(x) ? x : idOf(x)));
if (!Array.isArray(statusLists) || !Array.isArray(revocations)) throw new Error('verifyPresentation: statusLists and revocations are lists');
if (request != null && (typeof request !== 'string' || !DIGEST.test(request))) throw new Error('verifyPresentation: request is the digest of the request the verifier received (0x + 64 lowercase hex)');
try {
if (!((!!p && p.kind === 'aere-presentation' && p.v === VERSION && !!p.credential && !!p.binding && Array.isArray(p.disclosures) && Array.isArray(p.delegations)) /*PAZA:form*/)) {
ok('form', 'presentation: well formed', false, 'not an aere-presentation'); return gata();
@@ -382,6 +397,10 @@ export function verifyPresentation(p, { audience = null, nonce = null, now = new
else ok('audience', `presentation: made for ${audience}`, B.audience === audience /*PAZA:audience*/, `made for ${B.audience}`);
if (nonce == null) nejudecat('nonce', 'presentation: nonce', 'not judged: without the verifier\'s nonce an old presentation can be replayed');
else ok('nonce', 'presentation: carries the verifier\'s nonce', B.nonce === nonce /*PAZA:nonce*/, 'another nonce');
// the request: given by the verifier, the binding must carry exactly that digest (absent is a refusal); not given, a binding that
// carries one leaves it unjudged, and a binding without one has no row (as before the field existed)
if (request != null) ok('request', 'presentation: commits to the request the verifier received', B.request === request /*PAZA:request*/, Object.hasOwn(B, 'request') ? 'signed for another request' : 'the presentation commits to no request');
else if (Object.hasOwn(B, 'request')) nejudecat('request', 'presentation: request', 'not judged: the presentation commits to a request and the verifier gave none to compare it with');
const t = data(B.createdAt, 'createdAt');
ok('freshness', `presentation: made within ${maxAgeS} s of the verifier's clock`, Math.abs(acum - t) <= maxAgeS * 1000 /*PAZA:freshness*/, `made at ${B.createdAt}`);
// 7. lantul de delegare