@w-r-l/verify 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -8
- package/lib/format.js +14 -6
- package/lib/key-resolver.js +29 -2
- package/lib/verify.js +29 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Verify the cryptographic integrity of [WRL](https://github.com/benpeter/web-resource-ledger) WACZ capture bundles -- offline, zero-install.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
6
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## What it checks
|
|
@@ -20,19 +20,31 @@ Exit code `0` means all applicable checks passed. Exit code `1` means one or mor
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
-
### Remote capture
|
|
23
|
+
### Remote capture with share token
|
|
24
|
+
|
|
25
|
+
Capture retrieval requires a share token. Use the share URL provided by the tenant:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx @w-r-l/verify "https://api.webresourceledger.com/v1/captures/cap_abc123...?token=wrl_share_..."
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The `?token=` parameter is automatically forwarded to the artifact download. The signing key is fetched from the server automatically.
|
|
32
|
+
|
|
33
|
+
### Remote capture via server-side verify endpoint (no token needed)
|
|
34
|
+
|
|
35
|
+
The `/v1/verify/` endpoint is public and does not require a token. Use it when you don't have a share URL:
|
|
24
36
|
|
|
25
37
|
```bash
|
|
26
|
-
npx @w-r-l/verify https://
|
|
38
|
+
npx @w-r-l/verify https://api.webresourceledger.com/v1/verify/cap_abc123def456...
|
|
27
39
|
```
|
|
28
40
|
|
|
29
|
-
|
|
41
|
+
Note: this uses server-side verification rather than downloading and verifying the WACZ locally.
|
|
30
42
|
|
|
31
43
|
### Local file
|
|
32
44
|
|
|
33
45
|
```bash
|
|
34
46
|
# Fetch the key from the operator
|
|
35
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
47
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com
|
|
36
48
|
|
|
37
49
|
# Or provide the key directly
|
|
38
50
|
npx @w-r-l/verify capture.wacz --key <base64-encoded-public-key>
|
|
@@ -54,7 +66,7 @@ Uses the key embedded in the WACZ. This proves the archive is internally consist
|
|
|
54
66
|
### JSON output
|
|
55
67
|
|
|
56
68
|
```bash
|
|
57
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
69
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com --json
|
|
58
70
|
```
|
|
59
71
|
|
|
60
72
|
Outputs a single JSON object to stdout. All human messages go to stderr in JSON mode.
|
|
@@ -79,7 +91,7 @@ Outputs a single JSON object to stdout. All human messages go to stderr in JSON
|
|
|
79
91
|
"keyResolution": {
|
|
80
92
|
"keyId": "a1b2c3d4",
|
|
81
93
|
"source": "origin",
|
|
82
|
-
"origin": "https://
|
|
94
|
+
"origin": "https://api.webresourceledger.com",
|
|
83
95
|
"endpoint": "/.well-known/signing-keys"
|
|
84
96
|
},
|
|
85
97
|
"source": "capture.wacz",
|
|
@@ -96,7 +108,7 @@ On errors, `verified` is `null` (not `false`) and an `error` field is present:
|
|
|
96
108
|
### Additional trusted roots
|
|
97
109
|
|
|
98
110
|
```bash
|
|
99
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
111
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com --trust-root /path/to/extra-root.pem
|
|
100
112
|
```
|
|
101
113
|
|
|
102
114
|
The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to add PEM certificates for other timestamp authorities. Can be specified multiple times.
|
|
@@ -121,6 +133,30 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
|
|
|
121
133
|
|
|
122
134
|
Node.js 20 or later.
|
|
123
135
|
|
|
136
|
+
## Releasing
|
|
137
|
+
|
|
138
|
+
Releases are published to npm automatically when a `verify/v*` tag is pushed.
|
|
139
|
+
|
|
140
|
+
**Steps:**
|
|
141
|
+
|
|
142
|
+
1. Generate the changelog (review and edit before proceeding):
|
|
143
|
+
```bash
|
|
144
|
+
./scripts/changelog-verify.sh patch # or minor, major
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
2. Bump version, commit, and create tag:
|
|
148
|
+
```bash
|
|
149
|
+
cd packages/verify && npm version patch -m "chore(verify): release %s"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
3. Push the commit and tag:
|
|
153
|
+
```bash
|
|
154
|
+
git push origin main --follow-tags
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The CI workflow runs tests and publishes to npm with provenance attestation.
|
|
158
|
+
If the version already exists on npm, the publish step exits cleanly.
|
|
159
|
+
|
|
124
160
|
## License
|
|
125
161
|
|
|
126
162
|
[Apache 2.0](../../LICENSE)
|
package/lib/format.js
CHANGED
|
@@ -43,11 +43,12 @@ function bold(text, color) { return color ? `${ANSI_BOLD}${text}${ANSI_RESET}`
|
|
|
43
43
|
// ---------------------------------------------------------------------------
|
|
44
44
|
|
|
45
45
|
const CHECK_LABELS = {
|
|
46
|
-
artifactHashes:
|
|
47
|
-
bundleHash:
|
|
48
|
-
signature:
|
|
49
|
-
timestamp:
|
|
50
|
-
|
|
46
|
+
artifactHashes: 'File integrity',
|
|
47
|
+
bundleHash: 'Bundle integrity',
|
|
48
|
+
signature: 'Digital signature',
|
|
49
|
+
timestamp: 'Timestamp imprint',
|
|
50
|
+
qualifiedTimestamp: 'Qualified timestamp',
|
|
51
|
+
timestampChain: 'Timestamp chain',
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
// Fixed display order
|
|
@@ -56,6 +57,7 @@ const CHECK_ORDER = [
|
|
|
56
57
|
'bundleHash',
|
|
57
58
|
'signature',
|
|
58
59
|
'timestamp',
|
|
60
|
+
'qualifiedTimestamp',
|
|
59
61
|
'timestampChain',
|
|
60
62
|
];
|
|
61
63
|
|
|
@@ -84,7 +86,8 @@ function checkLabel(name) {
|
|
|
84
86
|
* signature?: string,
|
|
85
87
|
* publicKey?: string,
|
|
86
88
|
* signedAt?: string,
|
|
87
|
-
* timestamp?: { genTime: string, tsa: string }
|
|
89
|
+
* timestamp?: { genTime: string, tsa: string },
|
|
90
|
+
* qualifiedTimestamp?: { genTime: string, tsa: string }
|
|
88
91
|
* },
|
|
89
92
|
* keyResolution?: {
|
|
90
93
|
* keyId: string,
|
|
@@ -150,6 +153,11 @@ export function formatHuman(result, opts = {}) {
|
|
|
150
153
|
process.stdout.write(` TSA ${tsa}\n`);
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
const qtsa = result.capture?.qualifiedTimestamp?.tsa;
|
|
157
|
+
if (qtsa) {
|
|
158
|
+
process.stdout.write(` QTSA ${qtsa} (eIDAS)\n`);
|
|
159
|
+
}
|
|
160
|
+
|
|
153
161
|
const kr = result.keyResolution;
|
|
154
162
|
if (kr?.keyId) {
|
|
155
163
|
let keySource;
|
package/lib/key-resolver.js
CHANGED
|
@@ -36,6 +36,21 @@ export function isWrlCaptureUrl(input) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Extracts the share token from a WRL capture URL, if present.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} urlStr
|
|
43
|
+
* @returns {string|null}
|
|
44
|
+
*/
|
|
45
|
+
export function shareTokenFromUrl(urlStr) {
|
|
46
|
+
try {
|
|
47
|
+
const url = new URL(urlStr);
|
|
48
|
+
return url.searchParams.get('token');
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
/**
|
|
40
55
|
* Extracts the origin (scheme + host + port) from a URL string.
|
|
41
56
|
*
|
|
@@ -86,6 +101,15 @@ async function fetchBytes(url, { timeoutMs = KEY_FETCH_TIMEOUT_MS, maxBytes = MA
|
|
|
86
101
|
clearTimeout(timer);
|
|
87
102
|
|
|
88
103
|
if (!response.ok) {
|
|
104
|
+
if (response.status === 401) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`HTTP 401 fetching ${url}\n\n` +
|
|
107
|
+
`This capture requires a share token. Use a share URL with ?token=:\n` +
|
|
108
|
+
` npx @w-r-l/verify "https://wrl.../v1/captures/cap_abc?token=wrl_share_..."\n\n` +
|
|
109
|
+
`Or verify via the server-side endpoint (no token needed):\n` +
|
|
110
|
+
` npx @w-r-l/verify "https://wrl.../v1/verify/cap_abc"`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
89
113
|
throw new Error(`HTTP ${response.status} fetching ${url}`);
|
|
90
114
|
}
|
|
91
115
|
|
|
@@ -127,7 +151,10 @@ async function fetchBytes(url, { timeoutMs = KEY_FETCH_TIMEOUT_MS, maxBytes = MA
|
|
|
127
151
|
export async function fetchWaczFromCaptureUrl(captureUrl) {
|
|
128
152
|
const origin = originFromUrl(captureUrl);
|
|
129
153
|
const captureId = captureIdFromUrl(captureUrl);
|
|
130
|
-
const
|
|
154
|
+
const token = shareTokenFromUrl(captureUrl);
|
|
155
|
+
|
|
156
|
+
let waczUrl = `${origin}/v1/captures/${captureId}/artifacts/wacz`;
|
|
157
|
+
if (token) waczUrl += `?token=${encodeURIComponent(token)}`;
|
|
131
158
|
|
|
132
159
|
process.stderr.write(`Fetching capture from ${waczUrl}\n`);
|
|
133
160
|
|
|
@@ -407,7 +434,7 @@ export async function resolveKey(options) {
|
|
|
407
434
|
`insecure -- an attacker who modifies the capture can also replace the\n` +
|
|
408
435
|
`embedded key.\n\n` +
|
|
409
436
|
`Specify one of:\n` +
|
|
410
|
-
` --origin https://
|
|
437
|
+
` --origin https://api.webresourceledger.com Fetch key from the operator\n` +
|
|
411
438
|
` --key <base64> Provide key directly\n` +
|
|
412
439
|
` --key-file <path> Read key from file\n\n` +
|
|
413
440
|
`The embedded keyId is: ${embeddedKeyId}`
|
package/lib/verify.js
CHANGED
|
@@ -233,7 +233,32 @@ export async function verifyWacz(waczBytes, publicKeyBytes, options = {}) {
|
|
|
233
233
|
// For v0.1.0: no timestamp check at all (3 checks, not 4)
|
|
234
234
|
|
|
235
235
|
// ---------------------------------------------------------------------------
|
|
236
|
-
// Check 5:
|
|
236
|
+
// Check 5: qualifiedTimestamp (v0.2.0 only, when present)
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
let qualifiedTimestampData = null;
|
|
239
|
+
if (version === '0.2.0') {
|
|
240
|
+
const sigs = signedData?.signatures ?? [];
|
|
241
|
+
const qtsEntry = sigs.find(s => s.type === 'rfc3161_qualified');
|
|
242
|
+
|
|
243
|
+
if (!qtsEntry) {
|
|
244
|
+
// Absent = not requested. Do NOT push a skip check -- simply omit.
|
|
245
|
+
} else {
|
|
246
|
+
try {
|
|
247
|
+
const result = verifyTimestamp(qtsEntry.token, signedData.hash);
|
|
248
|
+
if (result.valid) {
|
|
249
|
+
checks.push({ name: 'qualifiedTimestamp', status: 'pass' });
|
|
250
|
+
qualifiedTimestampData = { genTime: result.genTime, tsa: qtsEntry.tsa };
|
|
251
|
+
} else {
|
|
252
|
+
checks.push({ name: 'qualifiedTimestamp', status: 'fail', detail: 'Qualified timestamp structurally invalid' });
|
|
253
|
+
}
|
|
254
|
+
} catch {
|
|
255
|
+
checks.push({ name: 'qualifiedTimestamp', status: 'fail', detail: 'Qualified timestamp structurally invalid' });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// Check 6: timestampChain (CLI only -- CMS certificate chain validation)
|
|
237
262
|
// ---------------------------------------------------------------------------
|
|
238
263
|
if (version === '0.2.0' && tsToken && trustedRoots && trustedRoots.length > 0 && doCmsChain) {
|
|
239
264
|
try {
|
|
@@ -279,6 +304,9 @@ export async function verifyWacz(waczBytes, publicKeyBytes, options = {}) {
|
|
|
279
304
|
if (timestampData) {
|
|
280
305
|
result.capture.timestamp = timestampData;
|
|
281
306
|
}
|
|
307
|
+
if (qualifiedTimestampData) {
|
|
308
|
+
result.capture.qualifiedTimestamp = qualifiedTimestampData;
|
|
309
|
+
}
|
|
282
310
|
}
|
|
283
311
|
|
|
284
312
|
return result;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w-r-l/verify",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Verify cryptographic integrity of WRL WACZ web capture bundles",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Ben Peter <bp@ben-peter.com>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/benpeter/web-resource-ledger.git",
|
|
9
|
+
"url": "git+https://github.com/benpeter/web-resource-ledger.git",
|
|
10
10
|
"directory": "packages/verify"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/benpeter/web-resource-ledger/tree/main/packages/verify#readme",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "node --test 'test/**/*.test.js'"
|
|
27
27
|
},
|
|
28
28
|
"bin": {
|
|
29
|
-
"wrl-verify": "
|
|
29
|
+
"wrl-verify": "bin/wrl-verify.js"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=20.0.0"
|