@w-r-l/verify 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,25 +20,25 @@ 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 with share token
24
-
25
- Capture retrieval requires a share token. Use the share URL provided by the tenant:
23
+ ### Remote capture
26
24
 
27
25
  ```bash
28
- npx @w-r-l/verify "https://api.webresourceledger.com/v1/captures/cap_abc123...?token=wrl_share_..."
26
+ npx @w-r-l/verify "https://api.webresourceledger.com/v1/captures/cap_abc123def456..."
29
27
  ```
30
28
 
31
- The `?token=` parameter is automatically forwarded to the artifact download. The signing key is fetched from the server automatically.
29
+ The signing key is fetched from the server automatically. Individual captures are publicly accessible -- no authentication or tokens are needed.
32
30
 
33
- ### Remote capture via server-side verify endpoint (no token needed)
31
+ ### Remote capture via server-side verify endpoint
34
32
 
35
- The `/v1/verify/` endpoint is public and does not require a token. Use it when you don't have a share URL:
33
+ The `/v1/verify/cap_<id>` endpoint returns a server-side verification result as JSON or HTML, without downloading the WACZ locally. Use it when you want a lightweight check or don't need local verification:
36
34
 
37
35
  ```bash
38
36
  npx @w-r-l/verify https://api.webresourceledger.com/v1/verify/cap_abc123def456...
39
37
  ```
40
38
 
41
- Note: this uses server-side verification rather than downloading and verifying the WACZ locally.
39
+ The distinction:
40
+ - `/v1/captures/cap_<id>` -- CLI downloads the WACZ and verifies it locally (cryptographic proof)
41
+ - `/v1/verify/cap_<id>` -- server returns its own verification result (JSON or HTML)
42
42
 
43
43
  ### Local file
44
44
 
@@ -63,6 +63,27 @@ npx @w-r-l/verify capture.wacz --trust-embedded
63
63
 
64
64
  Uses the key embedded in the WACZ. This proves the archive is internally consistent, but not that it came from a trusted operator.
65
65
 
66
+ ### Legal report
67
+
68
+ ```bash
69
+ npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com --legal
70
+ ```
71
+
72
+ Produces a structured plain-text report designed for use in legal proceedings or formal documentation. No ANSI color codes are written -- the output is safe to redirect to a file or attach as a document.
73
+
74
+ The report is organized into seven sections: a plain-language summary, a description of the subject (captured URL, capture time), per-check explanations in non-technical terms, a chain of custody narrative, applicable legal standards (FRE 901(b)(9) and eIDAS Art. 41), a methodology description, and full technical details with untruncated cryptographic values. The format version is WRL-LEGAL-1.0, which appears in the report header.
75
+
76
+ Standard and qualified timestamps are reported separately when both are present. A standard RFC 3161 timestamp (DigiCert) is included for every capture. An eIDAS-qualified timestamp appears only when the capturing account has opted into a qualified Trust Service Provider; the report identifies which tier applies and what legal weight it carries.
77
+
78
+ ```bash
79
+ # Machine-readable version of the same report
80
+ npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com --legal --json
81
+ ```
82
+
83
+ `--legal --json` produces a JSON object with the same seven sections as structured fields. All cryptographic values are untruncated in both output modes.
84
+
85
+ For a full explanation of the legal context and frameworks the report references, see the [Legal Evidence guide](https://webresourceledger.com/legal-evidence/).
86
+
66
87
  ### JSON output
67
88
 
68
89
  ```bash
@@ -121,6 +142,7 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
121
142
  --key-file <path> Read public key from file
122
143
  --trust-embedded Use the embedded key (insecure)
123
144
  --trust-root <path> Additional trusted root certificate (PEM)
145
+ --legal Produce a structured plain-text legal report (WRL-LEGAL-1.0)
124
146
  --json Output machine-readable JSON to stdout
125
147
  --no-color Disable colored output
126
148
  -h, --help Show this help message
@@ -129,6 +151,8 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
129
151
 
130
152
  `--origin`, `--key`, `--key-file`, and `--trust-embedded` are mutually exclusive.
131
153
 
154
+ `--legal` can be combined with `--json` for a machine-readable version of the same report. `--legal` implies `--no-color` -- ANSI codes are never written in legal mode.
155
+
132
156
  ## Requirements
133
157
 
134
158
  Node.js 20 or later.
@@ -159,4 +183,4 @@ If the version already exists on npm, the publish step exits cleanly.
159
183
 
160
184
  ## License
161
185
 
162
- [Apache 2.0](../../LICENSE)
186
+ [PolyForm Shield 1.0.0](../../LICENSE)
package/lib/cli.js CHANGED
@@ -21,6 +21,7 @@ import { dirname, join } from 'node:path';
21
21
  import { verifyWacz } from './verify.js';
22
22
  import { loadTrustedRoots } from './cms-verify.js';
23
23
  import { formatHuman, formatJson, formatJsonError } from './format.js';
24
+ import { formatLegal, formatLegalJson } from './format-legal.js';
24
25
  import {
25
26
  resolveKey,
26
27
  isWrlCaptureUrl,
@@ -51,6 +52,7 @@ OPTIONS
51
52
  --trust-embedded Use the embedded key (insecure, see below)
52
53
  --trust-root <path> Additional trusted root certificate (PEM)
53
54
  --json Output machine-readable JSON to stdout
55
+ --legal Detailed verification report for legal proceedings
54
56
  --no-color Disable colored output
55
57
  -h, --help Show this help message
56
58
  --version Show version number
@@ -84,6 +86,7 @@ TRUST MODEL
84
86
  * trustEmbedded: boolean,
85
87
  * trustRoots: string[],
86
88
  * json: boolean,
89
+ * legal: boolean,
87
90
  * noColor: boolean,
88
91
  * help: boolean,
89
92
  * version: boolean,
@@ -99,13 +102,14 @@ export function parseArgs(argv) {
99
102
  trustEmbedded: false,
100
103
  trustRoots: [],
101
104
  json: false,
105
+ legal: false,
102
106
  noColor: false,
103
107
  help: false,
104
108
  version: false,
105
109
  };
106
110
 
107
111
  const VALUE_FLAGS = new Set(['--origin', '--key', '--key-file', '--trust-root']);
108
- const BOOL_FLAGS = new Set(['--trust-embedded', '--json', '--no-color', '-h', '--help', '--version']);
112
+ const BOOL_FLAGS = new Set(['--trust-embedded', '--json', '--legal', '--no-color', '-h', '--help', '--version']);
109
113
 
110
114
  let i = 0;
111
115
  while (i < argv.length) {
@@ -135,6 +139,12 @@ export function parseArgs(argv) {
135
139
  continue;
136
140
  }
137
141
 
142
+ if (arg === '--legal') {
143
+ opts.legal = true;
144
+ i++;
145
+ continue;
146
+ }
147
+
138
148
  if (arg === '--no-color') {
139
149
  opts.noColor = true;
140
150
  i++;
@@ -397,7 +407,13 @@ export async function run(argv) {
397
407
  // -----------------------------------------------------------------------
398
408
  // Format and output
399
409
  // -----------------------------------------------------------------------
400
- if (opts.json) {
410
+ if (opts.legal) {
411
+ if (opts.json) {
412
+ formatLegalJson(result, { version: getVersion() });
413
+ } else {
414
+ formatLegal(result, { version: getVersion() });
415
+ }
416
+ } else if (opts.json) {
401
417
  formatJson(result);
402
418
  } else {
403
419
  formatHuman(result, { noColor: opts.noColor });
@@ -0,0 +1,721 @@
1
+ /**
2
+ * format-legal.js -- Legal verification report formatters for wrl-verify.
3
+ *
4
+ * Produces comprehensive, plain-language verification reports suitable for
5
+ * submission in legal proceedings. No ANSI codes. All values untruncated.
6
+ * Timestamps shown separately (not merged like formatHuman).
7
+ *
8
+ * Two output modes:
9
+ * formatLegal() -- structured plain text for terminal/file
10
+ * formatLegalJson() -- machine-readable JSON for document assembly
11
+ */ // tva
12
+
13
+ import { checkLabel } from './format.js';
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Report format version -- bumped when report structure changes
17
+ // ---------------------------------------------------------------------------
18
+
19
+ const REPORT_FORMAT = 'WRL-LEGAL-1.0';
20
+
21
+ // ---------------------------------------------------------------------------
22
+ // Explanatory content constants
23
+ // ---------------------------------------------------------------------------
24
+
25
+ const EXPLANATIONS = {
26
+ artifactHashes: {
27
+ what: 'Each file within the web archive was independently verified by ' +
28
+ 'recomputing its SHA-256 hash (a cryptographic fingerprint standardized ' +
29
+ 'by NIST in FIPS 180-4) and comparing it to the hash recorded in the ' +
30
+ 'archive manifest.',
31
+ pass: 'All files within the archive match their recorded hashes. No ' +
32
+ 'file has been added, removed, or modified since the archive was created.',
33
+ fail: 'One or more files within the archive do not match their recorded ' +
34
+ 'hashes. The archive contents may have been modified after creation.',
35
+ skip: 'File integrity verification was not applicable for this archive.',
36
+ significance: 'Establishes that the individual captured resources ' +
37
+ '(HTML pages, images, scripts) are identical to those recorded at ' +
38
+ 'capture time.',
39
+ },
40
+ bundleHash: {
41
+ what: 'The archive manifest (a JSON document listing all captured ' +
42
+ 'resources and their properties) was re-serialized using canonical ' +
43
+ 'JSON encoding, and its SHA-256 hash was compared to the hash ' +
44
+ 'recorded in the signed digest.',
45
+ pass: 'The manifest hash matches. The list of captured resources and ' +
46
+ 'their metadata have not been altered.',
47
+ fail: 'The manifest hash does not match. The archive metadata may ' +
48
+ 'have been modified after signing.',
49
+ skip: 'Bundle integrity verification was not applicable.',
50
+ significance: 'Establishes that the archive metadata (resource list, ' +
51
+ 'file sizes, individual hashes) is identical to what was originally signed.',
52
+ },
53
+ signature: {
54
+ what: 'The digital signature on the archive was verified using Ed25519 ' +
55
+ '(an elliptic-curve signature algorithm standardized in RFC 8032). ' +
56
+ 'The signature covers the bundle hash, binding the archive contents ' +
57
+ 'to the signing key.',
58
+ pass: 'The digital signature is valid. The archive was signed by the ' +
59
+ 'holder of the corresponding private key, and the signed content has ' +
60
+ 'not been modified.',
61
+ fail: 'The digital signature is invalid. Either the archive contents ' +
62
+ 'have been modified after signing, or the wrong verification key was used.',
63
+ skip: 'Digital signature verification was not applicable.',
64
+ significance: 'Establishes that a specific party (identified by their ' +
65
+ 'signing key) attested to the archive contents at the time of signing.',
66
+ },
67
+ timestamp: {
68
+ what: 'An independent timestamp was obtained from a Time Stamping ' +
69
+ 'Authority (TSA) at the time of capture, using the RFC 3161 protocol. ' +
70
+ 'The TSA signed a timestamp token containing the bundle hash and the ' +
71
+ 'current time, providing independent evidence of when the archive existed.',
72
+ pass: 'The RFC 3161 timestamp is valid. The bundle hash embedded in ' +
73
+ 'the timestamp token matches the archive, confirming the archive ' +
74
+ 'existed at the recorded time.',
75
+ fail: 'The RFC 3161 timestamp verification failed. The timestamp may ' +
76
+ 'be corrupt or may not correspond to this archive.',
77
+ skip: 'No independent timestamp was obtained for this capture. The ' +
78
+ 'TSA may have been unreachable at capture time.',
79
+ significance: 'Provides independent, third-party evidence of the date ' +
80
+ 'and time at which the archive existed in its current form. Unlike the ' +
81
+ 'capture service\'s self-asserted creation time, this timestamp comes ' +
82
+ 'from an independent authority.',
83
+ },
84
+ qualifiedTimestamp: {
85
+ what: 'A qualified electronic timestamp was obtained from a Qualified ' +
86
+ 'Trust Service Provider (QTSP) under the eIDAS Regulation (EU) ' +
87
+ 'No 910/2014. Qualified timestamps carry additional legal significance ' +
88
+ 'beyond standard RFC 3161 timestamps.',
89
+ pass: 'The qualified timestamp is valid. The bundle hash embedded in ' +
90
+ 'the timestamp token matches the archive.',
91
+ fail: 'The qualified timestamp verification failed structurally.',
92
+ skip: 'No qualified timestamp was requested or obtained for this capture.',
93
+ significance: 'Under eIDAS Regulation (EU) No 910/2014, Article 41(2), ' +
94
+ 'a qualified electronic timestamp enjoys a presumption of accuracy of ' +
95
+ 'the date and time it indicates, and of the integrity of the data to ' +
96
+ 'which the date and time are bound. This presumption is rebuttable but ' +
97
+ 'shifts the burden of proof.',
98
+ },
99
+ timestampChain: {
100
+ what: 'The TSA certificate chain was validated against trusted root ' +
101
+ 'certificates using CMS/PKCS#7 (RFC 5652) signature verification. ' +
102
+ 'This confirms the timestamp was issued by a legitimate TSA whose ' +
103
+ 'identity can be traced to a known certificate authority.',
104
+ pass: 'The TSA certificate chain is valid. The timestamp was issued ' +
105
+ 'by a TSA whose certificate chains to a trusted root.',
106
+ fail: 'The TSA certificate chain could not be validated.',
107
+ skip: 'Certificate chain verification was not performed. No trusted ' +
108
+ 'root certificates were provided for chain validation.',
109
+ significance: 'Establishes the identity and legitimacy of the Time ' +
110
+ 'Stamping Authority that issued the timestamp.',
111
+ },
112
+ };
113
+
114
+ const TRUST_MODELS = {
115
+ embedded:
116
+ 'TRUST LEVEL: SELF-ASSERTED (LIMITED)\n\n' +
117
+ 'This verification used the signing key embedded within the archive\n' +
118
+ 'itself. This confirms the archive\'s contents have not been modified\n' +
119
+ 'since they were last signed, but it does not establish who performed\n' +
120
+ 'the signing or whether the archive originated from a trusted source.\n' +
121
+ 'A party who modifies the archive could also replace the embedded key\n' +
122
+ 'and re-sign it.',
123
+ origin:
124
+ 'The signing key was retrieved from the capture service operator\'s\n' +
125
+ 'HTTPS endpoint. This establishes that the operator published this\n' +
126
+ 'key as their signing key at the time of verification. The trust in\n' +
127
+ 'this verification depends on the authenticity of the operator\'s\n' +
128
+ 'HTTPS endpoint and the integrity of the TLS connection used to\n' +
129
+ 'retrieve the key.',
130
+ pinned:
131
+ 'The signing key was provided directly by the verifier. The trust\n' +
132
+ 'in this verification depends on the verifier\'s confidence that\n' +
133
+ 'this key belongs to the expected signing party.',
134
+ };
135
+
136
+ const LEGAL_DISCLAIMER =
137
+ 'This report is a technical verification document. It does not\n' +
138
+ 'constitute legal advice. The admissibility of this evidence and\n' +
139
+ 'the legal weight of the verification results are matters for\n' +
140
+ 'determination by the relevant court or tribunal.';
141
+
142
+ const LIMITATIONS = [
143
+ 'This tool verifies cryptographic integrity only. It does not ' +
144
+ 'verify the accuracy, legality, or completeness of the captured ' +
145
+ 'web content itself.',
146
+ 'CRL/OCSP certificate revocation checking is not performed. This ' +
147
+ 'tool is designed for offline verification where network access to ' +
148
+ 'revocation services may be unavailable.',
149
+ 'This tool does not independently verify a TSA\'s eIDAS ' +
150
+ 'qualification status against the EU Trusted List. The ' +
151
+ 'qualification of a timestamp service provider should be ' +
152
+ 'confirmed through official channels.',
153
+ 'Cryptographic verification is deterministic: the same archive ' +
154
+ 'and signing key will always produce the same verification result.',
155
+ ];
156
+
157
+ const ALGORITHMS = [
158
+ { name: 'SHA-256', standard: 'FIPS 180-4 (NIST)', purpose: 'Hash computation for file and bundle integrity' },
159
+ { name: 'Ed25519', standard: 'RFC 8032', purpose: 'Digital signature verification' },
160
+ { name: 'RFC 3161', standard: 'RFC 3161 (IETF)', purpose: 'Timestamp token verification' },
161
+ { name: 'CMS/PKCS#7', standard: 'RFC 5652', purpose: 'Timestamp certificate chain validation' },
162
+ ];
163
+
164
+ // ---------------------------------------------------------------------------
165
+ // Helpers
166
+ // ---------------------------------------------------------------------------
167
+
168
+ const LINE = '---------------------------------------------------------------------------';
169
+ const DOUBLE = '===========================================================================';
170
+
171
+ function shellQuote(s) {
172
+ return "'" + String(s ?? '').replace(/'/g, "'\\''") + "'";
173
+ }
174
+
175
+ function toolLine(version) {
176
+ return `@w-r-l/verify ${version} (Node.js ${process.versions.node}, ` +
177
+ `${process.platform} ${process.arch})`;
178
+ }
179
+
180
+ function wrap(text, indent = 0, width = 78) {
181
+ const prefix = ' '.repeat(indent);
182
+ const maxLen = width - indent;
183
+ const words = text.split(/\s+/);
184
+ const lines = [];
185
+ let current = '';
186
+ for (const word of words) {
187
+ if (current.length + 1 + word.length > maxLen && current.length > 0) {
188
+ lines.push(prefix + current);
189
+ current = word;
190
+ } else {
191
+ current = current ? current + ' ' + word : word;
192
+ }
193
+ }
194
+ if (current) lines.push(prefix + current);
195
+ return lines.join('\n');
196
+ }
197
+
198
+ function statusLabel(status) {
199
+ if (status === 'pass') return 'PASSED';
200
+ if (status === 'fail') return 'FAILED';
201
+ return 'NOT APPLICABLE';
202
+ }
203
+
204
+ // ---------------------------------------------------------------------------
205
+ // formatLegal -- Plain-text legal report
206
+ // ---------------------------------------------------------------------------
207
+
208
+ /**
209
+ * Formats a verification result as a comprehensive plain-text legal report.
210
+ * No ANSI codes. All values untruncated. Timestamps shown separately.
211
+ *
212
+ * @param {object} result The verification result from verifyWacz()
213
+ * @param {{ version: string }} opts Options including tool version
214
+ */
215
+ export function formatLegal(result, opts = {}) {
216
+ const out = [];
217
+ const version = opts.version ?? '0.0.0';
218
+ const verifiedAt = new Date().toISOString();
219
+
220
+ // Header
221
+ out.push(DOUBLE);
222
+ out.push('VERIFICATION REPORT: WEB RESOURCE CAPTURE');
223
+ out.push(DOUBLE);
224
+ out.push('');
225
+ out.push(`Format: ${REPORT_FORMAT}`);
226
+ out.push(`Generated: ${verifiedAt}`);
227
+ out.push(`Tool: ${toolLine(version)}`);
228
+ out.push('');
229
+
230
+ // Section 1: Summary
231
+ out.push('1. SUMMARY');
232
+ out.push(LINE);
233
+ out.push('');
234
+
235
+ // Trust model warning leads if embedded key
236
+ const kr = result.keyResolution;
237
+ if (kr?.source === 'embedded') {
238
+ out.push(TRUST_MODELS.embedded);
239
+ out.push('');
240
+ }
241
+
242
+ const checks = result.checks ?? [];
243
+
244
+ // Display order for legal report -- all checks shown individually
245
+ const checkOrder = [
246
+ 'artifactHashes',
247
+ 'bundleHash',
248
+ 'signature',
249
+ 'timestamp',
250
+ 'qualifiedTimestamp',
251
+ 'timestampChain',
252
+ ];
253
+
254
+ // Summary counts use only checks that appear in Section 3
255
+ const reportedChecks = checks.filter(c => checkOrder.includes(c.name));
256
+ const applicable = reportedChecks.filter(c => c.status !== 'skip');
257
+ const failed = applicable.filter(c => c.status === 'fail');
258
+
259
+ if (failed.length === 0) {
260
+ out.push(wrap(
261
+ `Result: All ${applicable.length} cryptographic checks passed. ` +
262
+ 'No evidence of modification was detected.'
263
+ ));
264
+ } else {
265
+ out.push(wrap(
266
+ `Result: ${failed.length} of ${applicable.length} check(s) failed. ` +
267
+ 'This capture cannot be verified as unmodified.'
268
+ ));
269
+ }
270
+ out.push('');
271
+ out.push(`Source: ${result.source ?? 'unknown'}`);
272
+ out.push(`Verified: ${verifiedAt}`);
273
+ out.push('');
274
+
275
+ // Section 2: Subject of Verification
276
+ out.push('2. SUBJECT OF VERIFICATION');
277
+ out.push(LINE);
278
+ out.push('');
279
+ out.push(wrap(
280
+ 'A web resource capture is a snapshot of web content (HTML pages, ' +
281
+ 'images, stylesheets, and other resources) preserved in a WACZ ' +
282
+ '(Web Archive Collection Zipped) archive format. The archive ' +
283
+ 'includes a cryptographic manifest listing each captured resource ' +
284
+ 'and its hash, a digital signature binding the manifest to a ' +
285
+ 'signing key, and optionally one or more timestamps from ' +
286
+ 'independent authorities.'
287
+ ));
288
+ out.push('');
289
+
290
+ const capture = result.capture ?? {};
291
+ out.push(`Source: ${result.source ?? 'unknown'}`);
292
+ if (capture.signedAt) {
293
+ out.push(`Created: ${capture.signedAt}`);
294
+ }
295
+ if (capture.bundleHash) {
296
+ out.push(`Bundle hash: ${capture.bundleHash}`);
297
+ }
298
+ out.push('');
299
+
300
+ // Section 3: Verification Checks Performed
301
+ out.push('3. VERIFICATION CHECKS PERFORMED');
302
+ out.push(LINE);
303
+ out.push('');
304
+
305
+ let subNum = 1;
306
+ for (const name of checkOrder) {
307
+ const check = checks.find(c => c.name === name);
308
+ if (!check) continue;
309
+
310
+ const label = checkLabel(name);
311
+ const expl = EXPLANATIONS[name];
312
+
313
+ out.push(`3.${subNum} ${label}`);
314
+ out.push('');
315
+ out.push(`Status: ${statusLabel(check.status)}`);
316
+ out.push('');
317
+
318
+ if (expl) {
319
+ out.push(wrap(expl.what));
320
+ out.push('');
321
+
322
+ if (check.status === 'pass') {
323
+ out.push(wrap(expl.pass));
324
+ } else if (check.status === 'fail') {
325
+ out.push(wrap(expl.fail));
326
+ if (check.detail) {
327
+ out.push('');
328
+ out.push(wrap(`Detail: ${check.detail}`));
329
+ }
330
+ } else {
331
+ out.push(wrap(expl.skip));
332
+ if (check.detail) {
333
+ out.push('');
334
+ out.push(wrap(`Detail: ${check.detail}`));
335
+ }
336
+ }
337
+ out.push('');
338
+ out.push(wrap(`Evidentiary significance: ${expl.significance}`));
339
+ }
340
+ out.push('');
341
+
342
+ // Timestamp-specific details
343
+ if (name === 'timestamp' && capture.timestamp) {
344
+ out.push(` TSA: ${capture.timestamp.tsa}`);
345
+ out.push(` Time: ${capture.timestamp.genTime}`);
346
+ out.push('');
347
+ }
348
+ if (name === 'qualifiedTimestamp' && capture.qualifiedTimestamp) {
349
+ out.push(` QTSA: ${capture.qualifiedTimestamp.tsa}`);
350
+ out.push(` Time: ${capture.qualifiedTimestamp.genTime}`);
351
+ out.push('');
352
+ out.push(wrap(
353
+ 'A standard RFC 3161 timestamp provides cryptographic evidence of ' +
354
+ 'time from an independent authority. A qualified electronic ' +
355
+ 'timestamp additionally carries a legal presumption under eIDAS ' +
356
+ 'Regulation (EU) No 910/2014, Article 41(2), that the date, time, ' +
357
+ 'and data integrity are accurate until proven otherwise.'
358
+ ));
359
+ out.push('');
360
+ }
361
+
362
+ subNum++;
363
+ }
364
+
365
+ // Section 4: Chain of Custody
366
+ out.push('4. CHAIN OF CUSTODY');
367
+ out.push(LINE);
368
+ out.push('');
369
+ out.push(wrap(
370
+ `The archive was obtained from: ${result.source ?? 'unknown'}`
371
+ ));
372
+ out.push('');
373
+
374
+ if (kr) {
375
+ if (kr.source === 'origin' && kr.origin) {
376
+ out.push(wrap(
377
+ `The signing key (ID: ${kr.keyId ?? 'unknown'}) was retrieved ` +
378
+ `from the capture service operator's HTTPS endpoint at ` +
379
+ `${kr.origin}. The key retrieval was performed over an ` +
380
+ 'encrypted TLS connection.'
381
+ ));
382
+ } else if (kr.source === 'embedded') {
383
+ out.push(wrap(
384
+ `The signing key (ID: ${kr.keyId ?? 'unknown'}) was extracted ` +
385
+ 'from the archive itself (embedded key). See the trust level ' +
386
+ 'warning in Section 1.'
387
+ ));
388
+ } else if (kr.source === 'pinned') {
389
+ out.push(wrap(
390
+ `The signing key (ID: ${kr.keyId ?? 'unknown'}) was provided ` +
391
+ 'directly by the party performing this verification.'
392
+ ));
393
+ }
394
+ out.push('');
395
+ }
396
+
397
+ out.push(wrap(
398
+ 'Verification was performed locally on the machine identified in ' +
399
+ 'the Methodology section. No data was transmitted to external ' +
400
+ 'services during verification.'
401
+ ));
402
+ out.push('');
403
+ out.push(wrap(
404
+ 'This report is plain text and is not itself digitally signed. ' +
405
+ 'The integrity of the verification results can be confirmed by ' +
406
+ 're-running the verification using the instructions in the ' +
407
+ 'Methodology section.'
408
+ ));
409
+ out.push('');
410
+
411
+ // Section 5: Applicable Legal Standards
412
+ out.push('5. APPLICABLE LEGAL STANDARDS');
413
+ out.push(LINE);
414
+ out.push('');
415
+ out.push(wrap(
416
+ 'United States -- Federal Rule of Evidence 901(b)(9): This rule ' +
417
+ 'provides for authentication of evidence through "evidence ' +
418
+ 'describing a process or system and showing that it produces an ' +
419
+ 'accurate result." This report is structured to support ' +
420
+ 'authentication under this provision by describing the ' +
421
+ 'verification process, the cryptographic algorithms employed, ' +
422
+ 'and the results obtained.'
423
+ ));
424
+ out.push('');
425
+
426
+ // eIDAS section -- always present, but qualified timestamp significance
427
+ // highlighted when one exists
428
+ const hasQualified = checks.some(
429
+ c => c.name === 'qualifiedTimestamp' && c.status === 'pass'
430
+ );
431
+ out.push(wrap(
432
+ 'European Union -- eIDAS Regulation (EU) No 910/2014: Article 41(1) ' +
433
+ 'provides that an electronic timestamp shall not be denied legal ' +
434
+ 'effect and admissibility as evidence in legal proceedings solely ' +
435
+ 'on the grounds that it is in electronic form or that it does not ' +
436
+ 'meet the requirements of a qualified electronic timestamp.'
437
+ ));
438
+ out.push('');
439
+
440
+ if (hasQualified) {
441
+ out.push(wrap(
442
+ 'This capture includes a qualified electronic timestamp. Under ' +
443
+ 'Article 41(2), a qualified electronic timestamp enjoys a ' +
444
+ 'presumption of the accuracy of the date and time it indicates ' +
445
+ 'and of the integrity of the data to which the date and time ' +
446
+ 'are bound.'
447
+ ));
448
+ out.push('');
449
+ }
450
+
451
+ out.push(wrap(LEGAL_DISCLAIMER));
452
+ out.push('');
453
+
454
+ // Section 6: Methodology
455
+ out.push('6. METHODOLOGY');
456
+ out.push(LINE);
457
+ out.push('');
458
+ out.push(`Tool: @w-r-l/verify`);
459
+ out.push(`Version: ${version}`);
460
+ out.push(`Source: https://www.npmjs.com/package/@w-r-l/verify`);
461
+ out.push(`Runtime: Node.js ${process.versions.node}`);
462
+ out.push(`Platform: ${process.platform} ${process.arch}`);
463
+ out.push('');
464
+
465
+ out.push('Cryptographic algorithms:');
466
+ for (const alg of ALGORITHMS) {
467
+ out.push(` ${alg.name.padEnd(12)} ${alg.standard.padEnd(20)} ${alg.purpose}`);
468
+ }
469
+ out.push('');
470
+
471
+ out.push(wrap(
472
+ 'All cryptographic operations use the Node.js built-in crypto ' +
473
+ 'module (Web Crypto API for Ed25519 signature verification).'
474
+ ));
475
+ out.push('');
476
+
477
+ out.push('Limitations:');
478
+ for (const lim of LIMITATIONS) {
479
+ out.push(wrap(`- ${lim}`, 2));
480
+ }
481
+ out.push('');
482
+
483
+ // Reproducibility
484
+ out.push('Reproducibility:');
485
+ out.push(wrap(
486
+ 'To independently verify this capture, install @w-r-l/verify ' +
487
+ `version ${version} and run:`
488
+ ));
489
+ out.push('');
490
+ // Build command from result, not process.argv (security: avoid leaking paths)
491
+ let cmd = ` npx @w-r-l/verify@${version} ${shellQuote(result.source ?? '<file-or-url>')}`;
492
+ if (kr?.source === 'origin' && kr.origin) {
493
+ cmd += ` --origin ${shellQuote(kr.origin)}`;
494
+ } else if (kr?.source === 'embedded') {
495
+ cmd += ' --trust-embedded';
496
+ }
497
+ cmd += ' --legal';
498
+ out.push(cmd);
499
+ out.push('');
500
+ out.push(wrap(
501
+ 'If custom trust root certificates were used during the original ' +
502
+ 'verification (via --trust-root), they must be supplied again when ' +
503
+ 're-running the command above.'
504
+ ));
505
+ out.push('');
506
+
507
+ // Section 7: Full Technical Details
508
+ out.push('7. FULL TECHNICAL DETAILS');
509
+ out.push(LINE);
510
+ out.push('');
511
+ out.push(wrap(
512
+ 'The following values are provided untruncated for independent ' +
513
+ 'verification and cross-reference with other records.'
514
+ ));
515
+ out.push('');
516
+
517
+ if (capture.bundleHash) {
518
+ out.push(`Bundle hash: ${capture.bundleHash}`);
519
+ }
520
+ if (capture.signature) {
521
+ out.push(`Signature: ${capture.signature}`);
522
+ }
523
+ if (capture.publicKey) {
524
+ out.push(`Embedded key: ${capture.publicKey}`);
525
+ // Repeat trust warning inline for embedded key
526
+ if (kr?.source === 'embedded') {
527
+ out.push(' (SELF-ASSERTED -- see trust warning in');
528
+ out.push(' Section 1)');
529
+ }
530
+ }
531
+ if (kr?.keyId) {
532
+ out.push(`Key ID: ${kr.keyId}`);
533
+ }
534
+ if (kr?.source) {
535
+ const sourceLabel = kr.source === 'origin'
536
+ ? `operator (${kr.origin ?? 'unknown'})`
537
+ : kr.source === 'embedded'
538
+ ? 'embedded in archive (self-asserted)'
539
+ : 'user-provided';
540
+ out.push(`Key source: ${sourceLabel}`);
541
+ }
542
+ out.push('');
543
+
544
+ out.push('Timestamps:');
545
+ out.push('');
546
+ if (capture.signedAt) {
547
+ out.push(` Capture time: ${capture.signedAt}`);
548
+ out.push(' (self-asserted by capture service)');
549
+ }
550
+ if (capture.timestamp) {
551
+ out.push(` TSA time: ${capture.timestamp.genTime}`);
552
+ out.push(` TSA identity: ${capture.timestamp.tsa}`);
553
+ out.push(' (independent RFC 3161 timestamp)');
554
+ }
555
+ if (capture.qualifiedTimestamp) {
556
+ out.push(` QTSA time: ${capture.qualifiedTimestamp.genTime}`);
557
+ out.push(` QTSA identity: ${capture.qualifiedTimestamp.tsa}`);
558
+ out.push(' (qualified timestamp -- eIDAS Art. 41)');
559
+ }
560
+ out.push(` Verification time: ${verifiedAt}`);
561
+ out.push(' (time this report was generated)');
562
+ out.push('');
563
+
564
+ out.push(DOUBLE);
565
+ out.push('END OF VERIFICATION REPORT');
566
+ out.push(DOUBLE);
567
+ out.push('');
568
+
569
+ process.stdout.write(out.join('\n'));
570
+ }
571
+
572
+ // ---------------------------------------------------------------------------
573
+ // formatLegalJson -- JSON legal report
574
+ // ---------------------------------------------------------------------------
575
+
576
+ /**
577
+ * Formats a verification result as a JSON legal report.
578
+ * Includes explanatory fields, legal context, and methodology.
579
+ *
580
+ * @param {object} result The verification result from verifyWacz()
581
+ * @param {{ version: string }} opts Options including tool version
582
+ */
583
+ export function formatLegalJson(result, opts = {}) {
584
+ const version = opts.version ?? '0.0.0';
585
+ const verifiedAt = new Date().toISOString();
586
+ const capture = result.capture ?? {};
587
+ const kr = result.keyResolution ?? {};
588
+ const checks = result.checks ?? [];
589
+
590
+ const applicable = checks.filter(c => c.status !== 'skip');
591
+ const failed = applicable.filter(c => c.status === 'fail');
592
+
593
+ let summaryStatement;
594
+ if (failed.length === 0) {
595
+ summaryStatement =
596
+ `All ${applicable.length} cryptographic checks passed. ` +
597
+ 'No evidence of modification was detected.';
598
+ } else {
599
+ summaryStatement =
600
+ `${failed.length} of ${applicable.length} check(s) failed. ` +
601
+ 'This capture cannot be verified as unmodified.';
602
+ }
603
+
604
+ const enrichedChecks = checks.map(c => {
605
+ const expl = EXPLANATIONS[c.name] ?? {};
606
+ return {
607
+ name: c.name,
608
+ label: checkLabel(c.name),
609
+ status: c.status,
610
+ detail: c.detail ?? null,
611
+ explanation: expl.what ?? null,
612
+ result: expl[c.status] ?? null,
613
+ significance: expl.significance ?? null,
614
+ };
615
+ });
616
+
617
+ // Timestamps -- separate standard and qualified
618
+ const timestamps = {};
619
+ if (capture.timestamp) {
620
+ timestamps.standard = {
621
+ genTime: capture.timestamp.genTime,
622
+ tsa: capture.timestamp.tsa,
623
+ type: 'RFC 3161',
624
+ };
625
+ }
626
+ if (capture.qualifiedTimestamp) {
627
+ timestamps.qualified = {
628
+ genTime: capture.qualifiedTimestamp.genTime,
629
+ tsa: capture.qualifiedTimestamp.tsa,
630
+ type: 'eIDAS qualified (EU No 910/2014, Art. 41)',
631
+ };
632
+ }
633
+ if (capture.signedAt) {
634
+ timestamps.capture = {
635
+ time: capture.signedAt,
636
+ source: 'self-asserted by capture service',
637
+ };
638
+ }
639
+ timestamps.verification = {
640
+ time: verifiedAt,
641
+ source: 'generated by verification tool',
642
+ };
643
+
644
+ // Key resolution with trust model
645
+ let trustModel;
646
+ if (kr.source === 'embedded') {
647
+ trustModel = 'Self-asserted (limited). The signing key was embedded ' +
648
+ 'in the archive. This proves internal consistency only, not provenance.';
649
+ } else if (kr.source === 'origin') {
650
+ trustModel = `Operator-published. The signing key was retrieved from ` +
651
+ `${kr.origin ?? 'the operator'} over HTTPS.`;
652
+ } else if (kr.source === 'pinned') {
653
+ trustModel = 'User-provided. The signing key was supplied directly ' +
654
+ 'by the verifier.';
655
+ } else {
656
+ trustModel = null;
657
+ }
658
+
659
+ const out = {
660
+ reportFormat: REPORT_FORMAT,
661
+ verified: result.verified ?? null,
662
+ tool: {
663
+ name: '@w-r-l/verify',
664
+ version,
665
+ nodeVersion: process.versions.node,
666
+ platform: process.platform,
667
+ arch: process.arch,
668
+ },
669
+ summary: {
670
+ statement: summaryStatement,
671
+ verified: result.verified ?? null,
672
+ source: result.source ?? null,
673
+ captureDate: capture.signedAt ?? null,
674
+ },
675
+ checks: enrichedChecks,
676
+ capture: {
677
+ bundleHash: capture.bundleHash ?? null,
678
+ signature: capture.signature ?? null,
679
+ embeddedPublicKey: capture.publicKey ?? null,
680
+ signedAt: capture.signedAt ?? null,
681
+ },
682
+ timestamps,
683
+ keyResolution: {
684
+ keyId: kr.keyId ?? null,
685
+ source: kr.source ?? null,
686
+ origin: kr.origin ?? null,
687
+ endpoint: kr.endpoint ?? null,
688
+ publicKey: capture.publicKey ?? null,
689
+ trustModel,
690
+ },
691
+ legalContext: {
692
+ disclaimer: LEGAL_DISCLAIMER.replace(/\n/g, ' '),
693
+ applicableFrameworks: [
694
+ {
695
+ jurisdiction: 'United States',
696
+ reference: 'Federal Rule of Evidence 901(b)(9)',
697
+ relevance: 'Authentication of evidence through description of ' +
698
+ 'a process or system showing it produces an accurate result.',
699
+ },
700
+ {
701
+ jurisdiction: 'European Union',
702
+ reference: 'eIDAS Regulation (EU) No 910/2014, Article 41',
703
+ relevance: 'Electronic timestamps shall not be denied legal ' +
704
+ 'effect solely on the grounds of electronic form.',
705
+ },
706
+ ],
707
+ },
708
+ methodology: {
709
+ algorithms: ALGORITHMS.map(a => ({
710
+ name: a.name,
711
+ standard: a.standard,
712
+ purpose: a.purpose,
713
+ })),
714
+ cryptoLibrary: 'Node.js built-in crypto (Web Crypto API for Ed25519)',
715
+ limitations: LIMITATIONS,
716
+ },
717
+ verifiedAt,
718
+ };
719
+
720
+ process.stdout.write(JSON.stringify(out, null, 2) + '\n');
721
+ }
package/lib/format.js CHANGED
@@ -48,6 +48,7 @@ const CHECK_LABELS = {
48
48
  signature: 'Digital signature',
49
49
  timestamp: 'Timestamp imprint',
50
50
  qualifiedTimestamp: 'Qualified timestamp',
51
+ timeVerification: 'Time verification',
51
52
  timestampChain: 'Timestamp chain',
52
53
  };
53
54
 
@@ -56,8 +57,7 @@ const CHECK_ORDER = [
56
57
  'artifactHashes',
57
58
  'bundleHash',
58
59
  'signature',
59
- 'timestamp',
60
- 'qualifiedTimestamp',
60
+ 'timeVerification',
61
61
  'timestampChain',
62
62
  ];
63
63
 
@@ -67,10 +67,75 @@ const CHECK_ORDER = [
67
67
  * @param {string} name
68
68
  * @returns {string}
69
69
  */
70
- function checkLabel(name) {
70
+ export function checkLabel(name) {
71
71
  return CHECK_LABELS[name] ?? name;
72
72
  }
73
73
 
74
+ export { CHECK_LABELS };
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Timestamp check merging
78
+ // ---------------------------------------------------------------------------
79
+
80
+ /**
81
+ * Merges `timestamp` and `qualifiedTimestamp` checks into a single
82
+ * `timeVerification` check. The merged entry replaces the first removed entry
83
+ * in the array, preserving display order. Used only by the human formatter --
84
+ * JSON output is not affected.
85
+ *
86
+ * Status priority: fail > pass > skip.
87
+ *
88
+ * @param {Array<{ name: string, status: string, detail?: string }>} checks
89
+ * @returns {Array<{ name: string, status: string, detail?: string }>}
90
+ */
91
+ function mergeTimestampChecks(checks) {
92
+ const ts = checks.find(c => c.name === 'timestamp');
93
+ const qts = checks.find(c => c.name === 'qualifiedTimestamp');
94
+
95
+ if (!ts && !qts) return checks;
96
+
97
+ // Determine merged status: fail > pass > skip
98
+ let mergedStatus = 'skip';
99
+ let mergedDetail;
100
+ if ((ts && ts.status === 'fail') || (qts && qts.status === 'fail')) {
101
+ mergedStatus = 'fail';
102
+ mergedDetail = (ts && ts.status === 'fail') ? ts.detail : qts.detail;
103
+ } else if ((ts && ts.status === 'pass') || (qts && qts.status === 'pass')) {
104
+ mergedStatus = 'pass';
105
+ }
106
+
107
+ // Determine detail text for the merged check
108
+ if (mergedStatus !== 'fail') {
109
+ if (qts && qts.status === 'pass') {
110
+ mergedDetail = 'Qualified electronic timestamp (eIDAS Art. 41)';
111
+ } else if (!qts && ts && ts.status === 'pass') {
112
+ mergedDetail = 'Independent RFC 3161 timestamp';
113
+ } else if (!qts && ts && ts.status === 'skip') {
114
+ mergedDetail = 'No independent timestamp obtained';
115
+ }
116
+ }
117
+
118
+ const merged = { name: 'timeVerification', status: mergedStatus };
119
+ if (mergedDetail !== undefined) merged.detail = mergedDetail;
120
+
121
+ // Replace at position of first removed entry
122
+ const firstIdx = checks.findIndex(c => c.name === 'timestamp' || c.name === 'qualifiedTimestamp');
123
+ const result = [];
124
+ const removed = new Set(['timestamp', 'qualifiedTimestamp']);
125
+ let inserted = false;
126
+ for (let i = 0; i < checks.length; i++) {
127
+ if (removed.has(checks[i].name)) {
128
+ if (!inserted) {
129
+ result.push(merged);
130
+ inserted = true;
131
+ }
132
+ } else {
133
+ result.push(checks[i]);
134
+ }
135
+ }
136
+ return result;
137
+ }
138
+
74
139
  // ---------------------------------------------------------------------------
75
140
  // Human-readable formatter
76
141
  // ---------------------------------------------------------------------------
@@ -102,13 +167,16 @@ function checkLabel(name) {
102
167
  export function formatHuman(result, opts = {}) {
103
168
  const color = shouldColor(opts);
104
169
 
170
+ // Merge timestamp checks before ordering
171
+ const merged = mergeTimestampChecks(result.checks);
172
+
105
173
  // Sort checks into fixed display order, preserving any extras at the end
106
174
  const orderedChecks = [];
107
175
  for (const name of CHECK_ORDER) {
108
- const c = result.checks.find(ch => ch.name === name);
176
+ const c = merged.find(ch => ch.name === name);
109
177
  if (c) orderedChecks.push(c);
110
178
  }
111
- for (const c of result.checks) {
179
+ for (const c of merged) {
112
180
  if (!CHECK_ORDER.includes(c.name)) orderedChecks.push(c);
113
181
  }
114
182
 
@@ -36,21 +36,6 @@ 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
-
54
39
  /**
55
40
  * Extracts the origin (scheme + host + port) from a URL string.
56
41
  *
@@ -104,10 +89,10 @@ async function fetchBytes(url, { timeoutMs = KEY_FETCH_TIMEOUT_MS, maxBytes = MA
104
89
  if (response.status === 401) {
105
90
  throw new Error(
106
91
  `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"`
92
+ `Individual captures are publicly accessible -- a 401 is unexpected.\n` +
93
+ `Check that the URL points to a specific capture (e.g., /v1/captures/cap_<id>).\n\n` +
94
+ `If you have a local .wacz file, verify it directly:\n` +
95
+ ` npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com`
111
96
  );
112
97
  }
113
98
  throw new Error(`HTTP ${response.status} fetching ${url}`);
@@ -151,10 +136,8 @@ async function fetchBytes(url, { timeoutMs = KEY_FETCH_TIMEOUT_MS, maxBytes = MA
151
136
  export async function fetchWaczFromCaptureUrl(captureUrl) {
152
137
  const origin = originFromUrl(captureUrl);
153
138
  const captureId = captureIdFromUrl(captureUrl);
154
- const token = shareTokenFromUrl(captureUrl);
155
139
 
156
- let waczUrl = `${origin}/v1/captures/${captureId}/artifacts/wacz`;
157
- if (token) waczUrl += `?token=${encodeURIComponent(token)}`;
140
+ const waczUrl = `${origin}/v1/captures/${captureId}/artifacts/wacz`;
158
141
 
159
142
  process.stderr.write(`Fetching capture from ${waczUrl}\n`);
160
143
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@w-r-l/verify",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Verify cryptographic integrity of WRL WACZ web capture bundles",
5
- "license": "Apache-2.0",
5
+ "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Ben Peter <bp@ben-peter.com>",
7
7
  "repository": {
8
8
  "type": "git",