@agledger/verify-core 2.2.0 → 4.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 +18 -18
- package/README.md +797 -29
- package/dist/acknowledgements.d.ts +32 -0
- package/dist/acknowledgements.js +88 -0
- package/dist/anchors.d.ts +349 -0
- package/dist/anchors.js +654 -0
- package/dist/attestation.d.ts +98 -0
- package/dist/attestation.js +145 -0
- package/dist/audit-export.d.ts +343 -20
- package/dist/audit-export.js +400 -22
- package/dist/batch-head.d.ts +28 -0
- package/dist/batch-head.js +169 -0
- package/dist/batch.d.ts +69 -0
- package/dist/batch.js +99 -0
- package/dist/bulk-export.d.ts +161 -0
- package/dist/bulk-export.js +711 -0
- package/dist/chain.d.ts +135 -13
- package/dist/chain.js +229 -24
- package/dist/claim.d.ts +23 -0
- package/dist/claim.js +100 -0
- package/dist/export-anchors.d.ts +84 -0
- package/dist/export-anchors.js +109 -0
- package/dist/export-evidence.d.ts +90 -0
- package/dist/export-evidence.js +186 -0
- package/dist/export-pages.d.ts +476 -0
- package/dist/export-pages.js +586 -0
- package/dist/failures.d.ts +20 -16
- package/dist/failures.js +44 -16
- package/dist/federation-wire.d.ts +78 -11
- package/dist/federation-wire.js +199 -57
- package/dist/history-seal.d.ts +100 -0
- package/dist/history-seal.js +301 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.js +17 -4
- package/dist/key-statements.d.ts +138 -5
- package/dist/key-statements.js +191 -20
- package/dist/ml-dsa-kats.d.ts +18 -0
- package/dist/ml-dsa-kats.js +241 -0
- package/dist/primitives.d.ts +255 -18
- package/dist/primitives.js +612 -55
- package/dist/read-log.d.ts +350 -0
- package/dist/read-log.js +816 -0
- package/dist/schema-chain-export.d.ts +82 -0
- package/dist/schema-chain-export.js +474 -0
- package/dist/walk-anchors.d.ts +115 -0
- package/dist/walk-anchors.js +133 -0
- package/dist/walk-checkpoints.d.ts +125 -0
- package/dist/walk-checkpoints.js +118 -0
- package/package.json +6 -5
package/dist/anchors.js
ADDED
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holding a chain to the anchor bucket: the documents the Server writes under
|
|
3
|
+
* `vault-anchors/<instanceId>/<chainKey>/<chainPosition>.json`, one per
|
|
4
|
+
* checkpoint it anchors, and the acknowledgements of lost history (signed
|
|
5
|
+
* RESTORE_EPOCH entries on the platform-ops chain) that account for an anchor
|
|
6
|
+
* the chain no longer matches.
|
|
7
|
+
*
|
|
8
|
+
* Only the signed `coseSign1` inside a document is evidence. A document is
|
|
9
|
+
* kept when that envelope verifies as a vault checkpoint of the chain under a
|
|
10
|
+
* published key, at a signed `iat` inside the key's window; every other
|
|
11
|
+
* object is reported as not comparable and is evidence of nothing. A kept
|
|
12
|
+
* document at position P is compared with the chain: P above the last entry
|
|
13
|
+
* is a cut, a signed tip that is not the entry's payloadHash at P is a
|
|
14
|
+
* rewrite, and two kept documents at one position over different tips are a
|
|
15
|
+
* fork. Each is accounted for, and is lost history an operator declared, when
|
|
16
|
+
* an acknowledgement that verifies lists `{ recordId: chainKey, lo, hi }` in
|
|
17
|
+
* its signed `coveredFindings` with lo < P <= hi and lo at or below the last
|
|
18
|
+
* entry, and was signed after the anchor.
|
|
19
|
+
*/
|
|
20
|
+
import { distrustAccounts, placeInKeyWindow, writtenWhileSigning } from './chain.js';
|
|
21
|
+
import { decodeSignedClaim, UNSIGNED_KID, uuidSubjectDigest } from './claim.js';
|
|
22
|
+
import { PLATFORM_OPS_CHAIN_KEY } from './history-seal.js';
|
|
23
|
+
import { entryRun, isVerifyingAsIfHostComputed, sha256Hex, sha256HexString, uncomputableAlgorithm, verifyCoseSign1 } from './primitives.js';
|
|
24
|
+
/** The `version` of the anchor documents a Server writes. Version 1 carried a raw signature and no COSE envelope, and no Server reads it. */
|
|
25
|
+
export const ANCHOR_DOCUMENT_VERSION = 2;
|
|
26
|
+
/** The in-toto `predicateType` of a vault checkpoint. */
|
|
27
|
+
export const VAULT_CHECKPOINT_PREDICATE_TYPE = 'https://agledger.ai/predicates/vault-checkpoint/v1';
|
|
28
|
+
/**
|
|
29
|
+
* How far a signed `iat` may sit outside its key's window at each edge and
|
|
30
|
+
* still be inside it: the Server's allowance for clock skew between hosts.
|
|
31
|
+
*/
|
|
32
|
+
export const KEY_WINDOW_CLOCK_SKEW_SECONDS = 300;
|
|
33
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
34
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
35
|
+
const OBJECT_KEY = /^vault-anchors\/([^/]+)\/([^/]+)\/(\d+)\.json$/;
|
|
36
|
+
function isRecord(value) {
|
|
37
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
38
|
+
}
|
|
39
|
+
/** The ISO instant of a signed `iat`, or null when it is not a time a Date holds. */
|
|
40
|
+
function iatInstant(iat) {
|
|
41
|
+
const ms = iat * 1000;
|
|
42
|
+
return Number.isFinite(ms) && Math.abs(ms) <= 8.64e15 ? new Date(ms).toISOString() : null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Place an envelope in its key's window by its signed `iat` (whole seconds),
|
|
46
|
+
* allowing {@link KEY_WINDOW_CLOCK_SKEW_SECONDS} at the activation and
|
|
47
|
+
* retirement edges as the Server's offline procedure does. A distrust cutoff
|
|
48
|
+
* is held without the allowance: what a distrusted key signed at or after it
|
|
49
|
+
* counts for nothing.
|
|
50
|
+
*/
|
|
51
|
+
export function placeSignedIat(key, iat, what) {
|
|
52
|
+
const at = iatInstant(iat);
|
|
53
|
+
if (at === null)
|
|
54
|
+
return { placement: 'unplaceable', detail: `${what} signs iat ${iat}, which is not a time, so it cannot be placed inside key ${key.keyId}'s window.` };
|
|
55
|
+
const widen = (edge, by) => {
|
|
56
|
+
if (typeof edge !== 'string')
|
|
57
|
+
return edge;
|
|
58
|
+
const ms = Date.parse(edge);
|
|
59
|
+
return Number.isNaN(ms) ? edge : new Date(ms + by * 1000).toISOString();
|
|
60
|
+
};
|
|
61
|
+
const widened = {
|
|
62
|
+
...key,
|
|
63
|
+
...(key.activatedAt !== undefined ? { activatedAt: widen(key.activatedAt, -KEY_WINDOW_CLOCK_SKEW_SECONDS) } : {}),
|
|
64
|
+
...(key.retiredAt !== undefined ? { retiredAt: widen(key.retiredAt, KEY_WINDOW_CLOCK_SKEW_SECONDS) } : {}),
|
|
65
|
+
};
|
|
66
|
+
const placed = placeInKeyWindow(widened, at, what);
|
|
67
|
+
if (placed.placement === 'not-yet-active') {
|
|
68
|
+
return { placement: 'not-yet-active', detail: `${what} signs iat ${at}, more than ${KEY_WINDOW_CLOCK_SKEW_SECONDS} seconds before key ${key.keyId} was activated (${String(key.activatedAt)}).` };
|
|
69
|
+
}
|
|
70
|
+
if (placed.placement === 'expired') {
|
|
71
|
+
return typeof key.distrustCutoff === 'string' && Date.parse(at) > Date.parse(key.distrustCutoff)
|
|
72
|
+
? { placement: 'expired', detail: `${what} signs iat ${at}, after ${key.distrustCutoff}, the instant distrustedKeys gives for key ${key.keyId}.` }
|
|
73
|
+
: { placement: 'expired', detail: `${what} signs iat ${at}, more than ${KEY_WINDOW_CLOCK_SKEW_SECONDS} seconds after key ${key.keyId} was retired (${String(key.retiredAt)}).` };
|
|
74
|
+
}
|
|
75
|
+
return placed;
|
|
76
|
+
}
|
|
77
|
+
/** Whether this host refused to compute signatures under `key`: its algorithm, or the only statement linking it to an anchor. */
|
|
78
|
+
function refusedByHost(key) {
|
|
79
|
+
return key.trust === 'undecided' || uncomputableAlgorithm(key.spkiBase64)?.cause === 'host';
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Read one document as far as no key is needed: its shape, its key, its
|
|
83
|
+
* envelope as a vault checkpoint, and the claim's own consistency.
|
|
84
|
+
*/
|
|
85
|
+
function readDocument(input) {
|
|
86
|
+
const doc = input.document;
|
|
87
|
+
const fail = (reason, detail, claim = null) => ({ ok: false, reason, detail, claim });
|
|
88
|
+
if (!isRecord(doc))
|
|
89
|
+
return fail('not_an_anchor_document', 'not a JSON object');
|
|
90
|
+
if (doc['kind'] === 'scitt-tree-head') {
|
|
91
|
+
return fail('scitt_head_document', 'a SCITT tree-head anchor: it commits to an org\'s SCITT log at a tree size, not to a chain position');
|
|
92
|
+
}
|
|
93
|
+
if (doc['version'] !== ANCHOR_DOCUMENT_VERSION) {
|
|
94
|
+
return doc['version'] === 1
|
|
95
|
+
? fail('unsupported_document_version', 'an anchor document of version 1, which carries a raw signature and no COSE_Sign1 envelope; no current Server reads one')
|
|
96
|
+
: fail(Number.isInteger(doc['version']) ? 'unsupported_document_version' : 'not_an_anchor_document', `version ${JSON.stringify(doc['version'] ?? null)} is not ${ANCHOR_DOCUMENT_VERSION}`);
|
|
97
|
+
}
|
|
98
|
+
const shapeOk = typeof doc['instanceId'] === 'string'
|
|
99
|
+
&& typeof doc['recordId'] === 'string'
|
|
100
|
+
&& Number.isInteger(doc['chainPosition'])
|
|
101
|
+
&& typeof doc['payloadHash'] === 'string'
|
|
102
|
+
&& typeof doc['coseSign1'] === 'string'
|
|
103
|
+
&& (doc['signingKeyId'] === null || typeof doc['signingKeyId'] === 'string')
|
|
104
|
+
&& typeof doc['anchoredAt'] === 'string';
|
|
105
|
+
if (!shapeOk) {
|
|
106
|
+
return fail('not_an_anchor_document', 'not the anchor document shape { version, instanceId, recordId, chainPosition, payloadHash, coseSign1, signingKeyId, anchoredAt }');
|
|
107
|
+
}
|
|
108
|
+
if (input.objectKey !== undefined) {
|
|
109
|
+
const m = OBJECT_KEY.exec(input.objectKey);
|
|
110
|
+
if (m === null || m[1] !== doc['instanceId'] || m[2] !== doc['recordId'] || Number(m[3]) !== doc['chainPosition']) {
|
|
111
|
+
return fail('key_mismatch', `its instanceId, recordId and chainPosition do not name the key it was stored under (${input.objectKey}), so it is no anchor of that position`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const bytes = Buffer.from(doc['coseSign1'], 'base64');
|
|
115
|
+
const claim = decodeSignedClaim(bytes);
|
|
116
|
+
if (claim === null)
|
|
117
|
+
return fail('not_a_checkpoint', 'its coseSign1 does not decode as a signed AGLedger claim');
|
|
118
|
+
if (claim.predicateType !== VAULT_CHECKPOINT_PREDICATE_TYPE) {
|
|
119
|
+
return fail('not_a_checkpoint', `its envelope is a ${claim.predicateType} statement, not a vault checkpoint`, claim);
|
|
120
|
+
}
|
|
121
|
+
const p = claim.predicate;
|
|
122
|
+
const range = isRecord(p['range']) ? p['range'] : {};
|
|
123
|
+
const tipRaw = p['chain_tip_hash'];
|
|
124
|
+
const tip = typeof tipRaw === 'string' && tipRaw.startsWith('sha256:') ? tipRaw.slice('sha256:'.length) : '';
|
|
125
|
+
if (!Number.isSafeInteger(claim.position) || claim.position < 1 || p['count'] !== claim.position
|
|
126
|
+
|| range['start'] !== 1 || range['end'] !== claim.position || !HEX64.test(tip)) {
|
|
127
|
+
return fail('not_a_checkpoint', `its signed claim does not name one position: chain position ${claim.position}, count ${JSON.stringify(p['count'] ?? null)}, range ${JSON.stringify(p['range'] ?? null)}, chain_tip_hash ${JSON.stringify(tipRaw ?? null)}`, claim);
|
|
128
|
+
}
|
|
129
|
+
const unsigned = [];
|
|
130
|
+
if (typeof doc['recordId'] === 'string' && doc['recordId'].toLowerCase() !== claim.sub.toLowerCase())
|
|
131
|
+
unsigned.push(`recordId ${JSON.stringify(doc['recordId'])} where the checkpoint signs ${claim.sub}`);
|
|
132
|
+
if (doc['chainPosition'] !== claim.position)
|
|
133
|
+
unsigned.push(`chainPosition ${String(doc['chainPosition'])} where the checkpoint signs ${claim.position}`);
|
|
134
|
+
if (doc['payloadHash'] !== tip)
|
|
135
|
+
unsigned.push(`payloadHash ${JSON.stringify(doc['payloadHash'])} where the checkpoint signs sha256:${tip}`);
|
|
136
|
+
if ((doc['signingKeyId'] ?? UNSIGNED_KID) !== claim.kid)
|
|
137
|
+
unsigned.push(`signingKeyId ${JSON.stringify(doc['signingKeyId'])} where the envelope signs kid ${claim.kid}`);
|
|
138
|
+
return { ok: true, doc: { input, claim, bytes, tip, unsignedDisagreements: unsigned } };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The chain key an anchor document's checkpoint signs (`cwt.sub`, lowercase),
|
|
142
|
+
* or null when the document is not a version 2 anchor document whose envelope
|
|
143
|
+
* decodes as a vault checkpoint. For sorting documents by chain before
|
|
144
|
+
* {@link compareCheckpointAnchors}, which holds each to its chain's subject
|
|
145
|
+
* digest.
|
|
146
|
+
*/
|
|
147
|
+
export function anchorDocumentChainKey(input) {
|
|
148
|
+
const read = readDocument(input);
|
|
149
|
+
return read.ok ? read.doc.claim.sub.toLowerCase() : null;
|
|
150
|
+
}
|
|
151
|
+
/** The signed `iat` of an anchor document's checkpoint, or null when it does not read. */
|
|
152
|
+
export function anchorDocumentIat(input) {
|
|
153
|
+
const read = readDocument(input);
|
|
154
|
+
return read.ok ? read.doc.claim.iat : null;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The verdict on a document {@link readDocument} could not read, for a
|
|
158
|
+
* caller sorting documents by chain before the comparison.
|
|
159
|
+
*/
|
|
160
|
+
export function unreadableAnchorVerdict(input) {
|
|
161
|
+
const read = readDocument(input);
|
|
162
|
+
if (read.ok)
|
|
163
|
+
return null;
|
|
164
|
+
return {
|
|
165
|
+
kind: 'not_comparable',
|
|
166
|
+
reason: read.reason,
|
|
167
|
+
source: input.source,
|
|
168
|
+
...(input.objectKey !== undefined ? { objectKey: input.objectKey } : {}),
|
|
169
|
+
position: read.claim?.position ?? null,
|
|
170
|
+
iat: read.claim?.iat ?? null,
|
|
171
|
+
keyId: read.claim?.kid ?? null,
|
|
172
|
+
detail: `${input.source}: ${read.detail}.`,
|
|
173
|
+
unsignedDisagreements: [],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function judgeEnvelope(doc, keys) {
|
|
177
|
+
const { claim } = doc;
|
|
178
|
+
const drop = (reason, detail) => ({ state: 'dropped', doc, reason, detail });
|
|
179
|
+
if (claim.kid === UNSIGNED_KID) {
|
|
180
|
+
return drop('unsigned_checkpoint', 'its checkpoint is unsigned, which anyone who can read the chain tip can make');
|
|
181
|
+
}
|
|
182
|
+
const key = keys.get(claim.kid);
|
|
183
|
+
if (key === undefined)
|
|
184
|
+
return drop('key_unknown', `its kid ${claim.kid} names no published key`);
|
|
185
|
+
const distrusted = distrustAccounts(key, iatInstant(claim.iat));
|
|
186
|
+
if (key.trust === 'unanchored' && !distrusted) {
|
|
187
|
+
return drop('key_unanchored', `key ${key.keyId} is not linked by signed key statements to a trust anchor`);
|
|
188
|
+
}
|
|
189
|
+
// Signature shape, header alg and the key window need no computation, so
|
|
190
|
+
// they read the same on every host and run before the host is asked.
|
|
191
|
+
const outcome = verifyCoseSign1(doc.bytes, key.spkiBase64);
|
|
192
|
+
if (outcome !== 'ok' && outcome !== 'unsupported-key-algorithm') {
|
|
193
|
+
return drop('signature_invalid', `its signature does not verify under key ${key.keyId} (${outcome})`);
|
|
194
|
+
}
|
|
195
|
+
if (outcome === 'ok' && distrusted) {
|
|
196
|
+
return drop('key_distrusted', `key ${key.keyId} signed it at or after the instant distrustedKeys gives for that key, so it counts for nothing`);
|
|
197
|
+
}
|
|
198
|
+
const placed = placeSignedIat(key, claim.iat, 'The checkpoint');
|
|
199
|
+
if (placed.placement === 'not-yet-active' || placed.placement === 'expired' || placed.placement === 'unplaceable') {
|
|
200
|
+
return drop('outside_key_window', placed.detail);
|
|
201
|
+
}
|
|
202
|
+
if (refusedByHost(key) || outcome === 'unsupported-key-algorithm')
|
|
203
|
+
return { state: 'refused', doc, key };
|
|
204
|
+
return { state: 'kept', doc };
|
|
205
|
+
}
|
|
206
|
+
/** What a kept document shows against the chain, before acknowledgements. */
|
|
207
|
+
function compareOne(doc, chain, byPosition) {
|
|
208
|
+
const P = doc.claim.position;
|
|
209
|
+
const last = chain.lastEntryPosition;
|
|
210
|
+
if (last === null || P > last) {
|
|
211
|
+
return {
|
|
212
|
+
kind: 'disagree',
|
|
213
|
+
code: 'ANCHOR_CHAIN_CUT',
|
|
214
|
+
detail: last === null
|
|
215
|
+
? `the anchor signs position ${P} of a chain of which nothing is held: ${entryRun(1, P, 'are')} missing`
|
|
216
|
+
: `the anchor signs position ${P} and the last entry held is ${last}: ${entryRun(last + 1, P, 'are')} missing`,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const held = byPosition.get(P);
|
|
220
|
+
if (held === undefined) {
|
|
221
|
+
return { kind: 'disagree', code: 'ANCHOR_CHAIN_CUT', detail: `the anchor signs position ${P} and no entry is held there` };
|
|
222
|
+
}
|
|
223
|
+
if (held !== doc.tip) {
|
|
224
|
+
return {
|
|
225
|
+
kind: 'disagree',
|
|
226
|
+
code: 'ANCHOR_CHAIN_REWRITTEN',
|
|
227
|
+
detail: `the anchor signs tip sha256:${doc.tip} at position ${P} and the entry held there has payloadHash ${JSON.stringify(held)}: the chain was written again at or below position ${P}`,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const sha = sha256Hex(doc.bytes);
|
|
231
|
+
const same = (chain.checkpoints ?? []).some((c) => c.chainPosition === P && c.coseSign1Sha256 === sha);
|
|
232
|
+
return {
|
|
233
|
+
kind: 'agree',
|
|
234
|
+
how: same ? 'same_bytes' : 'same_tip',
|
|
235
|
+
detail: same
|
|
236
|
+
? `the anchor holds the same checkpoint envelope the artifact carries at position ${P}`
|
|
237
|
+
: `the anchor's signed tip at position ${P} is the payloadHash of the entry held there`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The acknowledgement that accounts for a disagreement at `position` signed
|
|
242
|
+
* at `anchorIat`, by the Server's rule: a signed finding `{ recordId:
|
|
243
|
+
* chainKey, lo, hi }` with lo < P <= hi and lo at or below the last entry,
|
|
244
|
+
* signed after the anchor (whole seconds, so an anchor in the same second is
|
|
245
|
+
* not before it). A verified one first; else one this host could not compute.
|
|
246
|
+
*/
|
|
247
|
+
function coveringAcknowledgement(acknowledgements, chain, position, anchorIat) {
|
|
248
|
+
const lastHeld = chain.lastEntryPosition ?? 0;
|
|
249
|
+
const covers = (a) => a.iat > anchorIat && a.coveredFindings.some((f) => f.recordId.toLowerCase() === chain.chainKey.toLowerCase() && f.lo < position && position <= f.hi && f.lo <= lastHeld);
|
|
250
|
+
const verified = acknowledgements.find((a) => a.state === 'verified' && covers(a));
|
|
251
|
+
if (verified !== undefined)
|
|
252
|
+
return { verified };
|
|
253
|
+
const uncomputable = acknowledgements.find((a) => a.state === 'uncomputable' && covers(a));
|
|
254
|
+
return uncomputable !== undefined ? { uncomputable } : {};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Compare anchor documents with one chain.
|
|
258
|
+
*
|
|
259
|
+
* Every document gets one verdict: `agree`, `disagree` (with its code),
|
|
260
|
+
* `accounted` (a disagreement an acknowledgement that verifies covers) or
|
|
261
|
+
* `not_comparable` (with the reason). `findings` carries each unaccounted
|
|
262
|
+
* disagreement, at most one per position and code, every ANCHOR_FORK before
|
|
263
|
+
* any ANCHOR_CHAIN_CUT or ANCHOR_CHAIN_REWRITTEN (the failure order the
|
|
264
|
+
* conformance corpus states: an acknowledgement that does not verify, which
|
|
265
|
+
* the caller reports first, then a fork, then a cut or a rewrite), and a
|
|
266
|
+
* CHAIN_UNSUPPORTED_ALGORITHM for each anchor this host refused to compute
|
|
267
|
+
* and each disagreement only an acknowledgement this host refused would
|
|
268
|
+
* account for. A refused anchor is never evidence either way: in a run that
|
|
269
|
+
* assumes the host's refusals verified (`verifyAsIfHostComputed`) it is left
|
|
270
|
+
* out rather than assumed, so a disagreement it would show never fails a
|
|
271
|
+
* verdict, and an agreement never passes one.
|
|
272
|
+
*
|
|
273
|
+
* `keys` is the registry the artifact's entries are verified under, after the
|
|
274
|
+
* trust walk. `acknowledgements` are the ones already judged
|
|
275
|
+
* (`verifyRewindAcknowledgements` for an export, the platform-ops chain's
|
|
276
|
+
* RESTORE_EPOCH entries for a dump).
|
|
277
|
+
*/
|
|
278
|
+
export function compareCheckpointAnchors(documents, chain, keys, acknowledgements = []) {
|
|
279
|
+
const out = {
|
|
280
|
+
applicability: documents.length === 0 ? 'skipped_no_input' : 'not_checked',
|
|
281
|
+
chainKey: chain.chainKey,
|
|
282
|
+
judgedThroughIat: chain.judgedThroughIat,
|
|
283
|
+
verdicts: [],
|
|
284
|
+
counts: { agree: 0, disagree: 0, accounted: 0, notComparable: 0 },
|
|
285
|
+
findings: [],
|
|
286
|
+
capped: [],
|
|
287
|
+
};
|
|
288
|
+
const subject = uuidSubjectDigest(chain.chainKey);
|
|
289
|
+
const byPosition = new Map(chain.entries.map((e) => [e.chainPosition, e.payloadHash]));
|
|
290
|
+
const base = (input, claim, unsigned) => ({
|
|
291
|
+
source: input.source,
|
|
292
|
+
...(input.objectKey !== undefined ? { objectKey: input.objectKey } : {}),
|
|
293
|
+
position: claim?.position ?? null,
|
|
294
|
+
iat: claim?.iat ?? null,
|
|
295
|
+
keyId: claim?.kid ?? null,
|
|
296
|
+
unsignedDisagreements: unsigned,
|
|
297
|
+
});
|
|
298
|
+
const verdictAt = documents.map(() => null);
|
|
299
|
+
const kept = [];
|
|
300
|
+
documents.forEach((input, i) => {
|
|
301
|
+
const read = readDocument(input);
|
|
302
|
+
if (!read.ok) {
|
|
303
|
+
verdictAt[i] = { ...base(input, read.claim, []), kind: 'not_comparable', reason: read.reason, detail: `${input.source}: ${read.detail}.` };
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const { doc } = read;
|
|
307
|
+
if (subject === null || doc.claim.subjectSha256 !== subject) {
|
|
308
|
+
verdictAt[i] = { ...base(input, doc.claim, doc.unsignedDisagreements), kind: 'not_comparable', reason: 'other_chain', detail: `${input.source}: a checkpoint of chain ${doc.claim.sub}, not of ${chain.chainKey}.` };
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const judged = judgeEnvelope(doc, keys);
|
|
312
|
+
if (judged.state === 'dropped') {
|
|
313
|
+
verdictAt[i] = { ...base(input, doc.claim, doc.unsignedDisagreements), kind: 'not_comparable', reason: judged.reason, detail: `${input.source}: ${judged.detail}; it is evidence of nothing.` };
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const P = doc.claim.position;
|
|
317
|
+
const part = chain.heldInPart;
|
|
318
|
+
const outside = part !== undefined && ((part.firstHeld !== undefined && P < part.firstHeld) || (part.lastHeld !== undefined && P > part.lastHeld));
|
|
319
|
+
const timed = chain.judgedThroughIat !== null && doc.claim.iat > chain.judgedThroughIat;
|
|
320
|
+
const untimed = chain.judgedThroughIat === null && (chain.lastEntryPosition === null || P > chain.lastEntryPosition);
|
|
321
|
+
const outcome = compareOne(doc, chain, byPosition);
|
|
322
|
+
const unchecked = judged.state === 'refused' ? ` Its signature could NOT BE CHECKED on this host (key ${judged.key.keyId}) either.` : '';
|
|
323
|
+
if (outside) {
|
|
324
|
+
verdictAt[i] = {
|
|
325
|
+
...base(input, doc.claim, doc.unsignedDisagreements),
|
|
326
|
+
kind: 'not_comparable',
|
|
327
|
+
reason: 'chain_held_in_part',
|
|
328
|
+
detail: `${input.source}: its checkpoint signs position ${P}, outside the run of the chain this artifact holds (${part.firstHeld ?? 1} to ${part.lastHeld ?? chain.lastEntryPosition ?? 'none'}): ${part.reason}${unchecked}`,
|
|
329
|
+
};
|
|
330
|
+
// A verified signed tip for its position still counts for the fork question.
|
|
331
|
+
if (judged.state === 'kept')
|
|
332
|
+
kept.push({ i, doc, outcome: { kind: 'agree', how: 'same_tip', detail: '' } });
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (judged.state === 'refused' && !timed && !untimed) {
|
|
336
|
+
const wouldBe = outcome.kind === 'agree' ? 'agree' : outcome.code;
|
|
337
|
+
verdictAt[i] = {
|
|
338
|
+
...base(input, doc.claim, doc.unsignedDisagreements),
|
|
339
|
+
kind: 'not_comparable',
|
|
340
|
+
reason: 'unsupported_algorithm',
|
|
341
|
+
ifVerified: wouldBe,
|
|
342
|
+
detail: `${input.source}: the signature of the checkpoint at position ${P} could NOT BE CHECKED on this host (key ${judged.key.keyId}), so it is evidence neither way; were it verified, ${outcome.detail}.`,
|
|
343
|
+
};
|
|
344
|
+
// Left out of a run that assumes the host's refusals verified: an
|
|
345
|
+
// anchor this host cannot verify never fails a verdict, nor passes one.
|
|
346
|
+
if (!isVerifyingAsIfHostComputed()) {
|
|
347
|
+
out.findings.push({ position: P, code: 'CHAIN_UNSUPPORTED_ALGORITHM', detail: `Anchor ${input.source} at position ${P}: its checkpoint's signature could NOT BE CHECKED: key ${judged.key.keyId} commits to an algorithm this host cannot compute, or is reached only through a key statement this host could not check.` });
|
|
348
|
+
}
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const aboveEnd = chain.lastEntryPosition === null || P > chain.lastEntryPosition;
|
|
352
|
+
if (timed) {
|
|
353
|
+
const ownWord = aboveEnd && chain.readTimeGiven !== true;
|
|
354
|
+
verdictAt[i] = {
|
|
355
|
+
...base(input, doc.claim, doc.unsignedDisagreements),
|
|
356
|
+
kind: 'not_comparable',
|
|
357
|
+
reason: 'signed_after_read',
|
|
358
|
+
detail: ownWord
|
|
359
|
+
? `${input.source}: its checkpoint signs position ${P}, above the last entry held (${chain.lastEntryPosition ?? 'none'}), at iat ${doc.claim.iat}, after ${chain.judgedThroughIat}, the latest iat judged against the read time the artifact states about itself. That time is unsigned, so this anchor is either entries written after the read or a cut, and the verdict reads at best not anchored. Give the time the artifact was read as exportDate to judge it.${unchecked}`
|
|
360
|
+
: `${input.source}: its checkpoint at position ${P} was signed at iat ${doc.claim.iat}, after ${chain.judgedThroughIat}, the latest iat judged against this read; it may cover entries written since.${unchecked}`,
|
|
361
|
+
};
|
|
362
|
+
if (ownWord)
|
|
363
|
+
out.capped.push(`Anchor ${input.source} signs position ${P}, above the last entry held (${chain.lastEntryPosition ?? 'none'}), after the read time the artifact states about itself, which is unsigned. Give the time the artifact was read as exportDate to judge it.`);
|
|
364
|
+
// A verified signed tip for its position still counts for the fork question.
|
|
365
|
+
if (judged.state === 'kept')
|
|
366
|
+
kept.push({ i, doc, outcome: { kind: 'agree', how: 'same_tip', detail: '' } });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (untimed) {
|
|
370
|
+
verdictAt[i] = {
|
|
371
|
+
...base(input, doc.claim, doc.unsignedDisagreements),
|
|
372
|
+
kind: 'not_comparable',
|
|
373
|
+
reason: 'no_read_time',
|
|
374
|
+
detail: `${input.source}: its checkpoint signs position ${P}, above the last entry held (${chain.lastEntryPosition ?? 'none'}), and no read time is known, so entries written after the read cannot be told from a cut, and the verdict reads at best not anchored. Give the time the artifact was read as exportDate to judge it.${unchecked}`,
|
|
375
|
+
};
|
|
376
|
+
out.capped.push(`Anchor ${input.source} signs position ${P}, above the last entry held (${chain.lastEntryPosition ?? 'none'}), and no read time is known. Give the time the artifact was read as exportDate to judge it.`);
|
|
377
|
+
if (judged.state === 'kept')
|
|
378
|
+
kept.push({ i, doc, outcome: { kind: 'agree', how: 'same_tip', detail: '' } });
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
kept.push({ i, doc, outcome });
|
|
382
|
+
});
|
|
383
|
+
// A fork: two verified documents of one position over different signed
|
|
384
|
+
// tips, whatever their read time, since a position is anchored once.
|
|
385
|
+
const tipsAt = new Map();
|
|
386
|
+
for (const k of kept) {
|
|
387
|
+
const set = tipsAt.get(k.doc.claim.position) ?? new Set();
|
|
388
|
+
set.add(k.doc.tip);
|
|
389
|
+
tipsAt.set(k.doc.claim.position, set);
|
|
390
|
+
}
|
|
391
|
+
const reported = new Set();
|
|
392
|
+
for (const k of kept) {
|
|
393
|
+
const P = k.doc.claim.position;
|
|
394
|
+
const forked = (tipsAt.get(P)?.size ?? 0) > 1;
|
|
395
|
+
const existing = verdictAt[k.i];
|
|
396
|
+
if (existing !== null && !forked)
|
|
397
|
+
continue;
|
|
398
|
+
const b = base(k.doc.input, k.doc.claim, k.doc.unsignedDisagreements);
|
|
399
|
+
let code;
|
|
400
|
+
let detail;
|
|
401
|
+
let anchorIat = k.doc.claim.iat;
|
|
402
|
+
if (forked) {
|
|
403
|
+
code = 'ANCHOR_FORK';
|
|
404
|
+
const others = kept.filter((o) => o.doc.claim.position === P);
|
|
405
|
+
anchorIat = Math.max(...others.map((o) => o.doc.claim.iat));
|
|
406
|
+
detail = `${[...(tipsAt.get(P) ?? [])].length} anchors whose checkpoints verify sign different tips for position ${P} (${[...(tipsAt.get(P) ?? [])].map((t) => `sha256:${t}`).join(', ')})`;
|
|
407
|
+
}
|
|
408
|
+
else if (k.outcome.kind === 'agree') {
|
|
409
|
+
verdictAt[k.i] = { ...b, kind: 'agree', how: k.outcome.how, detail: `${k.doc.input.source}: ${k.outcome.detail}.` };
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
code = k.outcome.code;
|
|
414
|
+
detail = k.outcome.detail;
|
|
415
|
+
}
|
|
416
|
+
const cover = coveringAcknowledgement(acknowledgements, chain, P, anchorIat);
|
|
417
|
+
if (cover.verified !== undefined) {
|
|
418
|
+
const a = cover.verified;
|
|
419
|
+
verdictAt[k.i] = {
|
|
420
|
+
...b,
|
|
421
|
+
kind: 'accounted',
|
|
422
|
+
code,
|
|
423
|
+
acknowledgement: { entryId: a.entryId, chainPosition: a.chainPosition, linkChecked: a.linkChecked },
|
|
424
|
+
detail: `${k.doc.input.source}: ${detail}; an acknowledgement of lost history accounts for it (RESTORE_EPOCH ${a.entryId ?? 'with no id'} at platform-ops position ${a.chainPosition}, signed at iat ${a.iat}${a.linkChecked ? '' : '; its link in the platform-ops chain is established only by a dump of that chain'}).`,
|
|
425
|
+
};
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
const key = `${code}:${P}`;
|
|
429
|
+
if (cover.uncomputable !== undefined) {
|
|
430
|
+
const a = cover.uncomputable;
|
|
431
|
+
verdictAt[k.i] = {
|
|
432
|
+
...b,
|
|
433
|
+
kind: 'disagree',
|
|
434
|
+
code,
|
|
435
|
+
acknowledgementUncomputable: { entryId: a.entryId, chainPosition: a.chainPosition },
|
|
436
|
+
detail: `${k.doc.input.source}: ${detail}; an acknowledgement this host could NOT CHECK (RESTORE_EPOCH ${a.entryId ?? 'with no id'} at platform-ops position ${a.chainPosition}) would account for it.`,
|
|
437
|
+
};
|
|
438
|
+
if (!reported.has(key)) {
|
|
439
|
+
reported.add(key);
|
|
440
|
+
out.findings.push({ position: P, code: 'CHAIN_UNSUPPORTED_ALGORITHM', detail: `Anchor at position ${P}: ${detail}, and the acknowledgement that would account for it could NOT BE CHECKED on this host.` });
|
|
441
|
+
}
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
verdictAt[k.i] = { ...b, kind: 'disagree', code, detail: `${k.doc.input.source}: ${detail}.` };
|
|
445
|
+
if (!reported.has(key)) {
|
|
446
|
+
reported.add(key);
|
|
447
|
+
out.findings.push({ position: P, code, detail: `Anchor ${k.doc.input.source}: ${detail}, and no acknowledgement of lost history that verifies accounts for it.` });
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
for (const v of verdictAt) {
|
|
451
|
+
if (v === null)
|
|
452
|
+
continue;
|
|
453
|
+
out.verdicts.push(v);
|
|
454
|
+
if (v.kind === 'agree')
|
|
455
|
+
out.counts.agree++;
|
|
456
|
+
else if (v.kind === 'disagree')
|
|
457
|
+
out.counts.disagree++;
|
|
458
|
+
else if (v.kind === 'accounted')
|
|
459
|
+
out.counts.accounted++;
|
|
460
|
+
else
|
|
461
|
+
out.counts.notComparable++;
|
|
462
|
+
}
|
|
463
|
+
if (out.counts.agree + out.counts.disagree + out.counts.accounted > 0
|
|
464
|
+
|| out.verdicts.some((v) => v.kind === 'not_comparable' && v.reason === 'unsupported_algorithm')) {
|
|
465
|
+
out.applicability = 'applied';
|
|
466
|
+
}
|
|
467
|
+
// A fork is the first failure wherever it sits: whichever tip the chain
|
|
468
|
+
// holds, one of two signed documents disagrees with it, so a cut or a
|
|
469
|
+
// rewrite read from either document alone follows from the fork. The sort
|
|
470
|
+
// is stable, so each class keeps the order the documents were given in.
|
|
471
|
+
const rank = (f) => (f.code === 'ANCHOR_FORK' ? 0 : 1);
|
|
472
|
+
out.findings.sort((a, b) => rank(a) - rank(b));
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* The acknowledgement a RESTORE_EPOCH envelope signs, read from the signed
|
|
477
|
+
* bytes alone: null when it is not a platform-ops RESTORE_EPOCH whose signed
|
|
478
|
+
* payload carries `coveredFindings` (a restore marker carries none). Its
|
|
479
|
+
* signature and link are the caller's to have checked; `state` and
|
|
480
|
+
* `linkChecked` say what the caller established.
|
|
481
|
+
*/
|
|
482
|
+
export function rewindAcknowledgementOf(coseSign1, entryId, state, linkChecked) {
|
|
483
|
+
const claim = decodeSignedClaim(coseSign1);
|
|
484
|
+
if (claim === null)
|
|
485
|
+
return null;
|
|
486
|
+
const read = signedCoveredFindings(claim);
|
|
487
|
+
if (read === null)
|
|
488
|
+
return null;
|
|
489
|
+
return { entryId, chainPosition: claim.position, state, iat: claim.iat, coveredFindings: read, linkChecked };
|
|
490
|
+
}
|
|
491
|
+
/** The signed `coveredFindings` of a platform-ops RESTORE_EPOCH claim, or null when the claim is not one. */
|
|
492
|
+
function signedCoveredFindings(claim) {
|
|
493
|
+
const p = claim.predicate;
|
|
494
|
+
if (p['entry_type'] !== 'RESTORE_EPOCH' || p['record_id'] !== PLATFORM_OPS_CHAIN_KEY)
|
|
495
|
+
return null;
|
|
496
|
+
// A chain entry's subject digests the uuid's text, where a checkpoint's digests its 16 bytes.
|
|
497
|
+
if (claim.subjectSha256 !== sha256HexString(PLATFORM_OPS_CHAIN_KEY))
|
|
498
|
+
return null;
|
|
499
|
+
const payload = p['payload'];
|
|
500
|
+
if (!isRecord(payload) || !Array.isArray(payload['coveredFindings']))
|
|
501
|
+
return null;
|
|
502
|
+
const out = [];
|
|
503
|
+
for (const f of payload['coveredFindings']) {
|
|
504
|
+
if (!isRecord(f))
|
|
505
|
+
continue;
|
|
506
|
+
const { recordId, lo, hi, finding } = f;
|
|
507
|
+
if (typeof recordId === 'string' && typeof lo === 'number' && typeof hi === 'number') {
|
|
508
|
+
out.push({ recordId, lo, hi, finding: typeof finding === 'string' ? finding : String(finding) });
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Hold a bulk export page's `acknowledgedRewinds` item to its envelope, as a
|
|
515
|
+
* record export's is: the Server writes its unsigned `coveredRanges` as the
|
|
516
|
+
* signed `coveredFindings` that name a chain the page holds rows of, each
|
|
517
|
+
* with its `recordId`, in signed order. The reason they differ, or null when
|
|
518
|
+
* they agree or the envelope does not decode (which the acknowledgement's
|
|
519
|
+
* own verification reports).
|
|
520
|
+
*/
|
|
521
|
+
export function pageAcknowledgementCopyDisagreement(item, pageChainKeys) {
|
|
522
|
+
if (!isRecord(item) || typeof item['coseSign1'] !== 'string')
|
|
523
|
+
return null;
|
|
524
|
+
const claim = decodeSignedClaim(Buffer.from(item['coseSign1'], 'base64'));
|
|
525
|
+
const signed = claim === null ? null : signedCoveredFindings(claim);
|
|
526
|
+
if (signed === null)
|
|
527
|
+
return null;
|
|
528
|
+
const mine = signed.filter((f) => pageChainKeys.has(f.recordId.toLowerCase())).map((f) => ({ recordId: f.recordId, lo: f.lo, hi: f.hi, finding: f.finding }));
|
|
529
|
+
const ranges = item['coveredRanges'];
|
|
530
|
+
if (!Array.isArray(ranges))
|
|
531
|
+
return `it carries no coveredRanges, and its signed coveredFindings for the chains the page holds are ${JSON.stringify(mine)}`;
|
|
532
|
+
const copy = ranges.map((r) => (isRecord(r) ? { recordId: r['recordId'], lo: r['lo'], hi: r['hi'], finding: r['finding'] } : r));
|
|
533
|
+
return JSON.stringify(copy) === JSON.stringify(mine) ? null : `the unsigned coveredRanges ${JSON.stringify(copy)} are not the signed coveredFindings for the chains the page holds ${JSON.stringify(mine)}`;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Verify the acknowledgements of lost history an export lists for its chain:
|
|
537
|
+
* each envelope decodes as a platform-ops RESTORE_EPOCH at the position its
|
|
538
|
+
* row names, under the kid its row names, verifies under an anchored key
|
|
539
|
+
* inside that key's window at its signed `iat`, and its row's unsigned
|
|
540
|
+
* `coveredRanges` are its signed `coveredFindings` for this chain. A failure
|
|
541
|
+
* is REWIND_ACKNOWLEDGEMENT_INVALID (CHAIN_SIGNATURE_MISSING_KEY for a kid no
|
|
542
|
+
* key answers to), and the acknowledgement then covers nothing. One this host
|
|
543
|
+
* refused to compute is CHAIN_UNSUPPORTED_ALGORITHM and covers nothing here.
|
|
544
|
+
*/
|
|
545
|
+
export function verifyRewindAcknowledgements(items, chainKey, keys, signingSince, supplied = false) {
|
|
546
|
+
const list = Array.isArray(items) ? items : [];
|
|
547
|
+
const report = { applicability: list.length === 0 ? 'skipped_no_input' : 'applied', present: list.length, verified: 0, items: [], linkChecked: false };
|
|
548
|
+
const acknowledgements = [];
|
|
549
|
+
const findings = [];
|
|
550
|
+
if (items !== undefined && items !== null && !Array.isArray(items)) {
|
|
551
|
+
report.applicability = 'applied';
|
|
552
|
+
findings.push({ position: 0, code: 'REWIND_ACKNOWLEDGEMENT_INVALID', detail: supplied ? 'The acknowledgements given are not an array.' : 'checkpointEvidence.acknowledgedRewinds is not an array.' });
|
|
553
|
+
return { report, acknowledgements, findings };
|
|
554
|
+
}
|
|
555
|
+
list.forEach((raw, index) => {
|
|
556
|
+
const item = isRecord(raw) ? raw : {};
|
|
557
|
+
const entryId = typeof item.entryId === 'string' ? item.entryId : null;
|
|
558
|
+
const position = Number.isSafeInteger(item.chainPosition) ? item.chainPosition : null;
|
|
559
|
+
const label = `${supplied ? 'Given acknowledgement' : 'Acknowledgement'} ${index + 1} (RESTORE_EPOCH ${entryId ?? 'with no entryId'})`;
|
|
560
|
+
const verdict = (state, detail, covered = []) => {
|
|
561
|
+
report.items.push({ entryId, chainPosition: position, state, coveredFindings: covered, detail });
|
|
562
|
+
};
|
|
563
|
+
const fail = (detail, code = 'REWIND_ACKNOWLEDGEMENT_INVALID', covered = []) => {
|
|
564
|
+
verdict(code === 'CHAIN_UNSUPPORTED_ALGORITHM' ? 'uncomputable' : 'failed', `${label}: ${detail}`, covered);
|
|
565
|
+
findings.push({ position: 0, code, detail: `${label}: ${detail}` });
|
|
566
|
+
};
|
|
567
|
+
if (entryId === null || position === null || typeof item.coseSign1 !== 'string' || (!supplied && !Array.isArray(item.coveredRanges))
|
|
568
|
+
|| !(item.signingKeyId === null || typeof item.signingKeyId === 'string')) {
|
|
569
|
+
fail(`the item is not { entryId, chainPosition, createdAt, signingKeyId, coseSign1${supplied ? '' : ', coveredRanges'} }.`);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const bytes = Buffer.from(item.coseSign1, 'base64');
|
|
573
|
+
const claim = decodeSignedClaim(bytes);
|
|
574
|
+
const signed = claim === null ? null : signedCoveredFindings(claim);
|
|
575
|
+
if (claim === null || signed === null) {
|
|
576
|
+
fail('its coseSign1 does not decode as a signed platform-ops RESTORE_EPOCH carrying coveredFindings.');
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const mine = supplied ? signed : signed.filter((f) => f.recordId === chainKey);
|
|
580
|
+
if (claim.position !== position || claim.kid !== (item.signingKeyId ?? UNSIGNED_KID)) {
|
|
581
|
+
fail(`its row says platform-ops position ${position} and key ${JSON.stringify(item.signingKeyId)}, and its envelope signs position ${claim.position} and kid ${claim.kid}.`, 'REWIND_ACKNOWLEDGEMENT_INVALID', mine);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
// A given acknowledgement's unsigned copy, when it carries one, is the
|
|
585
|
+
// view of the chain it was exported with, not of this one: only the
|
|
586
|
+
// signed coveredFindings are read.
|
|
587
|
+
const copy = supplied ? null : (item.coveredRanges ?? []).map((r) => (isRecord(r) ? { lo: r['lo'], hi: r['hi'], finding: r['finding'] } : r));
|
|
588
|
+
const signedCopy = mine.map((f) => ({ lo: f.lo, hi: f.hi, finding: f.finding }));
|
|
589
|
+
if (copy !== null && JSON.stringify(copy) !== JSON.stringify(signedCopy)) {
|
|
590
|
+
fail(`the unsigned coveredRanges ${JSON.stringify(copy)} are not the signed coveredFindings for this chain ${JSON.stringify(signedCopy)}.`, 'REWIND_ACKNOWLEDGEMENT_INVALID', mine);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (item.signingKeyId === null) {
|
|
594
|
+
if (writtenWhileSigning(item.createdAt, signingSince)) {
|
|
595
|
+
fail(`it is unsigned and was written ${String(item.createdAt)}, at or after the install began signing (${String(signingSince)}).`, 'REWIND_ACKNOWLEDGEMENT_INVALID', mine);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
verdict('unsigned', `${label}: unsigned, written before the install began signing; it covers nothing here.`, mine);
|
|
599
|
+
}
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const key = keys.get(item.signingKeyId);
|
|
603
|
+
if (key === undefined) {
|
|
604
|
+
fail(`its signingKeyId ${item.signingKeyId} is not among the keys this verification holds.`, 'CHAIN_SIGNATURE_MISSING_KEY', mine);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
const distrusted = distrustAccounts(key, iatInstant(claim.iat));
|
|
608
|
+
if (key.trust === 'unanchored' && !distrusted) {
|
|
609
|
+
fail(`key ${key.keyId} is not linked by signed key statements to a trust anchor.`, 'REWIND_ACKNOWLEDGEMENT_INVALID', mine);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const outcome = verifyCoseSign1(bytes, key.spkiBase64);
|
|
613
|
+
if (outcome !== 'ok' && outcome !== 'unsupported-key-algorithm') {
|
|
614
|
+
fail(`its signature does not verify under key ${key.keyId} (${outcome}).`, 'REWIND_ACKNOWLEDGEMENT_INVALID', mine);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (outcome === 'ok' && distrusted) {
|
|
618
|
+
verdict('accounted', `${label}: signed by key ${key.keyId} at or after the instant distrustedKeys gives for it; it covers nothing.`, mine);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
const placed = placeSignedIat(key, claim.iat, 'The acknowledgement');
|
|
622
|
+
if (placed.placement === 'not-yet-active' || placed.placement === 'expired' || placed.placement === 'unplaceable') {
|
|
623
|
+
fail(placed.detail, 'REWIND_ACKNOWLEDGEMENT_INVALID', mine);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
// A run that assumes this host's refusals verified takes the signature as
|
|
627
|
+
// verified; a key type this build cannot compute stays refused.
|
|
628
|
+
const assumed = isVerifyingAsIfHostComputed() && outcome === 'ok';
|
|
629
|
+
if (!assumed && (outcome === 'unsupported-key-algorithm' || refusedByHost(key))) {
|
|
630
|
+
fail(`its signature could NOT BE CHECKED: key ${key.keyId} commits to an algorithm this host cannot compute, or is reached only through a key statement this host could not check. It covers nothing here.`, 'CHAIN_UNSUPPORTED_ALGORITHM', mine);
|
|
631
|
+
acknowledgements.push({ entryId, chainPosition: position, state: 'uncomputable', iat: claim.iat, coveredFindings: signed, linkChecked: false });
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
report.verified++;
|
|
635
|
+
verdict('verified', `${label}: verified under key ${key.keyId}; its link in the platform-ops chain is established only by a dump of that chain.`, mine);
|
|
636
|
+
acknowledgements.push({ entryId, chainPosition: position, state: 'verified', iat: claim.iat, coveredFindings: signed, linkChecked: false });
|
|
637
|
+
});
|
|
638
|
+
return { report, acknowledgements, findings };
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* The relative path of a file in a copy of the anchor bucket, as the key it
|
|
642
|
+
* was stored under: a path ending `vault-anchors/<instanceId>/<chainKey>/<P>.json`
|
|
643
|
+
* keeps that tail, and one that is exactly `<instanceId>/<chainKey>/<P>.json`
|
|
644
|
+
* (a copy of the `vault-anchors/` prefix) gains the prefix. Undefined for any
|
|
645
|
+
* other path, which names no key.
|
|
646
|
+
*/
|
|
647
|
+
export function anchorObjectKeyOfPath(relativePath) {
|
|
648
|
+
const parts = relativePath.split(/[\\/]+/).filter((p) => p !== '' && p !== '.');
|
|
649
|
+
const at = parts.lastIndexOf('vault-anchors');
|
|
650
|
+
const tail = at !== -1 && parts.length - at === 4 ? parts.slice(at + 1) : parts.length === 3 ? parts : null;
|
|
651
|
+
if (tail === null || !UUID.test(tail[1] ?? '') || !/^\d+\.json$/.test(tail[2] ?? ''))
|
|
652
|
+
return undefined;
|
|
653
|
+
return `vault-anchors/${tail.join('/')}`;
|
|
654
|
+
}
|