@agledger/verify-core 2.0.0 → 2.2.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 +140 -21
- package/dist/audit-export.d.ts +124 -16
- package/dist/audit-export.js +171 -16
- package/dist/cbor-strict.d.ts +9 -0
- package/dist/cbor-strict.js +14 -0
- package/dist/chain.d.ts +144 -19
- package/dist/chain.js +212 -41
- package/dist/failures.d.ts +25 -11
- package/dist/failures.js +39 -15
- package/dist/federation-wire.d.ts +171 -0
- package/dist/federation-wire.js +515 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +2 -1
- package/dist/instant.d.ts +1 -1
- package/dist/instant.js +1 -1
- package/dist/key-statements.d.ts +27 -11
- package/dist/key-statements.js +74 -44
- package/dist/options.js +4 -4
- package/dist/primitives.d.ts +35 -32
- package/dist/primitives.js +65 -50
- package/package.json +7 -4
package/dist/audit-export.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* normalized entry and runs `verifyChain`.
|
|
7
7
|
*
|
|
8
8
|
* The three row-level input-gated checks run on the export path when the wire
|
|
9
|
-
* carries their inputs (
|
|
9
|
+
* carries their inputs (Server 0.26 and later): 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
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* tampering of the human-readable `payload`/`criteria` view: the verifier
|
|
15
15
|
* re-decodes the signed predicate from `coseSign1` and deep-equals it against
|
|
16
16
|
* the row `payload`, so a rewritten `payload` with an intact envelope fails
|
|
17
|
-
* CHAIN_PAYLOAD_BINDING_MISMATCH (validated against a real
|
|
17
|
+
* CHAIN_PAYLOAD_BINDING_MISMATCH (validated against a real Server v0.26.4
|
|
18
18
|
* export; `buildPredicateForRow` reconstructs the signed predicate exactly).
|
|
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".
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
import { buildAgentKeyRegistry, buildKeyRegistry, earliestKeyActivation, verifyChain, } from './chain.js';
|
|
23
23
|
import { instantMs } from './instant.js';
|
|
24
24
|
import { assertKnownOptions } from './options.js';
|
|
25
|
+
import { decodeCoseSign1, decodePredicate } from './primitives.js';
|
|
26
|
+
import { buildFederationKeyRegistry } from './federation-wire.js';
|
|
25
27
|
import { applyKeyTrust, assertNotPinnedAndDistrusted, computeKeyTrust, keyStatementsFromExport, statementsFromMap, reportKeyTrust, settleKeyTrust, verdictOf, } from './key-statements.js';
|
|
26
28
|
const SUPPORTED_FORMAT_VERSION = '2.0';
|
|
27
29
|
const SUPPORTED_CANONICALIZATION = 'RFC8949-CDE';
|
|
@@ -49,17 +51,28 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
49
51
|
throw new TypeError('distrustedKeys act only inside the key-statement walk, which runs from trustAnchors; pass trustAnchors as well.');
|
|
50
52
|
}
|
|
51
53
|
assertNotPinnedAndDistrusted(options.trustAnchors, options.distrustedKeys);
|
|
54
|
+
if (options.expectedEntryCount !== undefined
|
|
55
|
+
&& !(typeof options.expectedEntryCount === 'number' && Number.isInteger(options.expectedEntryCount) && options.expectedEntryCount >= 0)) {
|
|
56
|
+
throw new TypeError(`verifyAuditExport: expectedEntryCount must be a non-negative integer (got ${JSON.stringify(options.expectedEntryCount)}).`);
|
|
57
|
+
}
|
|
58
|
+
// Caller-supplied keys are refused before the export is read, so a bad option
|
|
59
|
+
// is reported as such whatever the input holds.
|
|
60
|
+
const agentKeys = options.agentKeys !== undefined ? buildAgentKeyRegistry(options.agentKeys) : undefined;
|
|
61
|
+
const federationKeys = options.federationKeys !== undefined ? buildFederationKeyRegistry(options.federationKeys) : undefined;
|
|
52
62
|
const meta = exportData.exportMetadata;
|
|
53
63
|
const entries = exportData.entries ?? [];
|
|
54
|
-
if (meta.exportFormatVersion
|
|
55
|
-
return earlyFailure(meta.recordId, entries.length,
|
|
64
|
+
if (meta.exportFormatVersion !== SUPPORTED_FORMAT_VERSION) {
|
|
65
|
+
return earlyFailure(meta.recordId, entries.length, meta.exportFormatVersion === undefined || meta.exportFormatVersion === null || meta.exportFormatVersion === ''
|
|
66
|
+
? `The export states no exportFormatVersion (this verifier reads ${SUPPORTED_FORMAT_VERSION}).`
|
|
67
|
+
: `Unsupported exportFormatVersion ${JSON.stringify(meta.exportFormatVersion)} (this verifier reads ${SUPPORTED_FORMAT_VERSION}).`);
|
|
56
68
|
}
|
|
57
|
-
if (meta.canonicalization
|
|
58
|
-
return earlyFailure(meta.recordId, entries.length,
|
|
69
|
+
if (meta.canonicalization !== SUPPORTED_CANONICALIZATION) {
|
|
70
|
+
return earlyFailure(meta.recordId, entries.length, meta.canonicalization === undefined || meta.canonicalization === null || meta.canonicalization === ''
|
|
71
|
+
? `The export states no canonicalization (only ${SUPPORTED_CANONICALIZATION} supported).`
|
|
72
|
+
: `Unsupported canonicalization ${JSON.stringify(meta.canonicalization)} (only ${SUPPORTED_CANONICALIZATION} supported).`);
|
|
59
73
|
}
|
|
60
74
|
const resolvedKeys = resolveKeys(exportData, options);
|
|
61
75
|
let keys = buildKeyRegistry(resolvedKeys);
|
|
62
|
-
const agentKeys = options.agentKeys !== undefined ? buildAgentKeyRegistry(options.agentKeys) : undefined;
|
|
63
76
|
// An empty trustAnchors is the same as none: no walk, keyTrust 'no_anchor'.
|
|
64
77
|
const trust = options.trustAnchors !== undefined && options.trustAnchors.length > 0
|
|
65
78
|
? computeKeyTrust({
|
|
@@ -71,7 +84,7 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
71
84
|
: null;
|
|
72
85
|
if (trust !== null)
|
|
73
86
|
keys = applyKeyTrust(keys, trust);
|
|
74
|
-
// When the install began signing, for CHAIN_ENTRY_UNSIGNED. The
|
|
87
|
+
// When the install began signing, for CHAIN_ENTRY_UNSIGNED. The Server reads
|
|
75
88
|
// it as min(activated_at) over its whole key registry, retired keys included,
|
|
76
89
|
// and `signingKeyWindows` publishes that whole registry. So the instant is
|
|
77
90
|
// taken over every key the verifier holds (with each key's window resolved
|
|
@@ -89,6 +102,12 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
89
102
|
const signedActivations = trust === null ? [] : [...trust.byDigest.values()].filter((k) => k.trusted);
|
|
90
103
|
const signingSince = earliestKeyActivation([...resolvedKeys, ...windowOnly, ...signedActivations]);
|
|
91
104
|
const walkReport = reportKeyTrust(keys, trust, meta.anchoredFrom ?? null);
|
|
105
|
+
// An entry's `payload` and `entryType` are what the binding check and the
|
|
106
|
+
// federation-wire check read. Once any entry carries them, or the caller
|
|
107
|
+
// supplied federation keys, an entry without them is a check that cannot
|
|
108
|
+
// run on it, which is a failure and not a skip.
|
|
109
|
+
const carriesBinding = (raw) => isRecord(raw) && (raw.payload !== undefined || raw.entryType !== undefined);
|
|
110
|
+
const bindingExpected = options.federationKeys !== undefined || entries.some(carriesBinding);
|
|
92
111
|
const normalized = entries.map((raw) => {
|
|
93
112
|
// An entry or integrity block that is not an object carries none of the
|
|
94
113
|
// fields the walk reads, and fails CHAIN_MALFORMED_ENTRY there.
|
|
@@ -104,7 +123,7 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
104
123
|
createdAt: e.createdAt,
|
|
105
124
|
};
|
|
106
125
|
// Binding-integrity: when the export carries the denormalized row `payload`
|
|
107
|
-
// (
|
|
126
|
+
// (Server 0.26 and later), cross-check it against the predicate decoded from the
|
|
108
127
|
// signed bytes, the export's own verificationGuide step 4. The threat is
|
|
109
128
|
// post-export tampering of the human-readable `payload`/`criteria` view: an
|
|
110
129
|
// attacker rewrites `payload` and leaves `coseSign1` intact. The verifier
|
|
@@ -116,8 +135,21 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
116
135
|
recordId: e.recordId ?? null,
|
|
117
136
|
entryType: e.entryType,
|
|
118
137
|
payload: e.payload,
|
|
138
|
+
extensionsProjected: true,
|
|
119
139
|
};
|
|
120
140
|
}
|
|
141
|
+
else if (bindingExpected) {
|
|
142
|
+
const missing = [e.payload === undefined ? 'payload' : null, e.entryType === undefined ? 'entryType' : null].filter((m) => m !== null).join(' and ');
|
|
143
|
+
base.bindingRequired = {
|
|
144
|
+
detail: `The entry carries no ${missing}, which the binding and federation-wire checks read: ${options.federationKeys !== undefined && !entries.some(carriesBinding) ? 'federationKeys were supplied' : 'other entries of this export carry it'}, so an entry without it cannot be checked.`,
|
|
145
|
+
federationWire: options.federationKeys !== undefined,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// An inlined evidence body is unsigned; it is re-bound to the hash the
|
|
149
|
+
// entry signs, so a null or a non-object there fails rather than reading
|
|
150
|
+
// as no body at all.
|
|
151
|
+
if (e.evidence !== undefined && e.evidence !== null)
|
|
152
|
+
base.inlinedEvidence = { value: e.evidence };
|
|
121
153
|
// Actor attribution: the export's own guide tells an auditor that
|
|
122
154
|
// `actorId`/`actorOwnerId` ARE the trustworthy attribution (only
|
|
123
155
|
// actorDisplayName / actorOwnerType / humanReadableLabel are listed as
|
|
@@ -148,6 +180,8 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
148
180
|
requireKeyId: options.requireKeyId,
|
|
149
181
|
requireSuppliedKeys: options.requireSuppliedKeys,
|
|
150
182
|
agentKeys,
|
|
183
|
+
federationKeys,
|
|
184
|
+
allowAfterRetirement: options.allowAfterRetirement === true,
|
|
151
185
|
signingSince,
|
|
152
186
|
});
|
|
153
187
|
// Under a walk every key a signature verifies against is anchored, so the
|
|
@@ -159,12 +193,14 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
159
193
|
// A finding on the key statements has no chain position; it is reported
|
|
160
194
|
// at position 0, the place for findings that precede the walk.
|
|
161
195
|
const registryFinding = keyTrust.findings[0];
|
|
196
|
+
const count = statedEntryCount(meta, entries.length, options.expectedEntryCount);
|
|
197
|
+
const identity = signedRecordId(meta.recordId, entries);
|
|
162
198
|
const brokenAt = chain.brokenAt
|
|
163
199
|
? { position: chain.brokenAt.position, code: chain.brokenAt.code, detail: chain.brokenAt.detail }
|
|
164
200
|
: registryFinding
|
|
165
201
|
? { position: 0, code: registryFinding.code, detail: registryFinding.detail }
|
|
166
|
-
:
|
|
167
|
-
const valid = chain.valid && keyTrust.findings.length === 0;
|
|
202
|
+
: identity.finding ?? count.finding;
|
|
203
|
+
const valid = chain.valid && keyTrust.findings.length === 0 && count.finding === undefined && identity.finding === undefined;
|
|
168
204
|
return {
|
|
169
205
|
valid,
|
|
170
206
|
totalEntries: chain.totalEntries,
|
|
@@ -177,17 +213,130 @@ export function verifyAuditExport(exportData, given = {}) {
|
|
|
177
213
|
detail: r.failure?.detail,
|
|
178
214
|
signature: r.signature,
|
|
179
215
|
})),
|
|
180
|
-
recordId:
|
|
216
|
+
recordId: identity.recordId,
|
|
181
217
|
signatureCoverage: chain.signatureCoverage,
|
|
182
|
-
optionalChecks: chain.optionalChecks,
|
|
218
|
+
optionalChecks: { ...chain.optionalChecks, entry_count: count.applied ? 'applied' : 'skipped_no_input' },
|
|
183
219
|
keyProvenance: chain.keyProvenance,
|
|
184
220
|
unsignedProjectionFields: exportData.verificationGuide?.unsignedFields ?? [],
|
|
185
221
|
agentSignatures: chain.agentSignatures,
|
|
222
|
+
federationWire: chain.federationWire,
|
|
223
|
+
evidenceBinding: chain.evidenceBinding,
|
|
224
|
+
entryCount: count.entryCount,
|
|
186
225
|
keyTrust,
|
|
187
|
-
verdict: verdictOf({ valid, keyTrust })
|
|
226
|
+
verdict: verdictOf({ valid, keyTrust }, () => {
|
|
227
|
+
const { trustAnchors: _pinned, distrustedKeys: _distrusted, ...unpinned } = options;
|
|
228
|
+
return verifyAuditExport(exportData, unpinned).valid;
|
|
229
|
+
}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Hold the chain's length to the counts the export states. A chain that was
|
|
234
|
+
* cut from the end still links and verifies entry by entry, so its length is
|
|
235
|
+
* the only thing that shows the cut: against the latest checkpoint position
|
|
236
|
+
* (a chain shorter than its checkpoint lost rows below it) and against the number of
|
|
237
|
+
* entries the Server wrote. A count that is present and is not a non-negative
|
|
238
|
+
* integer is refused rather than skipped.
|
|
239
|
+
*/
|
|
240
|
+
function statedEntryCount(meta, held, supplied) {
|
|
241
|
+
const read = (name) => {
|
|
242
|
+
const value = meta[name];
|
|
243
|
+
if (value === undefined || value === null)
|
|
244
|
+
return null;
|
|
245
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : 'malformed';
|
|
246
|
+
};
|
|
247
|
+
const expected = read('expectedEntries');
|
|
248
|
+
const stated = read('totalEntries');
|
|
249
|
+
const entryCount = {
|
|
250
|
+
expectedEntries: expected === 'malformed' ? null : expected,
|
|
251
|
+
statedEntries: stated === 'malformed' ? null : stated,
|
|
252
|
+
};
|
|
253
|
+
for (const [name, value] of [['expectedEntries', expected], ['totalEntries', stated]]) {
|
|
254
|
+
if (value === 'malformed') {
|
|
255
|
+
return {
|
|
256
|
+
entryCount,
|
|
257
|
+
applied: true,
|
|
258
|
+
finding: { position: 0, code: 'UNSUPPORTED_FORMAT', detail: `exportMetadata.${name} is ${JSON.stringify(meta[name])}, not a non-negative integer or null, so the chain's length cannot be held to it.` },
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (supplied !== undefined && held !== supplied) {
|
|
263
|
+
return {
|
|
264
|
+
entryCount,
|
|
265
|
+
applied: true,
|
|
266
|
+
finding: {
|
|
267
|
+
position: Math.min(held, supplied) + 1,
|
|
268
|
+
code: 'CHAIN_POSITION_GAP',
|
|
269
|
+
detail: `The export carries ${held} ${held === 1 ? 'entry' : 'entries'} and expectedEntryCount, supplied by the caller, is ${supplied}: ${held < supplied ? 'entries were removed from the end' : 'entries were added past the end'} of the chain.`,
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if (entryCount.expectedEntries !== null && held < entryCount.expectedEntries) {
|
|
274
|
+
return {
|
|
275
|
+
entryCount,
|
|
276
|
+
applied: true,
|
|
277
|
+
finding: {
|
|
278
|
+
position: entryCount.expectedEntries,
|
|
279
|
+
code: 'CHECKPOINT_ROW_MISSING',
|
|
280
|
+
detail: `The export states a signed checkpoint at position ${entryCount.expectedEntries} and carries ${held} ${held === 1 ? 'entry' : 'entries'}: the chain was cut below its checkpoint.`,
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (entryCount.statedEntries !== null && held < entryCount.statedEntries) {
|
|
285
|
+
return {
|
|
286
|
+
entryCount,
|
|
287
|
+
applied: true,
|
|
288
|
+
finding: {
|
|
289
|
+
position: held + 1,
|
|
290
|
+
code: 'CHAIN_POSITION_GAP',
|
|
291
|
+
detail: `The export states ${entryCount.statedEntries} entries and carries ${held}: entries were removed from the end after the Server wrote it.`,
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return { entryCount, applied: supplied !== undefined || entryCount.expectedEntries !== null || entryCount.statedEntries !== null };
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The record id the export is about, taken from what it signs. The id in
|
|
299
|
+
* `exportMetadata` is unsigned, so it is held to the id each entry's signed
|
|
300
|
+
* predicate names and to the entry's own `recordId` column: any disagreement,
|
|
301
|
+
* among the entries or with the metadata, fails CHAIN_PAYLOAD_BINDING_MISMATCH,
|
|
302
|
+
* and the id reported is the signed one, never the metadata's.
|
|
303
|
+
*/
|
|
304
|
+
function signedRecordId(stated, entries) {
|
|
305
|
+
const seen = [];
|
|
306
|
+
entries.forEach((raw, i) => {
|
|
307
|
+
if (!isRecord(raw))
|
|
308
|
+
return;
|
|
309
|
+
const position = typeof raw.chainPosition === 'number' ? raw.chainPosition : typeof raw.position === 'number' ? raw.position : i + 1;
|
|
310
|
+
if (typeof raw.recordId === 'string')
|
|
311
|
+
seen.push({ id: raw.recordId, position, source: 'its recordId column' });
|
|
312
|
+
const integrity = raw.integrity;
|
|
313
|
+
if (!isRecord(integrity) || typeof integrity.coseSign1 !== 'string')
|
|
314
|
+
return;
|
|
315
|
+
const parts = decodeCoseSign1(Buffer.from(integrity.coseSign1, 'base64'));
|
|
316
|
+
const signed = parts === null ? null : decodePredicate(parts.payloadBstr)?.['record_id'];
|
|
317
|
+
if (typeof signed === 'string')
|
|
318
|
+
seen.push({ id: signed, position, source: 'its signed predicate' });
|
|
319
|
+
});
|
|
320
|
+
const statedId = typeof stated === 'string' ? stated : '';
|
|
321
|
+
const first = seen.find((s) => s.source === 'its signed predicate') ?? seen[0];
|
|
322
|
+
if (first === undefined)
|
|
323
|
+
return { recordId: statedId };
|
|
324
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
325
|
+
const other = seen.find((s) => !same(s.id, first.id));
|
|
326
|
+
if (other === undefined && same(statedId, first.id))
|
|
327
|
+
return { recordId: first.id };
|
|
328
|
+
return {
|
|
329
|
+
recordId: first.id,
|
|
330
|
+
finding: {
|
|
331
|
+
position: (other ?? first).position,
|
|
332
|
+
code: 'CHAIN_PAYLOAD_BINDING_MISMATCH',
|
|
333
|
+
detail: other !== undefined
|
|
334
|
+
? `The entries of this export name different records: ${first.id} (${first.source}) and ${other.id} (${other.source}).`
|
|
335
|
+
: `The entries of this export are about record ${first.id} (${first.source}) and exportMetadata.recordId says ${JSON.stringify(stated)}: the unsigned metadata was edited.`,
|
|
336
|
+
},
|
|
188
337
|
};
|
|
189
338
|
}
|
|
190
|
-
const EXPORT_OPTIONS = ['publicKeys', 'requireKeyId', 'requireSuppliedKeys', 'trustAnchors', 'distrustedKeys', 'agentKeys'];
|
|
339
|
+
const EXPORT_OPTIONS = ['publicKeys', 'requireKeyId', 'requireSuppliedKeys', 'trustAnchors', 'distrustedKeys', 'agentKeys', 'federationKeys', 'allowAfterRetirement', 'expectedEntryCount'];
|
|
191
340
|
function isKeysEnvelope(value) {
|
|
192
341
|
return isRecord(value) && Array.isArray(value.data);
|
|
193
342
|
}
|
|
@@ -264,10 +413,16 @@ function earlyFailure(recordId, totalEntries, detail) {
|
|
|
264
413
|
key_temporal: 'skipped_no_input',
|
|
265
414
|
agent_signature: 'skipped_no_input',
|
|
266
415
|
key_anchoring: 'skipped_no_input',
|
|
416
|
+
federation_wire: 'skipped_no_input',
|
|
417
|
+
evidence_binding: 'skipped_no_input',
|
|
418
|
+
entry_count: 'skipped_no_input',
|
|
267
419
|
},
|
|
268
420
|
keyProvenance: { supplied: 0, embedded: 0 },
|
|
269
421
|
unsignedProjectionFields: [],
|
|
270
422
|
agentSignatures: { present: 0, verified: 0 },
|
|
423
|
+
federationWire: { present: 0, verified: 0, failed: 0, afterRetirement: 0 },
|
|
424
|
+
evidenceBinding: { present: 0, verified: 0, clientHashed: 0, failed: 0 },
|
|
425
|
+
entryCount: { expectedEntries: null, statedEntries: null },
|
|
271
426
|
keyTrust: reportKeyTrust(new Map(), null, null),
|
|
272
427
|
verdict: 'failed',
|
|
273
428
|
};
|
|
@@ -298,7 +453,7 @@ function resolveKeys(exportData, options) {
|
|
|
298
453
|
});
|
|
299
454
|
}
|
|
300
455
|
}
|
|
301
|
-
// Attach activation/retirement windows from exportMetadata (
|
|
456
|
+
// Attach activation/retirement windows from exportMetadata (Server 0.26 and later).
|
|
302
457
|
// Older exports omit signingKeyWindows; keys stay without a window and
|
|
303
458
|
// verifyChain reports `key_temporal` as `skipped_no_input`.
|
|
304
459
|
const windows = meta.signingKeyWindows;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DecodeOptions } from 'cborg';
|
|
2
|
+
/**
|
|
3
|
+
* Decode options for every CBOR value this package reads. The signed bytes
|
|
4
|
+
* are deterministic CBOR (RFC 8949 section 4.2.1), so anything a conforming
|
|
5
|
+
* encoder would not emit is refused rather than tolerated: duplicate map
|
|
6
|
+
* keys (two readers could take different values), non-minimal integer and
|
|
7
|
+
* length encodings, indefinite lengths, `undefined`, and invalid UTF-8.
|
|
8
|
+
*/
|
|
9
|
+
export declare const STRICT_CBOR_DECODE: Pick<DecodeOptions, 'strict' | 'allowIndefinite' | 'allowUndefined' | 'rejectDuplicateMapKeys' | 'rejectInvalidUtf8'>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode options for every CBOR value this package reads. The signed bytes
|
|
3
|
+
* are deterministic CBOR (RFC 8949 section 4.2.1), so anything a conforming
|
|
4
|
+
* encoder would not emit is refused rather than tolerated: duplicate map
|
|
5
|
+
* keys (two readers could take different values), non-minimal integer and
|
|
6
|
+
* length encodings, indefinite lengths, `undefined`, and invalid UTF-8.
|
|
7
|
+
*/
|
|
8
|
+
export const STRICT_CBOR_DECODE = {
|
|
9
|
+
strict: true,
|
|
10
|
+
allowIndefinite: false,
|
|
11
|
+
allowUndefined: false,
|
|
12
|
+
rejectDuplicateMapKeys: true,
|
|
13
|
+
rejectInvalidUtf8: true,
|
|
14
|
+
};
|
package/dist/chain.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* inputs): binding-integrity, OIDC-actor cross-check, temporal
|
|
20
20
|
* key-validity, the agent-signature re-check, and key anchoring (a
|
|
21
21
|
* registry marked by `applyKeyTrust`). The first three run on
|
|
22
|
-
* the dump and on any export from
|
|
22
|
+
* the dump and on any export from a Server that ships the row fields
|
|
23
23
|
* (>= v0.26.x). The agent-signature check needs the cert's public key,
|
|
24
24
|
* which neither surface carries, so it runs only when the caller passes
|
|
25
25
|
* `agentKeys`. A check without its input is reported `skipped_no_input`,
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
* branch comes LAST, after the binding/OIDC checks, so a row written without a
|
|
30
30
|
* signing key is still subject to every structural check, and a tamper finding
|
|
31
31
|
* on it is reported under its own code rather than as CHAIN_ENTRY_UNSIGNED.
|
|
32
|
-
* That branch grades the entry the way the
|
|
32
|
+
* That branch grades the entry the way the Server does: an unsigned entry
|
|
33
33
|
* after a signed one in its chain, or written at or after the earliest key
|
|
34
34
|
* activation (`signingSince`), is CHAIN_ENTRY_UNSIGNED; an earlier one is a
|
|
35
35
|
* `skipped` signature, reduced coverage rather than a break.
|
|
36
36
|
*/
|
|
37
37
|
import { type AgentPublicKeyJwk } from './primitives.js';
|
|
38
|
+
import { type FederationKeyRegistry } from './federation-wire.js';
|
|
38
39
|
import type { FailureCode } from './failures.js';
|
|
39
40
|
/**
|
|
40
41
|
* Where a verification key came from. `supplied`: the caller passed it (from
|
|
@@ -57,18 +58,18 @@ export type KeyTrustState = 'anchored' | 'unanchored' | 'undecided';
|
|
|
57
58
|
/** A public key the walk can verify signatures against. */
|
|
58
59
|
export interface VerificationKey {
|
|
59
60
|
keyId: string;
|
|
60
|
-
/** SPKI DER, base64-encoded (the
|
|
61
|
+
/** SPKI DER, base64-encoded (the shape the Server's key registry publishes). */
|
|
61
62
|
spkiBase64: string;
|
|
62
63
|
/**
|
|
63
64
|
* `supplied` = passed by the caller. `embedded` = shipped inside the
|
|
64
|
-
* artifact being verified (the export or dump the
|
|
65
|
+
* artifact being verified (the export or dump the Server produced). Surfaced
|
|
65
66
|
* in the result so a caller can tell whether it verified against a key it
|
|
66
67
|
* brought or against the artifact's own answer key.
|
|
67
68
|
*/
|
|
68
69
|
source: KeySource;
|
|
69
70
|
/**
|
|
70
|
-
* Algorithm the key registry DECLARES for this key (the
|
|
71
|
-
*
|
|
71
|
+
* Algorithm the key registry DECLARES for this key (the Server's
|
|
72
|
+
* registry algorithm field), when the input surface carries it.
|
|
72
73
|
* Cross-checked against the algorithm the SPKI key material actually commits
|
|
73
74
|
* to: a divergence means the registry row lies about its own key and fails
|
|
74
75
|
* CHAIN_ALG_MISMATCH. The declared string never selects the verification
|
|
@@ -115,7 +116,7 @@ export type KeyRegistry = ReadonlyMap<string, VerificationKey>;
|
|
|
115
116
|
export declare function buildKeyRegistry(keys: readonly VerificationKey[]): KeyRegistry;
|
|
116
117
|
/**
|
|
117
118
|
* Agent cert keys for the agent-signature check, indexed by the RFC 7638
|
|
118
|
-
* thumbprint (`sha256:<hex>`) the
|
|
119
|
+
* thumbprint (`sha256:<hex>`) the Server seals as
|
|
119
120
|
* `predicate.on_behalf_of.cert.thumbprint`. Values are SPKI DER, base64.
|
|
120
121
|
*/
|
|
121
122
|
export type AgentKeyRegistry = ReadonlyMap<string, string>;
|
|
@@ -139,7 +140,7 @@ export interface NormalizedEntry {
|
|
|
139
140
|
signingKeyId: string | null;
|
|
140
141
|
/**
|
|
141
142
|
* ISO-8601 write time, for temporal key-validity and the unsigned-entry
|
|
142
|
-
* rule. The
|
|
143
|
+
* rule. The Server writes one on every entry, so wherever the walk needs it
|
|
143
144
|
* (the entry's key carries a window, or the entry is unsigned and the key
|
|
144
145
|
* set dates the start of signing) a missing or unparseable value fails
|
|
145
146
|
* CHAIN_MALFORMED_ENTRY rather than skipping the check.
|
|
@@ -150,6 +151,25 @@ export interface NormalizedEntry {
|
|
|
150
151
|
recordId: string | null;
|
|
151
152
|
entryType: string;
|
|
152
153
|
payload: Record<string, unknown>;
|
|
154
|
+
/**
|
|
155
|
+
* True when `payload` is a projection that carries every envelope
|
|
156
|
+
* extension the entry signed, as an export entry's does: the Server
|
|
157
|
+
* writes `on_behalf_of` and `traceparent` into it from the signed
|
|
158
|
+
* predicate. Then a signed extension missing from `payload` is a
|
|
159
|
+
* mismatch. A vault row's payload never holds them, so the dump path
|
|
160
|
+
* leaves this unset.
|
|
161
|
+
*/
|
|
162
|
+
extensionsProjected?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Set on an entry that lacks the `binding` inputs where the walk needs them
|
|
166
|
+
* (a sibling carries them, or the caller supplied federation keys), with
|
|
167
|
+
* what is missing. The entry then fails CHAIN_PAYLOAD_BINDING_MISMATCH
|
|
168
|
+
* rather than reading as an entry with nothing to check.
|
|
169
|
+
*/
|
|
170
|
+
bindingRequired?: {
|
|
171
|
+
detail: string;
|
|
172
|
+
federationWire: boolean;
|
|
153
173
|
};
|
|
154
174
|
/** Inputs for the OIDC-actor cross-check (dump path). */
|
|
155
175
|
oidcActor?: {
|
|
@@ -168,14 +188,23 @@ export interface NormalizedEntry {
|
|
|
168
188
|
actorRole: string | null;
|
|
169
189
|
actorOwnerId: string | null;
|
|
170
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* The evidence body an `?evidence=true` export inlines at the entry's
|
|
193
|
+
* `evidence` (export path). Present on the entry, however it is spelled, →
|
|
194
|
+
* the evidence-binding check runs: the body is an unsigned projection, and
|
|
195
|
+
* its authority comes only from hashing to the hash the entry signs.
|
|
196
|
+
*/
|
|
197
|
+
inlinedEvidence?: {
|
|
198
|
+
value: unknown;
|
|
199
|
+
};
|
|
171
200
|
}
|
|
172
201
|
/**
|
|
173
202
|
* Checks that run only when their input is present. `agent_signature` is
|
|
174
|
-
* applied when at least one entry carrying
|
|
203
|
+
* applied when at least one entry carrying a Server-validated agent signature
|
|
175
204
|
* had its cert key supplied by the caller (`agentKeys`); neither the export
|
|
176
205
|
* nor the dump carries cert public keys.
|
|
177
206
|
*/
|
|
178
|
-
export type OptionalCheck = 'payload_binding' | 'oidc_actor' | 'actor_attribution' | 'key_temporal' | 'agent_signature' | 'key_anchoring';
|
|
207
|
+
export type OptionalCheck = 'payload_binding' | 'oidc_actor' | 'actor_attribution' | 'key_temporal' | 'agent_signature' | 'key_anchoring' | 'federation_wire' | 'evidence_binding';
|
|
179
208
|
/**
|
|
180
209
|
* `applied`: the check ran. `skipped_no_input`: the input it needs is absent.
|
|
181
210
|
* `not_checked`: the input was given but no entry reached the check, because
|
|
@@ -187,9 +216,9 @@ export interface SignatureOutcome {
|
|
|
187
216
|
/**
|
|
188
217
|
* - `ok` / `invalid` / `decode-fail`: the signature was checked (and passed,
|
|
189
218
|
* failed, or the envelope would not decode).
|
|
190
|
-
* - `unsigned`:
|
|
191
|
-
*
|
|
192
|
-
* `invalid` (CHAIN_SIGNATURE_INVALID), as the
|
|
219
|
+
* - `unsigned`: kept for type compatibility; `verifyChain` does not
|
|
220
|
+
* produce it. An all-zero signature on an entry that names a key is
|
|
221
|
+
* `invalid` (CHAIN_SIGNATURE_INVALID), as the Server grades it.
|
|
193
222
|
* - `skipped`: the chain is intact but this entry has no signing key, so the
|
|
194
223
|
* signature check was deliberately not run. Only an entry written before
|
|
195
224
|
* the install began signing gets here: before any signed entry in its
|
|
@@ -237,13 +266,13 @@ export type AccountedEntryCode = typeof ACCOUNTED_ENTRY_CODE;
|
|
|
237
266
|
* `distrustedKeys` names, that falls outside what the key is trusted for
|
|
238
267
|
* (the key is unanchored, or the entry was written at or after its cutoff),
|
|
239
268
|
* and that was written before a key the walk trusts retired it. The distrust
|
|
240
|
-
* entry and that retirement account for it, as the
|
|
269
|
+
* entry and that retirement account for it, as the Server's scan lists it in
|
|
241
270
|
* `distrustedEntries`: it is listed, it is not verified, and it fails
|
|
242
271
|
* nothing. An entry written after that retirement, or under a distrusted key
|
|
243
272
|
* no trusted key has retired, fails as before (CHAIN_SIGNING_KEY_UNANCHORED
|
|
244
273
|
* or CHAIN_KEY_EXPIRED). An audit export never carries one.
|
|
245
274
|
*
|
|
246
|
-
* `chain` and `recordId`/`orgId` name the chain as the
|
|
275
|
+
* `chain` and `recordId`/`orgId` name the chain as the Server does: a record
|
|
247
276
|
* chain by its record id, the platform-ops chain (record id
|
|
248
277
|
* 00000000-0000-0000-0000-000000000000) as `admin`, and an org's schema chain
|
|
249
278
|
* (`schema:<orgId>`, `schema:__platform__` for the platform's) as `schema`.
|
|
@@ -304,6 +333,45 @@ export interface ChainResult {
|
|
|
304
333
|
present: number;
|
|
305
334
|
verified: number;
|
|
306
335
|
};
|
|
336
|
+
/**
|
|
337
|
+
* Federation messages sealed on this chain (`payload.wire` on a receiving
|
|
338
|
+
* Server's FEDERATION_* entries). `present` counts entries that passed every
|
|
339
|
+
* other check and carry one, each held to its own body hash and to the entry
|
|
340
|
+
* that carries it; `verified` counts those whose sealed signature was also
|
|
341
|
+
* checked under a `federationKeys` entry for the sending hub and found good;
|
|
342
|
+
* `failed` counts those that failed a check (a body hash, the entry, or the
|
|
343
|
+
* signature under the key given for the hub). `present - verified - failed`
|
|
344
|
+
* is the messages from a hub with no key supplied. `afterRetirement`
|
|
345
|
+
* counts verified ones sealed under a key the sender's history retired
|
|
346
|
+
* before the sender signed the message (see `FederationWireOutcome`): in
|
|
347
|
+
* order when the receiver revoked the peer after them, so check its
|
|
348
|
+
* `federation.peer_revoked` audit row.
|
|
349
|
+
*/
|
|
350
|
+
federationWire: {
|
|
351
|
+
present: number;
|
|
352
|
+
verified: number;
|
|
353
|
+
failed: number;
|
|
354
|
+
afterRetirement: number;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Evidence bodies an `?evidence=true` export inlines (`entries[].evidence`
|
|
358
|
+
* on COMPLETION_SUBMITTED and DISPUTE_EVIDENCE). `present` counts entries
|
|
359
|
+
* that passed every other check and carry one; `verified` those whose body
|
|
360
|
+
* hashes, under RFC 8785 and SHA-256, to the signed `payload.evidenceHash`
|
|
361
|
+
* or `payload.payloadHash`; `clientHashed` those on an encrypted-mode
|
|
362
|
+
* completion (`payload.verifiedBy: "client"`), whose signed hash covers a
|
|
363
|
+
* cleartext the export does not carry, so the inlined ciphertext cannot be
|
|
364
|
+
* re-bound offline; `failed` those that did not hash to it, or sit where
|
|
365
|
+
* nothing signed binds a body. Always zero on a dump, which carries none.
|
|
366
|
+
*/
|
|
367
|
+
evidenceBinding: EvidenceBindingCounts;
|
|
368
|
+
}
|
|
369
|
+
/** See {@link ChainResult.evidenceBinding}. */
|
|
370
|
+
export interface EvidenceBindingCounts {
|
|
371
|
+
present: number;
|
|
372
|
+
verified: number;
|
|
373
|
+
clientHashed: number;
|
|
374
|
+
failed: number;
|
|
307
375
|
}
|
|
308
376
|
export interface VerifyChainOptions {
|
|
309
377
|
/** Require every entry's signingKeyId to equal this id (else CHAIN_KEY_POLICY_VIOLATION). */
|
|
@@ -318,11 +386,27 @@ export interface VerifyChainOptions {
|
|
|
318
386
|
requireSuppliedKeys?: boolean;
|
|
319
387
|
/**
|
|
320
388
|
* Agent cert keys (see `buildAgentKeyRegistry`). When an entry's signed
|
|
321
|
-
* payload carries
|
|
389
|
+
* payload carries a Server-validated `on_behalf_of.agent_signature` and its
|
|
322
390
|
* sealed cert thumbprint matches a key here, the signature is re-verified
|
|
323
391
|
* offline; a failure is CHAIN_AGENT_SIGNATURE_INVALID.
|
|
324
392
|
*/
|
|
325
393
|
agentKeys?: AgentKeyRegistry;
|
|
394
|
+
/**
|
|
395
|
+
* Sending hubs' federation keys (see `buildFederationKeyRegistry`). An entry
|
|
396
|
+
* that seals a peer's message (`payload.wire`) from a hub listed here has
|
|
397
|
+
* that message's signature re-verified under the key; a failure is
|
|
398
|
+
* CHAIN_FEDERATION_WIRE_INVALID. The hash and the entry's agreement with
|
|
399
|
+
* the sealed body are checked on every sealed message, with or without a key.
|
|
400
|
+
*/
|
|
401
|
+
federationKeys?: FederationKeyRegistry;
|
|
402
|
+
/**
|
|
403
|
+
* Accept a sealed federation message signed by a key its sender's history
|
|
404
|
+
* had retired before the message was signed (beyond the clock-skew
|
|
405
|
+
* allowance), counting it in `federationWire.afterRetirement`. For the short
|
|
406
|
+
* gap while a publisher restarts onto its new key. Without it such a
|
|
407
|
+
* message fails CHAIN_FEDERATION_WIRE_INVALID.
|
|
408
|
+
*/
|
|
409
|
+
allowAfterRetirement?: boolean;
|
|
326
410
|
/**
|
|
327
411
|
* The instant this install began signing: the earliest `activatedAt` across
|
|
328
412
|
* its whole signing key set, retired keys included. An entry with a null
|
|
@@ -342,9 +426,9 @@ export interface VerifyChainOptions {
|
|
|
342
426
|
/**
|
|
343
427
|
* The earliest `activatedAt` among `keys`, as the ISO string it was given in,
|
|
344
428
|
* or `null` when no key carries a parseable one. This is the instant from
|
|
345
|
-
* which the
|
|
429
|
+
* which the Server treats every chain entry and checkpoint as required to be
|
|
346
430
|
* signed; pass every key the verifier knows, retired ones included, since the
|
|
347
|
-
*
|
|
431
|
+
* Server reads it as `min(activated_at)` over its whole key registry.
|
|
348
432
|
*/
|
|
349
433
|
export declare function earliestKeyActivation(keys: Iterable<{
|
|
350
434
|
activatedAt?: string | null;
|
|
@@ -358,7 +442,7 @@ export declare function earliestKeyActivation(keys: Iterable<{
|
|
|
358
442
|
*
|
|
359
443
|
* False when `signingSince` is absent or unparseable: with no instant from
|
|
360
444
|
* which the install signs, nothing has to be signed. True when `signingSince`
|
|
361
|
-
* is known and `writtenAt` is missing or not strict RFC 3339: the
|
|
445
|
+
* is known and `writtenAt` is missing or not strict RFC 3339: the Server times every
|
|
362
446
|
* row, so a row with no readable time was edited, and it cannot be placed
|
|
363
447
|
* before signing began. It fails closed rather than reading as early history.
|
|
364
448
|
*/
|
|
@@ -369,3 +453,44 @@ export declare function writtenWhileSigning(writtenAt: unknown, signingSince: st
|
|
|
369
453
|
* validates the true chain; tampering surfaces through the hash links).
|
|
370
454
|
*/
|
|
371
455
|
export declare function verifyChain(entries: readonly NormalizedEntry[], keys: KeyRegistry, options?: VerifyChainOptions): ChainResult;
|
|
456
|
+
/**
|
|
457
|
+
* Where a signed artifact other than a chain entry falls against the window
|
|
458
|
+
* of the key that signed it. `inside`: the key's window covers its write time,
|
|
459
|
+
* or the key carries no window. `accounted`: it was written at or after the
|
|
460
|
+
* instant `distrustedKeys` gives for the key and before a key the walk trusts
|
|
461
|
+
* retired it. `not-yet-active` and `expired`: outside the window. `unplaceable`:
|
|
462
|
+
* the write time or a window edge is not an RFC 3339 instant, so the artifact
|
|
463
|
+
* cannot be placed and the caller fails closed.
|
|
464
|
+
*/
|
|
465
|
+
export type KeyWindowPlacement = {
|
|
466
|
+
placement: 'inside' | 'accounted';
|
|
467
|
+
} | {
|
|
468
|
+
placement: 'not-yet-active' | 'expired' | 'unplaceable';
|
|
469
|
+
detail: string;
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* Place a vault checkpoint, a read-log leaf or a read-log tree head in the
|
|
473
|
+
* signed window of its key, by the time its row was written. The rule is the
|
|
474
|
+
* one chain entries are held to (CHAIN_KEY_NOT_YET_ACTIVE, CHAIN_KEY_EXPIRED):
|
|
475
|
+
* each edge is checked only when the key carries it, at millisecond
|
|
476
|
+
* precision, and an artifact written exactly at the key's retirement is
|
|
477
|
+
* inside. `what` names the artifact in the detail ("Checkpoint", "Leaf").
|
|
478
|
+
*
|
|
479
|
+
* The caller verifies the signature first: the Server reports a signature
|
|
480
|
+
* that does not verify ahead of a window finding.
|
|
481
|
+
*/
|
|
482
|
+
export declare function placeInKeyWindow(key: VerificationKey, writtenAt: unknown, what: string): KeyWindowPlacement;
|
|
483
|
+
/**
|
|
484
|
+
* Whether a `distrustedKeys` entry and the retirement a trusted key signed
|
|
485
|
+
* account for an artifact signed under `key` and written at `writtenAt`: the
|
|
486
|
+
* key is unanchored only because of the entry, or anchored and the artifact
|
|
487
|
+
* written at or after the entry's instant, and in both cases the artifact was
|
|
488
|
+
* written before that retirement. The same condition lists a chain entry as
|
|
489
|
+
* CHAIN_SIGNED_BY_DISTRUSTED_KEY.
|
|
490
|
+
*
|
|
491
|
+
* Such an artifact is listed, never verified, and never evidence for or
|
|
492
|
+
* against anything else. The caller still verifies its signature under the
|
|
493
|
+
* key before setting it aside: anything else under the key's id is bytes
|
|
494
|
+
* whoever writes to the database wrote.
|
|
495
|
+
*/
|
|
496
|
+
export declare function distrustAccounts(key: VerificationKey, writtenAt: unknown): boolean;
|