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