@agledger/verify-core 2.1.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 +869 -53
- 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 +404 -29
- package/dist/audit-export.js +547 -28
- 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/cbor-strict.d.ts +9 -0
- package/dist/cbor-strict.js +14 -0
- package/dist/chain.d.ts +221 -31
- package/dist/chain.js +339 -65
- 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 +44 -26
- package/dist/failures.js +81 -31
- package/dist/federation-wire.d.ts +106 -20
- package/dist/federation-wire.js +286 -76
- package/dist/history-seal.d.ts +100 -0
- package/dist/history-seal.js +301 -0
- package/dist/index.d.ts +37 -9
- package/dist/index.js +18 -5
- package/dist/instant.d.ts +1 -1
- package/dist/instant.js +1 -1
- package/dist/key-statements.d.ts +160 -11
- package/dist/key-statements.js +261 -60
- package/dist/ml-dsa-kats.d.ts +18 -0
- package/dist/ml-dsa-kats.js +241 -0
- package/dist/options.js +4 -4
- package/dist/primitives.d.ts +287 -47
- package/dist/primitives.js +673 -101
- 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 +9 -5
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ The shared offline verification core for AGLedger audit chains. Decodes
|
|
|
4
4
|
canonical **COSE_Sign1** envelopes (RFC 9052, tag 18) over in-toto v1
|
|
5
5
|
Statement payloads, walks the per-record hash chain, and verifies the
|
|
6
6
|
signature over each `Sig_structure` under the algorithm the verification key
|
|
7
|
-
commits to (Ed25519 or
|
|
7
|
+
commits to (Ed25519, ES256, ES384 or ML-DSA), with no Server, no database, and no network.
|
|
8
8
|
|
|
9
|
-
Reads exports and dumps from an AGLedger Server 2.0 or later. For a 1.x Server
|
|
9
|
+
Reads exports and dumps from an AGLedger Server 2.0 or later. For exports from a 1.x Server, use `npm i @agledger/verify-core@1.5.0`, the last release that reads them.
|
|
10
10
|
|
|
11
11
|
This is the single body of logic that underpins the SDK `/verify` subpath
|
|
12
12
|
(`@agledger/sdk/verify`), the [`@agledger/cli`](https://github.com/agledger-ai/cli)
|
|
@@ -26,7 +26,10 @@ CBOR decoding.
|
|
|
26
26
|
npm install @agledger/verify-core
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Node 24 or newer
|
|
29
|
+
Node.js 24.6.0 or newer, the first release that computes ML-DSA, the Server's
|
|
30
|
+
default signing algorithm. `runtimeBelowFloor()` reports an older runtime, and a
|
|
31
|
+
result reached on one carries `runtime` (show `belowFloorNotice(result.runtime)`
|
|
32
|
+
first, and verify again on a current Node.js before acting on the verdict). If you want a ready-made verifier rather than a library, use
|
|
30
33
|
[`@agledger/verify`](https://github.com/agledger-ai/verify) for a full-vault dump
|
|
31
34
|
or the `verify` command in [`@agledger/cli`](https://github.com/agledger-ai/cli)
|
|
32
35
|
for a single record export.
|
|
@@ -45,15 +48,33 @@ if (result.verdict === 'failed') {
|
|
|
45
48
|
console.error(`Broken at position ${result.brokenAt?.position}: ${result.brokenAt?.code}`);
|
|
46
49
|
process.exit(1);
|
|
47
50
|
}
|
|
48
|
-
console.log(result.verdict); // 'trusted',
|
|
51
|
+
console.log(result.verdict); // 'trusted', 'unanchored' when nothing pinned backs the pass, or 'unverifiable'
|
|
49
52
|
// { valid: true, verdict, verifiedEntries, totalEntries, keyTrust, keyProvenance: { supplied, embedded }, ... }
|
|
50
53
|
```
|
|
51
54
|
|
|
52
55
|
Read `verdict` rather than `valid`: a valid result with no `trustAnchors` is
|
|
53
|
-
`unanchored`, which is not a trusted verdict.
|
|
56
|
+
`unanchored`, which is not a trusted verdict. The four verdicts:
|
|
57
|
+
|
|
58
|
+
- `trusted`: every check passed, and the walk from your `trustAnchors`
|
|
59
|
+
anchored the keys the signatures verified under.
|
|
60
|
+
- `unanchored`: every check passed, but nothing you pinned backs it (see
|
|
61
|
+
"Anchoring keys"). Also a pinned result that fails only because the pin was
|
|
62
|
+
not met, or only because the pin predates the move to ML-DSA.
|
|
63
|
+
- `unverifiable`: `valid` is false, this host refused to compute signatures
|
|
64
|
+
under an algorithm this build supports, and the result would be valid if
|
|
65
|
+
the checks this host refused had verified. Under a pin this host can
|
|
66
|
+
compute, a key is trusted only through signatures this host computed.
|
|
67
|
+
The signatures this host refused were not verified, so this is not a
|
|
68
|
+
verified result (see "Verifying on a FIPS-locked host").
|
|
69
|
+
- `failed`: anything else that failed. A real failure anywhere (a hash
|
|
70
|
+
mismatch, a signature that was checked and did not verify, a key-statement
|
|
71
|
+
finding, a count that does not hold) is `failed`, whatever else is
|
|
72
|
+
uncomputed beside it.
|
|
73
|
+
|
|
74
|
+
An option the function does not
|
|
54
75
|
read throws `TypeError` rather than being ignored, so a misspelt option, or
|
|
55
|
-
`requireOutOfBandKeys` (
|
|
56
|
-
check off without a word.
|
|
76
|
+
the old name `requireOutOfBandKeys` (the option is `requireSuppliedKeys`),
|
|
77
|
+
cannot turn a check off without a word.
|
|
57
78
|
|
|
58
79
|
## What it verifies
|
|
59
80
|
|
|
@@ -64,8 +85,9 @@ check off without a word.
|
|
|
64
85
|
- **Signed chain-claim cross-check**: the chain position and linkage claimed in
|
|
65
86
|
the COSE protected header match the row columns.
|
|
66
87
|
- **Envelope signature**: over the reconstructed `Sig_structure`, against the
|
|
67
|
-
matched verification key, under the algorithm its SPKI commits to (Ed25519
|
|
68
|
-
or
|
|
88
|
+
matched verification key, under the algorithm its SPKI commits to (Ed25519,
|
|
89
|
+
ES256, ES384, or ML-DSA-44, -65 or -87; anything else fails closed as
|
|
90
|
+
`CHAIN_UNSUPPORTED_ALGORITHM`).
|
|
69
91
|
- **Signed-kid binding**: the row's `signingKeyId` names the key the protected
|
|
70
92
|
header signed. An entry that names a key but carries an all-zero signature
|
|
71
93
|
fails `CHAIN_SIGNATURE_INVALID`.
|
|
@@ -101,16 +123,218 @@ check off without a word.
|
|
|
101
123
|
`result.evidenceBinding` counts them. An encrypted-mode completion signs a
|
|
102
124
|
hash over a cleartext the export does not carry, so its ciphertext is counted
|
|
103
125
|
as `clientHashed`, not re-bound.
|
|
126
|
+
- **The chain's length**, against the two counts the export states: fewer
|
|
127
|
+
entries than `exportMetadata.expectedEntries` (the position of the record's
|
|
128
|
+
latest checkpoint) fails `CHECKPOINT_ROW_MISSING`, and fewer than
|
|
129
|
+
`exportMetadata.totalEntries` (what the Server wrote) fails
|
|
130
|
+
`CHAIN_POSITION_GAP`. `result.entryCount` reports both, each null when the
|
|
131
|
+
export does not state it. Those counts sit in unsigned metadata, which
|
|
132
|
+
whoever cut the chain can also edit, so pass the count you obtained out of
|
|
133
|
+
band as `expectedEntryCount`: an export carrying a different number of
|
|
134
|
+
entries fails `CHAIN_POSITION_GAP`. `optionalChecks.entry_count` is
|
|
135
|
+
`applied` when any count was held and `skipped_no_input` when none was.
|
|
136
|
+
- **The checkpoint**, when `exportMetadata.checkpointEvidence` embeds one
|
|
137
|
+
(Server 4.0.0 or later):
|
|
138
|
+
the entry at its position must exist (else `CHECKPOINT_ROW_MISSING`) and
|
|
139
|
+
carry its tip hash (else `CHECKPOINT_HASH_MISMATCH`); its signed claim must
|
|
140
|
+
be a vault checkpoint naming that position (as `count` and as `range` 1 to
|
|
141
|
+
the position), tip, record and key (else `CHECKPOINT_CLAIM_MISMATCH`);
|
|
142
|
+
and its signature must verify under a key resolved and anchored the same way
|
|
143
|
+
as the entries' keys, with the `iat` it signs inside that key's window, give
|
|
144
|
+
or take 300 seconds at each edge (`CHECKPOINT_SIGNATURE_INVALID`,
|
|
145
|
+
`CHECKPOINT_KEY_UNANCHORED`, `CHECKPOINT_KEY_NOT_YET_ACTIVE`,
|
|
146
|
+
`CHECKPOINT_KEY_EXPIRED`). Unlike the counts above, the checkpoint is
|
|
147
|
+
signed, so a cut below it shows whatever the metadata says.
|
|
148
|
+
`result.checkpointEvidence` reports its position and state;
|
|
149
|
+
`optionalChecks.checkpoint_evidence` is `skipped_no_input` on an export
|
|
150
|
+
that embeds none.
|
|
151
|
+
- **Receipts**, on an export taken with `?receipts=true`: each entry's
|
|
152
|
+
`integrity.receipt` must verify under the key its kid names and prove the
|
|
153
|
+
entry's own `coseSign1` bytes at leaf `chainPosition - 1` of a tree no larger
|
|
154
|
+
than the chain. A Receipt that does not, or one missing from some entries
|
|
155
|
+
only, fails `RECEIPT_INVALID`. `result.receipts` counts them.
|
|
156
|
+
- **The coverage the checkpoint block states**: `lastEntryPosition`,
|
|
157
|
+
`coveredThroughPosition`, `coverage`, `uncoveredFromPosition` and
|
|
158
|
+
`uncoveredEntries` in `exportMetadata.checkpointEvidence` must be the values
|
|
159
|
+
the entries and the embedded checkpoint give, or the export fails
|
|
160
|
+
`CHECKPOINT_COVERAGE_MISMATCH`; a `lastEntryPosition` above the last entry
|
|
161
|
+
carried fails `CHAIN_POSITION_GAP`. `result.checkpointCoverage` lists the
|
|
162
|
+
fields held.
|
|
163
|
+
- **Acknowledgements of lost history** (`checkpointEvidence.acknowledgedRewinds`):
|
|
164
|
+
see [The anchor bucket](#the-anchor-bucket).
|
|
165
|
+
- **Anchor documents**, when you pass `anchorDocuments`: see
|
|
166
|
+
[The anchor bucket](#the-anchor-bucket).
|
|
167
|
+
- **Compliance attestations**: a `COMPLIANCE_ATTESTATION` or
|
|
168
|
+
`AI_IMPACT_ASSESSMENT` entry that signs `contentHash` or `attestedAt` must
|
|
169
|
+
sign them in the Server's forms (`sha256:` and 64 lowercase hex characters;
|
|
170
|
+
an RFC 3339 instant), or fails `CONTENT_BINDING_MALFORMED`. Pass the
|
|
171
|
+
responses of `GET /v1/records/{id}/compliance-records/{complianceRecordId}`
|
|
172
|
+
as `complianceRecords` (one, an array, or the list body `{ data: [...] }`)
|
|
173
|
+
and each is bound by its `id` to the entry that names it: its `attestation`
|
|
174
|
+
must hash, as SHA-256 over its RFC 8785 form, to the signed `contentHash`
|
|
175
|
+
(else `CONTENT_HASH_MISMATCH`), and its `recordId`, `recordType`,
|
|
176
|
+
`attestedBy` and `attestedAt` must be the signed values (else
|
|
177
|
+
`CONTENT_FIELD_DRIFT`). A supplied record of this record that no entry names
|
|
178
|
+
fails `CONTENT_ROW_UNSIGNED`; one of another record is listed in
|
|
179
|
+
`result.attestations.otherRecords`. `optionalChecks.attestation_bodies` says
|
|
180
|
+
whether a body was held. Each entry's `serverContentBinding` in
|
|
181
|
+
`result.attestations.entries` is the export's `integrity.contentBinding`:
|
|
182
|
+
the Server's own answer, unsigned, reported beside the verdict and kept out
|
|
183
|
+
of it.
|
|
184
|
+
- **Batched entries**, on an export from a Server on the batched signing
|
|
185
|
+
cadence: an entry with the batch marker in its protected header is verified
|
|
186
|
+
through `integrity.batch` and the head it names in
|
|
187
|
+
`exportMetadata.batchHeads` (see [Batched signing](#batched-signing)).
|
|
188
|
+
- **The record id**: `result.recordId` is the id the entries sign, never the
|
|
189
|
+
unsigned `exportMetadata.recordId`. A metadata id that disagrees with what
|
|
190
|
+
the entries sign, or entries that name different records, fails
|
|
191
|
+
`CHAIN_PAYLOAD_BINDING_MISMATCH`.
|
|
192
|
+
- **The format**: an export that does not state `exportFormatVersion` and
|
|
193
|
+
`canonicalization`, or states others than this verifier reads, fails
|
|
194
|
+
`UNSUPPORTED_FORMAT`.
|
|
104
195
|
|
|
105
196
|
The payload, OIDC, attribution and key-window checks run when the export
|
|
106
|
-
carries their inputs, which every current Server does.
|
|
197
|
+
carries their inputs, which every current Server does. Once one entry carries
|
|
198
|
+
its `payload` and `entryType`, or you pass `federationKeys`, an entry without
|
|
199
|
+
them fails `CHAIN_PAYLOAD_BINDING_MISMATCH` and the check reads `not_checked`,
|
|
200
|
+
so deleting them cannot switch a check off. The result's `optionalChecks` says
|
|
107
201
|
which ran, so "not checked" never reads as "passed".
|
|
108
202
|
|
|
203
|
+
### SCITT receipts
|
|
204
|
+
|
|
205
|
+
`verifyAuditExport` verifies the Receipts an export carries. To verify one on
|
|
206
|
+
its own (from SCRAPI, say), call
|
|
207
|
+
`verifyReceipt(receiptBytes, signedStatementBytes, transparencyServicePublicKeyBase64)`,
|
|
208
|
+
which returns `'ok'` or the reason it failed.
|
|
209
|
+
|
|
210
|
+
## Batched signing
|
|
211
|
+
|
|
212
|
+
A Server can sign chain entries in batches (`vaultSigningCadence: "batched"`
|
|
213
|
+
on `/v1/conformance`). A batched record-chain or schema-chain entry carries
|
|
214
|
+
protected-header label `-65541` with value 1 and an empty signature. The marker
|
|
215
|
+
is inside the protected header, so the entry's `payloadHash` covers it. A
|
|
216
|
+
signed batch head then covers the entry: one COSE_Sign1 under a vault key over
|
|
217
|
+
an RFC 9162 Merkle root. The platform-ops chain is always signed per entry.
|
|
218
|
+
|
|
219
|
+
`verifyAuditExport` verifies a batched entry in three steps:
|
|
220
|
+
|
|
221
|
+
1. **The entry.** Its key is resolved, anchored and held to its window as for
|
|
222
|
+
any entry, its header `alg` must be one that key signs under, and its
|
|
223
|
+
signature must be empty. A marked entry that carries a signature, and an
|
|
224
|
+
unmarked entry with an empty one, fail `CHAIN_SIGNATURE_INVALID`.
|
|
225
|
+
2. **The proof.** `integrity.batch` (`batchId`, `leafIndex`, `treeSize`,
|
|
226
|
+
`auditPath`) must reach the head's signed root from the entry's own leaf:
|
|
227
|
+
56 bytes holding the record id, the chain position and the entry's
|
|
228
|
+
`payloadHash`. A proof that does not is `BATCH_LEAF_MISMATCH`.
|
|
229
|
+
3. **The head.** The entry in `exportMetadata.batchHeads` with that id must be
|
|
230
|
+
a batch head for that id, signed by a key that is anchored and inside its
|
|
231
|
+
window at the head's `createdAt`. The head's key can differ from the
|
|
232
|
+
entry's. Anything else is `BATCH_HEAD_INVALID`.
|
|
233
|
+
|
|
234
|
+
An entry signed this way counts in `signatureCoverage.signed` and in
|
|
235
|
+
`signatureCoverage.batched`.
|
|
236
|
+
|
|
237
|
+
A batched entry with no proof is one no head covers yet. The Server gives an
|
|
238
|
+
entry 300 seconds to be covered, so the verifier reads one written within 300
|
|
239
|
+
seconds before `exportMetadata.exportDate` as `pending`: the result stays
|
|
240
|
+
valid, the entry counts in `signatureCoverage.pending` and not as signed, and
|
|
241
|
+
a result with no signed entry is not a trusted verdict. An entry with no proof
|
|
242
|
+
that is older than that, or an export that does not say when it was cut, fails
|
|
243
|
+
`BATCH_UNATTESTED`. Export the record again to get the proof.
|
|
244
|
+
|
|
245
|
+
To check a head or a proof yourself:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { buildBatchHeadRegistry, checkBatchProof } from '@agledger/verify-core';
|
|
249
|
+
|
|
250
|
+
// `keys` is a KeyRegistry (buildKeyRegistry, then applyKeyTrust when you pin).
|
|
251
|
+
const heads = buildBatchHeadRegistry(exportDocument.exportMetadata.batchHeads ?? [], keys);
|
|
252
|
+
const head = heads.get(proof.batchId.toLowerCase());
|
|
253
|
+
if (head?.state === 'ok') {
|
|
254
|
+
// null when the proof reaches the signed root, else what is wrong with it.
|
|
255
|
+
const wrong = checkBatchProof(recordId, chainPosition, payloadHash, proof, head);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## History seal
|
|
260
|
+
|
|
261
|
+
A Server that moves to ML-DSA keeps the records its Ed25519, ES256 or ES384
|
|
262
|
+
keys signed. When it retires such a key from a process that signs with ML-DSA,
|
|
263
|
+
it writes one history seal: an ML-DSA signature over an RFC 9162 Merkle root
|
|
264
|
+
with one leaf per chain, each leaf that chain's tip at the retirement. The
|
|
265
|
+
retirement waits out every write under the retired key first. The closure that
|
|
266
|
+
retires the key names the seal (`history: { seal, root, treeSize }`), and the
|
|
267
|
+
seal names the closure, both signed by one key.
|
|
268
|
+
|
|
269
|
+
An export carries every seal in `exportMetadata.historySeals`, each with the
|
|
270
|
+
record chain's inclusion proof. On a verification whose `trustAnchors` reach an
|
|
271
|
+
ML-DSA key, `verifyAuditExport` holds every entry a classical key signed to the
|
|
272
|
+
seal that covers that key:
|
|
273
|
+
|
|
274
|
+
- the seal verifies under an anchored ML-DSA key inside its window, and it and
|
|
275
|
+
the closure name each other (`HISTORY_SEAL_INVALID` otherwise);
|
|
276
|
+
- the chain's proof reaches the signed root, and the entry at the sealed
|
|
277
|
+
position is the one the leaf names (`HISTORY_SEAL_INVALID`);
|
|
278
|
+
- the entry sits at or below the sealed position (`HISTORY_SEAL_EXCEEDED`);
|
|
279
|
+
- the seal has a leaf for the chain (`HISTORY_SEAL_MISSING_CHAIN`).
|
|
280
|
+
|
|
281
|
+
So the ML-DSA-signed root, through the hash chain below the sealed tip, is what
|
|
282
|
+
vouches for those entries. A chain rewritten and re-signed under the classical
|
|
283
|
+
key no longer matches the leaf.
|
|
284
|
+
|
|
285
|
+
The seal that covers a key is its own. A key retired before any seal was
|
|
286
|
+
written is held to the first seal written after its retirement, since every
|
|
287
|
+
seal covers every chain's tip.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { verifyAuditExport } from '@agledger/verify-core';
|
|
291
|
+
|
|
292
|
+
const result = verifyAuditExport(exportDocument, { trustAnchors: ['sha256:<the ML-DSA key>'] });
|
|
293
|
+
result.historySeal; // { sealed: 12, unsealed: 0, unsealedKeys: [] }
|
|
294
|
+
result.optionalChecks.history_seal; // 'applied'
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Unsealed keys.** A classical key that no seal covers (it is still signing
|
|
298
|
+
between the succession and its retirement, or the export carries no seal for
|
|
299
|
+
it) leaves its entries valid and resting on their classical signatures alone.
|
|
300
|
+
Such a result reads `unanchored`, never `trusted`, and
|
|
301
|
+
`historySeal.unsealedKeys` names each key and what seals it: retire the key on
|
|
302
|
+
the Server and take the export again.
|
|
303
|
+
|
|
304
|
+
**Which pin.** An ML-DSA key is reached only through an ML-DSA signature. A
|
|
305
|
+
succession from a classical key to an ML-DSA key is signed by both; the walk
|
|
306
|
+
takes the ML-DSA key's half, which leads back to the classical key, and gives
|
|
307
|
+
the classical key's half no power to admit the ML-DSA key. Pin the ML-DSA key:
|
|
308
|
+
from it the walk reaches every key before it, except past a key retired with
|
|
309
|
+
`force`, which voids every edge out of that key. Where the history holds a
|
|
310
|
+
forced retirement, pin the key it retired as well, once you have confirmed
|
|
311
|
+
it with the Server's operator.
|
|
312
|
+
|
|
313
|
+
**A pin held since before the upgrade.** A walk pinned to a classical key
|
|
314
|
+
stops at the handover: the ML-DSA key, what it signed and the retirement it
|
|
315
|
+
signed for the old key are not anchored, and those read as failures
|
|
316
|
+
(`CHAIN_SIGNING_KEY_UNANCHORED`, `KEY_CLOSURE_INVALID`). When the same input
|
|
317
|
+
verifies with the handed-over key pinned as well, nothing else is wrong, and
|
|
318
|
+
the result says so: `verdict` is `unanchored`, `valid` stays false,
|
|
319
|
+
`keyTrust.successorPins` lists the keys to pin, and
|
|
320
|
+
`pinPredatesDetail(result.keyTrust.successorPins)` is the sentence to show.
|
|
321
|
+
Confirm the current pin with the Server's operator before using it; the keys
|
|
322
|
+
named come from the artifact. Anything else wrong beside the stale pin still
|
|
323
|
+
reads `failed`.
|
|
324
|
+
|
|
325
|
+
A Server that signs with ES384 throughout (a FIPS host) writes no seal, and a
|
|
326
|
+
verification that reaches no ML-DSA key is held to none.
|
|
327
|
+
|
|
328
|
+
`planHistorySeals`, `judgeHistorySeal` and `resolveHistorySealLeaf` are
|
|
329
|
+
exported for a verifier that reads seals from another artifact, with
|
|
330
|
+
`historySeals` and `historySealProofs` as the matching `verifyChain` options.
|
|
331
|
+
|
|
109
332
|
## Anchoring keys
|
|
110
333
|
|
|
111
334
|
A vault key the Server publishes comes from its database, and anything with
|
|
112
335
|
write access to that database can add a key row and entries signed with it.
|
|
113
|
-
What it cannot add
|
|
336
|
+
What it cannot add, unless it also holds the private half of a key you trust,
|
|
337
|
+
is a **key statement**: a COSE_Sign1 signed by a key the
|
|
114
338
|
Server already trusted (and, for a new key, by the new key too). Pass the SPKI
|
|
115
339
|
digest of a vault key you hold or took out of band as `trustAnchors`, and the
|
|
116
340
|
verifier walks the statements from it:
|
|
@@ -134,11 +358,17 @@ statements sign. `keyTrust.status` says whether a pass can be trusted:
|
|
|
134
358
|
- `no_anchored_signature`: the walk ran, but no entry verified under a key it
|
|
135
359
|
anchors, so `optionalChecks.key_anchoring` is `not_checked`. An export of
|
|
136
360
|
entries written before the install began signing passes under any pin, and
|
|
137
|
-
|
|
361
|
+
says nothing about the pin.
|
|
138
362
|
|
|
139
363
|
A pass on `no_anchor` or `no_anchored_signature` is not a trusted verdict; the
|
|
140
364
|
`detail` says so, and `verdict` (and every AGLedger surface) reports it as
|
|
141
|
-
`unanchored`.
|
|
365
|
+
`unanchored`. So is a pinned result that fails only because the pin reaches no
|
|
366
|
+
key in the export at all, as with an export checked against another Server's
|
|
367
|
+
pin: `valid` is false, but the same export verified without the pin passes,
|
|
368
|
+
so nothing in it was tampered with, and the verdict says the pin was not met
|
|
369
|
+
rather than `failed`. Once the pin anchors any key, an entry under a key it
|
|
370
|
+
does not reach is a substitution and the verdict is `failed`.
|
|
371
|
+
`distrustedKeys` without `trustAnchors` throws `TypeError`, since
|
|
142
372
|
nothing would apply them, and so does a pinned key distrusted with no instant,
|
|
143
373
|
which the Server refuses to start with. A pin beside a dated entry
|
|
144
374
|
(`sha256:<hex>@<instant>`) is how a leaked key's history stays verifiable: the
|
|
@@ -197,15 +427,15 @@ no longer trusted and its window no longer graded.
|
|
|
197
427
|
|
|
198
428
|
Statements are walked in the order the Server's database stored them,
|
|
199
429
|
`createdAt` then the row `id`, never by an instant a statement signs. A dump
|
|
200
|
-
carries that order (`created_at`), and so does every key document
|
|
201
|
-
|
|
430
|
+
carries that order (`created_at`), and so does every key document a Server 2.0
|
|
431
|
+
or later serves: each statement in an export's `signingKeyStatements`,
|
|
202
432
|
`/v1/verification-keys` and `/.well-known/agledger-vault-keys.json` carries
|
|
203
433
|
its row `id` and `createdAt` at microsecond precision, and `keyTrust.order`
|
|
204
434
|
reads `written`. A `createdAt` that is not strict RFC 3339 (a `T`, an offset
|
|
205
435
|
or `Z`, a real calendar date) places nothing, and its statement is
|
|
206
436
|
`KEY_STATEMENT_INVALID`. Such a document lists under a trusted key its
|
|
207
437
|
admission, every later admission it signed, and the closures that count for
|
|
208
|
-
it, so a walk over it dates each window and cuts each edge back as the
|
|
438
|
+
it, so a walk over it dates each window and cuts each edge back as the Server
|
|
209
439
|
does. Where it cannot (a later succession whose endorser the document does not
|
|
210
440
|
carry, or a closure by a key it does not list), the walk grades the window
|
|
211
441
|
more loosely than the listed one, and the listed `activatedAt` or `retiredAt`
|
|
@@ -229,14 +459,14 @@ out of a distrusted key never admits a key or keeps one reachable, whatever
|
|
|
229
459
|
time it carries. Such a statement still counts for everything that can only
|
|
230
460
|
narrow trust: it dates its subject's window, cuts the subject's edge back as a
|
|
231
461
|
later admission, and a closure the key signed still ends a window. Where the
|
|
232
|
-
document dates it before the cutoff, so the
|
|
462
|
+
document dates it before the cutoff, so the Server would count it, it is no
|
|
233
463
|
finding: it is listed in `keyTrust.notes`, which never fails a verdict, and an
|
|
234
464
|
honest rotation away from the key passes when you pin its successor. Pinned
|
|
235
465
|
only on the distrusted key, its successor is not anchored. This is narrower
|
|
236
|
-
than the
|
|
466
|
+
than the Server, which holds the key to the time its statements were really
|
|
237
467
|
stored, and never wider. Only
|
|
238
468
|
a dump walk holds a distrusted key's statements to their `created_at`, as the
|
|
239
|
-
|
|
469
|
+
Server does, and that adds assurance only for a dump you took from the Server
|
|
240
470
|
yourself or over a channel you trust; for any other dump it assures no more
|
|
241
471
|
than the stored times its holder chose.
|
|
242
472
|
|
|
@@ -285,17 +515,25 @@ and, once its chains are walked, settles it with
|
|
|
285
515
|
verified: with none, the status becomes `no_anchored_signature`.
|
|
286
516
|
`writtenWhileSigning(rowTime, signingSince)` is the unsigned-row rule for
|
|
287
517
|
checkpoints and read-log rows, and fails closed on a row with no readable time
|
|
288
|
-
once signing began.
|
|
518
|
+
once signing began. `placeInKeyWindow(key, rowTime, 'Checkpoint')` holds a
|
|
519
|
+
vault checkpoint, a read-log leaf or a read-log tree head to the signed window
|
|
520
|
+
of its key by the rule entries are held to (`inside`, `not-yet-active`,
|
|
521
|
+
`expired`, `accounted`, or `unplaceable` when a time cannot be read), and
|
|
522
|
+
`distrustAccounts(key, rowTime)` says whether a `distrustedKeys` entry and the
|
|
523
|
+
trusted retirement account for it. Verify the signature first: an artifact
|
|
524
|
+
that is accounted for is set aside only when its signature verifies under the
|
|
525
|
+
key, and a signature that does not verify is reported ahead of a window
|
|
526
|
+
finding.
|
|
289
527
|
|
|
290
528
|
A dump row repeating an earlier row's signed payload counts once, at its
|
|
291
529
|
first write: a row copied in the database under a new id and time says
|
|
292
|
-
nothing new, as the
|
|
530
|
+
nothing new, as the Server reads it. On a key document a copy stays a second
|
|
293
531
|
statement, since its `createdAt` is the holder's word.
|
|
294
532
|
|
|
295
533
|
On a dump, a `distrustedKeys` key that a key the walk trusts has retired is
|
|
296
534
|
bounded by that retirement (its `DistrustSpan` in `trust.distrustSpans`; only a
|
|
297
|
-
retirement by a key the walk trusts counts, as in the
|
|
298
|
-
what it signed before then is accounted for rather than failed, as the
|
|
535
|
+
retirement by a key the walk trusts counts, as in the Server), and
|
|
536
|
+
what it signed before then is accounted for rather than failed, as the Server's
|
|
299
537
|
scan lists it: a key statement it signed that counts for nothing is listed in
|
|
300
538
|
`trust.accounted` (and the report's `accounted`) instead of `findings`, and a
|
|
301
539
|
chain entry whose signature verifies under it, outside what the key is
|
|
@@ -320,30 +558,40 @@ entries under it are `CHAIN_UNSUPPORTED_ALGORITHM` rather than unanchored.
|
|
|
320
558
|
An agent that authenticates with an ephemeral cert can sign each request body
|
|
321
559
|
it sends. The Server checks that signature, then seals it into the chain entry
|
|
322
560
|
as `predicate.on_behalf_of.agent_signature`, beside the RFC 7638 thumbprint of
|
|
323
|
-
the cert's public key. The envelope signature
|
|
324
|
-
|
|
561
|
+
the cert's public key. The envelope signature covers it as the Server wrote it. To
|
|
562
|
+
check that the agent itself signed, without taking the Server's word for it,
|
|
325
563
|
re-verify the agent signature against the cert's public key.
|
|
326
564
|
|
|
327
|
-
The export does not carry cert public keys. Supply them as the
|
|
328
|
-
|
|
329
|
-
|
|
565
|
+
The export does not carry cert public keys. Supply them as the JWK the agent
|
|
566
|
+
sent to `POST /v1/auth/oidc/cert` (the same key is the `cnf.jwk` claim inside
|
|
567
|
+
the `certJws` it got back). A cert key is ML-DSA-87 or ML-DSA-65
|
|
568
|
+
(`{ kty: 'AKP', alg, pub }`, RFC 9964) or P-384 (`{ kty: 'EC', crv: 'P-384', x, y }`).
|
|
569
|
+
A cert a Server before 4.0.0 issued holds an Ed25519 key
|
|
570
|
+
(`{ kty: 'OKP', crv: 'Ed25519', x }`), which still verifies:
|
|
330
571
|
|
|
331
572
|
```ts
|
|
332
573
|
import { verifyAuditExport } from '@agledger/verify-core';
|
|
333
574
|
|
|
334
|
-
|
|
575
|
+
// The agent's own publicKeyJwk, as it sent it at cert exchange.
|
|
576
|
+
const agentKey = { kty: 'EC', crv: 'P-384', x: 'qc7r...', y: 'Xk2f...' } as const;
|
|
335
577
|
const result = verifyAuditExport(exportDocument, { agentKeys: [agentKey] });
|
|
336
578
|
|
|
337
579
|
console.log(result.optionalChecks.agent_signature); // 'applied'
|
|
338
580
|
console.log(result.agentSignatures); // e.g. { present: 6, verified: 6 }
|
|
339
581
|
```
|
|
340
582
|
|
|
583
|
+
`agentKeys` takes each key bare, as above, or as an agent records it,
|
|
584
|
+
`{ certId, publicKeyJwk: {...} }`: only `publicKeyJwk` is read. The file
|
|
585
|
+
`agledger-verify --agent-keys` reads holds the same entries.
|
|
586
|
+
|
|
341
587
|
A key is matched to an entry only through the thumbprint that entry signed, so
|
|
342
588
|
a key for some other cert is never checked against it and where the key came
|
|
343
589
|
from needs no trust. `present` counts entries carrying an agent signature and
|
|
344
590
|
`verified` those re-checked and found good; `present > verified` on a valid
|
|
345
591
|
result means some were not checked, never that they failed. One that does not
|
|
346
|
-
verify fails `CHAIN_AGENT_SIGNATURE_INVALID`. The
|
|
592
|
+
verify fails `CHAIN_AGENT_SIGNATURE_INVALID`. The algorithm is the cert key's
|
|
593
|
+
own: a sealed `alg` that names another one fails the same way, and never
|
|
594
|
+
chooses how the signature is checked. The check runs only where
|
|
347
595
|
`on_behalf_of.validated` is `true`: on a caller-asserted identity the two fields
|
|
348
596
|
may be passthrough from an older Server, and the export cannot tell which.
|
|
349
597
|
|
|
@@ -355,13 +603,15 @@ peer signed it, the peer's registered key, the hub ids, the body hash, the
|
|
|
355
603
|
timestamp, the nonce and the signature. Every sealed message is held to its
|
|
356
604
|
body hash and to the entry that carries it (`federation_wire` in
|
|
357
605
|
`optionalChecks`, `applied` once one was seen). Pass the peer's federation key,
|
|
358
|
-
as its operator gives it
|
|
359
|
-
|
|
606
|
+
as its operator gives it, to also re-verify the peer's signature. A federation
|
|
607
|
+
key is ML-DSA-87 or ES384, as base64 SPKI DER. A Server before 4.0.0 held an
|
|
608
|
+
Ed25519 key, which is taken as base64 SPKI DER or base64 of the raw 32 bytes,
|
|
609
|
+
so the messages it sealed still verify:
|
|
360
610
|
|
|
361
611
|
```ts
|
|
362
612
|
import { verifyAuditExport } from '@agledger/verify-core';
|
|
363
613
|
|
|
364
|
-
const result = verifyAuditExport(exportDocument, { federationKeys: { 'hub-b': '
|
|
614
|
+
const result = verifyAuditExport(exportDocument, { federationKeys: { 'hub-b': 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE...' } });
|
|
365
615
|
|
|
366
616
|
console.log(result.federationWire); // e.g. { present: 2, verified: 2, failed: 0, afterRetirement: 0 }
|
|
367
617
|
```
|
|
@@ -379,7 +629,7 @@ const response = await fetch('https://hub-b.example.com/.well-known/agledger-fed
|
|
|
379
629
|
const history = (await response.json()) as FederationKeyHistoryDocument;
|
|
380
630
|
|
|
381
631
|
const result = verifyAuditExport(exportDocument, {
|
|
382
|
-
federationKeys: [{ hubId: 'hub-b', publicKey: '
|
|
632
|
+
federationKeys: [{ hubId: 'hub-b', publicKey: 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE...', history }],
|
|
383
633
|
});
|
|
384
634
|
```
|
|
385
635
|
|
|
@@ -387,19 +637,30 @@ The windows come from the signed statements, not the document's `keys`
|
|
|
387
637
|
summary. Each message is placed by its sealed `wire.timestamp`, which the peer
|
|
388
638
|
signed and the receiver sealed under its own signature, and which comes from
|
|
389
639
|
the peer's clock, the same clock its windows are written by. The entry's
|
|
390
|
-
`createdAt` is not signed, so it places nothing.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
640
|
+
`createdAt` is not signed, so it places nothing. The timestamp is the signing
|
|
641
|
+
process's clock and the window is the peer's database clock, so each edge
|
|
642
|
+
carries an allowance of 300 seconds (`FEDERATION_KEY_WINDOW_SKEW_MS`), as the
|
|
643
|
+
Server's own receiver guidance gives it. A message signed under a key more
|
|
644
|
+
than that before the key's activation fails. One signed under a key more than
|
|
645
|
+
that after the key's retirement fails `CHAIN_FEDERATION_WIRE_INVALID`, since a
|
|
646
|
+
retired key signing later is also what a leaked key does. Pass
|
|
647
|
+
`allowAfterRetirement: true` for the short gap while a peer's publisher
|
|
648
|
+
restarts onto its new key: such a message then verifies and is counted in
|
|
649
|
+
`federationWire.afterRetirement`. A key behind a genesis that named it only by digest
|
|
396
650
|
(`linked: false`) is not linked to the newer keys; name the hub a second time
|
|
397
651
|
with that key once its operator confirms it. The same goes for a key the
|
|
398
652
|
history does not list at all, such as the key in use before a change made with
|
|
399
653
|
neither predecessor setting: a second entry for the hub pins it, and it is
|
|
400
654
|
trusted on its own. A history that is another hub's, carries a statement that
|
|
401
655
|
does not verify, or lists none of the keys pinned for its hub throws
|
|
402
|
-
`TypeError` before anything is verified.
|
|
656
|
+
`TypeError` before anything is verified. Federation key histories need a Server 2.2 or later on the peer.
|
|
657
|
+
|
|
658
|
+
The signature's algorithm is the key's. Under ML-DSA-87 or ES384 it is
|
|
659
|
+
base64url without padding, at exactly the algorithm's length (4627 bytes, or
|
|
660
|
+
the 96-byte `r||s` of ES384 with low S); under an Ed25519 key it is 128 hex
|
|
661
|
+
characters. Any other spelling fails, as it does on the Server. A key history
|
|
662
|
+
can cross algorithms: each half of a succession is signed in its own key's
|
|
663
|
+
form.
|
|
403
664
|
|
|
404
665
|
A sealed signature that does not verify, a sealed key that is not the one
|
|
405
666
|
supplied for that hub, a body that no longer hashes to what was signed, or an
|
|
@@ -415,19 +676,481 @@ live cert record (`cert_missing`, `cert_actor_drift`, `cert_window_drift`,
|
|
|
415
676
|
counterpart; the signed bytes already fix the cert id, thumbprint and expiry an
|
|
416
677
|
entry sealed.
|
|
417
678
|
|
|
679
|
+
### Acknowledgements and counter-signatures
|
|
680
|
+
|
|
681
|
+
A Server answers a federated message with a signature of its own, and
|
|
682
|
+
counter-signs a co-sign request. Both verify offline under that Server's
|
|
683
|
+
ML-DSA-87 or ES384 federation key, in the same one spelling a sealed message's
|
|
684
|
+
signature takes:
|
|
685
|
+
|
|
686
|
+
```ts
|
|
687
|
+
import { verifyFederationAck, verifyFederationCoSign } from '@agledger/verify-core';
|
|
688
|
+
|
|
689
|
+
verifyFederationAck({ kind: 'ack', recordId, value: 'FULFILLED', serverTimestamp, serverSignature, signerPublicKey });
|
|
690
|
+
verifyFederationCoSign({ claim, counterSignature, signerPublicKey });
|
|
691
|
+
// { state: 'ok' } | { state: 'invalid', code: 'FEDERATION_SIGNATURE_INVALID', detail } | { state: 'unsupported', detail }
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
A signature a Server before 4.0.0 made verifies the same way under its Ed25519
|
|
695
|
+
key, in 128 hex characters.
|
|
696
|
+
|
|
697
|
+
An acknowledgement covers
|
|
698
|
+
`agledger.federation.ack.v1:<kind>:<recordId>:<value>:<serverTimestamp>`, with
|
|
699
|
+
`kind` one of `ack` (a state transition, `value` the state), `signal` (`value`
|
|
700
|
+
the recommendation) or `dispute` (`value` the action). A counter-signature
|
|
701
|
+
covers `agledger.federation.co-sign.v1:` followed by the RFC 8785 form of the
|
|
702
|
+
claim, which holds exactly `recordId`, `outcome`, `recommendation`,
|
|
703
|
+
`outcomeHash`, `state`, `performerHubId` and `validUntil`. Each signature
|
|
704
|
+
covers its own domain, so one made for a sealed message, or for another
|
|
705
|
+
acknowledgement kind, does not verify here.
|
|
706
|
+
|
|
707
|
+
### A key history that does not hold
|
|
708
|
+
|
|
709
|
+
In a key history, a statement that does not verify takes no part in the walk:
|
|
710
|
+
the keys it alone would link are not trusted, and the rest of the history
|
|
711
|
+
stands. `buildFederationKeyRegistry` throws `FederationKeyHistoryError` (a
|
|
712
|
+
`TypeError` with `code: 'FEDERATION_KEY_HISTORY_INVALID'`) when no key pinned
|
|
713
|
+
for a hub is a key its history admits, which is also what a pin reads when the
|
|
714
|
+
statement admitting it does not verify. Trusted keys are listed newest first.
|
|
715
|
+
|
|
716
|
+
## The anchor bucket
|
|
717
|
+
|
|
718
|
+
A Server with anchoring on writes each checkpoint to its anchor bucket as a
|
|
719
|
+
JSON document at `vault-anchors/<instanceId>/<chainKey>/<chainPosition>.json`,
|
|
720
|
+
once per position for the life of the install. Read them from the bucket (or a
|
|
721
|
+
copy of it) and pass them to `verifyAuditExport` as `anchorDocuments`, each as
|
|
722
|
+
`{ source, document, objectKey? }` with `document` the parsed JSON and
|
|
723
|
+
`objectKey` the key it was stored under. `compareCheckpointAnchors(documents,
|
|
724
|
+
chain, keys, acknowledgements)` runs the same comparison on a chain you hold
|
|
725
|
+
some other way.
|
|
726
|
+
|
|
727
|
+
Only the signed `coseSign1` inside a document is evidence. A document is
|
|
728
|
+
compared when that envelope decodes as a vault checkpoint of this chain and
|
|
729
|
+
verifies under one of the export's keys, resolved and anchored like the
|
|
730
|
+
entries' keys, with its signed `iat` inside the key's window (300 seconds of
|
|
731
|
+
skew at each edge). Each compared document reads:
|
|
732
|
+
|
|
733
|
+
- `agree`: its signed tip is the `payloadHash` of the entry at its position
|
|
734
|
+
(`how: 'same_bytes'` when it carries the very envelope the export embeds).
|
|
735
|
+
- `disagree`, which fails the verdict: `ANCHOR_CHAIN_CUT` when its position is
|
|
736
|
+
above the last entry, `ANCHOR_CHAIN_REWRITTEN` when the entry there has
|
|
737
|
+
another `payloadHash`, `ANCHOR_FORK` when two compared documents sign
|
|
738
|
+
different tips for one position.
|
|
739
|
+
- `accounted`: a disagreement an acknowledgement of lost history covers. The
|
|
740
|
+
acknowledgement is a RESTORE_EPOCH entry on the platform-ops chain, written
|
|
741
|
+
by `POST /v1/admin/vault/rewind/acknowledge`, that verifies under an anchored
|
|
742
|
+
key inside its window and lists `{ recordId: <chainKey>, lo, hi }` in its
|
|
743
|
+
signed `coveredFindings` with `lo < position <= hi` and `lo` at or below the
|
|
744
|
+
last entry, and that was signed after the anchor. An export lists the ones
|
|
745
|
+
naming its chain in `checkpointEvidence.acknowledgedRewinds`; each is
|
|
746
|
+
verified from its own envelope and its unsigned `coveredRanges` held to the
|
|
747
|
+
signed findings (else `REWIND_ACKNOWLEDGEMENT_INVALID`).
|
|
748
|
+
`result.acknowledgedRewinds.linkChecked` is false: an acknowledgement's link
|
|
749
|
+
in the platform-ops chain is established by a dump of that chain, which
|
|
750
|
+
`@agledger/verify` checks.
|
|
751
|
+
- `not_comparable`, with a `reason`, for everything else: a file that is no
|
|
752
|
+
version 2 anchor document, a SCITT tree-head anchor, a checkpoint of another
|
|
753
|
+
chain, one that is unsigned, under an unknown, unanchored or distrusted key,
|
|
754
|
+
whose signature fails, or outside its key's window. These are evidence of
|
|
755
|
+
nothing and leave the verdict as it was. So is an anchor signed after the
|
|
756
|
+
read time (`signed_after_read`), which may cover entries written since the
|
|
757
|
+
export was read, when that read time is yours.
|
|
758
|
+
|
|
759
|
+
The read time is the one you give as `exportDate` (the instant you read the
|
|
760
|
+
export), and otherwise the export's own
|
|
761
|
+
`checkpointEvidence.anchorsJudgedThroughIat`, less one second either way.
|
|
762
|
+
The export's own is unsigned, and moving it earlier would set aside an anchor
|
|
763
|
+
that shows a cut. So an anchor whose checkpoint verifies and signs a position
|
|
764
|
+
above the last entry the export holds, set aside on the export's own read
|
|
765
|
+
time or with no read time at all, is listed in `result.capped` (reason
|
|
766
|
+
`read_time_not_given`) and the verdict reads at best `unanchored`. Give
|
|
767
|
+
`exportDate` to judge it: signed before your read time, it fails
|
|
768
|
+
`ANCHOR_CHAIN_CUT` unless an acknowledgement accounts for it; signed after,
|
|
769
|
+
it is set aside. A read time the export states (`exportMetadata.exportDate`,
|
|
770
|
+
`checkpointEvidence.evidenceReadAt`, `anchorsJudgedThroughIat`) earlier than
|
|
771
|
+
the signed `iat` of an entry or checkpoint it holds fails
|
|
772
|
+
`EXPORT_READ_TIME_INVALID`; an `exportDate` you give that is earlier throws a
|
|
773
|
+
`TypeError` naming the entry.
|
|
774
|
+
|
|
775
|
+
An export lists only the acknowledgements naming its chain. Give others as
|
|
776
|
+
`acknowledgements`: record exports (their
|
|
777
|
+
`checkpointEvidence.acknowledgedRewinds`), pages of a bulk walk under a
|
|
778
|
+
platform key (the RESTORE_EPOCH rows of its platform-ops chain), or
|
|
779
|
+
`acknowledgedRewinds` items. Each is verified from its own envelope, only its
|
|
780
|
+
signed `coveredFindings` are read, and `result.suppliedAcknowledgements`
|
|
781
|
+
reports each. A `GET /v1/admin/vault/rewind` response carries no signed entry
|
|
782
|
+
and throws a `TypeError` that says where to get one.
|
|
783
|
+
|
|
784
|
+
Where more than one failure applies, `brokenAt` names the first in this
|
|
785
|
+
order: an acknowledgement that does not verify
|
|
786
|
+
(`REWIND_ACKNOWLEDGEMENT_INVALID`), then a fork (`ANCHOR_FORK`), then a cut
|
|
787
|
+
or a rewrite. Two documents of one position over different tips are a fork
|
|
788
|
+
whichever of them the export agrees with, though either alone may read as a
|
|
789
|
+
rewrite.
|
|
790
|
+
|
|
791
|
+
An anchor whose signature this host refuses to compute (an Ed25519 key on a
|
|
792
|
+
FIPS-locked host) reads `not_comparable` with `reason: 'unsupported_algorithm'`
|
|
793
|
+
and `ifVerified` naming what it would show, and the result reads
|
|
794
|
+
`unverifiable`: such an anchor is evidence neither way. A cut shown by an
|
|
795
|
+
anchor this host verified still fails.
|
|
796
|
+
|
|
797
|
+
Each document's unsigned fields (`recordId`, `chainPosition`, `payloadHash`,
|
|
798
|
+
`signingKeyId`) that differ from its signed claim are listed in its
|
|
799
|
+
`unsignedDisagreements`. `result.anchors.embeddedCheckpoint` says whether a
|
|
800
|
+
supplied document holds the checkpoint the export embeds, beside
|
|
801
|
+
`checkpointEvidence.anchor.objectKey`, the Server's hint of where it lies. A
|
|
802
|
+
plain sync of the bucket copies the current version of each key; supply every
|
|
803
|
+
object version of a key to see a fork.
|
|
804
|
+
|
|
805
|
+
## Cross-record exports
|
|
806
|
+
|
|
807
|
+
`verifyAuditExport` reads one record's audit export
|
|
808
|
+
(`GET /v1/records/{id}/audit-export`). The two exports that span chains are
|
|
809
|
+
read by their own functions, and handing a page of either to
|
|
810
|
+
`verifyAuditExport` throws a `TypeError` naming the one to call.
|
|
811
|
+
`auditVaultExportKind(doc)` answers `'bulk'`, `'schema-chain'` or `null`.
|
|
812
|
+
|
|
813
|
+
Both are paged, and the unit they verify is the walk: the pages of one
|
|
814
|
+
query, the last with a null `nextCursor`. Give the pages as parsed JSON, as
|
|
815
|
+
the text of each page (JSON, or NDJSON with `?format=ndjson`), or as one
|
|
816
|
+
NDJSON text holding them all, in any order. Each page from Server 4.0.0
|
|
817
|
+
states the cursor it was requested with (`exportMetadata.cursor`: null on the
|
|
818
|
+
first page, and page N's `nextCursor` on page N+1), and the functions put
|
|
819
|
+
pages that all state it in walk order by it. Pages that state none (a Server
|
|
820
|
+
before 4.0.0) are put in walk order by what they hold (a bulk page by its
|
|
821
|
+
first entry's id, a schema-chain page by its first entry's position; a page
|
|
822
|
+
with no entry after the page whose `nextCursor` it carries). `walk.order`
|
|
823
|
+
gives the index of each page as given. The Server ends a page's last line
|
|
824
|
+
with no newline, so join page texts with one.
|
|
825
|
+
|
|
826
|
+
`walk.endsAtNullCursor` is true when the pages end at a null `nextCursor` and
|
|
827
|
+
hold together up to it: the first page was requested with no cursor, each
|
|
828
|
+
later page with the `nextCursor` of the page before it, no page overlaps
|
|
829
|
+
another, and no chain starts above position 1 on a walk with no `from` bound.
|
|
830
|
+
`walk.incomplete` names each reason it is false, and such a walk reads at
|
|
831
|
+
best `unanchored`. The cursors are unsigned, so they catch a lost or
|
|
832
|
+
misordered page file; a page removed with every cursor rewritten to hide it
|
|
833
|
+
is caught where something signed names what it held: a chain that starts
|
|
834
|
+
above position 1, a gap inside a chain, or a checkpoints listing or anchor
|
|
835
|
+
document of a chain the walk holds no entry of (`chainSet`, below). On pages
|
|
836
|
+
that state no cursor, only those show a missing page, and `walk.notes`
|
|
837
|
+
says so.
|
|
838
|
+
|
|
839
|
+
```ts
|
|
840
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
841
|
+
import { join } from 'node:path';
|
|
842
|
+
import { verifyBulkExport, verifySchemaChainExport } from '@agledger/verify-core';
|
|
843
|
+
|
|
844
|
+
// Each page saved as its own file (page-01.json, page-02.json, ... or .ndjson), named in walk order.
|
|
845
|
+
const walkIn = (dir: string) => readdirSync(dir).sort().map((f) => readFileSync(join(dir, f), 'utf8'));
|
|
846
|
+
const pin = 'sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e';
|
|
847
|
+
|
|
848
|
+
// Each page dates itself (exportMetadata.exportDate). For pages that carry none,
|
|
849
|
+
// add exportDate: '<when the last page was read>' to the options.
|
|
850
|
+
const bulk = verifyBulkExport(walkIn('bulk-walk'), { trustAnchors: [pin] });
|
|
851
|
+
console.log(bulk.verdict); // the worst chain's verdict, or null on a walk that holds no entry
|
|
852
|
+
console.log(bulk.walk); // { pages, entries, endsAtNullCursor, incomplete: [...reasons], notes, order }
|
|
853
|
+
console.log(bulk.chainSet); // { state: 'pages_only' | 'held_to_listing' | 'undecided', detail, missing, undecided, outside }
|
|
854
|
+
console.log(bulk.capped); // [{ reason, detail }]: why a verdict that would be trusted reads unanchored
|
|
855
|
+
console.log(bulk.readTime); // { exportDate, source, chains: [{ chainKey, exportDate, source }], undated, detail }
|
|
856
|
+
for (const chain of bulk.chains) {
|
|
857
|
+
// heldTo: the last position verified, held by the page content or a signed checkpoint
|
|
858
|
+
console.log(chain.chainKey, chain.extent, chain.heldTo.position, chain.heldTo.by, chain.result.verdict, chain.sliceReason ?? '');
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const schema = verifySchemaChainExport(walkIn('schema-walk'), { trustAnchors: [pin] });
|
|
862
|
+
console.log(schema.orgId, schema.checkpointKey); // the org the entries sign (null: the Server-wide chain), and the chain id
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
`verifyBulkExport` groups the rows by `recordId`, puts each group in chain
|
|
866
|
+
order, and verifies it as `verifyAuditExport` verifies a record export of
|
|
867
|
+
those entries: keys and their trust walk, signatures, links, batch proofs,
|
|
868
|
+
the payload against the signed predicate (with `on_behalf_of` and
|
|
869
|
+
`traceparent`), and the signed record id. The key material of every page is
|
|
870
|
+
merged; a key, window, key statement, batch head or entry that differs
|
|
871
|
+
between pages fails `EXPORT_PAGE_CONFLICT`. Each chain's `result` is a full
|
|
872
|
+
`VerifyExportResult`.
|
|
873
|
+
|
|
874
|
+
A chain the walk holds from position 1, in a walk that ends at a null
|
|
875
|
+
`nextCursor`, is `whole` and gets that verdict. A chain is a `slice` when the
|
|
876
|
+
walk holds it from a later position (a `from` filter, or a page missing
|
|
877
|
+
before it), when the walk does not end at a null `nextCursor` (`walk.incomplete`
|
|
878
|
+
says why: a last page with a `nextCursor`, a held-back page, rows out of
|
|
879
|
+
entry-id order, pages that overlap or come from another query), or when the
|
|
880
|
+
query's `to` bound ends every chain at an
|
|
881
|
+
instant. The walk's cursors carry the bound; a walk of one page carries no
|
|
882
|
+
cursor, and its `bulkExport.queryHash` (the hash of the query's filter) is
|
|
883
|
+
matched against the filters the page makes possible. `query` reports the
|
|
884
|
+
filter the pages establish, and on a walk whose pages establish none every
|
|
885
|
+
chain is a slice. A slice's entries and the links between them are
|
|
886
|
+
verified, and its verdict reads at best `unanchored`. A missing position
|
|
887
|
+
inside a chain fails `CHAIN_POSITION_GAP`. A walk whose `endsAtNullCursor` is
|
|
888
|
+
false reads at best `unanchored` whatever holds its chains (`capped`, reason
|
|
889
|
+
`walk_not_read_to_end`).
|
|
890
|
+
|
|
891
|
+
A walk verifies each chain through the last position it holds of it, and
|
|
892
|
+
`chains[].heldTo` says what holds the chain there: `page_content`, or
|
|
893
|
+
`signed_checkpoint` when a signed checkpoint of that position is given.
|
|
894
|
+
Pass pages of `GET /v1/audit-vault/checkpoints` as `checkpoints`: each
|
|
895
|
+
checkpoint filed under a chain the walk holds is verified (its claim, key,
|
|
896
|
+
signature and key window) and held to the entry at its position, so a
|
|
897
|
+
disagreement fails `CHECKPOINT_HASH_MISMATCH`. One signed before the walk's
|
|
898
|
+
read time above the last entry of a chain whose tip the walk establishes
|
|
899
|
+
fails `CHECKPOINT_ROW_MISSING`. A slice from position 1 whose last position
|
|
900
|
+
a checkpoint signs is `whole` through that position. Each listed checkpoint
|
|
901
|
+
is reported in `chains[].heldTo.checkpoints` with its `outcome`: `agrees`,
|
|
902
|
+
`disagrees` (its envelope fails, or the walk's entries differ from it),
|
|
903
|
+
`unchecked` (signed under an algorithm this host cannot compute; the chain
|
|
904
|
+
reads `unverifiable`), `not_comparable` (a position the walk does not hold or
|
|
905
|
+
cannot judge) or `not_evidence` (unsigned, set aside by `distrustedKeys`, or
|
|
906
|
+
not a checkpoint row).
|
|
907
|
+
|
|
908
|
+
A listed checkpoint or anchor document of a chain the walk holds no entry of
|
|
909
|
+
is held to the walk's query, and `chainSet` reports it. A walk under a
|
|
910
|
+
platform key (its pages carry `bulkExports`, or it holds the platform-ops
|
|
911
|
+
chain) serves every record chain and the platform-ops chain; a walk under an
|
|
912
|
+
org admin key serves that org's record chains, which that org admin's listing
|
|
913
|
+
names; no walk serves a schema chain (`chainSet.outside`). A `recordId`
|
|
914
|
+
filter serves that chain alone. Under a `to` bound, a checkpoint signed more
|
|
915
|
+
than 300 seconds before it is inside the query. One inside the query whose
|
|
916
|
+
envelope verifies under a trusted key and that was signed before the read
|
|
917
|
+
time fails `CHECKPOINT_ROW_MISSING` (a listing row) or `ANCHOR_CHAIN_CUT`
|
|
918
|
+
(an anchor, unless an acknowledgement accounts for it), and `chainSet.missing`
|
|
919
|
+
names the chain. A checkpoint the pages cannot place inside or outside the
|
|
920
|
+
query (another org's chain may be in a platform listing beside an org admin's
|
|
921
|
+
walk, an anchor of a chain no org listing names, an `agentId` or `from`
|
|
922
|
+
filter on any chain, the platform-ops chain included, a query the pages do
|
|
923
|
+
not establish, a checkpoint this host could not
|
|
924
|
+
check) leaves `chainSet.state` `undecided` and the verdict at best
|
|
925
|
+
`unanchored` (`capped`, reason `chain_set_undecided`).
|
|
926
|
+
|
|
927
|
+
Anchor documents (`anchorDocuments`) are compared with the chain each
|
|
928
|
+
signs, as on a record export, judged through the walk's read time less one
|
|
929
|
+
second: the `exportDate` you give, else the latest page read time
|
|
930
|
+
(`readTime.exportDate`), which is unsigned; `anchors.judgedThroughSource`
|
|
931
|
+
says which. An anchor or listed checkpoint above the last entry the walk
|
|
932
|
+
holds of its chain, set aside on the pages' own read time or with no read
|
|
933
|
+
time, holds the verdict at best `unanchored` (`capped`, reason
|
|
934
|
+
`read_time_not_given`) until you give `exportDate`. A page whose
|
|
935
|
+
`exportDate` is earlier than the signed `iat` of an entry it holds fails
|
|
936
|
+
`EXPORT_READ_TIME_INVALID`, and an `exportDate` you give that is earlier than
|
|
937
|
+
an entry the pages hold throws a `TypeError` naming the entry. On a slice,
|
|
938
|
+
an anchor of a position outside the run the walk holds reads
|
|
939
|
+
`chain_held_in_part`; two anchors of one position over different tips fail
|
|
940
|
+
`ANCHOR_FORK` wherever they sit. The acknowledgements of lost history are
|
|
941
|
+
the RESTORE_EPOCH entries of the platform-ops chain, when the walk holds it
|
|
942
|
+
whole (a walk under a platform key), those a bulk page carries
|
|
943
|
+
(`exportMetadata.acknowledgedRewinds`, Server 4.0.0, served to every caller
|
|
944
|
+
for the chains on that page, so an org admin's walk carries its own), and
|
|
945
|
+
those you give as `acknowledgements` (as on a record export). Each is
|
|
946
|
+
counted once. A page's item is held to its envelope as a record export's
|
|
947
|
+
is: its unsigned `coveredRanges` must be its signed `coveredFindings` for the
|
|
948
|
+
chains that page holds, or it fails `REWIND_ACKNOWLEDGEMENT_INVALID` and
|
|
949
|
+
covers nothing.
|
|
950
|
+
`anchors` reports every document's verdict and where the acknowledgements
|
|
951
|
+
came from.
|
|
952
|
+
|
|
953
|
+
Each page states the instant the Server read it, `exportMetadata.exportDate`
|
|
954
|
+
(on NDJSON, the metadata line's `exportDate`), taken after its entries and
|
|
955
|
+
their batch proofs. A batched entry served with no inclusion proof is judged
|
|
956
|
+
against the read time of its own page: written within 300 seconds before it,
|
|
957
|
+
the entry is waiting for its batch head and reads `pending`; written
|
|
958
|
+
earlier, it fails `BATCH_UNATTESTED`. Pages from a Server before 4.0.0 state
|
|
959
|
+
no read time: for those, the `exportDate` option dates them. For batched
|
|
960
|
+
entries a page that states its own read time is read at it, and the option
|
|
961
|
+
dates only the pages that state none (`walk.notes` says when
|
|
962
|
+
every page stated its own). `readTime` reports the latest read time, where
|
|
963
|
+
the read times came from (`source`: `pages`, `option`, or `mixed` when pages
|
|
964
|
+
were dated from both), the same for each chain (`readTime.chains`), and in
|
|
965
|
+
`undated` each batched entry no read time dated, which fails
|
|
966
|
+
`BATCH_UNATTESTED`. `expectedEntryCount` holds one chain's length, so
|
|
967
|
+
`verifyBulkExport` refuses it.
|
|
968
|
+
|
|
969
|
+
`verifySchemaChainExport` verifies the schema-registry chain the same way,
|
|
970
|
+
filed under `checkpointKey` (the uuid derived from the org id). It also
|
|
971
|
+
holds each entry to being a schema-registry entry of that org: no record id,
|
|
972
|
+
a SCHEMA_REGISTERED, SCHEMA_IMPORTED or SCHEMA_DIGEST_MISMATCH entry type
|
|
973
|
+
whose outcome the entry signs, the schema-event predicate and its subject,
|
|
974
|
+
and the `org_id` it signs equal to `chainMetadata.orgId`. Each row's payload
|
|
975
|
+
is held to its signed statement: a payload key that is neither one the
|
|
976
|
+
statement carries (under the name the predicate reads) nor one the Server
|
|
977
|
+
writes unsigned on that entry type fails `CHAIN_PAYLOAD_BINDING_MISMATCH`.
|
|
978
|
+
The unsigned ones (`publisherId`, `compatibility`, `registeredBy`,
|
|
979
|
+
`importedBy`, and on a SCHEMA_DIGEST_MISMATCH entry `peerDigest`,
|
|
980
|
+
`localDigest`, `peerHubId`, `recordId` and `operation`) are listed in
|
|
981
|
+
`unsignedProjectionFields` as `payload.<key>`: nothing detects a change to
|
|
982
|
+
one. A stated
|
|
983
|
+
`checkpointKey` that is not the derived one fails the walk. A walk read from
|
|
984
|
+
position 1 to its end is held to the first page's `total`, `expectedEntries`
|
|
985
|
+
and `checkpointEvidence`, taken whole from that page. A walk that starts
|
|
986
|
+
above position 1 or stops early is a slice. Each page is read at its own
|
|
987
|
+
`exportDate`, as on a bulk walk; a page that states none, with no
|
|
988
|
+
`exportDate` option, is dated by the latest
|
|
989
|
+
`checkpointEvidence.evidenceReadAt` the pages state (`source:
|
|
990
|
+
'checkpoint_evidence'`). Anchor documents are judged through the `exportDate`
|
|
991
|
+
you give, else the block's `anchorsJudgedThroughIat` when the walk applies
|
|
992
|
+
the block, else the pages' read time, with the block's `acknowledgedRewinds`
|
|
993
|
+
and those you give.
|
|
994
|
+
|
|
995
|
+
The Server's own fields (`chainMetadata.hashChainValid` on a bulk page,
|
|
996
|
+
`chainIntegrity` and its reason on a schema page) are reported under
|
|
997
|
+
`serverStatement` and take no part in the verdict. A walk that holds no entry
|
|
998
|
+
has `verdict: null` and `empty: true`: nothing was verified.
|
|
999
|
+
|
|
418
1000
|
## Verifying on a FIPS-locked host
|
|
419
1001
|
|
|
420
1002
|
This package has no crypto of its own: it verifies through the host's Node
|
|
421
1003
|
runtime. An active OpenSSL FIPS provider carries no EdDSA, so **an Ed25519
|
|
422
|
-
chain cannot be verified on a FIPS-locked host**. ES256 chains can.
|
|
1004
|
+
chain cannot be verified on a FIPS-locked host**. ES256 and ES384 chains can.
|
|
1005
|
+
A refusal names the algorithm the host refused, and a cause only when one is
|
|
1006
|
+
known (an active FIPS provider for Ed25519 or ML-DSA, a Node.js older than
|
|
1007
|
+
24.6.0 for ML-DSA).
|
|
423
1008
|
|
|
424
1009
|
That is reported as `CHAIN_UNSUPPORTED_ALGORITHM`, never as a signature
|
|
425
|
-
failure. The
|
|
1010
|
+
failure. The two are kept apart because "I could not check this" and "I
|
|
426
1011
|
checked this and it failed" lead to opposite conclusions, and only one of them
|
|
427
|
-
is grounds for a tamper investigation.
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
the
|
|
1012
|
+
is grounds for a tamper investigation.
|
|
1013
|
+
|
|
1014
|
+
When this host refused signature checks under an algorithm this build
|
|
1015
|
+
supports, the verifier runs the same input again with the same options, as
|
|
1016
|
+
though those checks had verified. If that run is valid, the `verdict` is
|
|
1017
|
+
`unverifiable`. Nothing else is assumed in that run: a key of a type this
|
|
1018
|
+
build cannot compute still cannot be computed, a signature that was checked
|
|
1019
|
+
and did not verify still fails, and hash, link and count checks run as they
|
|
1020
|
+
are, so any of those makes the verdict `failed`. `valid` stays false, because
|
|
1021
|
+
an unverified chain is not a verified one, and every failure is still listed
|
|
1022
|
+
in `entries`.
|
|
1023
|
+
|
|
1024
|
+
What that run assumes depends on the pin:
|
|
1025
|
+
|
|
1026
|
+
- **A trust anchor this host computes** (one of `trustAnchors` is the digest
|
|
1027
|
+
of a key in the export whose algorithm this host computes): under a pin
|
|
1028
|
+
this host can compute, a key is trusted only through signatures this host
|
|
1029
|
+
computed. The run assumes only the refused signatures over data (entries,
|
|
1030
|
+
batch heads, checkpoints, receipts, agent signatures, peer messages, history
|
|
1031
|
+
seals); nothing is assumed about a key statement's refused half. A
|
|
1032
|
+
succession with one half this host refused carries exactly the edge whose
|
|
1033
|
+
own half this host computed and found valid, and only out of a key already
|
|
1034
|
+
trusted at that point of the walk, once every check that needs no
|
|
1035
|
+
computation has passed (an all-zero or wrong-length refused half makes the
|
|
1036
|
+
statement invalid). So the pinned ES384 key reaches the Ed25519 key it took
|
|
1037
|
+
over from through its own half of their succession, while entries
|
|
1038
|
+
re-signed under a key of someone else's, with a forged succession whose
|
|
1039
|
+
Ed25519 endorsement this host cannot check, still read `failed`: the edge
|
|
1040
|
+
into that key is carried only by the refused half. A refused closure is
|
|
1041
|
+
never assumed, and an ML-DSA key is still reached only through an ML-DSA
|
|
1042
|
+
signature. `uncomputable.assumed` is `'data'`:
|
|
1043
|
+
nothing was found wrong, and only signatures over data were left unchecked.
|
|
1044
|
+
- **No such anchor** (no `trustAnchors`, or every one that names a key here
|
|
1045
|
+
is of an algorithm this host refused, such as the pre-move Ed25519 pin on a
|
|
1046
|
+
FIPS-locked host): this host cannot establish any key itself, so the run
|
|
1047
|
+
assumes the refused key statements too, and the verdict reads the same for
|
|
1048
|
+
an export and a forgery of it. `uncomputable.assumed` is
|
|
1049
|
+
`'data-and-key-statements'`, `uncomputable.anchorAlgorithms` names the
|
|
1050
|
+
algorithms of the pins given that name a key here, and the sentence says
|
|
1051
|
+
only what is true: no signature was verified under an established key,
|
|
1052
|
+
and the two ways out are to pin
|
|
1053
|
+
the Server's current key of an algorithm this host computes (confirm it
|
|
1054
|
+
with the Server's operator) or to verify on a host that computes the
|
|
1055
|
+
algorithm. A pin that names no key in the input is such a case too: it
|
|
1056
|
+
anchors nothing on any host, so where the input does not pass without it
|
|
1057
|
+
on this host but would with the refused checks verified, the verdict is
|
|
1058
|
+
`unverifiable` with `uncomputable.pinUnmet: true`, as the same input reads
|
|
1059
|
+
with no pin. (An input this host passes without the pin reads `unanchored`,
|
|
1060
|
+
as everywhere.)
|
|
1061
|
+
|
|
1062
|
+
A finding that follows from a refused check is listed too: pinned on an
|
|
1063
|
+
Ed25519 key on a FIPS-locked host, the key statements that key signed cannot
|
|
1064
|
+
be checked, so the walk does not reach the keys after it, and their closures
|
|
1065
|
+
and entries read `KEY_CLOSURE_INVALID` or `CHAIN_SIGNING_KEY_UNANCHORED`.
|
|
1066
|
+
`uncomputable.consequences` names those codes on an `unverifiable` result.
|
|
1067
|
+
|
|
1068
|
+
Checks that need no computation run before the host is asked whether it
|
|
1069
|
+
computes the algorithm, so they read the same on every host: a signature of
|
|
1070
|
+
the wrong length is `CHAIN_SIGNATURE_INVALID`, an all-zero signature is the
|
|
1071
|
+
unsigned sentinel, and a protected-header `alg` the key cannot produce is
|
|
1072
|
+
`CHAIN_ALG_MISMATCH`. They run on an entry whose key this host could not
|
|
1073
|
+
establish too, and so does the key's window: an entry written after its key
|
|
1074
|
+
retired reads `CHAIN_KEY_EXPIRED` whatever this host can compute. Where this
|
|
1075
|
+
run finds no failure but could-not-compute ones and the second run fails,
|
|
1076
|
+
`brokenAt` is the second run's first break, which the refused checks do not
|
|
1077
|
+
explain.
|
|
1078
|
+
|
|
1079
|
+
The verdict is reserved for a refusal the verifier establishes on this host
|
|
1080
|
+
itself: whether the host computes an algorithm is decided by this build's own
|
|
1081
|
+
known-answer test, which nothing in the export can change. So on a host that
|
|
1082
|
+
computes every algorithm this build supports, the second run never starts and
|
|
1083
|
+
no export reads `unverifiable`. A key of a type this build cannot compute (an
|
|
1084
|
+
unrecognized key type, or ES512 or ES256K) is something the export alone
|
|
1085
|
+
asserts, so a result whose checks under one fail reads `failed`, with the
|
|
1086
|
+
detail on each entry saying to upgrade the verifier.
|
|
1087
|
+
|
|
1088
|
+
`result.uncomputable` counts the signature checks that could not be computed
|
|
1089
|
+
(entries, batch heads, checkpoints, receipts, agent signatures, peer messages,
|
|
1090
|
+
and key statements) and names the algorithms behind them, each with its cause
|
|
1091
|
+
(`host`: this build supports it and the runtime refused it; `build`: this
|
|
1092
|
+
build cannot compute it), on any verdict. On a `failed` result, `brokenAt` is
|
|
1093
|
+
the first failure that is not one of these, and `uncomputableNote(result.uncomputable)`
|
|
1094
|
+
gives the line to show beside it. Where the verdict is `unverifiable`,
|
|
1095
|
+
`brokenAt` is the first check that could not be computed, and
|
|
1096
|
+
`unverifiableDetail(result.uncomputable)` gives the sentence to show:
|
|
1097
|
+
|
|
1098
|
+
```ts
|
|
1099
|
+
import { unverifiableDetail, verifyAuditExport } from '@agledger/verify-core';
|
|
1100
|
+
|
|
1101
|
+
const result = verifyAuditExport(exportDocument);
|
|
1102
|
+
if (result.verdict === 'unverifiable') {
|
|
1103
|
+
// "3 signature checks under Ed25519 could not be computed on this host. ..."
|
|
1104
|
+
console.warn(unverifiableDetail(result.uncomputable));
|
|
1105
|
+
}
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
A Server that moved from Ed25519 to ES384 keeps its Ed25519 history, and a
|
|
1109
|
+
pin on the ES384 key reaches that history through the succession both keys
|
|
1110
|
+
signed. On a FIPS-locked host the Ed25519 half of it cannot be checked, so
|
|
1111
|
+
the Ed25519 key is `undecided` rather than anchored or unanchored, and its
|
|
1112
|
+
entries are `CHAIN_UNSUPPORTED_ALGORITHM`. Under the ES384 pin, alone or
|
|
1113
|
+
beside the Ed25519 pin, that history reads `unverifiable` with
|
|
1114
|
+
`uncomputable.assumed` `'data'`: the ES384 key's own half of the succession
|
|
1115
|
+
reaches the Ed25519 key, and only that key's entry signatures are assumed.
|
|
1116
|
+
Under the Ed25519 pin alone, the one an installer before the move printed,
|
|
1117
|
+
and unpinned, it reads `unverifiable` with every key statement assumed. A key
|
|
1118
|
+
reached only through another refused half (an earlier Ed25519 key, before
|
|
1119
|
+
the one the ES384 key succeeded) is not established on this host, and that
|
|
1120
|
+
history reads `failed`. On a host that computes
|
|
1121
|
+
Ed25519 the same export reads `trusted` under each of those pins.
|
|
1122
|
+
|
|
1123
|
+
To actually verify an Ed25519 chain, re-run on a host without the restriction;
|
|
1124
|
+
the export and keys are portable and the verification is entirely offline, so
|
|
1125
|
+
all it needs is a second host.
|
|
1126
|
+
|
|
1127
|
+
## Post-quantum signatures (ML-DSA)
|
|
1128
|
+
|
|
1129
|
+
A vault key can be an ML-DSA key (NIST FIPS 204): ML-DSA-44, -65 or -87,
|
|
1130
|
+
published as SPKI, with COSE `alg` -48, -49 or -50. ML-DSA is designed to
|
|
1131
|
+
resist forgery by a quantum computer; Ed25519, ES256 and ES384 are not.
|
|
1132
|
+
Signatures are pure ML-DSA with an empty context over the same
|
|
1133
|
+
`Sig_structure`, and the unsigned sentinel
|
|
1134
|
+
is all zeros at the parameter set's signature length (2420, 3309 or 4627
|
|
1135
|
+
bytes). A chain can mix Ed25519, ES256 or ES384 history with ML-DSA history;
|
|
1136
|
+
each entry verifies under its own key.
|
|
1137
|
+
|
|
1138
|
+
ML-DSA needs a Node.js build whose OpenSSL carries it, and a host whose
|
|
1139
|
+
active provider computes it. On a host that does not, an ML-DSA chain is
|
|
1140
|
+
`CHAIN_UNSUPPORTED_ALGORITHM`, never a signature failure: the detail says the
|
|
1141
|
+
active OpenSSL FIPS provider did not compute it when one is active, and to
|
|
1142
|
+
upgrade Node.js otherwise (Node.js computes ML-DSA from 24.6.0; a release that
|
|
1143
|
+
loads an ML-DSA key without reporting its type reads the same way). Its verdict follows the rule above, the same way an
|
|
1144
|
+
Ed25519 chain reads on a FIPS-locked host.
|
|
1145
|
+
|
|
1146
|
+
## ES384
|
|
1147
|
+
|
|
1148
|
+
A vault key can be an ECDSA P-384 key, the algorithm a Server on a FIPS host
|
|
1149
|
+
signs with. Its signatures carry COSE `alg` -35 and are ECDSA over SHA-384 as
|
|
1150
|
+
raw `r||s` (96 bytes). -35 is the only label taken for a P-384 key, on chain
|
|
1151
|
+
entries and on key statements. An entry written with no key carries the
|
|
1152
|
+
Server's default sentinel on every host, a FIPS one included: `alg` -50 and
|
|
1153
|
+
4627 zero bytes. It is read as unsigned by its null `signingKeyId`.
|
|
431
1154
|
|
|
432
1155
|
### Asking about an algorithm directly
|
|
433
1156
|
|
|
@@ -439,8 +1162,9 @@ so a consumer writing its own report can ask about either:
|
|
|
439
1162
|
import { algorithmByName, runtimeCanCompute, describeUnsupportedAlgorithm } from '@agledger/verify-core';
|
|
440
1163
|
|
|
441
1164
|
// runtimeCanCompute takes a KeyAlgorithm from this build's table, NOT a name
|
|
442
|
-
// string. Look one up with algorithmByName ('Ed25519', 'ES256', '
|
|
443
|
-
// 'ES512', 'ES256K'); it returns null for
|
|
1165
|
+
// string. Look one up with algorithmByName ('Ed25519', 'ES256', 'ML-DSA-44',
|
|
1166
|
+
// 'ML-DSA-65', 'ML-DSA-87', 'ES384', 'ES512', 'ES256K'); it returns null for
|
|
1167
|
+
// anything else.
|
|
444
1168
|
const ed25519 = algorithmByName('Ed25519');
|
|
445
1169
|
if (ed25519 && !runtimeCanCompute(ed25519)) {
|
|
446
1170
|
console.warn('This host cannot verify Ed25519 chains.');
|
|
@@ -452,6 +1176,10 @@ if (ed25519 && !runtimeCanCompute(ed25519)) {
|
|
|
452
1176
|
console.log(describeUnsupportedAlgorithm(spkiBase64));
|
|
453
1177
|
```
|
|
454
1178
|
|
|
1179
|
+
`uncomputableAlgorithm(spkiBase64)` gives the same answer as data: null when
|
|
1180
|
+
this build and this host can both compute the key, and otherwise its algorithm
|
|
1181
|
+
and whether the `host` or the `build` is the cause.
|
|
1182
|
+
|
|
455
1183
|
`algorithmByName` exists for the case `resolveKeyAlgorithm` cannot serve: a host
|
|
456
1184
|
that refuses to *load* a key of some algorithm produces no key object to
|
|
457
1185
|
resolve, which is exactly when the question matters most.
|
|
@@ -472,19 +1200,105 @@ Both are normalized at the boundary; anything else throws `TypeError`
|
|
|
472
1200
|
|
|
473
1201
|
## Org-read log
|
|
474
1202
|
|
|
475
|
-
|
|
476
|
-
the
|
|
1203
|
+
Every read an org admin makes of another party's record is a leaf of a
|
|
1204
|
+
per-org RFC 9162 Merkle tree, and the Server signs a tree head over it on a
|
|
1205
|
+
schedule. Three functions verify what the read-log API serves, offline:
|
|
1206
|
+
|
|
1207
|
+
| Function | Input | Establishes |
|
|
1208
|
+
|---|---|---|
|
|
1209
|
+
| `verifyOrgReadCheckpoint(checkpoint, options)` | one tree head (`GET /v1/audit/org-reads/checkpoints`, one item of `data`, or the co-sign response) | the tree size and root the Server signed for the org, at the time it signed them, under an anchored key in its window; a witness co-signature under `cosignerKeys` |
|
|
1210
|
+
| `verifyOrgReadProof(proof, checkpoint, leaf, options)` | the `.../checkpoints/{id}/proof?leaf=` response, its tree head, and the leaf | the tree head, then the audit path from the leaf hash at its index to the signed root |
|
|
1211
|
+
| `verifyOrgReadLog(entries, checkpoints, options)` | pages of `GET /v1/audit/org-reads` and of `.../checkpoints` | the leaves in order, recomputed into the signed root of every tree head they reach |
|
|
1212
|
+
|
|
1213
|
+
```ts
|
|
1214
|
+
import { readFileSync } from 'node:fs';
|
|
1215
|
+
import { verifyOrgReadCheckpoint, verifyOrgReadLog, verifyOrgReadProof } from '@agledger/verify-core';
|
|
1216
|
+
import type { OrgReadCheckpointInput, OrgReadCheckpointsPage, OrgReadEntriesPage, OrgReadEntryInput, OrgReadProofInput, VerifyOrgReadOptions } from '@agledger/verify-core';
|
|
1217
|
+
|
|
1218
|
+
const read = <T>(file: string): T => JSON.parse(readFileSync(file, 'utf8')) as T;
|
|
1219
|
+
const options: VerifyOrgReadOptions = {
|
|
1220
|
+
publicKeys: read('verification-keys.json'), // GET /v1/verification-keys, as served
|
|
1221
|
+
trustAnchors: ['sha256:15d63684b387235c47fe3a81e3004b928f4ea535236a2c1b47465ce5fdd7ce0e'],
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
const checkpoint = read<OrgReadCheckpointInput>('checkpoint.json');
|
|
1225
|
+
const head = verifyOrgReadCheckpoint(checkpoint, options);
|
|
1226
|
+
console.log(head.verdict, head.checkpoint.treeSize, head.checkpoint.rootHash);
|
|
1227
|
+
|
|
1228
|
+
const proof = read<OrgReadProofInput>('proof.json');
|
|
1229
|
+
const entry = read<OrgReadEntryInput>('entry.json'); // one row of GET /v1/audit/org-reads
|
|
1230
|
+
console.log(verifyOrgReadProof(proof, checkpoint, entry, options).inclusion); // 'included' or 'failed'
|
|
1231
|
+
|
|
1232
|
+
const walk = verifyOrgReadLog(read<OrgReadEntriesPage>('org-reads.json'), read<OrgReadCheckpointsPage>('checkpoints.json'), options);
|
|
1233
|
+
console.log(walk.verdict, walk.heldTo); // { by: 'signed_checkpoint', treeSize, checkpointId, detail }
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
Each result carries the house verdict (`trusted`, `unanchored`, `unverifiable`,
|
|
1237
|
+
`failed`), `brokenAt` and `findings` with a canonical code, `keyTrust`,
|
|
1238
|
+
`uncomputable`, and `runtime` below the Node.js floor, read as on
|
|
1239
|
+
`verifyAuditExport`.
|
|
1240
|
+
|
|
1241
|
+
What each input binds:
|
|
1242
|
+
|
|
1243
|
+
- **A tree head** is held to its own envelope. The claim signs the root as
|
|
1244
|
+
its subject digest and `chain_tip_hash`, the tree size as its position and
|
|
1245
|
+
`count`, `range` 0 to size minus 1, the org as `sub` (equal to `logId`), the
|
|
1246
|
+
key id as `kid`, and the time it was signed as `iat`. A served field that
|
|
1247
|
+
differs fails `TENANT_CHECKPOINT_CLAIM_MISMATCH`, and so does a
|
|
1248
|
+
`checkpointAt` more than 300 seconds before the signed `iat`: the database
|
|
1249
|
+
stamps that column when it writes the row, after the Server signed the
|
|
1250
|
+
claim at its own clock. The key's window is
|
|
1251
|
+
placed at `checkpointAt`. A tree head with no `signingKeyId` written after
|
|
1252
|
+
the earliest key activation fails `TENANT_CHECKPOINT_UNSIGNED`; one written
|
|
1253
|
+
before it is reported `unsigned` and anchors nothing.
|
|
1254
|
+
- **A leaf** is a row of the listing or a row of a dump's `org_admin_reads`.
|
|
1255
|
+
A listing row carries the leaf hash and no envelope, so its hash is placed
|
|
1256
|
+
in the tree and its other columns (record, reader, time, context) are bound
|
|
1257
|
+
to nothing signed: `leaf.fieldsBound` and `fieldsBound` say `false`. A dump
|
|
1258
|
+
row carries the envelope (`cose_sign1`): its leaf hash is recomputed from
|
|
1259
|
+
those bytes (`TENANT_READ_LEAF_HASH_MISMATCH` when it differs from the
|
|
1260
|
+
served `leaf_hash`), its signature is verified, and its columns are held to
|
|
1261
|
+
its claim (`TENANT_READ_CLAIM_MISMATCH`, `TENANT_READ_OIDC_MISMATCH`). Its
|
|
1262
|
+
`read_at` is stamped when the row is written, after the claim was signed
|
|
1263
|
+
(seconds after, on a large batch read), so it is held to be no more than 300
|
|
1264
|
+
seconds before the signed `iat`, as on a whole dump.
|
|
1265
|
+
- **A walk** recomputes the root of every tree head whose size the leaves
|
|
1266
|
+
reach, from index 0 (`TENANT_CHECKPOINT_ROOT_MISMATCH`). A tree head above
|
|
1267
|
+
the last leaf given, or every tree head when the leaves start above 0, is
|
|
1268
|
+
verified on its own and reported `leaves: 'not_comparable'`. `heldTo` names
|
|
1269
|
+
the largest tree head the leaves were recomputed into, and its `detail`
|
|
1270
|
+
names the leaves after it that only the listing holds. Two tree heads of one
|
|
1271
|
+
size with different roots fail `TENANT_CHECKPOINT_FORK`; two different rows
|
|
1272
|
+
at one index fail `EXPORT_PAGE_CONFLICT`; a missing index fails
|
|
1273
|
+
`TENANT_READ_LEAF_INDEX_GAP`.
|
|
1274
|
+
|
|
1275
|
+
A witness co-signature (`witnessKeyId`, `witnessSignature`) is stored by the
|
|
1276
|
+
Server as given and verified here over the tree head's envelope bytes (the
|
|
1277
|
+
decoded `coseSign1Base64`), under the key `cosignerKeys` gives for its
|
|
1278
|
+
`witnessKeyId`: `{ [witnessKeyId]: spkiBase64 }` or `[{ keyId, publicKey }]`.
|
|
1279
|
+
The signature is read as hex or base64; Ed25519, ECDSA (raw `r||s` or DER) and
|
|
1280
|
+
ML-DSA keys are taken. `checkpoint.cosignature.state` reads `verified`,
|
|
1281
|
+
`failed`, `no_key` (none given for its id), `not_checked` (this host cannot
|
|
1282
|
+
compute its algorithm) or `absent`. A failed one is
|
|
1283
|
+
`TENANT_CHECKPOINT_COSIGNATURE_INVALID`, and so is a missing or unverified one
|
|
1284
|
+
under `requireCosignature: true`.
|
|
1285
|
+
|
|
1286
|
+
The tree's hashes are lowercase hex, and the primitives are exported:
|
|
477
1287
|
|
|
478
1288
|
```ts
|
|
479
1289
|
import { orgReadLeafHash, orgReadMerkleRoot, verifyOrgReadInclusion } from '@agledger/verify-core';
|
|
480
1290
|
|
|
481
|
-
// leaf_hash = hex(sha256(0x00 || cose_sign1)); a
|
|
1291
|
+
// leaf_hash = hex(sha256(0x00 || cose_sign1)); a tree head's root is the RFC 9162 root over them.
|
|
482
1292
|
const leaf = orgReadLeafHash(Buffer.from('cose-sign1-bytes'));
|
|
483
1293
|
const root = orgReadMerkleRoot([leaf]);
|
|
484
|
-
//
|
|
1294
|
+
// A one-leaf tree has an empty path.
|
|
485
1295
|
console.log(root === leaf, verifyOrgReadInclusion(leaf, 0, 1, [], root!)); // true true
|
|
486
1296
|
```
|
|
487
1297
|
|
|
1298
|
+
`orgReadDocumentKind(value)` names which of these documents a parsed JSON
|
|
1299
|
+
value is: `org-read-checkpoint`, `org-read-checkpoints`, `org-read-proof`,
|
|
1300
|
+
`org-read-entries`, `org-read-entry`, or `null`.
|
|
1301
|
+
|
|
488
1302
|
## Canonical failure taxonomy
|
|
489
1303
|
|
|
490
1304
|
Every failure is a canonical SCREAMING_SNAKE `FailureCode`. Importing the
|
|
@@ -503,3 +1317,5 @@ a key fetched from the Server comes from its database too. Trust is what
|
|
|
503
1317
|
## License
|
|
504
1318
|
|
|
505
1319
|
Proprietary. See [LICENSE](./LICENSE). © AGLedger LLC. All rights reserved.
|
|
1320
|
+
|
|
1321
|
+
AGLedger is a trademark of AGLedger LLC. All other trademarks are the property of their respective owners. Patent pending.
|