@agledger/verify-core 1.4.2 → 2.0.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/LICENSE +10 -14
- package/README.md +316 -12
- package/dist/audit-export.d.ts +150 -37
- package/dist/audit-export.js +204 -39
- package/dist/chain.d.ts +262 -22
- package/dist/chain.js +369 -60
- package/dist/failures.d.ts +47 -2
- package/dist/failures.js +67 -6
- package/dist/index.d.ts +9 -5
- package/dist/index.js +5 -2
- package/dist/instant.d.ts +23 -0
- package/dist/instant.js +50 -0
- package/dist/key-statements.d.ts +429 -0
- package/dist/key-statements.js +1325 -0
- package/dist/options.d.ts +7 -0
- package/dist/options.js +29 -0
- package/dist/primitives.d.ts +133 -6
- package/dist/primitives.js +255 -43
- package/package.json +3 -3
package/dist/audit-export.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* then `verifyAuditExport(...)`. It maps the export wire shape onto the shared
|
|
6
6
|
* normalized entry and runs `verifyChain`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
8
|
+
* The three row-level input-gated checks run on the export path when the wire
|
|
9
|
+
* carries their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
10
10
|
* `actorOidcIss/Sub` enable the OIDC-actor cross-check; `signingKeyWindows` +
|
|
11
11
|
* per-entry `createdAt` enable temporal key-validity; and the per-entry
|
|
12
12
|
* denormalized `payload` + `entryType` enable binding-integrity, the export's
|
|
@@ -21,20 +21,36 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { type CheckApplicability, type OptionalCheck, type SignatureOutcome } from './chain.js';
|
|
23
23
|
import type { FailureCode } from './failures.js';
|
|
24
|
+
import type { AgentPublicKeyJwk } from './primitives.js';
|
|
25
|
+
import { type DistrustedKey, type KeyTrustReport, type PublishedKeyStatement, type Verdict } from './key-statements.js';
|
|
24
26
|
/** One entry of a `/audit-export` document. */
|
|
25
27
|
export interface AuditExportEntryInput {
|
|
26
28
|
/** 1-based chain position. Current exports emit `chainPosition`; pre-v0.25 used `position`. */
|
|
27
29
|
chainPosition?: number;
|
|
28
30
|
/** Legacy alias for `chainPosition`. */
|
|
29
31
|
position?: number;
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* ISO-8601 write time. Where the walk needs it (a key window, or an unsigned
|
|
34
|
+
* entry once signing began) a missing or unparseable one fails
|
|
35
|
+
* CHAIN_MALFORMED_ENTRY.
|
|
36
|
+
*/
|
|
37
|
+
createdAt?: string | null;
|
|
32
38
|
/** OIDC issuer the actor was synthesized from (engine ≥ v0.26.x). */
|
|
33
39
|
actorOidcIss?: string | null;
|
|
34
40
|
/** OIDC subject the actor was synthesized from (engine ≥ v0.26.x). */
|
|
35
41
|
actorOidcSub?: string | null;
|
|
36
42
|
/** Tri-state from `audit_vault.actor_oidc_synthesized` (engine ≥ v0.26.x). Marker for the OIDC-actor check. */
|
|
37
43
|
actorOidcSynthesized?: boolean | null;
|
|
44
|
+
/**
|
|
45
|
+
* API-key id of the credential that performed this state-change, mirroring
|
|
46
|
+
* the row's `actor_key_id`. Signature-covered at CWT_Claims label 15 ->
|
|
47
|
+
* private label -65539; present → the actor-attribution check runs.
|
|
48
|
+
*/
|
|
49
|
+
actorId?: string | null;
|
|
50
|
+
/** Role of that credential (`admin` / `agent` / `platform`), mirroring `actor_role`. */
|
|
51
|
+
actorRole?: string | null;
|
|
52
|
+
/** Owner id of that credential, mirroring `actor_owner_id`. */
|
|
53
|
+
actorOwnerId?: string | null;
|
|
38
54
|
/** The record this entry belongs to; pairs with `payload`/`entryType` to drive the binding check. */
|
|
39
55
|
recordId?: string | null;
|
|
40
56
|
/** The audit-vault entry type (e.g. `RECORD_CREATED`); drives the binding check's predicate reconstruction. */
|
|
@@ -53,6 +69,14 @@ export interface AuditExportEntryInput {
|
|
|
53
69
|
export interface SigningKeyWindow {
|
|
54
70
|
activatedAt: string;
|
|
55
71
|
retiredAt: string | null;
|
|
72
|
+
/**
|
|
73
|
+
* The Server's `VAULT_DISTRUSTED_KEYS` instant for the key, present only on
|
|
74
|
+
* a key it names (RFC 3339 UTC, microsecond precision). Where it is earlier
|
|
75
|
+
* than the retirement the key's closures sign, `retiredAt` is this instant
|
|
76
|
+
* truncated to the millisecond. It changes only how the walk words a
|
|
77
|
+
* finding on the window: see `TrustKeyInput.distrustedFrom`.
|
|
78
|
+
*/
|
|
79
|
+
distrustedFrom?: string;
|
|
56
80
|
}
|
|
57
81
|
/** A `/audit-export` document (only the fields the verifier reads). */
|
|
58
82
|
export interface RecordAuditExportInput {
|
|
@@ -61,60 +85,116 @@ export interface RecordAuditExportInput {
|
|
|
61
85
|
exportFormatVersion?: string;
|
|
62
86
|
canonicalization?: string;
|
|
63
87
|
signingPublicKeys?: Record<string, string>;
|
|
64
|
-
/** keyId → activation/retirement window
|
|
88
|
+
/** keyId → activation/retirement window, the values the key statements sign. */
|
|
65
89
|
signingKeyWindows?: Record<string, SigningKeyWindow>;
|
|
90
|
+
/** keyId → the signed key statements admitting that key (API 2.0). Walked from `trustAnchors`. */
|
|
91
|
+
signingKeyStatements?: Record<string, PublishedKeyStatement[]>;
|
|
92
|
+
/**
|
|
93
|
+
* `sha256:<hex>` of the exporting Server's own key. Reported against the
|
|
94
|
+
* caller's anchors, never used as one: it is the artifact's word.
|
|
95
|
+
*/
|
|
96
|
+
anchoredFrom?: string | null;
|
|
66
97
|
};
|
|
67
98
|
entries: AuditExportEntryInput[];
|
|
68
99
|
/**
|
|
69
100
|
* Self-describing verification guidance the engine ships in the export.
|
|
70
101
|
* `unsignedFields` lists per-entry fields that are UNSIGNED display projections
|
|
71
102
|
* (e.g. `actorDisplayName`) resolved at export time, not covered by the COSE_Sign1
|
|
72
|
-
* signature. A PASS does NOT vouch for these labels
|
|
73
|
-
* `actorOwnerId`/`actorId
|
|
103
|
+
* signature. A PASS does NOT vouch for these labels. The attribution the guide
|
|
104
|
+
* points at instead, `actorOwnerId`/`actorId`, IS signature-covered and IS
|
|
105
|
+
* cross-checked here (`actor_attribution`). Surfaced on the result so a verdict
|
|
106
|
+
* can say which labels it does not stand behind.
|
|
74
107
|
*/
|
|
75
108
|
verificationGuide?: {
|
|
76
109
|
unsignedFields?: string[];
|
|
77
110
|
};
|
|
78
111
|
}
|
|
79
112
|
/**
|
|
80
|
-
* Structural shape for a single
|
|
113
|
+
* Structural shape for a single supplied key in array form. Matches the SDK's
|
|
81
114
|
* `VerificationKey` (the `.data[]` from `client.verificationKeys.list()`) plus
|
|
82
115
|
* the SCITT COSE_KeySet (`/.well-known/scitt-keys`) entry shape; extra fields
|
|
83
116
|
* are ignored. `publicKey` must be SPKI DER base64.
|
|
84
117
|
*/
|
|
85
|
-
export interface
|
|
118
|
+
export interface SuppliedKeyEntry {
|
|
86
119
|
keyId: string;
|
|
87
120
|
publicKey: string;
|
|
88
121
|
/** Optional activation timestamp; feeds temporal key-validity when present. */
|
|
89
122
|
activatedAt?: string;
|
|
90
123
|
/** Optional retirement timestamp; `null` means "active, no scheduled retirement". */
|
|
91
124
|
retiredAt?: string | null;
|
|
125
|
+
/**
|
|
126
|
+
* The key's signed statements, as `/v1/verification-keys` lists them. Walked
|
|
127
|
+
* with the export's own when `trustAnchors` is given.
|
|
128
|
+
*/
|
|
129
|
+
statements?: PublishedKeyStatement[];
|
|
92
130
|
}
|
|
93
131
|
export interface VerifyExportOptions {
|
|
94
132
|
/**
|
|
95
|
-
* Public keys
|
|
96
|
-
*
|
|
97
|
-
* embedded in the export
|
|
98
|
-
*
|
|
133
|
+
* Public keys the caller supplies (GET /v1/verification-keys,
|
|
134
|
+
* /.well-known/scitt-keys, its own records). These override any key
|
|
135
|
+
* embedded in the export under the same id. A key the Server serves comes
|
|
136
|
+
* from its database, so supplying keys says where they came from, not that
|
|
137
|
+
* they are trusted: pin `trustAnchors` for that.
|
|
99
138
|
*
|
|
100
139
|
* Accepts either form:
|
|
101
140
|
* - `Record<keyId, base64SpkiDer>`: the compact map shape
|
|
102
|
-
* - `
|
|
141
|
+
* - `SuppliedKeyEntry[]`: the natural shape returned by
|
|
103
142
|
* `client.verificationKeys.list().data` and SCITT COSE_KeySet listings
|
|
104
143
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
144
|
+
* - `{ data: SuppliedKeyEntry[] }`: the `/v1/verification-keys` body as
|
|
145
|
+
* served, read as its `data`
|
|
146
|
+
*
|
|
147
|
+
* Anything else throws `TypeError` at the boundary.
|
|
108
148
|
*/
|
|
109
|
-
publicKeys?: Record<string, string> | ReadonlyArray<
|
|
149
|
+
publicKeys?: Record<string, string> | ReadonlyArray<SuppliedKeyEntry> | {
|
|
150
|
+
data: ReadonlyArray<SuppliedKeyEntry>;
|
|
151
|
+
};
|
|
110
152
|
/** Require every entry to reference this keyId (else CHAIN_KEY_POLICY_VIOLATION). */
|
|
111
153
|
requireKeyId?: string;
|
|
112
154
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* against its own embedded key is not an independent audit.
|
|
155
|
+
* Refuse keys embedded in the export: an entry whose only key is
|
|
156
|
+
* export-embedded fails CHAIN_KEY_POLICY_VIOLATION.
|
|
116
157
|
*/
|
|
117
|
-
|
|
158
|
+
requireSuppliedKeys?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* SPKI digests (`sha256:<64 hex>`) of vault keys pinned out of band: the
|
|
161
|
+
* installer prints one, and the Server's `signing-key-digest.js` derives it
|
|
162
|
+
* from a key. With at least one, the signed key statements the export
|
|
163
|
+
* carries (`exportMetadata.signingKeyStatements`, plus any `statements` on
|
|
164
|
+
* supplied keys) are walked from these anchors, every key is graded
|
|
165
|
+
* anchored or not, an entry signed by a key the walk does not anchor fails
|
|
166
|
+
* CHAIN_SIGNING_KEY_UNANCHORED, and each anchored key's window is the one
|
|
167
|
+
* its statements sign. Without anchors the result says so in `keyTrust` and
|
|
168
|
+
* `optionalChecks.key_anchoring`, and every key is taken on the word of
|
|
169
|
+
* whoever embedded or supplied it. An empty array is the same as omitting
|
|
170
|
+
* it: no walk runs and `keyTrust.status` is `no_anchor`. Malformed entries
|
|
171
|
+
* throw `TypeError`.
|
|
172
|
+
*/
|
|
173
|
+
trustAnchors?: readonly string[];
|
|
174
|
+
/**
|
|
175
|
+
* Keys distrusted from outside the database, in the Server's
|
|
176
|
+
* `VAULT_DISTRUSTED_KEYS` form (`sha256:<64 hex>`, optionally
|
|
177
|
+
* `@<RFC 3339 instant>`): what such a key stored at or after the instant
|
|
178
|
+
* (with none, from the retirement a trusted key signed for it, and with
|
|
179
|
+
* neither, ever) counts for nothing in the walk. Give auditors the entries
|
|
180
|
+
* the operator set. Used only with `trustAnchors`: given without them it
|
|
181
|
+
* throws `TypeError`, since nothing would apply it.
|
|
182
|
+
*/
|
|
183
|
+
distrustedKeys?: ReadonlyArray<string | DistrustedKey>;
|
|
184
|
+
/**
|
|
185
|
+
* Ed25519 public keys of agent ephemeral certs, as JWKs: the `publicKeyJwk`
|
|
186
|
+
* the agent sent to `POST /v1/auth/oidc/cert`, which is also the `cnf.jwk`
|
|
187
|
+
* claim inside the returned `certJws`. The export does not carry them.
|
|
188
|
+
*
|
|
189
|
+
* When an entry's signed payload carries an engine-validated
|
|
190
|
+
* `predicate.on_behalf_of.agent_signature` and its sealed cert thumbprint
|
|
191
|
+
* matches one of these keys, the signature is re-verified offline, proving
|
|
192
|
+
* the cert holder signed that request-body hash without trusting the
|
|
193
|
+
* engine's word for it. A key is matched only through the thumbprint the
|
|
194
|
+
* entry signed, so where a key came from does not need to be trusted.
|
|
195
|
+
* Anything that is not an Ed25519 JWK throws `TypeError`.
|
|
196
|
+
*/
|
|
197
|
+
agentKeys?: ReadonlyArray<AgentPublicKeyJwk>;
|
|
118
198
|
}
|
|
119
199
|
export interface EntryVerificationResult {
|
|
120
200
|
position: number;
|
|
@@ -143,34 +223,67 @@ export interface VerifyExportResult {
|
|
|
143
223
|
/**
|
|
144
224
|
* Which input-gated checks ran on this export.
|
|
145
225
|
*
|
|
146
|
-
* - `
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* - `payload_binding`
|
|
150
|
-
*
|
|
151
|
-
*
|
|
226
|
+
* - `actor_attribution` flips to `applied` when the export carries the
|
|
227
|
+
* `actorId` / `actorRole` / `actorOwnerId` columns and the envelope carries
|
|
228
|
+
* the signed actor claim, which is every current export.
|
|
229
|
+
* - `payload_binding`, `oidc_actor` and `key_temporal` flip to `applied`
|
|
230
|
+
* when the export wire carries their inputs (engine >= v0.26.x: per-entry
|
|
231
|
+
* `payload` + `entryType`, `actorOidcSynthesized`, `createdAt`, and
|
|
232
|
+
* `signingKeyWindows` in exportMetadata). Older exports without those
|
|
233
|
+
* fields stay `skipped_no_input`.
|
|
234
|
+
* - `agent_signature` is `applied` only when `agentKeys` supplied the cert
|
|
235
|
+
* key for at least one engine-validated agent signature on the chain.
|
|
152
236
|
*
|
|
153
|
-
* Older exports without the new fields stay `skipped_no_input` for all three.
|
|
154
237
|
* The applicability is surfaced so a caller never mistakes "not checked
|
|
155
238
|
* here" for "checked and passed".
|
|
156
239
|
*/
|
|
157
240
|
optionalChecks: Record<OptionalCheck, CheckApplicability>;
|
|
158
241
|
/**
|
|
159
|
-
* How many signature checks resolved against
|
|
160
|
-
* keys.
|
|
161
|
-
* that produced the export. Supply out-of-band keys for an independent audit.
|
|
242
|
+
* How many signature checks resolved against supplied vs export-embedded
|
|
243
|
+
* keys. Provenance only; whether a key is trusted is `keyTrust`.
|
|
162
244
|
*/
|
|
163
245
|
keyProvenance: {
|
|
164
|
-
|
|
246
|
+
supplied: number;
|
|
165
247
|
embedded: number;
|
|
166
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* Whether the keys were anchored, and to what. `status: 'no_anchor'` means
|
|
251
|
+
* no `trustAnchors` were given, and `status: 'no_anchored_signature'` that
|
|
252
|
+
* they were but no entry verified under a key they anchor: either way the
|
|
253
|
+
* verdict rests on nothing pinned, which is not a trusted verdict whatever
|
|
254
|
+
* `valid` says (see `KeyTrustStatus`). Findings on
|
|
255
|
+
* the key statements themselves (KEY_STATEMENT_INVALID, KEY_CLOSURE_INVALID,
|
|
256
|
+
* CHAIN_KEY_WINDOW_DRIFT) are listed here and make `valid` false.
|
|
257
|
+
*/
|
|
258
|
+
keyTrust: KeyTrustReport;
|
|
167
259
|
/**
|
|
168
260
|
* Per-entry fields the export self-describes as UNSIGNED display projections
|
|
169
261
|
* (from `verificationGuide.unsignedFields`), e.g. `actorDisplayName`.
|
|
170
|
-
* A valid signature does NOT cover these;
|
|
171
|
-
* `actorOwnerId`/`actorId
|
|
172
|
-
*
|
|
262
|
+
* A valid signature does NOT cover these; the attribution that IS covered,
|
|
263
|
+
* `actorOwnerId`/`actorId`, is cross-checked against the signed actor claim
|
|
264
|
+
* (see `optionalChecks.actor_attribution`). Empty when the export carries no
|
|
265
|
+
* such guidance. A caller surfacing a PASS should warn that these labels are
|
|
266
|
+
* not vouched for.
|
|
173
267
|
*/
|
|
174
268
|
unsignedProjectionFields: string[];
|
|
269
|
+
/** Agent signatures present on the chain vs re-verified offline (see `agentKeys`). */
|
|
270
|
+
agentSignatures: {
|
|
271
|
+
present: number;
|
|
272
|
+
verified: number;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* `trusted`, `unanchored` or `failed` (see `Verdict`). Read this rather
|
|
276
|
+
* than `valid` alone: a valid result with no `trustAnchors`, or none that
|
|
277
|
+
* anchored a signature, is `unanchored`, which is not a trusted verdict.
|
|
278
|
+
*/
|
|
279
|
+
verdict: Verdict;
|
|
175
280
|
}
|
|
176
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Verify one record's `/audit-export` document offline.
|
|
283
|
+
*
|
|
284
|
+
* Throws `TypeError` when the document is not an export at all (no
|
|
285
|
+
* `exportMetadata` object, or `entries` that is not an array), on a malformed
|
|
286
|
+
* option, and on `distrustedKeys` without `trustAnchors`. A malformed entry
|
|
287
|
+
* inside a well-formed document is a failure code on that entry, never a throw.
|
|
288
|
+
*/
|
|
289
|
+
export declare function verifyAuditExport(exportData: RecordAuditExportInput, given?: VerifyExportOptions): VerifyExportResult;
|
package/dist/audit-export.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* then `verifyAuditExport(...)`. It maps the export wire shape onto the shared
|
|
6
6
|
* normalized entry and runs `verifyChain`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
8
|
+
* The three row-level input-gated checks run on the export path when the wire
|
|
9
|
+
* carries their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
10
10
|
* `actorOidcIss/Sub` enable the OIDC-actor cross-check; `signingKeyWindows` +
|
|
11
11
|
* per-entry `createdAt` enable temporal key-validity; and the per-entry
|
|
12
12
|
* denormalized `payload` + `entryType` enable binding-integrity, the export's
|
|
@@ -19,10 +19,36 @@
|
|
|
19
19
|
* Older exports without these fields stay `skipped_no_input`, surfaced in the
|
|
20
20
|
* result so a caller never mistakes "not checked here" for "checked and passed".
|
|
21
21
|
*/
|
|
22
|
-
import { buildKeyRegistry, verifyChain, } from './chain.js';
|
|
22
|
+
import { buildAgentKeyRegistry, buildKeyRegistry, earliestKeyActivation, verifyChain, } from './chain.js';
|
|
23
|
+
import { instantMs } from './instant.js';
|
|
24
|
+
import { assertKnownOptions } from './options.js';
|
|
25
|
+
import { applyKeyTrust, assertNotPinnedAndDistrusted, computeKeyTrust, keyStatementsFromExport, statementsFromMap, reportKeyTrust, settleKeyTrust, verdictOf, } from './key-statements.js';
|
|
23
26
|
const SUPPORTED_FORMAT_VERSION = '2.0';
|
|
24
27
|
const SUPPORTED_CANONICALIZATION = 'RFC8949-CDE';
|
|
25
|
-
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Verify one record's `/audit-export` document offline.
|
|
33
|
+
*
|
|
34
|
+
* Throws `TypeError` when the document is not an export at all (no
|
|
35
|
+
* `exportMetadata` object, or `entries` that is not an array), on a malformed
|
|
36
|
+
* option, and on `distrustedKeys` without `trustAnchors`. A malformed entry
|
|
37
|
+
* inside a well-formed document is a failure code on that entry, never a throw.
|
|
38
|
+
*/
|
|
39
|
+
export function verifyAuditExport(exportData, given = {}) {
|
|
40
|
+
assertKnownOptions('verifyAuditExport', given, EXPORT_OPTIONS);
|
|
41
|
+
// The `/v1/verification-keys` body as served, `{ data: [...] }`, is its array.
|
|
42
|
+
const options = isKeysEnvelope(given.publicKeys) ? { ...given, publicKeys: given.publicKeys.data } : given;
|
|
43
|
+
if (!isRecord(exportData) || !isRecord(exportData.exportMetadata)
|
|
44
|
+
|| (exportData.entries !== undefined && exportData.entries !== null && !Array.isArray(exportData.entries))) {
|
|
45
|
+
throw new TypeError('Expected an /audit-export document: { exportMetadata: { recordId, ... }, entries: [...] }.');
|
|
46
|
+
}
|
|
47
|
+
if ((options.trustAnchors === undefined || options.trustAnchors.length === 0)
|
|
48
|
+
&& options.distrustedKeys !== undefined && options.distrustedKeys.length > 0) {
|
|
49
|
+
throw new TypeError('distrustedKeys act only inside the key-statement walk, which runs from trustAnchors; pass trustAnchors as well.');
|
|
50
|
+
}
|
|
51
|
+
assertNotPinnedAndDistrusted(options.trustAnchors, options.distrustedKeys);
|
|
26
52
|
const meta = exportData.exportMetadata;
|
|
27
53
|
const entries = exportData.entries ?? [];
|
|
28
54
|
if (meta.exportFormatVersion && meta.exportFormatVersion !== SUPPORTED_FORMAT_VERSION) {
|
|
@@ -31,15 +57,51 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
31
57
|
if (meta.canonicalization && meta.canonicalization !== SUPPORTED_CANONICALIZATION) {
|
|
32
58
|
return earlyFailure(meta.recordId, entries.length, `Unsupported canonicalization ${meta.canonicalization} (only ${SUPPORTED_CANONICALIZATION} supported).`);
|
|
33
59
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
60
|
+
const resolvedKeys = resolveKeys(exportData, options);
|
|
61
|
+
let keys = buildKeyRegistry(resolvedKeys);
|
|
62
|
+
const agentKeys = options.agentKeys !== undefined ? buildAgentKeyRegistry(options.agentKeys) : undefined;
|
|
63
|
+
// An empty trustAnchors is the same as none: no walk, keyTrust 'no_anchor'.
|
|
64
|
+
const trust = options.trustAnchors !== undefined && options.trustAnchors.length > 0
|
|
65
|
+
? computeKeyTrust({
|
|
66
|
+
keys: trustKeysOf(exportData, options),
|
|
67
|
+
statements: trustStatementsOf(exportData, options),
|
|
68
|
+
trustAnchors: options.trustAnchors,
|
|
69
|
+
...(options.distrustedKeys !== undefined ? { distrustedKeys: options.distrustedKeys } : {}),
|
|
70
|
+
})
|
|
71
|
+
: null;
|
|
72
|
+
if (trust !== null)
|
|
73
|
+
keys = applyKeyTrust(keys, trust);
|
|
74
|
+
// When the install began signing, for CHAIN_ENTRY_UNSIGNED. The engine reads
|
|
75
|
+
// it as min(activated_at) over its whole key registry, retired keys included,
|
|
76
|
+
// and `signingKeyWindows` publishes that whole registry. So the instant is
|
|
77
|
+
// taken over every key the verifier holds (with each key's window resolved
|
|
78
|
+
// under the trust hierarchy in resolveKeys) plus every window the export
|
|
79
|
+
// lists for a key it carries no public key for. Those windows are unsigned,
|
|
80
|
+
// and deleting them would move the instant later or clear it, so when the
|
|
81
|
+
// walk ran, every activation an anchored key's statements sign is taken as
|
|
82
|
+
// well: the earliest of all of them stands, and neither source can make the
|
|
83
|
+
// rule looser than the other. With no time anywhere (an older export, or
|
|
84
|
+
// caller keys without activatedAt, no export windows and no walk), it is null
|
|
85
|
+
// and only the signed-before half of the rule applies.
|
|
86
|
+
const windowOnly = Object.entries(meta.signingKeyWindows ?? {})
|
|
87
|
+
.filter(([keyId, window]) => !keys.has(keyId) && window !== null && typeof window === 'object')
|
|
88
|
+
.map(([, window]) => window);
|
|
89
|
+
const signedActivations = trust === null ? [] : [...trust.byDigest.values()].filter((k) => k.trusted);
|
|
90
|
+
const signingSince = earliestKeyActivation([...resolvedKeys, ...windowOnly, ...signedActivations]);
|
|
91
|
+
const walkReport = reportKeyTrust(keys, trust, meta.anchoredFrom ?? null);
|
|
92
|
+
const normalized = entries.map((raw) => {
|
|
93
|
+
// An entry or integrity block that is not an object carries none of the
|
|
94
|
+
// fields the walk reads, and fails CHAIN_MALFORMED_ENTRY there.
|
|
95
|
+
const e = isRecord(raw) ? raw : {};
|
|
96
|
+
const integrity = isRecord(e.integrity) ? e.integrity : {};
|
|
36
97
|
const base = {
|
|
37
98
|
scopeId: meta.recordId,
|
|
38
99
|
chainPosition: e.chainPosition ?? e.position ?? -1,
|
|
39
|
-
payloadHash:
|
|
40
|
-
previousHash:
|
|
41
|
-
coseSign1:
|
|
42
|
-
signingKeyId:
|
|
100
|
+
payloadHash: integrity.payloadHash,
|
|
101
|
+
previousHash: integrity.previousHash,
|
|
102
|
+
coseSign1: integrity.coseSign1,
|
|
103
|
+
signingKeyId: integrity.signingKeyId,
|
|
104
|
+
createdAt: e.createdAt,
|
|
43
105
|
};
|
|
44
106
|
// Binding-integrity: when the export carries the denormalized row `payload`
|
|
45
107
|
// (engine ≥ v0.26.x), cross-check it against the predicate decoded from the
|
|
@@ -56,8 +118,19 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
56
118
|
payload: e.payload,
|
|
57
119
|
};
|
|
58
120
|
}
|
|
59
|
-
|
|
60
|
-
|
|
121
|
+
// Actor attribution: the export's own guide tells an auditor that
|
|
122
|
+
// `actorId`/`actorOwnerId` ARE the trustworthy attribution (only
|
|
123
|
+
// actorDisplayName / actorOwnerType / humanReadableLabel are listed as
|
|
124
|
+
// unsigned projections), so those columns are cross-checked against the
|
|
125
|
+
// signed actor claim rather than displayed on trust. Any one of the three
|
|
126
|
+
// present is enough to run the check on what is there.
|
|
127
|
+
if (e.actorId !== undefined || e.actorOwnerId !== undefined || e.actorRole !== undefined) {
|
|
128
|
+
base.actorAttribution = {
|
|
129
|
+
actorId: e.actorId ?? null,
|
|
130
|
+
actorRole: e.actorRole ?? null,
|
|
131
|
+
actorOwnerId: e.actorOwnerId ?? null,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
61
134
|
// The synthesized flag is the marker that the export carries the OIDC
|
|
62
135
|
// wire shape at all. Older exports omit it entirely; new exports always
|
|
63
136
|
// include it (false/null/true). Setting `oidcActor` flips `oidc_actor`
|
|
@@ -73,15 +146,30 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
73
146
|
});
|
|
74
147
|
const chain = verifyChain(normalized, keys, {
|
|
75
148
|
requireKeyId: options.requireKeyId,
|
|
76
|
-
|
|
149
|
+
requireSuppliedKeys: options.requireSuppliedKeys,
|
|
150
|
+
agentKeys,
|
|
151
|
+
signingSince,
|
|
77
152
|
});
|
|
153
|
+
// Under a walk every key a signature verifies against is anchored, so the
|
|
154
|
+
// signed entries are the anchored signatures.
|
|
155
|
+
const keyTrust = settleKeyTrust(walkReport, chain.signatureCoverage.signed);
|
|
156
|
+
if (trust !== null && chain.optionalChecks.key_anchoring === 'skipped_no_input') {
|
|
157
|
+
chain.optionalChecks.key_anchoring = 'not_checked';
|
|
158
|
+
}
|
|
159
|
+
// A finding on the key statements has no chain position; it is reported
|
|
160
|
+
// at position 0, the place for findings that precede the walk.
|
|
161
|
+
const registryFinding = keyTrust.findings[0];
|
|
162
|
+
const brokenAt = chain.brokenAt
|
|
163
|
+
? { position: chain.brokenAt.position, code: chain.brokenAt.code, detail: chain.brokenAt.detail }
|
|
164
|
+
: registryFinding
|
|
165
|
+
? { position: 0, code: registryFinding.code, detail: registryFinding.detail }
|
|
166
|
+
: undefined;
|
|
167
|
+
const valid = chain.valid && keyTrust.findings.length === 0;
|
|
78
168
|
return {
|
|
79
|
-
valid
|
|
169
|
+
valid,
|
|
80
170
|
totalEntries: chain.totalEntries,
|
|
81
171
|
verifiedEntries: chain.verifiedEntries,
|
|
82
|
-
brokenAt
|
|
83
|
-
? { position: chain.brokenAt.position, code: chain.brokenAt.code, detail: chain.brokenAt.detail }
|
|
84
|
-
: undefined,
|
|
172
|
+
brokenAt,
|
|
85
173
|
entries: chain.entries.map((r) => ({
|
|
86
174
|
position: r.position,
|
|
87
175
|
valid: r.valid,
|
|
@@ -94,8 +182,72 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
94
182
|
optionalChecks: chain.optionalChecks,
|
|
95
183
|
keyProvenance: chain.keyProvenance,
|
|
96
184
|
unsignedProjectionFields: exportData.verificationGuide?.unsignedFields ?? [],
|
|
185
|
+
agentSignatures: chain.agentSignatures,
|
|
186
|
+
keyTrust,
|
|
187
|
+
verdict: verdictOf({ valid, keyTrust }),
|
|
97
188
|
};
|
|
98
189
|
}
|
|
190
|
+
const EXPORT_OPTIONS = ['publicKeys', 'requireKeyId', 'requireSuppliedKeys', 'trustAnchors', 'distrustedKeys', 'agentKeys'];
|
|
191
|
+
function isKeysEnvelope(value) {
|
|
192
|
+
return isRecord(value) && Array.isArray(value.data);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The keys the walk reads: the export's own, with the windows it lists as the
|
|
196
|
+
* columns the drift check holds against the signed values, and the supplied
|
|
197
|
+
* keys as key material only (the caller's catalogue is not the artifact).
|
|
198
|
+
*/
|
|
199
|
+
function trustKeysOf(exportData, options) {
|
|
200
|
+
const meta = exportData.exportMetadata;
|
|
201
|
+
const out = [];
|
|
202
|
+
for (const [keyId, publicKey] of Object.entries(meta.signingPublicKeys ?? {})) {
|
|
203
|
+
const window = meta.signingKeyWindows?.[keyId];
|
|
204
|
+
out.push(window && typeof window === 'object'
|
|
205
|
+
? {
|
|
206
|
+
keyId,
|
|
207
|
+
publicKey,
|
|
208
|
+
activatedAt: window.activatedAt,
|
|
209
|
+
retiredAt: window.retiredAt,
|
|
210
|
+
status: window.retiredAt === null ? 'active' : 'retired',
|
|
211
|
+
...(typeof window.distrustedFrom === 'string' ? { distrustedFrom: window.distrustedFrom } : {}),
|
|
212
|
+
}
|
|
213
|
+
: { keyId, publicKey });
|
|
214
|
+
}
|
|
215
|
+
for (const k of normalizeSuppliedKeys(options.publicKeys) ?? []) {
|
|
216
|
+
out.push({ keyId: k.keyId, publicKey: k.spkiBase64 });
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The export's key statements, plus any a supplied key carries (a
|
|
222
|
+
* /v1/verification-keys `data[]`). A statement both carry is one row, which
|
|
223
|
+
* the walk reads once by its id and write time. When one source publishes
|
|
224
|
+
* write order and the other does not (an export and a key document from
|
|
225
|
+
* Servers on either side of that change), a statement without a write time
|
|
226
|
+
* that the other source carries with one is dropped as the same row; if any
|
|
227
|
+
* other remains, the walk falls back to the signed order for all of them,
|
|
228
|
+
* which `keyTrust.order` reports.
|
|
229
|
+
*/
|
|
230
|
+
function trustStatementsOf(exportData, options) {
|
|
231
|
+
const own = keyStatementsFromExport(exportData.exportMetadata.signingKeyStatements);
|
|
232
|
+
if (!Array.isArray(options.publicKeys))
|
|
233
|
+
return own;
|
|
234
|
+
const byKey = {};
|
|
235
|
+
for (const k of options.publicKeys) {
|
|
236
|
+
if (k !== null && typeof k === 'object' && Array.isArray(k.statements))
|
|
237
|
+
byKey[k.keyId] = [...(byKey[k.keyId] ?? []), ...k.statements];
|
|
238
|
+
}
|
|
239
|
+
const supplied = statementsFromMap(Object.entries(byKey), 'signingKeyStatements', 'supplied:');
|
|
240
|
+
const all = [...own, ...supplied];
|
|
241
|
+
const timed = all.filter((s) => s.createdAt !== undefined);
|
|
242
|
+
if (timed.length === 0 || timed.length === all.length)
|
|
243
|
+
return all;
|
|
244
|
+
const bytesOf = (s) => s.cose.map((c) => (typeof c === 'string' ? c : Buffer.from(c).toString('base64'))).join('|');
|
|
245
|
+
const timedBytes = new Set(timed.map(bytesOf));
|
|
246
|
+
const rest = all.filter((s) => s.createdAt !== undefined || !timedBytes.has(bytesOf(s)));
|
|
247
|
+
if (rest.every((s) => s.createdAt !== undefined))
|
|
248
|
+
return rest;
|
|
249
|
+
return all.map(({ createdAt: _c, ...s }) => s);
|
|
250
|
+
}
|
|
99
251
|
function earlyFailure(recordId, totalEntries, detail) {
|
|
100
252
|
return {
|
|
101
253
|
valid: false,
|
|
@@ -108,10 +260,16 @@ function earlyFailure(recordId, totalEntries, detail) {
|
|
|
108
260
|
optionalChecks: {
|
|
109
261
|
payload_binding: 'skipped_no_input',
|
|
110
262
|
oidc_actor: 'skipped_no_input',
|
|
263
|
+
actor_attribution: 'skipped_no_input',
|
|
111
264
|
key_temporal: 'skipped_no_input',
|
|
265
|
+
agent_signature: 'skipped_no_input',
|
|
266
|
+
key_anchoring: 'skipped_no_input',
|
|
112
267
|
},
|
|
113
|
-
keyProvenance: {
|
|
268
|
+
keyProvenance: { supplied: 0, embedded: 0 },
|
|
114
269
|
unsignedProjectionFields: [],
|
|
270
|
+
agentSignatures: { present: 0, verified: 0 },
|
|
271
|
+
keyTrust: reportKeyTrust(new Map(), null, null),
|
|
272
|
+
verdict: 'failed',
|
|
115
273
|
};
|
|
116
274
|
}
|
|
117
275
|
function resolveKeys(exportData, options) {
|
|
@@ -122,19 +280,19 @@ function resolveKeys(exportData, options) {
|
|
|
122
280
|
byId.set(keyId, { keyId, spkiBase64, source: 'embedded' });
|
|
123
281
|
}
|
|
124
282
|
}
|
|
125
|
-
//
|
|
126
|
-
// previously-seen activation/retirement window if the
|
|
127
|
-
// its own.
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
for (const entry of
|
|
283
|
+
// Supplied keys override embedded keys of the same id, but inherit the
|
|
284
|
+
// previously-seen activation/retirement window if the supplied entry didn't
|
|
285
|
+
// carry its own.
|
|
286
|
+
const supplied = normalizeSuppliedKeys(options.publicKeys);
|
|
287
|
+
if (supplied) {
|
|
288
|
+
for (const entry of supplied) {
|
|
131
289
|
const existing = byId.get(entry.keyId);
|
|
132
290
|
const activatedAt = entry.activatedAt ?? existing?.activatedAt;
|
|
133
291
|
const retiredAt = entry.retiredAt !== undefined ? entry.retiredAt : existing?.retiredAt;
|
|
134
292
|
byId.set(entry.keyId, {
|
|
135
293
|
keyId: entry.keyId,
|
|
136
294
|
spkiBase64: entry.spkiBase64,
|
|
137
|
-
source: '
|
|
295
|
+
source: 'supplied',
|
|
138
296
|
...(activatedAt !== undefined ? { activatedAt } : {}),
|
|
139
297
|
...(retiredAt !== undefined ? { retiredAt } : {}),
|
|
140
298
|
});
|
|
@@ -147,19 +305,18 @@ function resolveKeys(exportData, options) {
|
|
|
147
305
|
if (windows) {
|
|
148
306
|
for (const [keyId, window] of Object.entries(windows)) {
|
|
149
307
|
const existing = byId.get(keyId);
|
|
150
|
-
if (!existing)
|
|
308
|
+
if (!existing || !isRecord(window))
|
|
151
309
|
continue;
|
|
152
310
|
// Trust hierarchy on the temporal axis: when the caller supplied this
|
|
153
|
-
// key
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
const oobCarriesWindow = existing.source === 'out-of-band' &&
|
|
311
|
+
// key AND brought their own activation/retirement window, the export's
|
|
312
|
+
// (untrusted) signingKeyWindows MUST NOT overwrite it. A compromised
|
|
313
|
+
// export could otherwise hide a retirement by setting retiredAt:null.
|
|
314
|
+
// When the caller did not carry a window, we fall through to the
|
|
315
|
+
// export's. With trustAnchors, an anchored key's window is the one its
|
|
316
|
+
// statements sign, whichever of these it carried.
|
|
317
|
+
const suppliedCarriesWindow = existing.source === 'supplied' &&
|
|
161
318
|
(existing.activatedAt !== undefined || existing.retiredAt !== undefined);
|
|
162
|
-
if (
|
|
319
|
+
if (suppliedCarriesWindow)
|
|
163
320
|
continue;
|
|
164
321
|
byId.set(keyId, {
|
|
165
322
|
...existing,
|
|
@@ -173,19 +330,19 @@ function resolveKeys(exportData, options) {
|
|
|
173
330
|
/**
|
|
174
331
|
* Normalize `options.publicKeys` into a uniform array of entries, or throw
|
|
175
332
|
* `TypeError` at the boundary if the shape is wrong. Fail-closed by design:
|
|
176
|
-
*
|
|
177
|
-
*
|
|
333
|
+
* a key argument that silently falls back to embedded keys would lie about
|
|
334
|
+
* which keys the verdict rests on.
|
|
178
335
|
*
|
|
179
336
|
* Accepts:
|
|
180
337
|
* - `Record<keyId, base64SpkiDer>`: compact map (string-keyed object whose
|
|
181
338
|
* values are all strings)
|
|
182
|
-
* - `
|
|
339
|
+
* - `SuppliedKeyEntry[]`: natural SDK shape from `verificationKeys.list()`,
|
|
183
340
|
* or COSE_KeySet shape from `/.well-known/scitt-keys`
|
|
184
341
|
*
|
|
185
342
|
* Returns `null` when no keys were supplied; otherwise an array of normalized
|
|
186
343
|
* entries ready to merge into the registry.
|
|
187
344
|
*/
|
|
188
|
-
function
|
|
345
|
+
function normalizeSuppliedKeys(publicKeys) {
|
|
189
346
|
if (publicKeys === undefined || publicKeys === null)
|
|
190
347
|
return null;
|
|
191
348
|
if (Array.isArray(publicKeys)) {
|
|
@@ -204,6 +361,14 @@ function normalizeOutOfBandKeys(publicKeys) {
|
|
|
204
361
|
const out = { keyId, spkiBase64: publicKey };
|
|
205
362
|
const activatedAt = entry.activatedAt;
|
|
206
363
|
const retiredAt = entry.retiredAt;
|
|
364
|
+
// A window the caller supplies is held to RFC 3339, as distrustedKeys
|
|
365
|
+
// is: one that is not would be read by the host's clock or not at all.
|
|
366
|
+
for (const [edge, value] of [['activatedAt', activatedAt], ['retiredAt', retiredAt]]) {
|
|
367
|
+
if (value !== undefined && value !== null && (typeof value !== 'string' || Number.isNaN(instantMs(value)))) {
|
|
368
|
+
throw new TypeError(`verifyAuditExport: publicKeys[${i}] (key ${keyId}) has ${edge} ${JSON.stringify(value)}, which is not an RFC 3339 instant ` +
|
|
369
|
+
'(2026-09-01T00:00:00.000Z: a T, an offset or Z, a real calendar date).');
|
|
370
|
+
}
|
|
371
|
+
}
|
|
207
372
|
if (typeof activatedAt === 'string')
|
|
208
373
|
out.activatedAt = activatedAt;
|
|
209
374
|
if (retiredAt === null || typeof retiredAt === 'string')
|