@agledger/verify-core 1.4.1 → 1.5.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 +13 -16
- package/README.md +56 -0
- package/dist/audit-export.d.ts +51 -14
- package/dist/audit-export.js +22 -3
- package/dist/chain.d.ts +84 -2
- package/dist/chain.js +112 -11
- package/dist/failures.d.ts +12 -1
- package/dist/failures.js +13 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/primitives.d.ts +105 -0
- package/dist/primitives.js +168 -0
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -17,16 +17,13 @@ Licensor grants you a limited, non-exclusive, non-transferable, revocable
|
|
|
17
17
|
license to install and use the Software solely for the purpose of integrating
|
|
18
18
|
with a self-hosted AGLedger deployment operated by you or your organization, or
|
|
19
19
|
by a third party on your behalf with your authorization. The Software is not
|
|
20
|
-
|
|
21
|
-
AGLedger operates the AGLedger software on a self-hosted model; there is no
|
|
22
|
-
hosted AGLedger API.
|
|
20
|
+
licensed for use with any AGLedger-hosted service.
|
|
23
21
|
|
|
24
|
-
AGLedger LLC
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
LLC receives no usage data or other data from your self-hosted deployment.
|
|
22
|
+
AGLedger LLC does not receive, access, inspect, or judge the data you process
|
|
23
|
+
through your self-hosted deployment, and does not use any such data to train,
|
|
24
|
+
fine-tune, evaluate, or benchmark any machine-learning or artificial-
|
|
25
|
+
intelligence model, or to develop any product or service. AGLedger LLC does not
|
|
26
|
+
collect product usage information from your self-hosted deployment.
|
|
30
27
|
|
|
31
28
|
2. RESTRICTIONS
|
|
32
29
|
|
|
@@ -84,8 +81,9 @@ cause of action accrues, to the maximum extent permitted by applicable law.
|
|
|
84
81
|
|
|
85
82
|
6. EXPORT COMPLIANCE
|
|
86
83
|
|
|
87
|
-
The Software may include cryptographic functionality
|
|
88
|
-
256-
|
|
84
|
+
The Software may include cryptographic functionality, including Ed25519
|
|
85
|
+
(EdDSA), ECDSA using curve P-256 with SHA-256, HMAC-SHA-256, AES-256-GCM,
|
|
86
|
+
HKDF-SHA-256, and SHA-256. AGLedger LLC classifies the Software under
|
|
89
87
|
ECCN 5D002 in good faith. To the extent AGLedger LLC makes the source code of
|
|
90
88
|
the Software publicly available through a public repository, that source code
|
|
91
89
|
is subject to the treatment afforded under 15 CFR § 742.15(b) of the U.S.
|
|
@@ -102,14 +100,13 @@ or trade-control laws.
|
|
|
102
100
|
|
|
103
101
|
7. TRADEMARKS
|
|
104
102
|
|
|
105
|
-
AGLedger
|
|
106
|
-
|
|
107
|
-
respective owners.
|
|
103
|
+
AGLedger and Settlement Signal are trademarks of AGLedger LLC. All other
|
|
104
|
+
trademarks are the property of their respective owners.
|
|
108
105
|
|
|
109
106
|
8. PATENTS
|
|
110
107
|
|
|
111
|
-
The Software is covered by one or more U.S.
|
|
112
|
-
|
|
108
|
+
The Software is covered by one or more issued or pending U.S. patents in
|
|
109
|
+
AGLedger LLC's patent portfolio.
|
|
113
110
|
|
|
114
111
|
9. RELATIONSHIP TO OTHER AGLEDGER AGREEMENTS
|
|
115
112
|
|
package/README.md
CHANGED
|
@@ -57,6 +57,62 @@ if (!result.valid) {
|
|
|
57
57
|
- **Envelope signature**: over the reconstructed `Sig_structure`, against the
|
|
58
58
|
matched verification key, under the algorithm its SPKI commits to (Ed25519
|
|
59
59
|
or ES256; anything else fails closed as `CHAIN_UNSUPPORTED_ALGORITHM`).
|
|
60
|
+
- **Signed-kid binding**: the row's `signingKeyId` names the key the protected
|
|
61
|
+
header signed.
|
|
62
|
+
- **Payload binding**: each entry's human-readable `payload` still matches the
|
|
63
|
+
predicate inside the signed bytes, so a rewritten view of the record fails
|
|
64
|
+
`CHAIN_PAYLOAD_BINDING_MISMATCH`.
|
|
65
|
+
- **OIDC actor**: the row's `actorOidcIss` / `actorOidcSub` match the identity
|
|
66
|
+
signed in `predicate.on_behalf_of`.
|
|
67
|
+
- **Actor attribution**: the row's `actorId`, `actorRole` and `actorOwnerId`,
|
|
68
|
+
the attribution an export's own guide tells an auditor to rely on, match the
|
|
69
|
+
actor claim signed in the protected header, so an export re-attributed to
|
|
70
|
+
another actor fails `CHAIN_ACTOR_ATTRIBUTION_MISMATCH`.
|
|
71
|
+
- **Key validity windows**: each entry was written inside its signing key's
|
|
72
|
+
activation window.
|
|
73
|
+
- **Agent signatures**, when you supply the agent's cert key (below).
|
|
74
|
+
|
|
75
|
+
The payload, OIDC, attribution and key-window checks run when the export
|
|
76
|
+
carries their inputs, which every current Server does. The result's `optionalChecks` says
|
|
77
|
+
which ran, so "not checked" never reads as "passed".
|
|
78
|
+
|
|
79
|
+
## Agent signatures
|
|
80
|
+
|
|
81
|
+
An agent that authenticates with an ephemeral cert can sign each request body
|
|
82
|
+
it sends. The Server checks that signature, then seals it into the chain entry
|
|
83
|
+
as `predicate.on_behalf_of.agent_signature`, beside the RFC 7638 thumbprint of
|
|
84
|
+
the cert's public key. The envelope signature proves the Server wrote that. To
|
|
85
|
+
prove the agent itself signed, without taking the Server's word for it,
|
|
86
|
+
re-verify the agent signature against the cert's public key.
|
|
87
|
+
|
|
88
|
+
The export does not carry cert public keys. Supply them as the Ed25519 JWK the
|
|
89
|
+
agent sent to `POST /v1/auth/oidc/cert` (the same key is the `cnf.jwk` claim
|
|
90
|
+
inside the `certJws` it got back):
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { verifyAuditExport } from '@agledger/verify-core';
|
|
94
|
+
|
|
95
|
+
const agentKey = { kty: 'OKP', crv: 'Ed25519', x: 'BKOgK3KibE8BZH8SXTX9dmAXcwgocTMHIv-R_eRB2lo' } as const;
|
|
96
|
+
const result = verifyAuditExport(exportDocument, { agentKeys: [agentKey] });
|
|
97
|
+
|
|
98
|
+
console.log(result.optionalChecks.agent_signature); // 'applied'
|
|
99
|
+
console.log(result.agentSignatures); // e.g. { present: 6, verified: 6 }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
A key is matched to an entry only through the thumbprint that entry signed, so
|
|
103
|
+
a key for some other cert is never checked against it and where the key came
|
|
104
|
+
from needs no trust. `present` counts entries carrying an agent signature and
|
|
105
|
+
`verified` those re-checked and found good; `present > verified` on a valid
|
|
106
|
+
result means some were not checked, never that they failed. One that does not
|
|
107
|
+
verify fails `CHAIN_AGENT_SIGNATURE_INVALID`. The check runs only where
|
|
108
|
+
`on_behalf_of.validated` is `true`: on a caller-asserted identity the two fields
|
|
109
|
+
may be passthrough from an older Server, and the export cannot tell which.
|
|
110
|
+
|
|
111
|
+
The Server's own chain verification also compares each sealed cert against its
|
|
112
|
+
live cert record (`cert_missing`, `cert_actor_drift`, `cert_window_drift`,
|
|
113
|
+
`cert_expired`). That record is not exported, so those checks have no offline
|
|
114
|
+
counterpart; the signed bytes already fix the cert id, thumbprint and expiry an
|
|
115
|
+
entry sealed.
|
|
60
116
|
|
|
61
117
|
## Verifying on a FIPS-locked host
|
|
62
118
|
|
package/dist/audit-export.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* then `verifyAuditExport(...)`. It maps the export wire shape onto the shared
|
|
6
6
|
* normalized entry and runs `verifyChain`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
8
|
+
* The three row-level input-gated checks run on the export path when the wire
|
|
9
|
+
* carries their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
10
10
|
* `actorOidcIss/Sub` enable the OIDC-actor cross-check; `signingKeyWindows` +
|
|
11
11
|
* per-entry `createdAt` enable temporal key-validity; and the per-entry
|
|
12
12
|
* denormalized `payload` + `entryType` enable binding-integrity, the export's
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { type CheckApplicability, type OptionalCheck, type SignatureOutcome } from './chain.js';
|
|
23
23
|
import type { FailureCode } from './failures.js';
|
|
24
|
+
import type { AgentPublicKeyJwk } from './primitives.js';
|
|
24
25
|
/** One entry of a `/audit-export` document. */
|
|
25
26
|
export interface AuditExportEntryInput {
|
|
26
27
|
/** 1-based chain position. Current exports emit `chainPosition`; pre-v0.25 used `position`. */
|
|
@@ -35,6 +36,16 @@ export interface AuditExportEntryInput {
|
|
|
35
36
|
actorOidcSub?: string | null;
|
|
36
37
|
/** Tri-state from `audit_vault.actor_oidc_synthesized` (engine ≥ v0.26.x). Marker for the OIDC-actor check. */
|
|
37
38
|
actorOidcSynthesized?: boolean | null;
|
|
39
|
+
/**
|
|
40
|
+
* API-key id of the credential that performed this state-change, mirroring
|
|
41
|
+
* the row's `actor_key_id`. Signature-covered at CWT_Claims label 15 ->
|
|
42
|
+
* private label -65539; present → the actor-attribution check runs.
|
|
43
|
+
*/
|
|
44
|
+
actorId?: string | null;
|
|
45
|
+
/** Role of that credential (`admin` / `agent` / `platform`), mirroring `actor_role`. */
|
|
46
|
+
actorRole?: string | null;
|
|
47
|
+
/** Owner id of that credential, mirroring `actor_owner_id`. */
|
|
48
|
+
actorOwnerId?: string | null;
|
|
38
49
|
/** The record this entry belongs to; pairs with `payload`/`entryType` to drive the binding check. */
|
|
39
50
|
recordId?: string | null;
|
|
40
51
|
/** The audit-vault entry type (e.g. `RECORD_CREATED`); drives the binding check's predicate reconstruction. */
|
|
@@ -69,8 +80,10 @@ export interface RecordAuditExportInput {
|
|
|
69
80
|
* Self-describing verification guidance the engine ships in the export.
|
|
70
81
|
* `unsignedFields` lists per-entry fields that are UNSIGNED display projections
|
|
71
82
|
* (e.g. `actorDisplayName`) resolved at export time, not covered by the COSE_Sign1
|
|
72
|
-
* signature. A PASS does NOT vouch for these labels
|
|
73
|
-
* `actorOwnerId`/`actorId
|
|
83
|
+
* signature. A PASS does NOT vouch for these labels. The attribution the guide
|
|
84
|
+
* points at instead, `actorOwnerId`/`actorId`, IS signature-covered and IS
|
|
85
|
+
* cross-checked here (`actor_attribution`). Surfaced on the result so a verdict
|
|
86
|
+
* can say which labels it does not stand behind.
|
|
74
87
|
*/
|
|
75
88
|
verificationGuide?: {
|
|
76
89
|
unsignedFields?: string[];
|
|
@@ -115,6 +128,20 @@ export interface VerifyExportOptions {
|
|
|
115
128
|
* against its own embedded key is not an independent audit.
|
|
116
129
|
*/
|
|
117
130
|
requireOutOfBandKeys?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Ed25519 public keys of agent ephemeral certs, as JWKs: the `publicKeyJwk`
|
|
133
|
+
* the agent sent to `POST /v1/auth/oidc/cert`, which is also the `cnf.jwk`
|
|
134
|
+
* claim inside the returned `certJws`. The export does not carry them.
|
|
135
|
+
*
|
|
136
|
+
* When an entry's signed payload carries an engine-validated
|
|
137
|
+
* `predicate.on_behalf_of.agent_signature` and its sealed cert thumbprint
|
|
138
|
+
* matches one of these keys, the signature is re-verified offline, proving
|
|
139
|
+
* the cert holder signed that request-body hash without trusting the
|
|
140
|
+
* engine's word for it. A key is matched only through the thumbprint the
|
|
141
|
+
* entry signed, so where a key came from does not need to be trusted.
|
|
142
|
+
* Anything that is not an Ed25519 JWK throws `TypeError`.
|
|
143
|
+
*/
|
|
144
|
+
agentKeys?: ReadonlyArray<AgentPublicKeyJwk>;
|
|
118
145
|
}
|
|
119
146
|
export interface EntryVerificationResult {
|
|
120
147
|
position: number;
|
|
@@ -143,14 +170,17 @@ export interface VerifyExportResult {
|
|
|
143
170
|
/**
|
|
144
171
|
* Which input-gated checks ran on this export.
|
|
145
172
|
*
|
|
146
|
-
* - `
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* - `payload_binding`
|
|
150
|
-
*
|
|
151
|
-
*
|
|
173
|
+
* - `actor_attribution` flips to `applied` when the export carries the
|
|
174
|
+
* `actorId` / `actorRole` / `actorOwnerId` columns and the envelope carries
|
|
175
|
+
* the signed actor claim, which is every current export.
|
|
176
|
+
* - `payload_binding`, `oidc_actor` and `key_temporal` flip to `applied`
|
|
177
|
+
* when the export wire carries their inputs (engine >= v0.26.x: per-entry
|
|
178
|
+
* `payload` + `entryType`, `actorOidcSynthesized`, `createdAt`, and
|
|
179
|
+
* `signingKeyWindows` in exportMetadata). Older exports without those
|
|
180
|
+
* fields stay `skipped_no_input`.
|
|
181
|
+
* - `agent_signature` is `applied` only when `agentKeys` supplied the cert
|
|
182
|
+
* key for at least one engine-validated agent signature on the chain.
|
|
152
183
|
*
|
|
153
|
-
* Older exports without the new fields stay `skipped_no_input` for all three.
|
|
154
184
|
* The applicability is surfaced so a caller never mistakes "not checked
|
|
155
185
|
* here" for "checked and passed".
|
|
156
186
|
*/
|
|
@@ -167,10 +197,17 @@ export interface VerifyExportResult {
|
|
|
167
197
|
/**
|
|
168
198
|
* Per-entry fields the export self-describes as UNSIGNED display projections
|
|
169
199
|
* (from `verificationGuide.unsignedFields`), e.g. `actorDisplayName`.
|
|
170
|
-
* A valid signature does NOT cover these;
|
|
171
|
-
* `actorOwnerId`/`actorId
|
|
172
|
-
*
|
|
200
|
+
* A valid signature does NOT cover these; the attribution that IS covered,
|
|
201
|
+
* `actorOwnerId`/`actorId`, is cross-checked against the signed actor claim
|
|
202
|
+
* (see `optionalChecks.actor_attribution`). Empty when the export carries no
|
|
203
|
+
* such guidance. A caller surfacing a PASS should warn that these labels are
|
|
204
|
+
* not vouched for.
|
|
173
205
|
*/
|
|
174
206
|
unsignedProjectionFields: string[];
|
|
207
|
+
/** Agent signatures present on the chain vs re-verified offline (see `agentKeys`). */
|
|
208
|
+
agentSignatures: {
|
|
209
|
+
present: number;
|
|
210
|
+
verified: number;
|
|
211
|
+
};
|
|
175
212
|
}
|
|
176
213
|
export declare function verifyAuditExport(exportData: RecordAuditExportInput, options?: VerifyExportOptions): VerifyExportResult;
|
package/dist/audit-export.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* then `verifyAuditExport(...)`. It maps the export wire shape onto the shared
|
|
6
6
|
* normalized entry and runs `verifyChain`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
8
|
+
* The three row-level input-gated checks run on the export path when the wire
|
|
9
|
+
* carries their inputs (engine ≥ v0.26.x): the `actorOidcSynthesized` flag +
|
|
10
10
|
* `actorOidcIss/Sub` enable the OIDC-actor cross-check; `signingKeyWindows` +
|
|
11
11
|
* per-entry `createdAt` enable temporal key-validity; and the per-entry
|
|
12
12
|
* denormalized `payload` + `entryType` enable binding-integrity, the export's
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* Older exports without these fields stay `skipped_no_input`, surfaced in the
|
|
20
20
|
* result so a caller never mistakes "not checked here" for "checked and passed".
|
|
21
21
|
*/
|
|
22
|
-
import { buildKeyRegistry, verifyChain, } from './chain.js';
|
|
22
|
+
import { buildAgentKeyRegistry, buildKeyRegistry, verifyChain, } from './chain.js';
|
|
23
23
|
const SUPPORTED_FORMAT_VERSION = '2.0';
|
|
24
24
|
const SUPPORTED_CANONICALIZATION = 'RFC8949-CDE';
|
|
25
25
|
export function verifyAuditExport(exportData, options = {}) {
|
|
@@ -32,6 +32,7 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
32
32
|
return earlyFailure(meta.recordId, entries.length, `Unsupported canonicalization ${meta.canonicalization} (only ${SUPPORTED_CANONICALIZATION} supported).`);
|
|
33
33
|
}
|
|
34
34
|
const keys = buildKeyRegistry(resolveKeys(exportData, options));
|
|
35
|
+
const agentKeys = options.agentKeys !== undefined ? buildAgentKeyRegistry(options.agentKeys) : undefined;
|
|
35
36
|
const normalized = entries.map((e) => {
|
|
36
37
|
const base = {
|
|
37
38
|
scopeId: meta.recordId,
|
|
@@ -56,6 +57,19 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
56
57
|
payload: e.payload,
|
|
57
58
|
};
|
|
58
59
|
}
|
|
60
|
+
// Actor attribution: the export's own guide tells an auditor that
|
|
61
|
+
// `actorId`/`actorOwnerId` ARE the trustworthy attribution (only
|
|
62
|
+
// actorDisplayName / actorOwnerType / humanReadableLabel are listed as
|
|
63
|
+
// unsigned projections), so those columns are cross-checked against the
|
|
64
|
+
// signed actor claim rather than displayed on trust. Any one of the three
|
|
65
|
+
// present is enough to run the check on what is there.
|
|
66
|
+
if (e.actorId !== undefined || e.actorOwnerId !== undefined || e.actorRole !== undefined) {
|
|
67
|
+
base.actorAttribution = {
|
|
68
|
+
actorId: e.actorId ?? null,
|
|
69
|
+
actorRole: e.actorRole ?? null,
|
|
70
|
+
actorOwnerId: e.actorOwnerId ?? null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
59
73
|
if (e.createdAt)
|
|
60
74
|
base.createdAt = e.createdAt;
|
|
61
75
|
// The synthesized flag is the marker that the export carries the OIDC
|
|
@@ -74,6 +88,7 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
74
88
|
const chain = verifyChain(normalized, keys, {
|
|
75
89
|
requireKeyId: options.requireKeyId,
|
|
76
90
|
requireOutOfBandKeys: options.requireOutOfBandKeys,
|
|
91
|
+
agentKeys,
|
|
77
92
|
});
|
|
78
93
|
return {
|
|
79
94
|
valid: chain.valid,
|
|
@@ -94,6 +109,7 @@ export function verifyAuditExport(exportData, options = {}) {
|
|
|
94
109
|
optionalChecks: chain.optionalChecks,
|
|
95
110
|
keyProvenance: chain.keyProvenance,
|
|
96
111
|
unsignedProjectionFields: exportData.verificationGuide?.unsignedFields ?? [],
|
|
112
|
+
agentSignatures: chain.agentSignatures,
|
|
97
113
|
};
|
|
98
114
|
}
|
|
99
115
|
function earlyFailure(recordId, totalEntries, detail) {
|
|
@@ -108,10 +124,13 @@ function earlyFailure(recordId, totalEntries, detail) {
|
|
|
108
124
|
optionalChecks: {
|
|
109
125
|
payload_binding: 'skipped_no_input',
|
|
110
126
|
oidc_actor: 'skipped_no_input',
|
|
127
|
+
actor_attribution: 'skipped_no_input',
|
|
111
128
|
key_temporal: 'skipped_no_input',
|
|
129
|
+
agent_signature: 'skipped_no_input',
|
|
112
130
|
},
|
|
113
131
|
keyProvenance: { outOfBand: 0, embedded: 0 },
|
|
114
132
|
unsignedProjectionFields: [],
|
|
133
|
+
agentSignatures: { present: 0, verified: 0 },
|
|
115
134
|
};
|
|
116
135
|
}
|
|
117
136
|
function resolveKeys(exportData, options) {
|
package/dist/chain.d.ts
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared per-chain verification walk.
|
|
3
|
+
*
|
|
4
|
+
* This is the single body of logic the SDK /verify, CLI, MCP server, and
|
|
5
|
+
* @agledger/verify all run, replacing four hand-vendored copies. It walks ONE
|
|
6
|
+
* hash chain (a single record's lifecycle, or a single per-org schema-event
|
|
7
|
+
* chain) over a normalized entry shape and emits the canonical failure
|
|
8
|
+
* taxonomy.
|
|
9
|
+
*
|
|
10
|
+
* Two input surfaces feed it through thin adapters:
|
|
11
|
+
* - the live `/audit-export` JSON (per-record; see audit-export.ts)
|
|
12
|
+
* - the offline NDJSON vault dump (full-vault; @agledger/verify)
|
|
13
|
+
*
|
|
14
|
+
* Checks split into two tiers:
|
|
15
|
+
* - ALWAYS-RUN (every surface): position monotonicity, payloadHash =
|
|
16
|
+
* sha256(cose_sign1), previous-hash link, COSE_Sign1 decode, the signed
|
|
17
|
+
* protected-header chain-claim cross-check, and the Ed25519 signature.
|
|
18
|
+
* - INPUT-GATED (only when the normalized entry, or the caller, supplies the
|
|
19
|
+
* inputs): binding-integrity, OIDC-actor cross-check, temporal
|
|
20
|
+
* key-validity, and the agent-signature re-check. The first three run on
|
|
21
|
+
* the dump and on any export from an engine that ships the row fields
|
|
22
|
+
* (>= v0.26.x). The agent-signature check needs the cert's public key,
|
|
23
|
+
* which neither surface carries, so it runs only when the caller passes
|
|
24
|
+
* `agentKeys`. A check without its input is reported `skipped_no_input`,
|
|
25
|
+
* NEVER folded into a green verdict.
|
|
26
|
+
*
|
|
27
|
+
* Failure ordering is fixed so `brokenAt` is deterministic. The null-key
|
|
28
|
+
* signature skip happens LAST, after the binding/OIDC checks, so a row written
|
|
29
|
+
* without a signing key is still subject to every structural check.
|
|
30
|
+
*/
|
|
31
|
+
import { type AgentPublicKeyJwk } from './primitives.js';
|
|
1
32
|
import type { FailureCode } from './failures.js';
|
|
2
33
|
/** Where a verification key came from: the trust-anchor provenance. */
|
|
3
34
|
export type KeySource = 'out-of-band' | 'embedded';
|
|
@@ -29,7 +60,21 @@ export interface VerificationKey {
|
|
|
29
60
|
}
|
|
30
61
|
export type KeyRegistry = ReadonlyMap<string, VerificationKey>;
|
|
31
62
|
export declare function buildKeyRegistry(keys: readonly VerificationKey[]): KeyRegistry;
|
|
32
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Agent cert keys for the agent-signature check, indexed by the RFC 7638
|
|
65
|
+
* thumbprint (`sha256:<hex>`) the engine seals as
|
|
66
|
+
* `predicate.on_behalf_of.cert.thumbprint`. Values are SPKI DER, base64.
|
|
67
|
+
*/
|
|
68
|
+
export type AgentKeyRegistry = ReadonlyMap<string, string>;
|
|
69
|
+
/**
|
|
70
|
+
* Index caller-supplied agent cert keys by thumbprint. A key is matched to an
|
|
71
|
+
* entry only through the thumbprint that entry signed, so a key supplied for
|
|
72
|
+
* the wrong cert is never checked against it: it simply matches nothing.
|
|
73
|
+
* That is also why the source of a key needs no trust: the signed thumbprint
|
|
74
|
+
* is what binds it. Throws `TypeError` on anything that is not an Ed25519 JWK.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildAgentKeyRegistry(jwks: readonly AgentPublicKeyJwk[]): AgentKeyRegistry;
|
|
77
|
+
/** One chain entry, plus the inputs the input-gated checks consume when the surface carries them. */
|
|
33
78
|
export interface NormalizedEntry {
|
|
34
79
|
/** Identity for messages: recordId (export) or chainKey (dump). */
|
|
35
80
|
scopeId: string;
|
|
@@ -53,8 +98,25 @@ export interface NormalizedEntry {
|
|
|
53
98
|
sub: string | null;
|
|
54
99
|
synthesized: boolean | undefined;
|
|
55
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Inputs for the actor-attribution cross-check: the row columns a report
|
|
103
|
+
* displays as "who did this". The export carries them as `actorId` /
|
|
104
|
+
* `actorRole` / `actorOwnerId`, the dump as `actor_key_id` / `actor_role` /
|
|
105
|
+
* `actor_owner_id`. Absent on older artifacts, which skips the check.
|
|
106
|
+
*/
|
|
107
|
+
actorAttribution?: {
|
|
108
|
+
actorId: string | null;
|
|
109
|
+
actorRole: string | null;
|
|
110
|
+
actorOwnerId: string | null;
|
|
111
|
+
};
|
|
56
112
|
}
|
|
57
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Checks that run only when their input is present. `agent_signature` is
|
|
115
|
+
* applied when at least one entry carrying an engine-validated agent signature
|
|
116
|
+
* had its cert key supplied by the caller (`agentKeys`); neither the export
|
|
117
|
+
* nor the dump carries cert public keys.
|
|
118
|
+
*/
|
|
119
|
+
export type OptionalCheck = 'payload_binding' | 'oidc_actor' | 'actor_attribution' | 'key_temporal' | 'agent_signature';
|
|
58
120
|
export type CheckApplicability = 'applied' | 'skipped_no_input';
|
|
59
121
|
export interface SignatureOutcome {
|
|
60
122
|
/**
|
|
@@ -112,6 +174,19 @@ export interface ChainResult {
|
|
|
112
174
|
outOfBand: number;
|
|
113
175
|
embedded: number;
|
|
114
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* Agent signatures on this chain. `present` counts entries that passed
|
|
179
|
+
* every other check and whose signed payload carries
|
|
180
|
+
* `predicate.on_behalf_of.agent_signature`; `verified`
|
|
181
|
+
* counts those re-checked against a caller-supplied cert key and found
|
|
182
|
+
* good. `present > verified` on a valid chain means some were not checked
|
|
183
|
+
* (no key supplied, or the identity was a caller assertion), never that
|
|
184
|
+
* they failed.
|
|
185
|
+
*/
|
|
186
|
+
agentSignatures: {
|
|
187
|
+
present: number;
|
|
188
|
+
verified: number;
|
|
189
|
+
};
|
|
115
190
|
}
|
|
116
191
|
export interface VerifyChainOptions {
|
|
117
192
|
/** Require every entry's signingKeyId to equal this id (else CHAIN_KEY_POLICY_VIOLATION). */
|
|
@@ -122,6 +197,13 @@ export interface VerifyChainOptions {
|
|
|
122
197
|
* CHAIN_KEY_POLICY_VIOLATION. Forces the caller to supply keys out of band.
|
|
123
198
|
*/
|
|
124
199
|
requireOutOfBandKeys?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Agent cert keys (see `buildAgentKeyRegistry`). When an entry's signed
|
|
202
|
+
* payload carries an engine-validated `on_behalf_of.agent_signature` and its
|
|
203
|
+
* sealed cert thumbprint matches a key here, the signature is re-verified
|
|
204
|
+
* offline; a failure is CHAIN_AGENT_SIGNATURE_INVALID.
|
|
205
|
+
*/
|
|
206
|
+
agentKeys?: AgentKeyRegistry;
|
|
125
207
|
}
|
|
126
208
|
/**
|
|
127
209
|
* Verify a single hash chain. `entries` are all the entries for one scope; they
|
package/dist/chain.js
CHANGED
|
@@ -15,26 +15,48 @@
|
|
|
15
15
|
* - ALWAYS-RUN (every surface): position monotonicity, payloadHash =
|
|
16
16
|
* sha256(cose_sign1), previous-hash link, COSE_Sign1 decode, the signed
|
|
17
17
|
* protected-header chain-claim cross-check, and the Ed25519 signature.
|
|
18
|
-
* - INPUT-GATED (only when the normalized entry
|
|
19
|
-
*
|
|
20
|
-
* key-validity
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* into a green verdict.
|
|
18
|
+
* - INPUT-GATED (only when the normalized entry, or the caller, supplies the
|
|
19
|
+
* inputs): binding-integrity, OIDC-actor cross-check, temporal
|
|
20
|
+
* key-validity, and the agent-signature re-check. The first three run on
|
|
21
|
+
* the dump and on any export from an engine that ships the row fields
|
|
22
|
+
* (>= v0.26.x). The agent-signature check needs the cert's public key,
|
|
23
|
+
* which neither surface carries, so it runs only when the caller passes
|
|
24
|
+
* `agentKeys`. A check without its input is reported `skipped_no_input`,
|
|
25
|
+
* NEVER folded into a green verdict.
|
|
26
26
|
*
|
|
27
27
|
* Failure ordering is fixed so `brokenAt` is deterministic. The null-key
|
|
28
28
|
* signature skip happens LAST, after the binding/OIDC checks, so a row written
|
|
29
29
|
* without a signing key is still subject to every structural check.
|
|
30
30
|
*/
|
|
31
|
-
import { buildPredicateForRow, decodeCoseSign1, decodePredicate, deepEqual, describeUnsupportedAlgorithm, extractChainClaim, extractKid, extractOnBehalfOfClaim, resolveKeyAlgorithm, sha256Hex, stripEnvelopeExtensions, verifyCoseSign1, } from './primitives.js';
|
|
31
|
+
import { buildPredicateForRow, decodeCoseSign1, decodePredicate, deepEqual, describeUnsupportedAlgorithm, ed25519JwkThumbprint, ed25519JwkToSpki, extractAgentSignatureClaim, extractActorClaim, extractChainClaim, extractKid, extractOnBehalfOfClaim, resolveKeyAlgorithm, sha256Hex, stripEnvelopeExtensions, envelopeExtensionsMatch, verifyAgentSignature, verifyCoseSign1, } from './primitives.js';
|
|
32
32
|
export function buildKeyRegistry(keys) {
|
|
33
33
|
const map = new Map();
|
|
34
34
|
for (const k of keys)
|
|
35
35
|
map.set(k.keyId, k);
|
|
36
36
|
return map;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Index caller-supplied agent cert keys by thumbprint. A key is matched to an
|
|
40
|
+
* entry only through the thumbprint that entry signed, so a key supplied for
|
|
41
|
+
* the wrong cert is never checked against it: it simply matches nothing.
|
|
42
|
+
* That is also why the source of a key needs no trust: the signed thumbprint
|
|
43
|
+
* is what binds it. Throws `TypeError` on anything that is not an Ed25519 JWK.
|
|
44
|
+
*/
|
|
45
|
+
export function buildAgentKeyRegistry(jwks) {
|
|
46
|
+
if (!Array.isArray(jwks)) {
|
|
47
|
+
throw new TypeError('agentKeys must be an array of Ed25519 JWKs ({ kty: "OKP", crv: "Ed25519", x }).');
|
|
48
|
+
}
|
|
49
|
+
const map = new Map();
|
|
50
|
+
jwks.forEach((jwk, i) => {
|
|
51
|
+
const thumbprint = ed25519JwkThumbprint(jwk);
|
|
52
|
+
const spki = ed25519JwkToSpki(jwk);
|
|
53
|
+
if (thumbprint === null || spki === null) {
|
|
54
|
+
throw new TypeError(`agentKeys[${i}] is not an Ed25519 public-key JWK. Expected { kty: "OKP", crv: "Ed25519", x: <base64url of 32 bytes> }, the publicKeyJwk sent at cert exchange (also the cnf.jwk claim inside the certJws).`);
|
|
55
|
+
}
|
|
56
|
+
map.set(thumbprint, spki);
|
|
57
|
+
});
|
|
58
|
+
return map;
|
|
59
|
+
}
|
|
38
60
|
/**
|
|
39
61
|
* Verify a single hash chain. `entries` are all the entries for one scope; they
|
|
40
62
|
* are sorted by chainPosition internally (so a reordered export array still
|
|
@@ -48,9 +70,12 @@ export function verifyChain(entries, keys, options = {}) {
|
|
|
48
70
|
const optionalChecks = {
|
|
49
71
|
payload_binding: 'skipped_no_input',
|
|
50
72
|
oidc_actor: 'skipped_no_input',
|
|
73
|
+
actor_attribution: 'skipped_no_input',
|
|
51
74
|
key_temporal: 'skipped_no_input',
|
|
75
|
+
agent_signature: 'skipped_no_input',
|
|
52
76
|
};
|
|
53
77
|
const keyProvenance = { outOfBand: 0, embedded: 0 };
|
|
78
|
+
const agentSignatures = { present: 0, verified: 0 };
|
|
54
79
|
let verifiedEntries = 0;
|
|
55
80
|
let brokenAt;
|
|
56
81
|
if (sorted.length === 0) {
|
|
@@ -64,13 +89,17 @@ export function verifyChain(entries, keys, options = {}) {
|
|
|
64
89
|
signatureCoverage: coverage,
|
|
65
90
|
optionalChecks,
|
|
66
91
|
keyProvenance,
|
|
92
|
+
agentSignatures,
|
|
67
93
|
};
|
|
68
94
|
}
|
|
69
95
|
let previousHash = null;
|
|
70
96
|
for (let i = 0; i < sorted.length; i++) {
|
|
71
97
|
const entry = sorted[i];
|
|
72
98
|
const expectedPosition = i + 1;
|
|
73
|
-
|
|
99
|
+
let result = verifyEntry(entry, expectedPosition, previousHash, keys, options, optionalChecks);
|
|
100
|
+
if (result.valid) {
|
|
101
|
+
result = checkAgentSignature(entry, result, options.agentKeys, optionalChecks, agentSignatures);
|
|
102
|
+
}
|
|
74
103
|
entryResults.push(result);
|
|
75
104
|
if (result.valid)
|
|
76
105
|
verifiedEntries++;
|
|
@@ -107,8 +136,46 @@ export function verifyChain(entries, keys, options = {}) {
|
|
|
107
136
|
signatureCoverage: coverage,
|
|
108
137
|
optionalChecks,
|
|
109
138
|
keyProvenance,
|
|
139
|
+
agentSignatures,
|
|
110
140
|
};
|
|
111
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Offline re-check of a sealed agent signature, on an entry that already
|
|
144
|
+
* passed every other check (so its payload is the engine's signed bytes).
|
|
145
|
+
*
|
|
146
|
+
* Runs only on an engine-validated identity (`on_behalf_of.validated: true`).
|
|
147
|
+
* On a caller-asserted one, entries written before the engine sealed these
|
|
148
|
+
* fields itself carry them as caller passthrough, and the marker telling the
|
|
149
|
+
* two apart is a column neither the export nor the dump publishes, so a
|
|
150
|
+
* failure there could not be told from a claim nobody ever checked.
|
|
151
|
+
*/
|
|
152
|
+
function checkAgentSignature(entry, result, agentKeys, optionalChecks, counts) {
|
|
153
|
+
const parts = decodeCoseSign1(Buffer.from(entry.coseSign1, 'base64'));
|
|
154
|
+
if (!parts)
|
|
155
|
+
return result;
|
|
156
|
+
const claim = extractAgentSignatureClaim(parts.payloadBstr);
|
|
157
|
+
if (claim === null)
|
|
158
|
+
return result;
|
|
159
|
+
counts.present++;
|
|
160
|
+
if (!claim.validated || !agentKeys || claim.certThumbprint === null)
|
|
161
|
+
return result;
|
|
162
|
+
const spki = agentKeys.get(claim.certThumbprint);
|
|
163
|
+
if (spki === undefined)
|
|
164
|
+
return result;
|
|
165
|
+
optionalChecks.agent_signature = 'applied';
|
|
166
|
+
const outcome = verifyAgentSignature(spki, claim);
|
|
167
|
+
if (outcome === 'ok') {
|
|
168
|
+
counts.verified++;
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
const certLabel = claim.certId ?? claim.certThumbprint;
|
|
172
|
+
if (outcome === 'unsupported') {
|
|
173
|
+
return fail(entry.scopeId, result.position, 'CHAIN_UNSUPPORTED_ALGORITHM', `Agent signature for cert ${certLabel} could not be checked: this host cannot compute Ed25519 (an active OpenSSL FIPS provider carries no EdDSA). Not verified, and not tamper evidence.`, result.signature);
|
|
174
|
+
}
|
|
175
|
+
return fail(entry.scopeId, result.position, 'CHAIN_AGENT_SIGNATURE_INVALID', outcome === 'malformed'
|
|
176
|
+
? `Sealed agent_signature for cert ${certLabel} has a shape nothing can verify (alg must be EdDSA, content_hash sha256:<hex64>, signature 64 bytes of standard base64).`
|
|
177
|
+
: `Sealed agent_signature for cert ${certLabel} does not verify under the supplied key with thumbprint ${claim.certThumbprint}.`, result.signature);
|
|
178
|
+
}
|
|
112
179
|
function fail(scopeId, position, code, detail, signature = 'not-checked') {
|
|
113
180
|
return { scopeId, position, valid: false, failure: { code, detail }, signature };
|
|
114
181
|
}
|
|
@@ -143,6 +210,36 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
|
|
|
143
210
|
chainClaim.previous_hash !== expectedPrev) {
|
|
144
211
|
return fail(scopeId, expectedPosition, 'CHAIN_COSE_HEADER_MISMATCH', `Signed protected-header chain claim (position=${chainClaim?.position ?? 'null'}, prev=${chainClaim?.previous_hash ?? 'null'}) diverges from row columns (position=${entry.chainPosition}, prev=${entry.previousHash ?? 'null'}).`);
|
|
145
212
|
}
|
|
213
|
+
// Input-gated: actor attribution. The row's actorId/actorOwnerId columns are
|
|
214
|
+
// the projection a report displays as "who did this", and the engine's own
|
|
215
|
+
// export guide names them as the trustworthy attribution while listing only
|
|
216
|
+
// actorDisplayName / actorOwnerType / humanReadableLabel as unsigned. They
|
|
217
|
+
// are signature-covered, at CWT_Claims label 15 -> private label -65539, so
|
|
218
|
+
// a rewritten column is a re-attribution of the action to another actor and
|
|
219
|
+
// must not verify. Same shape as the signed-kid check above: compare the
|
|
220
|
+
// column against the signed claim, and skip only when one side is absent
|
|
221
|
+
// (an older engine that never carried the claim, or an artifact that does
|
|
222
|
+
// not carry the columns).
|
|
223
|
+
const attribution = entry.actorAttribution;
|
|
224
|
+
if (attribution) {
|
|
225
|
+
const actorClaim = extractActorClaim(parts.protectedBstr);
|
|
226
|
+
if (actorClaim) {
|
|
227
|
+
optionalChecks.actor_attribution = 'applied';
|
|
228
|
+
const mismatches = [];
|
|
229
|
+
if (attribution.actorId !== null && attribution.actorId !== actorClaim.key_id) {
|
|
230
|
+
mismatches.push(`actorId=${attribution.actorId} vs signed ${actorClaim.key_id}`);
|
|
231
|
+
}
|
|
232
|
+
if (attribution.actorOwnerId !== null && attribution.actorOwnerId !== actorClaim.owner_id) {
|
|
233
|
+
mismatches.push(`actorOwnerId=${attribution.actorOwnerId} vs signed ${actorClaim.owner_id}`);
|
|
234
|
+
}
|
|
235
|
+
if (attribution.actorRole !== null && attribution.actorRole !== actorClaim.role) {
|
|
236
|
+
mismatches.push(`actorRole=${attribution.actorRole} vs signed ${actorClaim.role}`);
|
|
237
|
+
}
|
|
238
|
+
if (mismatches.length > 0) {
|
|
239
|
+
return fail(scopeId, expectedPosition, 'CHAIN_ACTOR_ATTRIBUTION_MISMATCH', `Row actor columns diverge from the signature-covered actor claim (${mismatches.join('; ')}).`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
146
243
|
// Input-gated: binding-integrity. Runs whenever the row payload is present:
|
|
147
244
|
// the dump always carries it, and the export now carries it too (engine ≥ v0.26.x).
|
|
148
245
|
if (entry.binding) {
|
|
@@ -150,7 +247,11 @@ function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, options, o
|
|
|
150
247
|
const decodedRaw = decodePredicate(parts.payloadBstr);
|
|
151
248
|
const rebuilt = buildPredicateForRow(entry.binding.recordId, entry.binding.entryType, entry.binding.payload);
|
|
152
249
|
const decoded = decodedRaw !== null ? stripEnvelopeExtensions(decodedRaw) : null;
|
|
153
|
-
if (
|
|
250
|
+
if (decodedRaw === null ||
|
|
251
|
+
decoded === null ||
|
|
252
|
+
rebuilt === null ||
|
|
253
|
+
!deepEqual(rebuilt, decoded) ||
|
|
254
|
+
!envelopeExtensionsMatch(entry.binding.payload, decodedRaw)) {
|
|
154
255
|
return fail(scopeId, expectedPosition, 'CHAIN_PAYLOAD_BINDING_MISMATCH', 'Denormalised row payload no longer matches the canonical projection of the signed predicate.');
|
|
155
256
|
}
|
|
156
257
|
}
|
package/dist/failures.d.ts
CHANGED
|
@@ -37,7 +37,18 @@
|
|
|
37
37
|
* started yet.
|
|
38
38
|
* - CHAIN_EMPTY (new) a chain/vault with nothing to verify is a non-clean
|
|
39
39
|
* verdict, never a silent pass.
|
|
40
|
+
*
|
|
41
|
+
* Server-side cert re-checks are not mirrored here. The engine's chain
|
|
42
|
+
* verification also reports `cert_missing`, `cert_actor_drift`,
|
|
43
|
+
* `cert_window_drift`, `cert_expired` and `agent_signature_invalid`, by
|
|
44
|
+
* comparing what an entry sealed in `predicate.on_behalf_of.cert` against the
|
|
45
|
+
* live `ephemeral_certs` row. Neither the export nor the dump carries that
|
|
46
|
+
* table, so an offline verifier cannot reproduce those comparisons, and it
|
|
47
|
+
* does not need to: it trusts only the signed bytes, which already fix the
|
|
48
|
+
* sealed cert id, thumbprint and expiry. The one cert-related check that can
|
|
49
|
+
* run offline is the agent signature, and only when the caller supplies the
|
|
50
|
+
* cert's public key (CHAIN_AGENT_SIGNATURE_INVALID below).
|
|
40
51
|
*/
|
|
41
|
-
export type FailureCode = 'UNSUPPORTED_FORMAT' | 'CHAIN_EMPTY' | 'CHAIN_POSITION_GAP' | 'CHAIN_GENESIS_INVALID' | 'CHAIN_LINK_BROKEN' | 'CHAIN_HASH_MISMATCH' | 'CHAIN_MALFORMED_ENTRY' | 'CHAIN_COSE_DECODE_FAILED' | 'CHAIN_COSE_HEADER_MISMATCH' | 'CHAIN_PAYLOAD_BINDING_MISMATCH' | 'CHAIN_OIDC_ACTOR_MISMATCH' | 'CHAIN_SIGNATURE_INVALID' | 'CHAIN_SIGNATURE_MISSING_KEY' | 'CHAIN_KEY_POLICY_VIOLATION' | 'CHAIN_KEY_EXPIRED' | 'CHAIN_KEY_NOT_YET_ACTIVE' | 'CHAIN_ALG_MISMATCH' | 'CHAIN_UNSUPPORTED_ALGORITHM' | 'CHAIN_SIGNING_KEY_DRIFT' | 'CHECKPOINT_ROW_MISSING' | 'CHECKPOINT_HASH_MISMATCH' | 'CHECKPOINT_SIGNATURE_INVALID' | 'TENANT_READ_LEAF_HASH_MISMATCH' | 'TENANT_READ_LEAF_INDEX_GAP' | 'TENANT_READ_SIGNATURE_INVALID' | 'TENANT_CHECKPOINT_LEAF_COUNT_MISMATCH' | 'TENANT_CHECKPOINT_ROOT_MISMATCH' | 'TENANT_CHECKPOINT_SIGNATURE_INVALID' | 'TENANT_CHECKPOINT_FORK';
|
|
52
|
+
export type FailureCode = 'UNSUPPORTED_FORMAT' | 'CHAIN_EMPTY' | 'CHAIN_POSITION_GAP' | 'CHAIN_GENESIS_INVALID' | 'CHAIN_LINK_BROKEN' | 'CHAIN_HASH_MISMATCH' | 'CHAIN_MALFORMED_ENTRY' | 'CHAIN_COSE_DECODE_FAILED' | 'CHAIN_COSE_HEADER_MISMATCH' | 'CHAIN_PAYLOAD_BINDING_MISMATCH' | 'CHAIN_OIDC_ACTOR_MISMATCH' | 'CHAIN_SIGNATURE_INVALID' | 'CHAIN_SIGNATURE_MISSING_KEY' | 'CHAIN_KEY_POLICY_VIOLATION' | 'CHAIN_KEY_EXPIRED' | 'CHAIN_KEY_NOT_YET_ACTIVE' | 'CHAIN_ALG_MISMATCH' | 'CHAIN_UNSUPPORTED_ALGORITHM' | 'CHAIN_SIGNING_KEY_DRIFT' | 'CHAIN_ACTOR_ATTRIBUTION_MISMATCH' | 'CHAIN_AGENT_SIGNATURE_INVALID' | 'CHECKPOINT_ROW_MISSING' | 'CHECKPOINT_HASH_MISMATCH' | 'CHECKPOINT_SIGNATURE_INVALID' | 'TENANT_READ_LEAF_HASH_MISMATCH' | 'TENANT_READ_LEAF_INDEX_GAP' | 'TENANT_READ_SIGNATURE_INVALID' | 'TENANT_CHECKPOINT_LEAF_COUNT_MISMATCH' | 'TENANT_CHECKPOINT_ROOT_MISMATCH' | 'TENANT_CHECKPOINT_SIGNATURE_INVALID' | 'TENANT_CHECKPOINT_FORK';
|
|
42
53
|
/** The actionable next step for a failure code. */
|
|
43
54
|
export declare function suggestion(code: FailureCode): string;
|
package/dist/failures.js
CHANGED
|
@@ -37,6 +37,17 @@
|
|
|
37
37
|
* started yet.
|
|
38
38
|
* - CHAIN_EMPTY (new) a chain/vault with nothing to verify is a non-clean
|
|
39
39
|
* verdict, never a silent pass.
|
|
40
|
+
*
|
|
41
|
+
* Server-side cert re-checks are not mirrored here. The engine's chain
|
|
42
|
+
* verification also reports `cert_missing`, `cert_actor_drift`,
|
|
43
|
+
* `cert_window_drift`, `cert_expired` and `agent_signature_invalid`, by
|
|
44
|
+
* comparing what an entry sealed in `predicate.on_behalf_of.cert` against the
|
|
45
|
+
* live `ephemeral_certs` row. Neither the export nor the dump carries that
|
|
46
|
+
* table, so an offline verifier cannot reproduce those comparisons, and it
|
|
47
|
+
* does not need to: it trusts only the signed bytes, which already fix the
|
|
48
|
+
* sealed cert id, thumbprint and expiry. The one cert-related check that can
|
|
49
|
+
* run offline is the agent signature, and only when the caller supplies the
|
|
50
|
+
* cert's public key (CHAIN_AGENT_SIGNATURE_INVALID below).
|
|
40
51
|
*/
|
|
41
52
|
/**
|
|
42
53
|
* Actionable next step per failure code. Kept terse and operational: what the
|
|
@@ -62,6 +73,8 @@ const SUGGESTIONS = {
|
|
|
62
73
|
CHAIN_ALG_MISMATCH: 'The algorithm in the signed protected header (label 1) is not one the entry\'s trusted verification key can produce, or the key registry\'s declared algorithm contradicts the key material itself. Tamper class: the header alg or the key registry was rewritten. Treat the entry as forged; obtain the verification keys out of band and re-run.',
|
|
63
74
|
CHAIN_UNSUPPORTED_ALGORITHM: 'The entry\'s trusted verification key commits to a signature algorithm that could not be computed, either because this verifier build does not implement it or because the host runtime refused it (an active OpenSSL FIPS provider carries no EdDSA). The chain is NOT verified, and this is NOT tamper evidence: the signature was never checked. Upgrade the verifier, or re-run on a host without the restriction. Never treat this result as a pass.',
|
|
64
75
|
CHAIN_SIGNING_KEY_DRIFT: 'The entry\'s signingKeyId column names a different key than the signature-covered kid in the COSE protected header. The column is a denormalized convenience and was rewritten after signing (possibly to point verification at another key). Trust the signed kid; treat the row as tampered.',
|
|
76
|
+
CHAIN_ACTOR_ATTRIBUTION_MISMATCH: 'The entry\'s actorId / actorOwnerId columns name a different actor than the signature-covered actor claim in the COSE protected header (CWT_Claims label 15, private label -65539). The columns are the projection a report displays and they were rewritten after signing, re-attributing the action to another actor. Trust the signed claim; treat the row as tampered and re-obtain the export from the operator.',
|
|
77
|
+
CHAIN_AGENT_SIGNATURE_INVALID: 'The agent signature sealed in predicate.on_behalf_of.agent_signature does not verify under the supplied key whose RFC 7638 thumbprint the entry itself names, or is sealed in a shape nothing can verify. The engine checks this signature at intake and the envelope signature says the engine wrote it, so this is not a caller mistake: treat the agent attribution of this entry as unproven and escalate to the operator.',
|
|
65
78
|
CHECKPOINT_ROW_MISSING: 'A signed checkpoint anchors a position that has no matching chain row. The chain was truncated below a checkpoint (out-of-band DELETE/TRUNCATE). The checkpoint is proof of the missing rows.',
|
|
66
79
|
CHECKPOINT_HASH_MISMATCH: 'A checkpoint\'s payloadHash does not match the chain row at its position. The chain diverged from what was checkpointed. Treat the chain as tampered.',
|
|
67
80
|
CHECKPOINT_SIGNATURE_INVALID: 'A checkpoint\'s COSE_Sign1 signature did not verify. The checkpoint was forged or altered. Re-run with out-of-band verification keys.',
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { suggestion } from './failures.js';
|
|
7
7
|
export type { FailureCode } from './failures.js';
|
|
8
|
-
export { buildKeyRegistry, verifyChain, } from './chain.js';
|
|
9
|
-
export type { KeySource, VerificationKey, KeyRegistry, NormalizedEntry, OptionalCheck, CheckApplicability, SignatureOutcome, ChainEntryResult, ChainResult, VerifyChainOptions, } from './chain.js';
|
|
8
|
+
export { buildAgentKeyRegistry, buildKeyRegistry, verifyChain, } from './chain.js';
|
|
9
|
+
export type { AgentKeyRegistry, KeySource, VerificationKey, KeyRegistry, NormalizedEntry, OptionalCheck, CheckApplicability, SignatureOutcome, ChainEntryResult, ChainResult, VerifyChainOptions, } from './chain.js';
|
|
10
10
|
export { verifyAuditExport } from './audit-export.js';
|
|
11
11
|
export type { AuditExportEntryInput, RecordAuditExportInput, SigningKeyWindow, VerifyExportOptions, OutOfBandKeyEntry, EntryVerificationResult, VerifyExportResult, } from './audit-export.js';
|
|
12
|
-
export { sha256Hex, sha256HexString, verifyEd25519Bytes, verifySignatureBytes, resolveKeyAlgorithm, algorithmByName, runtimeCanCompute, looksLikeEd25519Key, describeUnsupportedAlgorithm, decodeCoseSign1, verifyCoseSign1, extractChainClaim, extractKid, extractOnBehalfOfClaim, extractTraceparentClaim, decodePredicate, buildPredicateForRow, stripEnvelopeExtensions, deepEqual, merkleRoot, verifyInclusion, rfc9162LeafHash, rfc9162NodeHash, verifyRfc9162Inclusion, extractReceiptInclusionProof, verifyReceipt, } from './primitives.js';
|
|
13
|
-
export type { CoseSign1Parts, CoseVerifyOutcome, KeyAlgorithm, ChainClaim, ReceiptInclusionProof, ReceiptVerifyOutcome, } from './primitives.js';
|
|
12
|
+
export { sha256Hex, sha256HexString, verifyEd25519Bytes, verifySignatureBytes, resolveKeyAlgorithm, algorithmByName, runtimeCanCompute, looksLikeEd25519Key, describeUnsupportedAlgorithm, decodeCoseSign1, verifyCoseSign1, extractActorClaim, extractChainClaim, extractKid, extractOnBehalfOfClaim, extractTraceparentClaim, extractAgentSignatureClaim, ed25519JwkThumbprint, ed25519JwkToSpki, verifyAgentSignature, AGENT_SIGNATURE_CONTEXT, decodePredicate, buildPredicateForRow, stripEnvelopeExtensions, deepEqual, merkleRoot, verifyInclusion, rfc9162LeafHash, rfc9162NodeHash, verifyRfc9162Inclusion, extractReceiptInclusionProof, verifyReceipt, } from './primitives.js';
|
|
13
|
+
export type { CoseSign1Parts, CoseVerifyOutcome, KeyAlgorithm, ActorClaim, ChainClaim, AgentPublicKeyJwk, AgentSignatureClaim, AgentSignatureOutcome, ReceiptInclusionProof, ReceiptVerifyOutcome, } from './primitives.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* the MCP server, and @agledger/verify all build on this single body of logic.
|
|
5
5
|
*/
|
|
6
6
|
export { suggestion } from './failures.js';
|
|
7
|
-
export { buildKeyRegistry, verifyChain, } from './chain.js';
|
|
7
|
+
export { buildAgentKeyRegistry, buildKeyRegistry, verifyChain, } from './chain.js';
|
|
8
8
|
export { verifyAuditExport } from './audit-export.js';
|
|
9
|
-
export { sha256Hex, sha256HexString, verifyEd25519Bytes, verifySignatureBytes, resolveKeyAlgorithm, algorithmByName, runtimeCanCompute, looksLikeEd25519Key, describeUnsupportedAlgorithm, decodeCoseSign1, verifyCoseSign1, extractChainClaim, extractKid, extractOnBehalfOfClaim, extractTraceparentClaim, decodePredicate, buildPredicateForRow, stripEnvelopeExtensions, deepEqual, merkleRoot, verifyInclusion, rfc9162LeafHash, rfc9162NodeHash, verifyRfc9162Inclusion, extractReceiptInclusionProof, verifyReceipt, } from './primitives.js';
|
|
9
|
+
export { sha256Hex, sha256HexString, verifyEd25519Bytes, verifySignatureBytes, resolveKeyAlgorithm, algorithmByName, runtimeCanCompute, looksLikeEd25519Key, describeUnsupportedAlgorithm, decodeCoseSign1, verifyCoseSign1, extractActorClaim, extractChainClaim, extractKid, extractOnBehalfOfClaim, extractTraceparentClaim, extractAgentSignatureClaim, ed25519JwkThumbprint, ed25519JwkToSpki, verifyAgentSignature, AGENT_SIGNATURE_CONTEXT, decodePredicate, buildPredicateForRow, stripEnvelopeExtensions, deepEqual, merkleRoot, verifyInclusion, rfc9162LeafHash, rfc9162NodeHash, verifyRfc9162Inclusion, extractReceiptInclusionProof, verifyReceipt, } from './primitives.js';
|
package/dist/primitives.d.ts
CHANGED
|
@@ -191,6 +191,25 @@ export interface ChainClaim {
|
|
|
191
191
|
previous_hash: string | null;
|
|
192
192
|
}
|
|
193
193
|
export declare function extractChainClaim(protectedBstr: Uint8Array): ChainClaim | null;
|
|
194
|
+
/**
|
|
195
|
+
* Extract the actor identity claim (`-65539`) from a COSE_Sign1 protected
|
|
196
|
+
* header. It is nested inside CWT_Claims (RFC 9597, label 15) rather than
|
|
197
|
+
* sitting at the outer header level, because it IS an identity statement: the
|
|
198
|
+
* engine keeps the outer level to IANA-known labels plus chain mechanics.
|
|
199
|
+
*
|
|
200
|
+
* `key_id` and `owner_id` are UUIDs the engine encodes as 16-byte CBOR byte
|
|
201
|
+
* strings, returned here in canonical lowercase-hyphenated form so they
|
|
202
|
+
* compare directly against the export's `actorId` / `actorOwnerId` columns.
|
|
203
|
+
* Returns null when the claim is missing or malformed (engines older than the
|
|
204
|
+
* claim, or an envelope that will not decode) so the caller can skip rather
|
|
205
|
+
* than fail an entry that never carried it.
|
|
206
|
+
*/
|
|
207
|
+
export interface ActorClaim {
|
|
208
|
+
key_id: string;
|
|
209
|
+
role: string;
|
|
210
|
+
owner_id: string;
|
|
211
|
+
}
|
|
212
|
+
export declare function extractActorClaim(protectedBstr: Uint8Array): ActorClaim | null;
|
|
194
213
|
/**
|
|
195
214
|
* Extract the OIDC on-behalf-of context from a COSE_Sign1 payload bstr. The
|
|
196
215
|
* payload IS the in-toto v1 Statement; `predicate.on_behalf_of` carries the RFC
|
|
@@ -204,6 +223,71 @@ export declare function extractOnBehalfOfClaim(payloadBstr: Uint8Array): Record<
|
|
|
204
223
|
* partially-trusted string.
|
|
205
224
|
*/
|
|
206
225
|
export declare function extractTraceparentClaim(payloadBstr: Uint8Array): string | null;
|
|
226
|
+
/**
|
|
227
|
+
* Domain-separation prefix the engine applies before verifying an agent's
|
|
228
|
+
* `X-Agent-Signature` at intake: the agent signs the UTF-8 bytes of this
|
|
229
|
+
* prefix followed by the lowercase hex sha256 of the raw request body (the
|
|
230
|
+
* hex string, not the digest bytes). Distinct from the cert proof-of-possession
|
|
231
|
+
* prefix, so one signature cannot be replayed as the other.
|
|
232
|
+
*/
|
|
233
|
+
export declare const AGENT_SIGNATURE_CONTEXT = "agledger.agent.sig.v1\n";
|
|
234
|
+
/** An Ed25519 public key in JWK form, as sent in `publicKeyJwk` at cert exchange. */
|
|
235
|
+
export interface AgentPublicKeyJwk {
|
|
236
|
+
kty: 'OKP';
|
|
237
|
+
crv: 'Ed25519';
|
|
238
|
+
/** base64url of the raw 32-byte public key. */
|
|
239
|
+
x: string;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The agent-signature evidence the engine sealed into a chain entry, read from
|
|
243
|
+
* the signed payload. Fields are left `unknown` where the verifier must check
|
|
244
|
+
* their shape itself: a sealed value the engine never writes is a finding, not
|
|
245
|
+
* something to coerce.
|
|
246
|
+
*/
|
|
247
|
+
export interface AgentSignatureClaim {
|
|
248
|
+
/** `on_behalf_of.validated === true`: the engine vouched for the identity. */
|
|
249
|
+
validated: boolean;
|
|
250
|
+
/** `on_behalf_of.cert.id`, when a cert is sealed beside the signature. */
|
|
251
|
+
certId: string | null;
|
|
252
|
+
/** `on_behalf_of.cert.thumbprint`: `sha256:<hex>` RFC 7638 thumbprint of the cert's bound key. */
|
|
253
|
+
certThumbprint: string | null;
|
|
254
|
+
alg: unknown;
|
|
255
|
+
signature: unknown;
|
|
256
|
+
contentHash: unknown;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Read `predicate.on_behalf_of.agent_signature` and the cert beside it from a
|
|
260
|
+
* COSE_Sign1 payload bstr. Returns null when the entry carries no agent
|
|
261
|
+
* signature.
|
|
262
|
+
*/
|
|
263
|
+
export declare function extractAgentSignatureClaim(payloadBstr: Uint8Array): AgentSignatureClaim | null;
|
|
264
|
+
/**
|
|
265
|
+
* RFC 7638 thumbprint of an Ed25519 JWK in the engine's `sha256:<hex>` form,
|
|
266
|
+
* or null when the value is not an Ed25519 public-key JWK. The members are
|
|
267
|
+
* hashed in the RFC's lexicographic order (`crv`, `kty`, `x`), which is what
|
|
268
|
+
* the engine's thumbprint function produces for an OKP key.
|
|
269
|
+
*/
|
|
270
|
+
export declare function ed25519JwkThumbprint(jwk: unknown): string | null;
|
|
271
|
+
/** SPKI DER (base64) for an Ed25519 JWK, or null when it is not one. */
|
|
272
|
+
export declare function ed25519JwkToSpki(jwk: unknown): string | null;
|
|
273
|
+
export type AgentSignatureOutcome = 'ok' | 'invalid' | 'malformed' | 'unsupported';
|
|
274
|
+
/**
|
|
275
|
+
* Verify a sealed agent signature against the cert's Ed25519 key.
|
|
276
|
+
*
|
|
277
|
+
* - `ok`: the signature verifies over `AGENT_SIGNATURE_CONTEXT + <hex>`.
|
|
278
|
+
* - `invalid`: well formed, does not verify under this key.
|
|
279
|
+
* - `malformed`: a shape the engine never writes (alg other than EdDSA, a
|
|
280
|
+
* content hash not `sha256:<hex64>`, a signature that is not 64 bytes of
|
|
281
|
+
* standard base64). Nothing can verify it, which the engine also treats as
|
|
282
|
+
* a break.
|
|
283
|
+
* - `unsupported`: this host cannot compute Ed25519 (an active OpenSSL FIPS
|
|
284
|
+
* provider). NOT verified and NOT tamper evidence.
|
|
285
|
+
*
|
|
286
|
+
* What it proves: the holder of the cert's private key signed that content
|
|
287
|
+
* hash. It does not re-hash a request body; the export carries the hash, not
|
|
288
|
+
* the body.
|
|
289
|
+
*/
|
|
290
|
+
export declare function verifyAgentSignature(spkiBase64: string, claim: Pick<AgentSignatureClaim, 'alg' | 'signature' | 'contentHash'>): AgentSignatureOutcome;
|
|
207
291
|
/**
|
|
208
292
|
* Decode the predicate object from a COSE_Sign1 payload bstr. The payload IS
|
|
209
293
|
* the in-toto v1 Statement; the predicate body lives at `payload.predicate`.
|
|
@@ -239,6 +323,27 @@ export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
|
239
323
|
* signature and the OIDC-actor cross-check.
|
|
240
324
|
*/
|
|
241
325
|
export declare function stripEnvelopeExtensions(predicate: Record<string, unknown>): Record<string, unknown>;
|
|
326
|
+
/**
|
|
327
|
+
* Whether the envelope extensions a row's payload carries are the ones the
|
|
328
|
+
* entry signed. When a writer puts `on_behalf_of` (an object) or
|
|
329
|
+
* `traceparent` (a W3C v00 string; any other value is dropped) at the top
|
|
330
|
+
* level of the row payload, the engine lifts it into `predicate.on_behalf_of`
|
|
331
|
+
* / `predicate.traceparent`, so a row copy must equal the signed value. The
|
|
332
|
+
* row copy is what a reader of an export or dump sees, and
|
|
333
|
+
* {@link stripEnvelopeExtensions} takes both sides out of the predicate
|
|
334
|
+
* comparison, so without this check a rewritten or added row copy would still
|
|
335
|
+
* verify.
|
|
336
|
+
*
|
|
337
|
+
* Anything else under those keys is ignored, as the engine ignores it: it
|
|
338
|
+
* lifts only an object `on_behalf_of` and a v00 `traceparent`, so a genuine
|
|
339
|
+
* older row holding another shape signed nothing for it.
|
|
340
|
+
*
|
|
341
|
+
* A row without them is not a mismatch: the engine also signs an
|
|
342
|
+
* `on_behalf_of` built from the request's authentication rather than from the
|
|
343
|
+
* payload, and that one never reaches the row payload. Its identity is held to
|
|
344
|
+
* the row's actor columns by the OIDC-actor check instead.
|
|
345
|
+
*/
|
|
346
|
+
export declare function envelopeExtensionsMatch(rowPayload: Record<string, unknown>, signedPredicate: Record<string, unknown>): boolean;
|
|
242
347
|
/** RFC 9162 §2.1.1 leaf hash: SHA-256(0x00 || d). */
|
|
243
348
|
export declare function rfc9162LeafHash(leafData: Uint8Array): Uint8Array;
|
|
244
349
|
/** RFC 9162 §2.1.1 internal-node hash: SHA-256(0x01 || left || right). */
|
package/dist/primitives.js
CHANGED
|
@@ -505,6 +505,44 @@ export function extractChainClaim(protectedBstr) {
|
|
|
505
505
|
return null;
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
|
+
const COSE_HEADER_CWT_CLAIMS = 15;
|
|
509
|
+
const AGLEDGER_LABEL_ACTOR = -65539;
|
|
510
|
+
const ACTOR_SUBLABEL_KEY_ID = 1;
|
|
511
|
+
const ACTOR_SUBLABEL_ROLE = 2;
|
|
512
|
+
const ACTOR_SUBLABEL_OWNER_ID = 3;
|
|
513
|
+
/** 16 raw bytes to canonical lowercase-hyphenated UUID; null for any other length. */
|
|
514
|
+
function bytesToUuid(bytes) {
|
|
515
|
+
if (bytes.length !== 16)
|
|
516
|
+
return null;
|
|
517
|
+
const hex = Buffer.from(bytes).toString('hex');
|
|
518
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
519
|
+
}
|
|
520
|
+
export function extractActorClaim(protectedBstr) {
|
|
521
|
+
try {
|
|
522
|
+
const ph = cborDecode(protectedBstr, { useMaps: true });
|
|
523
|
+
const cwt = ph.get(COSE_HEADER_CWT_CLAIMS);
|
|
524
|
+
if (!(cwt instanceof Map))
|
|
525
|
+
return null;
|
|
526
|
+
const actor = cwt.get(AGLEDGER_LABEL_ACTOR);
|
|
527
|
+
if (!(actor instanceof Map))
|
|
528
|
+
return null;
|
|
529
|
+
const keyIdBytes = actor.get(ACTOR_SUBLABEL_KEY_ID);
|
|
530
|
+
const role = actor.get(ACTOR_SUBLABEL_ROLE);
|
|
531
|
+
const ownerIdBytes = actor.get(ACTOR_SUBLABEL_OWNER_ID);
|
|
532
|
+
if (!(keyIdBytes instanceof Uint8Array) || !(ownerIdBytes instanceof Uint8Array))
|
|
533
|
+
return null;
|
|
534
|
+
if (typeof role !== 'string')
|
|
535
|
+
return null;
|
|
536
|
+
const keyId = bytesToUuid(keyIdBytes);
|
|
537
|
+
const ownerId = bytesToUuid(ownerIdBytes);
|
|
538
|
+
if (keyId === null || ownerId === null)
|
|
539
|
+
return null;
|
|
540
|
+
return { key_id: keyId, role, owner_id: ownerId };
|
|
541
|
+
}
|
|
542
|
+
catch {
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
508
546
|
// --- Optional envelope extensions (OIDC on-behalf-of, traceparent) ---
|
|
509
547
|
const TRACEPARENT_REGEX = /^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/;
|
|
510
548
|
/**
|
|
@@ -552,6 +590,104 @@ export function extractTraceparentClaim(payloadBstr) {
|
|
|
552
590
|
return null;
|
|
553
591
|
}
|
|
554
592
|
}
|
|
593
|
+
// --- Agent signature (predicate.on_behalf_of.agent_signature) ---
|
|
594
|
+
/**
|
|
595
|
+
* Domain-separation prefix the engine applies before verifying an agent's
|
|
596
|
+
* `X-Agent-Signature` at intake: the agent signs the UTF-8 bytes of this
|
|
597
|
+
* prefix followed by the lowercase hex sha256 of the raw request body (the
|
|
598
|
+
* hex string, not the digest bytes). Distinct from the cert proof-of-possession
|
|
599
|
+
* prefix, so one signature cannot be replayed as the other.
|
|
600
|
+
*/
|
|
601
|
+
export const AGENT_SIGNATURE_CONTEXT = 'agledger.agent.sig.v1\n';
|
|
602
|
+
/**
|
|
603
|
+
* Read `predicate.on_behalf_of.agent_signature` and the cert beside it from a
|
|
604
|
+
* COSE_Sign1 payload bstr. Returns null when the entry carries no agent
|
|
605
|
+
* signature.
|
|
606
|
+
*/
|
|
607
|
+
export function extractAgentSignatureClaim(payloadBstr) {
|
|
608
|
+
const obo = extractOnBehalfOfClaim(payloadBstr);
|
|
609
|
+
if (obo === null)
|
|
610
|
+
return null;
|
|
611
|
+
const sig = obo['agent_signature'];
|
|
612
|
+
if (sig === undefined || sig === null)
|
|
613
|
+
return null;
|
|
614
|
+
const sigObj = typeof sig === 'object' && !Array.isArray(sig) ? sig : {};
|
|
615
|
+
const cert = obo['cert'];
|
|
616
|
+
const certObj = cert !== null && typeof cert === 'object' && !Array.isArray(cert)
|
|
617
|
+
? cert
|
|
618
|
+
: {};
|
|
619
|
+
return {
|
|
620
|
+
validated: obo['validated'] === true,
|
|
621
|
+
certId: typeof certObj['id'] === 'string' ? certObj['id'] : null,
|
|
622
|
+
certThumbprint: typeof certObj['thumbprint'] === 'string' ? certObj['thumbprint'] : null,
|
|
623
|
+
alg: sigObj['alg'],
|
|
624
|
+
signature: sigObj['signature'],
|
|
625
|
+
contentHash: sigObj['content_hash'],
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
const BASE64URL_32_BYTES = /^[A-Za-z0-9_-]{43}$/;
|
|
629
|
+
/**
|
|
630
|
+
* RFC 7638 thumbprint of an Ed25519 JWK in the engine's `sha256:<hex>` form,
|
|
631
|
+
* or null when the value is not an Ed25519 public-key JWK. The members are
|
|
632
|
+
* hashed in the RFC's lexicographic order (`crv`, `kty`, `x`), which is what
|
|
633
|
+
* the engine's thumbprint function produces for an OKP key.
|
|
634
|
+
*/
|
|
635
|
+
export function ed25519JwkThumbprint(jwk) {
|
|
636
|
+
if (jwk === null || typeof jwk !== 'object' || Array.isArray(jwk))
|
|
637
|
+
return null;
|
|
638
|
+
const { kty, crv, x } = jwk;
|
|
639
|
+
if (kty !== 'OKP' || crv !== 'Ed25519' || typeof x !== 'string' || !BASE64URL_32_BYTES.test(x)) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
if (Buffer.from(x, 'base64url').length !== 32)
|
|
643
|
+
return null;
|
|
644
|
+
return `sha256:${sha256HexString(JSON.stringify({ crv, kty, x }))}`;
|
|
645
|
+
}
|
|
646
|
+
/** SPKI DER (base64) for an Ed25519 JWK, or null when it is not one. */
|
|
647
|
+
export function ed25519JwkToSpki(jwk) {
|
|
648
|
+
if (ed25519JwkThumbprint(jwk) === null)
|
|
649
|
+
return null;
|
|
650
|
+
const raw = Buffer.from(jwk.x, 'base64url');
|
|
651
|
+
return Buffer.concat([ED25519_SPKI_PREFIX, raw]).toString('base64');
|
|
652
|
+
}
|
|
653
|
+
const CONTENT_HASH_PATTERN = /^sha256:([0-9a-f]{64})$/;
|
|
654
|
+
const STANDARD_BASE64_64_BYTES = /^[A-Za-z0-9+/]{86}(==)?$/;
|
|
655
|
+
/**
|
|
656
|
+
* Verify a sealed agent signature against the cert's Ed25519 key.
|
|
657
|
+
*
|
|
658
|
+
* - `ok`: the signature verifies over `AGENT_SIGNATURE_CONTEXT + <hex>`.
|
|
659
|
+
* - `invalid`: well formed, does not verify under this key.
|
|
660
|
+
* - `malformed`: a shape the engine never writes (alg other than EdDSA, a
|
|
661
|
+
* content hash not `sha256:<hex64>`, a signature that is not 64 bytes of
|
|
662
|
+
* standard base64). Nothing can verify it, which the engine also treats as
|
|
663
|
+
* a break.
|
|
664
|
+
* - `unsupported`: this host cannot compute Ed25519 (an active OpenSSL FIPS
|
|
665
|
+
* provider). NOT verified and NOT tamper evidence.
|
|
666
|
+
*
|
|
667
|
+
* What it proves: the holder of the cert's private key signed that content
|
|
668
|
+
* hash. It does not re-hash a request body; the export carries the hash, not
|
|
669
|
+
* the body.
|
|
670
|
+
*/
|
|
671
|
+
export function verifyAgentSignature(spkiBase64, claim) {
|
|
672
|
+
if (claim.alg !== 'EdDSA')
|
|
673
|
+
return 'malformed';
|
|
674
|
+
if (typeof claim.contentHash !== 'string')
|
|
675
|
+
return 'malformed';
|
|
676
|
+
const hashMatch = CONTENT_HASH_PATTERN.exec(claim.contentHash);
|
|
677
|
+
if (!hashMatch)
|
|
678
|
+
return 'malformed';
|
|
679
|
+
if (typeof claim.signature !== 'string' || !STANDARD_BASE64_64_BYTES.test(claim.signature)) {
|
|
680
|
+
return 'malformed';
|
|
681
|
+
}
|
|
682
|
+
const sigBytes = Buffer.from(claim.signature, 'base64');
|
|
683
|
+
if (sigBytes.length !== 64)
|
|
684
|
+
return 'malformed';
|
|
685
|
+
const ed25519 = algorithmByName('Ed25519');
|
|
686
|
+
if (ed25519 === null || !runtimeCanCompute(ed25519))
|
|
687
|
+
return 'unsupported';
|
|
688
|
+
const input = Buffer.from(`${AGENT_SIGNATURE_CONTEXT}${hashMatch[1]}`, 'utf8');
|
|
689
|
+
return verifyEd25519Bytes(spkiBase64, input, sigBytes) ? 'ok' : 'invalid';
|
|
690
|
+
}
|
|
555
691
|
// --- in-toto v1 predicate extraction + binding-integrity projection ---
|
|
556
692
|
/**
|
|
557
693
|
* Decode the predicate object from a COSE_Sign1 payload bstr. The payload IS
|
|
@@ -732,6 +868,38 @@ export function stripEnvelopeExtensions(predicate) {
|
|
|
732
868
|
}
|
|
733
869
|
return out;
|
|
734
870
|
}
|
|
871
|
+
/**
|
|
872
|
+
* Whether the envelope extensions a row's payload carries are the ones the
|
|
873
|
+
* entry signed. When a writer puts `on_behalf_of` (an object) or
|
|
874
|
+
* `traceparent` (a W3C v00 string; any other value is dropped) at the top
|
|
875
|
+
* level of the row payload, the engine lifts it into `predicate.on_behalf_of`
|
|
876
|
+
* / `predicate.traceparent`, so a row copy must equal the signed value. The
|
|
877
|
+
* row copy is what a reader of an export or dump sees, and
|
|
878
|
+
* {@link stripEnvelopeExtensions} takes both sides out of the predicate
|
|
879
|
+
* comparison, so without this check a rewritten or added row copy would still
|
|
880
|
+
* verify.
|
|
881
|
+
*
|
|
882
|
+
* Anything else under those keys is ignored, as the engine ignores it: it
|
|
883
|
+
* lifts only an object `on_behalf_of` and a v00 `traceparent`, so a genuine
|
|
884
|
+
* older row holding another shape signed nothing for it.
|
|
885
|
+
*
|
|
886
|
+
* A row without them is not a mismatch: the engine also signs an
|
|
887
|
+
* `on_behalf_of` built from the request's authentication rather than from the
|
|
888
|
+
* payload, and that one never reaches the row payload. Its identity is held to
|
|
889
|
+
* the row's actor columns by the OIDC-actor check instead.
|
|
890
|
+
*/
|
|
891
|
+
export function envelopeExtensionsMatch(rowPayload, signedPredicate) {
|
|
892
|
+
const obo = rowPayload['on_behalf_of'];
|
|
893
|
+
if (obo !== null && typeof obo === 'object' && !Array.isArray(obo)) {
|
|
894
|
+
if (!deepEqual(obo, signedPredicate['on_behalf_of']))
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
const tp = rowPayload['traceparent'];
|
|
898
|
+
if (typeof tp === 'string' && TRACEPARENT_REGEX.test(tp) && tp !== signedPredicate['traceparent']) {
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
735
903
|
// --- RFC 9162 Merkle (SCITT Receipt verifiable data structure) ---
|
|
736
904
|
const LEAF_PREFIX = new Uint8Array([0x00]);
|
|
737
905
|
const NODE_PREFIX = new Uint8Array([0x01]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agledger/verify-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Shared offline verification core for AGLedger audit chains: COSE_Sign1 (RFC 9052) decode/verify, Ed25519 + ES256, hash-chain walk, Merkle proofs, and the canonical failure taxonomy. One dependency (cborg); no network. The single source of truth the SDK, CLI, MCP server, and @agledger/verify all build on.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"prepublishOnly": "npm run build && npm run lint:pkg"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"cborg": "6.1.
|
|
37
|
+
"cborg": "6.1.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@arethetypeswrong/cli": "^0.18.3",
|
|
41
41
|
"@types/node": "^24.13.3",
|
|
42
42
|
"publint": "^0.3.22",
|
|
43
43
|
"typescript": "^7.0.2",
|
|
44
|
-
"vitest": "^
|
|
44
|
+
"vitest": "^5.0.0"
|
|
45
45
|
},
|
|
46
46
|
"repository": {
|
|
47
47
|
"type": "git",
|