plenipo 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/http/errors.js +1 -0
- package/dist/http/gateway.js +16 -4
- package/dist/openid4vp.d.ts +11 -1
- package/dist/openid4vp.js +11 -3
- package/dist/root.d.ts +9 -4
- package/dist/root.js +10 -5
- package/dist/status.d.ts +7 -1
- package/dist/status.js +30 -5
- package/dist/testing.js +6 -2
- package/dist/trust.d.ts +7 -0
- package/dist/trust.js +13 -4
- package/dist/types.d.ts +6 -1
- package/dist/verify.js +1 -1
- package/dist/x509-revocation.js +7 -2
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -13,9 +13,11 @@ Plenipo gives AI agents the same thing, with one difference: the powers are neve
|
|
|
13
13
|
Every mandate has a scope, limits and an expiry, every sub-delegation can only narrow it,
|
|
14
14
|
and the person can revoke it at any time.
|
|
15
15
|
|
|
16
|
-
> Status: 0.
|
|
17
|
-
>
|
|
18
|
-
>
|
|
16
|
+
> Status: 0.6.0, experimental. The cryptography is real; the banks in the examples and the sandbox
|
|
17
|
+
> are test doubles. The public sandbox accepts PIDs from the EU test issuer and has been run end to end
|
|
18
|
+
> with walt.id Wallet API 2 and with Plenipo builds of the EUDI reference wallet on Android and iOS
|
|
19
|
+
> ([docs/interop.md](docs/interop.md)). The code went through security reviews by independent
|
|
20
|
+
> AI review agents (two rounds for 0.3, two for 0.5), and their findings are fixed (see
|
|
19
21
|
> [CHANGELOG.md](CHANGELOG.md)); it has not yet been audited by an external security firm. Do not use it
|
|
20
22
|
> to protect real money or real data yet.
|
|
21
23
|
|
package/dist/http/errors.js
CHANGED
|
@@ -38,6 +38,7 @@ export const DENY_PROBLEMS = Object.freeze({
|
|
|
38
38
|
ATTESTATION_REVOKED: spec(401, 'attestation_revoked', 'An attestation is revoked or suspended', 'authentication'),
|
|
39
39
|
ROLE_EXCEEDED: spec(403, 'role_exceeded', 'The mandate exceeds the representative role', 'authorization'),
|
|
40
40
|
STATUS_UNAVAILABLE: spec(503, 'status_unavailable', 'A status list could not be checked', 'infrastructure'),
|
|
41
|
+
STATUS_UNTRUSTED: spec(401, 'status_untrusted', 'A status list could not be verified', 'authentication'),
|
|
41
42
|
IDEMPOTENCY_CONFLICT: spec(422, 'idempotency_conflict', 'The idempotency key was used for a different request', 'request'),
|
|
42
43
|
IDEMPOTENCY_IN_PROGRESS: spec(409, 'idempotency_in_progress', 'An attempt with this idempotency key is still running', 'conflict'),
|
|
43
44
|
IDEMPOTENCY_UNRESOLVED: spec(409, 'idempotency_unresolved', 'The outcome of an earlier attempt with this idempotency key is not known yet', 'conflict'),
|
package/dist/http/gateway.js
CHANGED
|
@@ -209,13 +209,25 @@ export function jsonMediaType(contentType) {
|
|
|
209
209
|
const t = type.toLowerCase();
|
|
210
210
|
if (!/^application\/([a-z0-9!#$&^_.-]+\+)?json$/.test(t))
|
|
211
211
|
return null;
|
|
212
|
-
for (const p of params)
|
|
213
|
-
|
|
214
|
-
if (!m || m[1].toLowerCase() !== 'utf-8')
|
|
212
|
+
for (const p of params)
|
|
213
|
+
if (charsetOf(p)?.toLowerCase() !== 'utf-8')
|
|
215
214
|
return null;
|
|
216
|
-
}
|
|
217
215
|
return t;
|
|
218
216
|
}
|
|
217
|
+
/** The value of a `charset=` parameter, optionally quoted; undefined for any other parameter. No regex: the header comes from the network. */
|
|
218
|
+
function charsetOf(param) {
|
|
219
|
+
if (param.slice(0, 7).toLowerCase() !== 'charset')
|
|
220
|
+
return undefined;
|
|
221
|
+
const rest = param.slice(7).trimStart();
|
|
222
|
+
if (!rest.startsWith('='))
|
|
223
|
+
return undefined;
|
|
224
|
+
let v = rest.slice(1).trimStart();
|
|
225
|
+
if (v.startsWith('"'))
|
|
226
|
+
v = v.slice(1);
|
|
227
|
+
if (v.endsWith('"'))
|
|
228
|
+
v = v.slice(0, -1);
|
|
229
|
+
return v.includes('"') ? undefined : v;
|
|
230
|
+
}
|
|
219
231
|
function makeContext(request, url, params, body) {
|
|
220
232
|
let text;
|
|
221
233
|
let json;
|
package/dist/openid4vp.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export interface MandateRequestOptions {
|
|
|
57
57
|
vcts?: string[];
|
|
58
58
|
identityClaims?: string[];
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* How long the request can be answered, in seconds. Default 600, the default `maxAgeSeconds` of
|
|
62
|
+
* `handleMandateResponse`. The signed request object carries it as `exp`, so a wallet that checks it
|
|
63
|
+
* refuses an expired request before the person reads and approves it.
|
|
64
|
+
*/
|
|
65
|
+
lifetimeSeconds?: number;
|
|
60
66
|
}
|
|
61
67
|
/** What the platform keeps between the request and the response. Contains a private key: keep it server-side. */
|
|
62
68
|
export interface MandateRequestSession {
|
|
@@ -68,6 +74,8 @@ export interface MandateRequestSession {
|
|
|
68
74
|
responseMode: 'direct_post' | 'direct_post.jwt';
|
|
69
75
|
decryptionKey?: CryptoKey;
|
|
70
76
|
createdAt: number;
|
|
77
|
+
/** When the request expires (`createdAt` + `lifetimeSeconds`). Responses after it are refused. */
|
|
78
|
+
expiresAt?: number;
|
|
71
79
|
/** The mandate, for e-mandate requests: the transaction data only carries its hash. */
|
|
72
80
|
mandate?: Mandate;
|
|
73
81
|
/** DCQL query ids besides `pid` whose presentations the response must contain. */
|
|
@@ -76,8 +84,10 @@ export interface MandateRequestSession {
|
|
|
76
84
|
export interface MandateRequest {
|
|
77
85
|
/** Authorization request parameters, as JSON. */
|
|
78
86
|
params: Record<string, unknown>;
|
|
79
|
-
/** Signed request object, when a signer was given: serve it at the request_uri
|
|
87
|
+
/** Signed request object, when a signer was given: serve it at the request_uri until `expiresAt`. */
|
|
80
88
|
requestObject?: string;
|
|
89
|
+
/** When the request expires, in seconds since the epoch: show it to the person, stop serving the request object after it. */
|
|
90
|
+
expiresAt: number;
|
|
81
91
|
session: MandateRequestSession;
|
|
82
92
|
}
|
|
83
93
|
/** Builds the OpenID4VP authorization request for a mandate. */
|
package/dist/openid4vp.js
CHANGED
|
@@ -21,6 +21,11 @@ export const REQUEST_OBJECT_TYP = 'oauth-authz-req+jwt';
|
|
|
21
21
|
export async function createMandateRequest(opts) {
|
|
22
22
|
const nonce = randomBytes(16).toString('base64url');
|
|
23
23
|
const state = randomUUID();
|
|
24
|
+
const lifetime = opts.lifetimeSeconds ?? 600;
|
|
25
|
+
if (!Number.isSafeInteger(lifetime) || lifetime <= 0)
|
|
26
|
+
throw new Error('lifetimeSeconds must be a positive integer');
|
|
27
|
+
const createdAt = Math.floor(Date.now() / 1000);
|
|
28
|
+
const expiresAt = createdAt + lifetime;
|
|
24
29
|
const emandate = opts.transactionDataType === 'emandate';
|
|
25
30
|
const em = opts.emandate ?? {};
|
|
26
31
|
const bindTo = em.credential ?? SCA_QUERY_ID;
|
|
@@ -87,11 +92,12 @@ export async function createMandateRequest(opts) {
|
|
|
87
92
|
};
|
|
88
93
|
let requestObject;
|
|
89
94
|
if (opts.signer) {
|
|
90
|
-
requestObject = await signCompactJwt({ ...params, aud: 'https://self-issued.me/v2', iat:
|
|
95
|
+
requestObject = await signCompactJwt({ ...params, aud: 'https://self-issued.me/v2', iat: createdAt, exp: expiresAt }, { alg: 'ES256', typ: REQUEST_OBJECT_TYP, ...(opts.signer.x5c ? { x5c: opts.signer.x5c } : {}) }, opts.signer.key);
|
|
91
96
|
}
|
|
92
97
|
return {
|
|
93
98
|
params,
|
|
94
99
|
requestObject,
|
|
100
|
+
expiresAt,
|
|
95
101
|
session: {
|
|
96
102
|
clientId: opts.clientId,
|
|
97
103
|
nonce,
|
|
@@ -100,7 +106,8 @@ export async function createMandateRequest(opts) {
|
|
|
100
106
|
mandateId: opts.mandate.id,
|
|
101
107
|
responseMode: encrypt ? 'direct_post.jwt' : 'direct_post',
|
|
102
108
|
decryptionKey,
|
|
103
|
-
createdAt
|
|
109
|
+
createdAt,
|
|
110
|
+
expiresAt,
|
|
104
111
|
...(emandate ? { mandate: opts.mandate } : {}),
|
|
105
112
|
...(extraQueries.length ? { extraQueries } : {}),
|
|
106
113
|
},
|
|
@@ -137,8 +144,9 @@ export async function handleMandateResponse(body, session, opts) {
|
|
|
137
144
|
if (typeof sessionRetention === 'number' && sessionRetention < (opts.maxAgeSeconds ?? 600)) {
|
|
138
145
|
throw new RootError('CONFIGURATION', 'the session store forgets responses before requests expire');
|
|
139
146
|
}
|
|
140
|
-
if (opts.now - session.createdAt > (opts.maxAgeSeconds ?? 600))
|
|
147
|
+
if (opts.now - session.createdAt > (opts.maxAgeSeconds ?? 600) || (typeof session.expiresAt === 'number' && opts.now > session.expiresAt)) {
|
|
141
148
|
throw new RootError('ROOT_INVALID', 'the request session has expired');
|
|
149
|
+
}
|
|
142
150
|
let payload = body;
|
|
143
151
|
if (session.responseMode === 'direct_post.jwt') {
|
|
144
152
|
if (typeof body.response !== 'string' || !session.decryptionKey) {
|
package/dist/root.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ import { type LegalPersonPrincipal, type Mandate, type RepresentationInfo, type
|
|
|
8
8
|
/** DCQL query id of the SCA attestation a TS12 e-mandate is bound to. */
|
|
9
9
|
export declare const SCA_QUERY_ID = "sca";
|
|
10
10
|
export declare class RootError extends Error {
|
|
11
|
-
readonly code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'REPLAY';
|
|
11
|
+
readonly code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'STATUS_UNTRUSTED' | 'REPLAY';
|
|
12
12
|
/** Internal detail for logs; never send it to the caller. */
|
|
13
13
|
readonly detail?: string | undefined;
|
|
14
|
-
constructor(code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'REPLAY', message: string,
|
|
14
|
+
constructor(code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'STATUS_UNTRUSTED' | 'REPLAY', message: string,
|
|
15
15
|
/** Internal detail for logs; never send it to the caller. */
|
|
16
16
|
detail?: string | undefined);
|
|
17
17
|
}
|
|
@@ -168,7 +168,8 @@ export declare function checkAttestationCertificates(c: DeferredCertificateCheck
|
|
|
168
168
|
/**
|
|
169
169
|
* Checks the status of an SCA or representation attestation. The list must be signed for the attestation
|
|
170
170
|
* issuer under the same trust that accepted the attestation, and served from that issuer's origin unless
|
|
171
|
-
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED
|
|
171
|
+
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED when the verified list marks it revoked
|
|
172
|
+
* or suspended, STATUS_UNAVAILABLE or STATUS_UNTRUSTED when the status cannot be determined.
|
|
172
173
|
*/
|
|
173
174
|
export declare function checkAttestationStatus(d: DeferredStatus, opts: {
|
|
174
175
|
now: number;
|
|
@@ -176,5 +177,9 @@ export declare function checkAttestationStatus(d: DeferredStatus, opts: {
|
|
|
176
177
|
statusCache?: StatusListCache;
|
|
177
178
|
maxStatusAgeSeconds?: number;
|
|
178
179
|
}): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Checks the status of a PID issued by `pidIss`. Throws RootError PID_REVOKED when the verified list marks it
|
|
182
|
+
* revoked or suspended, STATUS_UNAVAILABLE when the list cannot be fetched, STATUS_UNTRUSTED when it was
|
|
183
|
+
* fetched (or its origin is not allowed) but cannot be trusted.
|
|
184
|
+
*/
|
|
180
185
|
export declare function checkPidStatus(ref: StatusReference, pidIss: string, opts: RootOptions): Promise<void>;
|
package/dist/root.js
CHANGED
|
@@ -430,7 +430,8 @@ export async function checkAttestationCertificates(c, now) {
|
|
|
430
430
|
/**
|
|
431
431
|
* Checks the status of an SCA or representation attestation. The list must be signed for the attestation
|
|
432
432
|
* issuer under the same trust that accepted the attestation, and served from that issuer's origin unless
|
|
433
|
-
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED
|
|
433
|
+
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED when the verified list marks it revoked
|
|
434
|
+
* or suspended, STATUS_UNAVAILABLE or STATUS_UNTRUSTED when the status cannot be determined.
|
|
434
435
|
*/
|
|
435
436
|
export async function checkAttestationStatus(d, opts) {
|
|
436
437
|
const allowedOrigins = d.trust.statusOrigins ?? [httpsOrigin(d.issuer)].filter((o) => !!o);
|
|
@@ -447,7 +448,7 @@ export async function checkAttestationStatus(d, opts) {
|
|
|
447
448
|
});
|
|
448
449
|
}
|
|
449
450
|
catch (e) {
|
|
450
|
-
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : '
|
|
451
|
+
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'STATUS_UNTRUSTED', `${d.label} status could not be verified`, e.message);
|
|
451
452
|
}
|
|
452
453
|
if (status !== 0)
|
|
453
454
|
throw new RootError('ATTESTATION_REVOKED', `${d.label} is ${status === 2 ? 'suspended' : 'revoked'}`);
|
|
@@ -463,12 +464,16 @@ function statusOriginsOf(trust) {
|
|
|
463
464
|
return trust.statusOrigins;
|
|
464
465
|
return (trust.trustedIssuers ?? []).map((t) => httpsOrigin(t.iss)).filter((o) => o !== undefined);
|
|
465
466
|
}
|
|
466
|
-
/**
|
|
467
|
+
/**
|
|
468
|
+
* Checks the status of a PID issued by `pidIss`. Throws RootError PID_REVOKED when the verified list marks it
|
|
469
|
+
* revoked or suspended, STATUS_UNAVAILABLE when the list cannot be fetched, STATUS_UNTRUSTED when it was
|
|
470
|
+
* fetched (or its origin is not allowed) but cannot be trusted.
|
|
471
|
+
*/
|
|
467
472
|
export async function checkPidStatus(ref, pidIss, opts) {
|
|
468
473
|
const origin = httpsOrigin(ref.status_list.uri);
|
|
469
474
|
const custom = opts.pidStatusTrust;
|
|
470
475
|
const check = custom
|
|
471
|
-
? { trust: custom, signer: origin ?? '', allowedOrigins: statusOriginsOf(custom) }
|
|
476
|
+
? { trust: custom, signer: origin ?? '', alsoSigners: (origin && custom.statusSigners?.[origin]) || [], allowedOrigins: statusOriginsOf(custom) }
|
|
472
477
|
: { trust: opts, signer: pidIss, allowedOrigins: [httpsOrigin(pidIss)].filter((o) => !!o) };
|
|
473
478
|
let status;
|
|
474
479
|
try {
|
|
@@ -481,7 +486,7 @@ export async function checkPidStatus(ref, pidIss, opts) {
|
|
|
481
486
|
});
|
|
482
487
|
}
|
|
483
488
|
catch (e) {
|
|
484
|
-
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : '
|
|
489
|
+
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'STATUS_UNTRUSTED', 'PID status could not be verified', e.message);
|
|
485
490
|
}
|
|
486
491
|
if (status !== 0)
|
|
487
492
|
throw new RootError('PID_REVOKED', `PID status is ${status === 2 ? 'suspended' : 'revoked'}`);
|
package/dist/status.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ export interface StatusCheckOptions {
|
|
|
39
39
|
* with x5c the leaf certificate must name it.
|
|
40
40
|
*/
|
|
41
41
|
signer: string;
|
|
42
|
+
/**
|
|
43
|
+
* Further identities accepted for the signer, tried after `signer`: a status list service that serves
|
|
44
|
+
* lists signed by their issuers (see `TrustConfig.statusSigners`). Never taken from the token.
|
|
45
|
+
*/
|
|
46
|
+
alsoSigners?: string[];
|
|
42
47
|
/** Origins the list may be fetched from. A URI outside them is refused before any network access. */
|
|
43
48
|
allowedOrigins: string[];
|
|
44
49
|
fetcher?: StatusFetcher;
|
|
@@ -101,7 +106,8 @@ export declare function isStatusReference(x: unknown): x is StatusReference;
|
|
|
101
106
|
*/
|
|
102
107
|
/**
|
|
103
108
|
* The status list could not be obtained (network error, HTTP error, size limit). Distinct from a list that
|
|
104
|
-
* was obtained and failed verification,
|
|
109
|
+
* was obtained and failed verification, or sits on an origin that is not allowed: verifiers deny that with
|
|
110
|
+
* STATUS_UNTRUSTED, an outage with STATUS_UNAVAILABLE, and only a verified entry that is not 0 as revoked.
|
|
105
111
|
*/
|
|
106
112
|
export declare class StatusUnavailableError extends Error {
|
|
107
113
|
}
|
package/dist/status.js
CHANGED
|
@@ -162,18 +162,43 @@ export function isStatusReference(x) {
|
|
|
162
162
|
*/
|
|
163
163
|
/**
|
|
164
164
|
* The status list could not be obtained (network error, HTTP error, size limit). Distinct from a list that
|
|
165
|
-
* was obtained and failed verification,
|
|
165
|
+
* was obtained and failed verification, or sits on an origin that is not allowed: verifiers deny that with
|
|
166
|
+
* STATUS_UNTRUSTED, an outage with STATUS_UNAVAILABLE, and only a verified entry that is not 0 as revoked.
|
|
166
167
|
*/
|
|
167
168
|
export class StatusUnavailableError extends Error {
|
|
168
169
|
}
|
|
170
|
+
/** The signing key under `signer`, or else under the first of `alsoSigners` the certificate names. */
|
|
171
|
+
async function resolveStatusSigner(header, opts) {
|
|
172
|
+
const names = [opts.signer, ...(opts.alsoSigners ?? []).filter((n) => n !== opts.signer)];
|
|
173
|
+
let firstError;
|
|
174
|
+
for (const name of names) {
|
|
175
|
+
try {
|
|
176
|
+
return await resolveSigningKeyAsync(header, name, opts.trust, opts.now);
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
firstError ??= e;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
throw firstError;
|
|
183
|
+
}
|
|
169
184
|
export async function checkStatus(ref, opts) {
|
|
170
185
|
const { uri, idx } = ref.status_list;
|
|
171
186
|
const origin = httpsOrigin(uri);
|
|
172
|
-
if (!origin || !opts.allowedOrigins.includes(origin))
|
|
173
|
-
|
|
187
|
+
if (!origin || !opts.allowedOrigins.includes(origin)) {
|
|
188
|
+
// Name what was refused: without it a deployment cannot tell which origin to allow.
|
|
189
|
+
let shown = '(not a URI)';
|
|
190
|
+
try {
|
|
191
|
+
const u = new URL(uri);
|
|
192
|
+
shown = `${u.protocol}//${u.host}`;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// keep the placeholder
|
|
196
|
+
}
|
|
197
|
+
throw new Error(`status list origin ${shown} is not allowed`);
|
|
198
|
+
}
|
|
174
199
|
const maxBytes = opts.maxListBytes ?? DEFAULT_MAX_STATUS_LIST_BYTES;
|
|
175
200
|
// The bound is part of the key: a list accepted under a larger bound is not served to a stricter check.
|
|
176
|
-
const key = JSON.stringify([trustId(opts.trust), opts.signer, uri, maxBytes]);
|
|
201
|
+
const key = JSON.stringify([trustId(opts.trust), opts.signer, opts.alsoSigners ?? [], uri, maxBytes]);
|
|
177
202
|
const maxAge = opts.maxAgeSeconds;
|
|
178
203
|
if (maxAge !== undefined && (typeof maxAge !== 'number' || !Number.isFinite(maxAge) || maxAge < 0)) {
|
|
179
204
|
throw new Error('maxAgeSeconds must be a non-negative number');
|
|
@@ -192,7 +217,7 @@ export async function checkStatus(ref, opts) {
|
|
|
192
217
|
verifyStatusListJwtHeader(header);
|
|
193
218
|
if (header.alg !== 'ES256')
|
|
194
219
|
throw new Error('status list token must use ES256');
|
|
195
|
-
const signingKey = await
|
|
220
|
+
const signingKey = await resolveStatusSigner(header, opts);
|
|
196
221
|
const { payload } = await jwtVerify(token, await importJWK(signingKey.jwk, 'ES256'), {
|
|
197
222
|
algorithms: ['ES256'],
|
|
198
223
|
currentDate: new Date(opts.now * 1000),
|
package/dist/testing.js
CHANGED
|
@@ -376,14 +376,18 @@ function ts12EmandateValid(p) {
|
|
|
376
376
|
}
|
|
377
377
|
return true;
|
|
378
378
|
}
|
|
379
|
+
/** Claim names a verifier sends: none of them may reach a prototype. */
|
|
380
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
379
381
|
function claimsFrame(claims) {
|
|
380
|
-
const frame =
|
|
382
|
+
const frame = Object.create(null);
|
|
381
383
|
for (const c of claims ?? []) {
|
|
382
384
|
const [a, b] = c.path;
|
|
385
|
+
if (typeof a !== 'string' || UNSAFE_KEYS.has(a) || (b !== undefined && (typeof b !== 'string' || UNSAFE_KEYS.has(b))))
|
|
386
|
+
continue;
|
|
383
387
|
if (b === undefined)
|
|
384
388
|
frame[a] = true;
|
|
385
389
|
else if (frame[a] !== true)
|
|
386
|
-
(frame[a] ??=
|
|
390
|
+
(frame[a] ??= Object.create(null))[b] = true;
|
|
387
391
|
}
|
|
388
392
|
return frame;
|
|
389
393
|
}
|
package/dist/trust.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export interface TrustConfig {
|
|
|
31
31
|
* Defaults depend on the use: see `VerifyOptions.mandateStatusTrust` and `pidStatusTrust`.
|
|
32
32
|
*/
|
|
33
33
|
statusOrigins?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* For a status list origin, further identities whose certificate may sign the lists served from it, as
|
|
36
|
+
* `{ "https://status.example": ["https://issuer.example"] }`. For a status list service that hosts lists
|
|
37
|
+
* its issuers sign; without an entry the signing certificate must name the origin itself. The chain
|
|
38
|
+
* rules are unchanged.
|
|
39
|
+
*/
|
|
40
|
+
statusSigners?: Record<string, string[]>;
|
|
34
41
|
/**
|
|
35
42
|
* CRL and OCSP checking of x5c chains. Absent or `policy: 'off'` keeps the earlier behaviour: a revoked
|
|
36
43
|
* certificate stays trusted until it expires. Needs `resolveSigningKeyAsync`.
|
package/dist/trust.js
CHANGED
|
@@ -64,8 +64,9 @@ function checkCa(c, role, intermediatesBelow) {
|
|
|
64
64
|
throw new TrustError(`${role} may not sign certificates`);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* True when the leaf names `name`: exactly as a URI subject alternative name, or
|
|
68
|
-
*
|
|
67
|
+
* True when the leaf names `name`: exactly as a URI subject alternative name, or, when `name` is a bare
|
|
68
|
+
* https origin (no port, path, query or fragment), by that origin as a URI with or without the trailing slash
|
|
69
|
+
* or by its DNS name. Paths never match by DNS, so one
|
|
69
70
|
* tenant's certificate on a shared host cannot sign for another tenant's issuer URL.
|
|
70
71
|
*/
|
|
71
72
|
function namesIdentity(c, name) {
|
|
@@ -85,6 +86,10 @@ function namesIdentity(c, name) {
|
|
|
85
86
|
const bareOrigin = u.protocol === 'https:' && !u.port && (u.pathname === '/' || u.pathname === '') && !u.search && !u.hash;
|
|
86
87
|
if (!bareOrigin || name.replace(/\/$/, '') !== u.origin)
|
|
87
88
|
return false;
|
|
89
|
+
// For a bare https origin the empty path and "/" are the same URI (RFC 3986, section 6.2.3), and some
|
|
90
|
+
// issuers write the SAN with the slash: accept exactly those two spellings, nothing else.
|
|
91
|
+
if (items.some((n) => n.type === 'url' && (n.value === u.origin || n.value === `${u.origin}/`)))
|
|
92
|
+
return true;
|
|
88
93
|
return items.some((n) => n.type === 'dns' && n.value.toLowerCase() === u.hostname);
|
|
89
94
|
}
|
|
90
95
|
/**
|
|
@@ -180,8 +185,12 @@ export function verifyX5c(x5c, anchorsPem, now, name, opts = {}) {
|
|
|
180
185
|
throw new TrustError('the signing certificate has a critical extended key usage that cannot be checked');
|
|
181
186
|
}
|
|
182
187
|
}
|
|
183
|
-
if (!namesIdentity(leaf, name))
|
|
184
|
-
|
|
188
|
+
if (!namesIdentity(leaf, name)) {
|
|
189
|
+
// Say what the certificate does name: a deployment cannot otherwise tell which identity to configure.
|
|
190
|
+
const san = leaf.px.getExtension(x509.SubjectAlternativeNameExtension);
|
|
191
|
+
const names = san ? san.names.items.map((n) => `${n.type}:${n.value}`).join(', ') : 'no subject alternative name';
|
|
192
|
+
throw new TrustError(`the signing certificate does not name ${name} (it names ${names}; subject ${leaf.node.subject.replace(/\n/g, ', ')})`);
|
|
193
|
+
}
|
|
185
194
|
const jwk = leaf.node.publicKey.export({ format: 'jwk' });
|
|
186
195
|
if (jwk.kty !== 'EC' || jwk.crv !== 'P-256')
|
|
187
196
|
throw new TrustError('the signing key must be EC P-256');
|
package/dist/types.d.ts
CHANGED
|
@@ -123,8 +123,13 @@ export interface TrustedIssuer {
|
|
|
123
123
|
withoutStatusList?: boolean;
|
|
124
124
|
}
|
|
125
125
|
export type DenyCode = 'CONFIGURATION' | 'MALFORMED' | 'INVOCATION_MISMATCH' | 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'LIFETIME_POLICY' | 'DELEGATION_SIGNATURE_INVALID' | 'DELEGATION_PARENT_MISMATCH' | 'DELEGATION_NOT_ALLOWED' | 'ATTENUATION_VIOLATION' | 'NOT_YET_VALID' | 'EXPIRED' | 'REVOKED' | 'INVOCATION_SIGNATURE_INVALID' | 'INVOCATION_MANDATE_MISMATCH' | 'INVOCATION_STALE' | 'AUDIENCE_MISMATCH' | 'REPLAY' | 'ACTION_NOT_PERMITTED' | 'COUNTERPARTY_NOT_PERMITTED' | 'CURRENCY_MISMATCH' | 'LIMIT_PER_OPERATION' | 'LIMIT_TOTAL' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED'
|
|
126
|
-
/** A status list or revocation source could not be fetched
|
|
126
|
+
/** A status list or revocation source could not be fetched. Still a denial; a retry may succeed. */
|
|
127
127
|
| 'STATUS_UNAVAILABLE'
|
|
128
|
+
/**
|
|
129
|
+
* A status list was referenced but cannot be trusted: its origin is not allowed, or the token does not
|
|
130
|
+
* verify (signer, signature, claims, expiry). The credential may be valid; its status is unknown.
|
|
131
|
+
*/
|
|
132
|
+
| 'STATUS_UNTRUSTED'
|
|
128
133
|
/** The idempotency key was already used for a different request. */
|
|
129
134
|
| 'IDEMPOTENCY_CONFLICT'
|
|
130
135
|
/** An attempt with this idempotency key is still running; a retry later may get its result. */
|
package/dist/verify.js
CHANGED
|
@@ -394,7 +394,7 @@ export async function verifyAuthorization(chain, invocation, opts) {
|
|
|
394
394
|
});
|
|
395
395
|
}
|
|
396
396
|
catch (e) {
|
|
397
|
-
throw new Deny(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : '
|
|
397
|
+
throw new Deny(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'STATUS_UNTRUSTED', `status of mandate ${i} could not be verified`, i, e.message);
|
|
398
398
|
}
|
|
399
399
|
if (status !== 0)
|
|
400
400
|
throw new Deny('REVOKED', `mandate ${i} is ${status === 2 ? 'suspended' : 'revoked'} in its status list`, i);
|
package/dist/x509-revocation.js
CHANGED
|
@@ -348,11 +348,16 @@ export async function checkCertificateRevocation(chain, opts, now) {
|
|
|
348
348
|
}
|
|
349
349
|
return report;
|
|
350
350
|
}
|
|
351
|
+
const CRL_BEGIN = '-----BEGIN X509 CRL-----';
|
|
352
|
+
const CRL_END = '-----END X509 CRL-----';
|
|
353
|
+
/** PEM or base64 to DER. With indexOf, not a lazy regex, whose time grows with the square of a malformed input. */
|
|
351
354
|
function toDer(c) {
|
|
352
355
|
if (typeof c !== 'string')
|
|
353
356
|
return c;
|
|
354
|
-
const
|
|
355
|
-
|
|
357
|
+
const start = c.indexOf(CRL_BEGIN);
|
|
358
|
+
const end = start < 0 ? -1 : c.indexOf(CRL_END, start + CRL_BEGIN.length);
|
|
359
|
+
const body = start >= 0 && end > start + CRL_BEGIN.length ? c.slice(start + CRL_BEGIN.length, end) : c;
|
|
360
|
+
return new Uint8Array(Buffer.from(body, 'base64'));
|
|
356
361
|
}
|
|
357
362
|
// --- OCSP -------------------------------------------------------------------------------------------------
|
|
358
363
|
const SHA1 = '1.3.14.3.2.26';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plenipo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Wallet-anchored mandates for AI agents: EUDI Wallet PID as root, enforced attenuation, expiry and revocation, MCP guard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eudi-wallet",
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
"example:gateway": "tsx examples/bank-gateway.ts"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@owf/token-status-list": "^0.
|
|
73
|
-
"@peculiar/asn1-ocsp": "^
|
|
74
|
-
"@peculiar/asn1-schema": "^
|
|
75
|
-
"@peculiar/asn1-x509": "^
|
|
76
|
-
"@peculiar/x509": "^
|
|
72
|
+
"@owf/token-status-list": "^0.7.0",
|
|
73
|
+
"@peculiar/asn1-ocsp": "^3.0.0",
|
|
74
|
+
"@peculiar/asn1-schema": "^3.0.0",
|
|
75
|
+
"@peculiar/asn1-x509": "^3.0.0",
|
|
76
|
+
"@peculiar/x509": "^3.1.0",
|
|
77
77
|
"@sd-jwt/crypto-nodejs": "^0.19.0",
|
|
78
|
-
"@sd-jwt/sd-jwt-vc": "^0.
|
|
78
|
+
"@sd-jwt/sd-jwt-vc": "^0.24.3",
|
|
79
79
|
"canonicalize": "^5.1.0",
|
|
80
80
|
"jose": "^6.2.12",
|
|
81
81
|
"reflect-metadata": "^0.2.2",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@electric-sql/pglite": "^0.5.10",
|
|
86
86
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
87
|
-
"@owf/eudi-lote": "^0.
|
|
87
|
+
"@owf/eudi-lote": "^0.6.0",
|
|
88
88
|
"@types/express": "^5.0.3",
|
|
89
89
|
"@types/node": "^26.6.5",
|
|
90
90
|
"@types/pg": "^8.23.1",
|