@w-r-l/verify 0.2.1 → 0.4.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 +41 -12
- package/lib/cli.js +18 -2
- package/lib/format-legal.js +743 -0
- package/lib/format.js +113 -5
- package/lib/key-resolver.js +5 -22
- package/lib/verify.js +32 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @w-r-l/verify
|
|
2
2
|
|
|
3
|
-
Verify the cryptographic integrity of [WRL](https://github.com/benpeter/web-resource-ledger) WACZ capture bundles
|
|
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
6
|
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com
|
|
@@ -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
|
|
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/
|
|
26
|
+
npx @w-r-l/verify "https://api.webresourceledger.com/v1/captures/cap_abc123def456..."
|
|
29
27
|
```
|
|
30
28
|
|
|
31
|
-
The
|
|
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
|
|
31
|
+
### Remote capture via server-side verify endpoint
|
|
34
32
|
|
|
35
|
-
The `/v1/verify
|
|
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
|
-
|
|
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
|
|
|
@@ -53,7 +53,7 @@ npx @w-r-l/verify capture.wacz --key <base64-encoded-public-key>
|
|
|
53
53
|
npx @w-r-l/verify capture.wacz --key-file signing-key.pub
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Local files require an explicit key source. The WACZ embeds a public key, but using it would be insecure
|
|
56
|
+
Local files require an explicit key source. The WACZ embeds a public key, but using it would be insecure: an attacker who modifies the capture can also replace the embedded key.
|
|
57
57
|
|
|
58
58
|
### Self-consistency check
|
|
59
59
|
|
|
@@ -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, so 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 (the captured page, when it was captured and signed, its bundle hash, and what the capture service recorded about a partial render, a cut-off screenshot or an error answer from the site), 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 whenever the timestamp authority answered at capture time; the report says so when a capture has none. 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
|
|
@@ -86,6 +107,9 @@ Outputs a single JSON object to stdout. All human messages go to stderr in JSON
|
|
|
86
107
|
"signature": "...",
|
|
87
108
|
"embeddedPublicKey": "...",
|
|
88
109
|
"signedAt": "2026-03-16T14:22:07Z",
|
|
110
|
+
"url": "https://example.com/terms",
|
|
111
|
+
"capturedAt": "2026-03-16T14:22:05Z",
|
|
112
|
+
"quality": { "renderQuality": "full", "waitUntilReached": "load", "timedOut": false, "httpStatus": 200 },
|
|
89
113
|
"timestamp": { "genTime": "2026-03-16T14:22:08Z", "tsa": "DigiCert Timestamp Authority" }
|
|
90
114
|
},
|
|
91
115
|
"keyResolution": {
|
|
@@ -99,6 +123,8 @@ Outputs a single JSON object to stdout. All human messages go to stderr in JSON
|
|
|
99
123
|
}
|
|
100
124
|
```
|
|
101
125
|
|
|
126
|
+
`capture.quality` is the capture service's record of how the page loaded, read from `datapackage.json` and so covered by the signature: whether the render was `full` or `partial` and why (`timedOut`, `subresourceLimitReached`), whether the screenshot shows the whole page (`screenshotClipped`, `pageHeight`, `screenshotHeight`), and the HTTP status the site answered with (`httpStatus`). It is `null` for archives that record none; older captures have only some of the fields. The standard output and the legal report turn it into a note when the capture is partial, the screenshot is cut off, or the status is 400 or higher, for example `Note The site answered with HTTP 403; the capture shows that answer, which can be an error page or a block page`.
|
|
127
|
+
|
|
102
128
|
On errors, `verified` is `null` (not `false`) and an `error` field is present:
|
|
103
129
|
|
|
104
130
|
```json
|
|
@@ -121,6 +147,7 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
|
|
|
121
147
|
--key-file <path> Read public key from file
|
|
122
148
|
--trust-embedded Use the embedded key (insecure)
|
|
123
149
|
--trust-root <path> Additional trusted root certificate (PEM)
|
|
150
|
+
--legal Produce a structured plain-text legal report (WRL-LEGAL-1.0)
|
|
124
151
|
--json Output machine-readable JSON to stdout
|
|
125
152
|
--no-color Disable colored output
|
|
126
153
|
-h, --help Show this help message
|
|
@@ -129,6 +156,8 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
|
|
|
129
156
|
|
|
130
157
|
`--origin`, `--key`, `--key-file`, and `--trust-embedded` are mutually exclusive.
|
|
131
158
|
|
|
159
|
+
`--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.
|
|
160
|
+
|
|
132
161
|
## Requirements
|
|
133
162
|
|
|
134
163
|
Node.js 20 or later.
|
|
@@ -154,9 +183,9 @@ Releases are published to npm automatically when a `verify/v*` tag is pushed.
|
|
|
154
183
|
git push origin main --follow-tags
|
|
155
184
|
```
|
|
156
185
|
|
|
157
|
-
The CI workflow runs tests and publishes to npm with provenance attestation.
|
|
186
|
+
The CI workflow (`.github/workflows/publish-verify.yml`, on a `verify/v*` tag) runs the tests and publishes to npm with provenance attestation. It needs no npm token: npm trusts this repository's workflow as a trusted publisher (OpenID Connect), set up in the package's settings on npmjs.com.
|
|
158
187
|
If the version already exists on npm, the publish step exits cleanly.
|
|
159
188
|
|
|
160
189
|
## License
|
|
161
190
|
|
|
162
|
-
[Apache 2.0](../../LICENSE)
|
|
191
|
+
[Apache 2.0](LICENSE). The verifier is under a permissive license so that anyone (a court, an opposing expert, another archive) can run, copy and build it into their own tools. The rest of WRL is under [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.
|
|
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,743 @@
|
|
|
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, captureQualityNotes } 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
|
+
if (result.capture?.url) {
|
|
272
|
+
out.push(`Page: ${result.capture.url}`);
|
|
273
|
+
}
|
|
274
|
+
out.push(`Source: ${result.source ?? 'unknown'}`);
|
|
275
|
+
out.push(`Verified: ${verifiedAt}`);
|
|
276
|
+
out.push('');
|
|
277
|
+
|
|
278
|
+
// Section 2: Subject of Verification
|
|
279
|
+
out.push('2. SUBJECT OF VERIFICATION');
|
|
280
|
+
out.push(LINE);
|
|
281
|
+
out.push('');
|
|
282
|
+
out.push(wrap(
|
|
283
|
+
'A web resource capture is a snapshot of web content (HTML pages, ' +
|
|
284
|
+
'images, stylesheets, and other resources) preserved in a WACZ ' +
|
|
285
|
+
'(Web Archive Collection Zipped) archive format. The archive ' +
|
|
286
|
+
'includes a cryptographic manifest listing each captured resource ' +
|
|
287
|
+
'and its hash, a digital signature binding the manifest to a ' +
|
|
288
|
+
'signing key, and optionally one or more timestamps from ' +
|
|
289
|
+
'independent authorities.'
|
|
290
|
+
));
|
|
291
|
+
out.push('');
|
|
292
|
+
|
|
293
|
+
const capture = result.capture ?? {};
|
|
294
|
+
if (capture.url) {
|
|
295
|
+
out.push(`Captured page: ${capture.url}`);
|
|
296
|
+
}
|
|
297
|
+
if (capture.capturedAt) {
|
|
298
|
+
out.push(`Captured at: ${capture.capturedAt}`);
|
|
299
|
+
}
|
|
300
|
+
out.push(`Source: ${result.source ?? 'unknown'}`);
|
|
301
|
+
if (capture.signedAt) {
|
|
302
|
+
out.push(`Created: ${capture.signedAt}`);
|
|
303
|
+
}
|
|
304
|
+
if (capture.bundleHash) {
|
|
305
|
+
out.push(`Bundle hash: ${capture.bundleHash}`);
|
|
306
|
+
}
|
|
307
|
+
out.push('');
|
|
308
|
+
|
|
309
|
+
const qualityNotes = captureQualityNotes(capture.quality);
|
|
310
|
+
if (qualityNotes.length > 0) {
|
|
311
|
+
out.push('Recorded by the capture service and covered by the signature:');
|
|
312
|
+
for (const note of qualityNotes) {
|
|
313
|
+
out.push(wrap(`- ${note}.`));
|
|
314
|
+
}
|
|
315
|
+
out.push('');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Section 3: Verification Checks Performed
|
|
319
|
+
out.push('3. VERIFICATION CHECKS PERFORMED');
|
|
320
|
+
out.push(LINE);
|
|
321
|
+
out.push('');
|
|
322
|
+
|
|
323
|
+
let subNum = 1;
|
|
324
|
+
for (const name of checkOrder) {
|
|
325
|
+
const check = checks.find(c => c.name === name);
|
|
326
|
+
if (!check) continue;
|
|
327
|
+
|
|
328
|
+
const label = checkLabel(name);
|
|
329
|
+
const expl = EXPLANATIONS[name];
|
|
330
|
+
|
|
331
|
+
out.push(`3.${subNum} ${label}`);
|
|
332
|
+
out.push('');
|
|
333
|
+
out.push(`Status: ${statusLabel(check.status)}`);
|
|
334
|
+
out.push('');
|
|
335
|
+
|
|
336
|
+
if (expl) {
|
|
337
|
+
out.push(wrap(expl.what));
|
|
338
|
+
out.push('');
|
|
339
|
+
|
|
340
|
+
if (check.status === 'pass') {
|
|
341
|
+
out.push(wrap(expl.pass));
|
|
342
|
+
} else if (check.status === 'fail') {
|
|
343
|
+
out.push(wrap(expl.fail));
|
|
344
|
+
if (check.detail) {
|
|
345
|
+
out.push('');
|
|
346
|
+
out.push(wrap(`Detail: ${check.detail}`));
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
out.push(wrap(expl.skip));
|
|
350
|
+
if (check.detail) {
|
|
351
|
+
out.push('');
|
|
352
|
+
out.push(wrap(`Detail: ${check.detail}`));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
out.push('');
|
|
356
|
+
out.push(wrap(`Evidentiary significance: ${expl.significance}`));
|
|
357
|
+
}
|
|
358
|
+
out.push('');
|
|
359
|
+
|
|
360
|
+
// Timestamp-specific details
|
|
361
|
+
if (name === 'timestamp' && capture.timestamp) {
|
|
362
|
+
out.push(` TSA: ${capture.timestamp.tsa}`);
|
|
363
|
+
out.push(` Time: ${capture.timestamp.genTime}`);
|
|
364
|
+
out.push('');
|
|
365
|
+
}
|
|
366
|
+
if (name === 'qualifiedTimestamp' && capture.qualifiedTimestamp) {
|
|
367
|
+
out.push(` QTSA: ${capture.qualifiedTimestamp.tsa}`);
|
|
368
|
+
out.push(` Time: ${capture.qualifiedTimestamp.genTime}`);
|
|
369
|
+
out.push('');
|
|
370
|
+
out.push(wrap(
|
|
371
|
+
'A standard RFC 3161 timestamp provides cryptographic evidence of ' +
|
|
372
|
+
'time from an independent authority. A qualified electronic ' +
|
|
373
|
+
'timestamp additionally carries a legal presumption under eIDAS ' +
|
|
374
|
+
'Regulation (EU) No 910/2014, Article 41(2), that the date, time, ' +
|
|
375
|
+
'and data integrity are accurate until proven otherwise.'
|
|
376
|
+
));
|
|
377
|
+
out.push('');
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
subNum++;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Section 4: Chain of Custody
|
|
384
|
+
out.push('4. CHAIN OF CUSTODY');
|
|
385
|
+
out.push(LINE);
|
|
386
|
+
out.push('');
|
|
387
|
+
out.push(wrap(
|
|
388
|
+
`The archive was obtained from: ${result.source ?? 'unknown'}`
|
|
389
|
+
));
|
|
390
|
+
out.push('');
|
|
391
|
+
|
|
392
|
+
if (kr) {
|
|
393
|
+
if (kr.source === 'origin' && kr.origin) {
|
|
394
|
+
out.push(wrap(
|
|
395
|
+
`The signing key (ID: ${kr.keyId ?? 'unknown'}) was retrieved ` +
|
|
396
|
+
`from the capture service operator's HTTPS endpoint at ` +
|
|
397
|
+
`${kr.origin}. The key retrieval was performed over an ` +
|
|
398
|
+
'encrypted TLS connection.'
|
|
399
|
+
));
|
|
400
|
+
} else if (kr.source === 'embedded') {
|
|
401
|
+
out.push(wrap(
|
|
402
|
+
`The signing key (ID: ${kr.keyId ?? 'unknown'}) was extracted ` +
|
|
403
|
+
'from the archive itself (embedded key). See the trust level ' +
|
|
404
|
+
'warning in Section 1.'
|
|
405
|
+
));
|
|
406
|
+
} else if (kr.source === 'pinned') {
|
|
407
|
+
out.push(wrap(
|
|
408
|
+
`The signing key (ID: ${kr.keyId ?? 'unknown'}) was provided ` +
|
|
409
|
+
'directly by the party performing this verification.'
|
|
410
|
+
));
|
|
411
|
+
}
|
|
412
|
+
out.push('');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
out.push(wrap(
|
|
416
|
+
'Verification was performed locally on the machine identified in ' +
|
|
417
|
+
'the Methodology section. No data was transmitted to external ' +
|
|
418
|
+
'services during verification.'
|
|
419
|
+
));
|
|
420
|
+
out.push('');
|
|
421
|
+
out.push(wrap(
|
|
422
|
+
'This report is plain text and is not itself digitally signed. ' +
|
|
423
|
+
'The integrity of the verification results can be confirmed by ' +
|
|
424
|
+
're-running the verification using the instructions in the ' +
|
|
425
|
+
'Methodology section.'
|
|
426
|
+
));
|
|
427
|
+
out.push('');
|
|
428
|
+
|
|
429
|
+
// Section 5: Applicable Legal Standards
|
|
430
|
+
out.push('5. APPLICABLE LEGAL STANDARDS');
|
|
431
|
+
out.push(LINE);
|
|
432
|
+
out.push('');
|
|
433
|
+
out.push(wrap(
|
|
434
|
+
'United States -- Federal Rule of Evidence 901(b)(9): This rule ' +
|
|
435
|
+
'provides for authentication of evidence through "evidence ' +
|
|
436
|
+
'describing a process or system and showing that it produces an ' +
|
|
437
|
+
'accurate result." This report is structured to support ' +
|
|
438
|
+
'authentication under this provision by describing the ' +
|
|
439
|
+
'verification process, the cryptographic algorithms employed, ' +
|
|
440
|
+
'and the results obtained.'
|
|
441
|
+
));
|
|
442
|
+
out.push('');
|
|
443
|
+
|
|
444
|
+
// eIDAS section -- always present, but qualified timestamp significance
|
|
445
|
+
// highlighted when one exists
|
|
446
|
+
const hasQualified = checks.some(
|
|
447
|
+
c => c.name === 'qualifiedTimestamp' && c.status === 'pass'
|
|
448
|
+
);
|
|
449
|
+
out.push(wrap(
|
|
450
|
+
'European Union -- eIDAS Regulation (EU) No 910/2014: Article 41(1) ' +
|
|
451
|
+
'provides that an electronic timestamp shall not be denied legal ' +
|
|
452
|
+
'effect and admissibility as evidence in legal proceedings solely ' +
|
|
453
|
+
'on the grounds that it is in electronic form or that it does not ' +
|
|
454
|
+
'meet the requirements of a qualified electronic timestamp.'
|
|
455
|
+
));
|
|
456
|
+
out.push('');
|
|
457
|
+
|
|
458
|
+
if (hasQualified) {
|
|
459
|
+
out.push(wrap(
|
|
460
|
+
'This capture includes a qualified electronic timestamp. Under ' +
|
|
461
|
+
'Article 41(2), a qualified electronic timestamp enjoys a ' +
|
|
462
|
+
'presumption of the accuracy of the date and time it indicates ' +
|
|
463
|
+
'and of the integrity of the data to which the date and time ' +
|
|
464
|
+
'are bound.'
|
|
465
|
+
));
|
|
466
|
+
out.push('');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
out.push(wrap(LEGAL_DISCLAIMER));
|
|
470
|
+
out.push('');
|
|
471
|
+
|
|
472
|
+
// Section 6: Methodology
|
|
473
|
+
out.push('6. METHODOLOGY');
|
|
474
|
+
out.push(LINE);
|
|
475
|
+
out.push('');
|
|
476
|
+
out.push(`Tool: @w-r-l/verify`);
|
|
477
|
+
out.push(`Version: ${version}`);
|
|
478
|
+
out.push(`Source: https://www.npmjs.com/package/@w-r-l/verify`);
|
|
479
|
+
out.push(`Runtime: Node.js ${process.versions.node}`);
|
|
480
|
+
out.push(`Platform: ${process.platform} ${process.arch}`);
|
|
481
|
+
out.push('');
|
|
482
|
+
|
|
483
|
+
out.push('Cryptographic algorithms:');
|
|
484
|
+
for (const alg of ALGORITHMS) {
|
|
485
|
+
out.push(` ${alg.name.padEnd(12)} ${alg.standard.padEnd(20)} ${alg.purpose}`);
|
|
486
|
+
}
|
|
487
|
+
out.push('');
|
|
488
|
+
|
|
489
|
+
out.push(wrap(
|
|
490
|
+
'All cryptographic operations use the Node.js built-in crypto ' +
|
|
491
|
+
'module (Web Crypto API for Ed25519 signature verification).'
|
|
492
|
+
));
|
|
493
|
+
out.push('');
|
|
494
|
+
|
|
495
|
+
out.push('Limitations:');
|
|
496
|
+
for (const lim of LIMITATIONS) {
|
|
497
|
+
out.push(wrap(`- ${lim}`, 2));
|
|
498
|
+
}
|
|
499
|
+
out.push('');
|
|
500
|
+
|
|
501
|
+
// Reproducibility
|
|
502
|
+
out.push('Reproducibility:');
|
|
503
|
+
out.push(wrap(
|
|
504
|
+
'To independently verify this capture, install @w-r-l/verify ' +
|
|
505
|
+
`version ${version} and run:`
|
|
506
|
+
));
|
|
507
|
+
out.push('');
|
|
508
|
+
// Build command from result, not process.argv (security: avoid leaking paths)
|
|
509
|
+
let cmd = ` npx @w-r-l/verify@${version} ${shellQuote(result.source ?? '<file-or-url>')}`;
|
|
510
|
+
if (kr?.source === 'origin' && kr.origin) {
|
|
511
|
+
cmd += ` --origin ${shellQuote(kr.origin)}`;
|
|
512
|
+
} else if (kr?.source === 'embedded') {
|
|
513
|
+
cmd += ' --trust-embedded';
|
|
514
|
+
}
|
|
515
|
+
cmd += ' --legal';
|
|
516
|
+
out.push(cmd);
|
|
517
|
+
out.push('');
|
|
518
|
+
out.push(wrap(
|
|
519
|
+
'If custom trust root certificates were used during the original ' +
|
|
520
|
+
'verification (via --trust-root), they must be supplied again when ' +
|
|
521
|
+
're-running the command above.'
|
|
522
|
+
));
|
|
523
|
+
out.push('');
|
|
524
|
+
|
|
525
|
+
// Section 7: Full Technical Details
|
|
526
|
+
out.push('7. FULL TECHNICAL DETAILS');
|
|
527
|
+
out.push(LINE);
|
|
528
|
+
out.push('');
|
|
529
|
+
out.push(wrap(
|
|
530
|
+
'The following values are provided untruncated for independent ' +
|
|
531
|
+
'verification and cross-reference with other records.'
|
|
532
|
+
));
|
|
533
|
+
out.push('');
|
|
534
|
+
|
|
535
|
+
if (capture.bundleHash) {
|
|
536
|
+
out.push(`Bundle hash: ${capture.bundleHash}`);
|
|
537
|
+
}
|
|
538
|
+
if (capture.signature) {
|
|
539
|
+
out.push(`Signature: ${capture.signature}`);
|
|
540
|
+
}
|
|
541
|
+
if (capture.publicKey) {
|
|
542
|
+
out.push(`Embedded key: ${capture.publicKey}`);
|
|
543
|
+
// Repeat trust warning inline for embedded key
|
|
544
|
+
if (kr?.source === 'embedded') {
|
|
545
|
+
out.push(' (SELF-ASSERTED -- see trust warning in');
|
|
546
|
+
out.push(' Section 1)');
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (kr?.keyId) {
|
|
550
|
+
out.push(`Key ID: ${kr.keyId}`);
|
|
551
|
+
}
|
|
552
|
+
if (kr?.source) {
|
|
553
|
+
const sourceLabel = kr.source === 'origin'
|
|
554
|
+
? `operator (${kr.origin ?? 'unknown'})`
|
|
555
|
+
: kr.source === 'embedded'
|
|
556
|
+
? 'embedded in archive (self-asserted)'
|
|
557
|
+
: 'user-provided';
|
|
558
|
+
out.push(`Key source: ${sourceLabel}`);
|
|
559
|
+
}
|
|
560
|
+
out.push('');
|
|
561
|
+
|
|
562
|
+
out.push('Timestamps:');
|
|
563
|
+
out.push('');
|
|
564
|
+
if (capture.signedAt) {
|
|
565
|
+
out.push(` Capture time: ${capture.signedAt}`);
|
|
566
|
+
out.push(' (self-asserted by capture service)');
|
|
567
|
+
}
|
|
568
|
+
if (capture.timestamp) {
|
|
569
|
+
out.push(` TSA time: ${capture.timestamp.genTime}`);
|
|
570
|
+
out.push(` TSA identity: ${capture.timestamp.tsa}`);
|
|
571
|
+
out.push(' (independent RFC 3161 timestamp)');
|
|
572
|
+
}
|
|
573
|
+
if (capture.qualifiedTimestamp) {
|
|
574
|
+
out.push(` QTSA time: ${capture.qualifiedTimestamp.genTime}`);
|
|
575
|
+
out.push(` QTSA identity: ${capture.qualifiedTimestamp.tsa}`);
|
|
576
|
+
out.push(' (qualified timestamp -- eIDAS Art. 41)');
|
|
577
|
+
}
|
|
578
|
+
out.push(` Verification time: ${verifiedAt}`);
|
|
579
|
+
out.push(' (time this report was generated)');
|
|
580
|
+
out.push('');
|
|
581
|
+
|
|
582
|
+
out.push(DOUBLE);
|
|
583
|
+
out.push('END OF VERIFICATION REPORT');
|
|
584
|
+
out.push(DOUBLE);
|
|
585
|
+
out.push('');
|
|
586
|
+
|
|
587
|
+
process.stdout.write(out.join('\n'));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// ---------------------------------------------------------------------------
|
|
591
|
+
// formatLegalJson -- JSON legal report
|
|
592
|
+
// ---------------------------------------------------------------------------
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Formats a verification result as a JSON legal report.
|
|
596
|
+
* Includes explanatory fields, legal context, and methodology.
|
|
597
|
+
*
|
|
598
|
+
* @param {object} result The verification result from verifyWacz()
|
|
599
|
+
* @param {{ version: string }} opts Options including tool version
|
|
600
|
+
*/
|
|
601
|
+
export function formatLegalJson(result, opts = {}) {
|
|
602
|
+
const version = opts.version ?? '0.0.0';
|
|
603
|
+
const verifiedAt = new Date().toISOString();
|
|
604
|
+
const capture = result.capture ?? {};
|
|
605
|
+
const kr = result.keyResolution ?? {};
|
|
606
|
+
const checks = result.checks ?? [];
|
|
607
|
+
|
|
608
|
+
const applicable = checks.filter(c => c.status !== 'skip');
|
|
609
|
+
const failed = applicable.filter(c => c.status === 'fail');
|
|
610
|
+
|
|
611
|
+
let summaryStatement;
|
|
612
|
+
if (failed.length === 0) {
|
|
613
|
+
summaryStatement =
|
|
614
|
+
`All ${applicable.length} cryptographic checks passed. ` +
|
|
615
|
+
'No evidence of modification was detected.';
|
|
616
|
+
} else {
|
|
617
|
+
summaryStatement =
|
|
618
|
+
`${failed.length} of ${applicable.length} check(s) failed. ` +
|
|
619
|
+
'This capture cannot be verified as unmodified.';
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const enrichedChecks = checks.map(c => {
|
|
623
|
+
const expl = EXPLANATIONS[c.name] ?? {};
|
|
624
|
+
return {
|
|
625
|
+
name: c.name,
|
|
626
|
+
label: checkLabel(c.name),
|
|
627
|
+
status: c.status,
|
|
628
|
+
detail: c.detail ?? null,
|
|
629
|
+
explanation: expl.what ?? null,
|
|
630
|
+
result: expl[c.status] ?? null,
|
|
631
|
+
significance: expl.significance ?? null,
|
|
632
|
+
};
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
// Timestamps -- separate standard and qualified
|
|
636
|
+
const timestamps = {};
|
|
637
|
+
if (capture.timestamp) {
|
|
638
|
+
timestamps.standard = {
|
|
639
|
+
genTime: capture.timestamp.genTime,
|
|
640
|
+
tsa: capture.timestamp.tsa,
|
|
641
|
+
type: 'RFC 3161',
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
if (capture.qualifiedTimestamp) {
|
|
645
|
+
timestamps.qualified = {
|
|
646
|
+
genTime: capture.qualifiedTimestamp.genTime,
|
|
647
|
+
tsa: capture.qualifiedTimestamp.tsa,
|
|
648
|
+
type: 'eIDAS qualified (EU No 910/2014, Art. 41)',
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
if (capture.signedAt) {
|
|
652
|
+
timestamps.capture = {
|
|
653
|
+
time: capture.signedAt,
|
|
654
|
+
source: 'self-asserted by capture service',
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
timestamps.verification = {
|
|
658
|
+
time: verifiedAt,
|
|
659
|
+
source: 'generated by verification tool',
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// Key resolution with trust model
|
|
663
|
+
let trustModel;
|
|
664
|
+
if (kr.source === 'embedded') {
|
|
665
|
+
trustModel = 'Self-asserted (limited). The signing key was embedded ' +
|
|
666
|
+
'in the archive. This proves internal consistency only, not provenance.';
|
|
667
|
+
} else if (kr.source === 'origin') {
|
|
668
|
+
trustModel = `Operator-published. The signing key was retrieved from ` +
|
|
669
|
+
`${kr.origin ?? 'the operator'} over HTTPS.`;
|
|
670
|
+
} else if (kr.source === 'pinned') {
|
|
671
|
+
trustModel = 'User-provided. The signing key was supplied directly ' +
|
|
672
|
+
'by the verifier.';
|
|
673
|
+
} else {
|
|
674
|
+
trustModel = null;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
const out = {
|
|
678
|
+
reportFormat: REPORT_FORMAT,
|
|
679
|
+
verified: result.verified ?? null,
|
|
680
|
+
tool: {
|
|
681
|
+
name: '@w-r-l/verify',
|
|
682
|
+
version,
|
|
683
|
+
nodeVersion: process.versions.node,
|
|
684
|
+
platform: process.platform,
|
|
685
|
+
arch: process.arch,
|
|
686
|
+
},
|
|
687
|
+
summary: {
|
|
688
|
+
statement: summaryStatement,
|
|
689
|
+
verified: result.verified ?? null,
|
|
690
|
+
source: result.source ?? null,
|
|
691
|
+
capturedUrl: capture.url ?? null,
|
|
692
|
+
captureDate: capture.signedAt ?? null,
|
|
693
|
+
},
|
|
694
|
+
checks: enrichedChecks,
|
|
695
|
+
capture: {
|
|
696
|
+
bundleHash: capture.bundleHash ?? null,
|
|
697
|
+
signature: capture.signature ?? null,
|
|
698
|
+
embeddedPublicKey: capture.publicKey ?? null,
|
|
699
|
+
signedAt: capture.signedAt ?? null,
|
|
700
|
+
url: capture.url ?? null,
|
|
701
|
+
capturedAt: capture.capturedAt ?? null,
|
|
702
|
+
quality: capture.quality ?? null,
|
|
703
|
+
},
|
|
704
|
+
timestamps,
|
|
705
|
+
keyResolution: {
|
|
706
|
+
keyId: kr.keyId ?? null,
|
|
707
|
+
source: kr.source ?? null,
|
|
708
|
+
origin: kr.origin ?? null,
|
|
709
|
+
endpoint: kr.endpoint ?? null,
|
|
710
|
+
publicKey: capture.publicKey ?? null,
|
|
711
|
+
trustModel,
|
|
712
|
+
},
|
|
713
|
+
legalContext: {
|
|
714
|
+
disclaimer: LEGAL_DISCLAIMER.replace(/\n/g, ' '),
|
|
715
|
+
applicableFrameworks: [
|
|
716
|
+
{
|
|
717
|
+
jurisdiction: 'United States',
|
|
718
|
+
reference: 'Federal Rule of Evidence 901(b)(9)',
|
|
719
|
+
relevance: 'Authentication of evidence through description of ' +
|
|
720
|
+
'a process or system showing it produces an accurate result.',
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
jurisdiction: 'European Union',
|
|
724
|
+
reference: 'eIDAS Regulation (EU) No 910/2014, Article 41',
|
|
725
|
+
relevance: 'Electronic timestamps shall not be denied legal ' +
|
|
726
|
+
'effect solely on the grounds of electronic form.',
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
},
|
|
730
|
+
methodology: {
|
|
731
|
+
algorithms: ALGORITHMS.map(a => ({
|
|
732
|
+
name: a.name,
|
|
733
|
+
standard: a.standard,
|
|
734
|
+
purpose: a.purpose,
|
|
735
|
+
})),
|
|
736
|
+
cryptoLibrary: 'Node.js built-in crypto (Web Crypto API for Ed25519)',
|
|
737
|
+
limitations: LIMITATIONS,
|
|
738
|
+
},
|
|
739
|
+
verifiedAt,
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
process.stdout.write(JSON.stringify(out, null, 2) + '\n');
|
|
743
|
+
}
|
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
|
-
'
|
|
60
|
-
'qualifiedTimestamp',
|
|
60
|
+
'timeVerification',
|
|
61
61
|
'timestampChain',
|
|
62
62
|
];
|
|
63
63
|
|
|
@@ -67,10 +67,105 @@ 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
|
+
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Capture quality notes
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* What a reader should know about the capture before relying on it, from the
|
|
145
|
+
* capture service's signed record: a partial render, a screenshot that shows
|
|
146
|
+
* only the top of the page, an error answer from the site. Empty for a full
|
|
147
|
+
* capture of a page that answered normally.
|
|
148
|
+
*
|
|
149
|
+
* @param {object|null|undefined} quality result.capture.quality
|
|
150
|
+
* @returns {string[]} sentences without a full stop
|
|
151
|
+
*/
|
|
152
|
+
export function captureQualityNotes(quality) {
|
|
153
|
+
if (!quality) return [];
|
|
154
|
+
const notes = [];
|
|
155
|
+
if (quality.renderQuality === 'partial') {
|
|
156
|
+
notes.push(quality.subresourceLimitReached && !quality.timedOut
|
|
157
|
+
? 'Partial capture: the page made more requests than the capture service allows, so content that loads late may be missing'
|
|
158
|
+
: 'Partial capture: the page had not finished loading, so content that loads late may be missing');
|
|
159
|
+
}
|
|
160
|
+
if (quality.screenshotClipped && quality.screenshotHeight && quality.pageHeight) {
|
|
161
|
+
notes.push(`The screenshot shows the top ${quality.screenshotHeight} px of a ${quality.pageHeight} px page; the HTML has the whole page`);
|
|
162
|
+
}
|
|
163
|
+
if (quality.httpStatus >= 400) {
|
|
164
|
+
notes.push(`The site answered with HTTP ${quality.httpStatus}; the capture shows that answer, which can be an error page or a block page`);
|
|
165
|
+
}
|
|
166
|
+
return notes;
|
|
167
|
+
}
|
|
168
|
+
|
|
74
169
|
// ---------------------------------------------------------------------------
|
|
75
170
|
// Human-readable formatter
|
|
76
171
|
// ---------------------------------------------------------------------------
|
|
@@ -86,6 +181,7 @@ function checkLabel(name) {
|
|
|
86
181
|
* signature?: string,
|
|
87
182
|
* publicKey?: string,
|
|
88
183
|
* signedAt?: string,
|
|
184
|
+
* quality?: object|null,
|
|
89
185
|
* timestamp?: { genTime: string, tsa: string },
|
|
90
186
|
* qualifiedTimestamp?: { genTime: string, tsa: string }
|
|
91
187
|
* },
|
|
@@ -102,13 +198,16 @@ function checkLabel(name) {
|
|
|
102
198
|
export function formatHuman(result, opts = {}) {
|
|
103
199
|
const color = shouldColor(opts);
|
|
104
200
|
|
|
201
|
+
// Merge timestamp checks before ordering
|
|
202
|
+
const merged = mergeTimestampChecks(result.checks);
|
|
203
|
+
|
|
105
204
|
// Sort checks into fixed display order, preserving any extras at the end
|
|
106
205
|
const orderedChecks = [];
|
|
107
206
|
for (const name of CHECK_ORDER) {
|
|
108
|
-
const c =
|
|
207
|
+
const c = merged.find(ch => ch.name === name);
|
|
109
208
|
if (c) orderedChecks.push(c);
|
|
110
209
|
}
|
|
111
|
-
for (const c of
|
|
210
|
+
for (const c of merged) {
|
|
112
211
|
if (!CHECK_ORDER.includes(c.name)) orderedChecks.push(c);
|
|
113
212
|
}
|
|
114
213
|
|
|
@@ -143,6 +242,15 @@ export function formatHuman(result, opts = {}) {
|
|
|
143
242
|
// Metadata block
|
|
144
243
|
process.stdout.write('\n');
|
|
145
244
|
|
|
245
|
+
const pageUrl = result.capture?.url;
|
|
246
|
+
if (pageUrl) {
|
|
247
|
+
process.stdout.write(` Page ${pageUrl}\n`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
for (const note of captureQualityNotes(result.capture?.quality)) {
|
|
251
|
+
process.stdout.write(` Note ${note}\n`);
|
|
252
|
+
}
|
|
253
|
+
|
|
146
254
|
const signedAt = result.capture?.signedAt;
|
|
147
255
|
if (signedAt) {
|
|
148
256
|
process.stdout.write(` Signed ${signedAt}\n`);
|
package/lib/key-resolver.js
CHANGED
|
@@ -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
|
-
`
|
|
108
|
-
`
|
|
109
|
-
`
|
|
110
|
-
` npx @w-r-l/verify
|
|
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
|
-
|
|
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/lib/verify.js
CHANGED
|
@@ -34,6 +34,33 @@ const MAX_DECOMPRESSED = 100 * 1024 * 1024; // 100 MB
|
|
|
34
34
|
// Public API
|
|
35
35
|
// ---------------------------------------------------------------------------
|
|
36
36
|
|
|
37
|
+
const WAIT_MILESTONES = ['domcontentloaded', 'load', 'networkidle'];
|
|
38
|
+
const QUALITY_FLAGS = ['timedOut', 'subresourceLimitReached', 'screenshotClipped'];
|
|
39
|
+
const QUALITY_NUMBERS = ['pageHeight', 'screenshotHeight', 'httpStatus'];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reads the captureQuality record of datapackage.json: how far the page got,
|
|
43
|
+
* how much of it the screenshot shows, what status the site answered with.
|
|
44
|
+
* Keeps only the fields this tool knows, each with the type it expects, so
|
|
45
|
+
* nothing else from the archive reaches the output.
|
|
46
|
+
*
|
|
47
|
+
* @param {*} raw datapackage.captureQuality
|
|
48
|
+
* @returns {object|null} null when the archive records none
|
|
49
|
+
*/
|
|
50
|
+
function readCaptureQuality(raw) {
|
|
51
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
52
|
+
const quality = {};
|
|
53
|
+
if (raw.renderQuality === 'full' || raw.renderQuality === 'partial') quality.renderQuality = raw.renderQuality;
|
|
54
|
+
if (WAIT_MILESTONES.includes(raw.waitUntilReached)) quality.waitUntilReached = raw.waitUntilReached;
|
|
55
|
+
for (const name of QUALITY_FLAGS) {
|
|
56
|
+
if (typeof raw[name] === 'boolean') quality[name] = raw[name];
|
|
57
|
+
}
|
|
58
|
+
for (const name of QUALITY_NUMBERS) {
|
|
59
|
+
if (Number.isInteger(raw[name])) quality[name] = raw[name];
|
|
60
|
+
}
|
|
61
|
+
return Object.keys(quality).length > 0 ? quality : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
37
64
|
/**
|
|
38
65
|
* Verifies a WACZ file against a trusted Ed25519 public key.
|
|
39
66
|
*
|
|
@@ -300,6 +327,11 @@ export async function verifyWacz(waczBytes, publicKeyBytes, options = {}) {
|
|
|
300
327
|
signature: selfSig?.signature ?? null,
|
|
301
328
|
publicKey: selfSig?.publicKey ?? null, // informational only -- NOT used for verification
|
|
302
329
|
signedAt: signedData.created ?? null,
|
|
330
|
+
// The captured page, from datapackage.json: covered by the bundle hash
|
|
331
|
+
url: typeof datapackage.mainPageUrl === 'string' ? datapackage.mainPageUrl : null,
|
|
332
|
+
capturedAt: typeof datapackage.mainPageDate === 'string' ? datapackage.mainPageDate : null,
|
|
333
|
+
// How the page loaded, as the capture service recorded it: also in datapackage.json
|
|
334
|
+
quality: readCaptureQuality(datapackage.captureQuality),
|
|
303
335
|
};
|
|
304
336
|
if (timestampData) {
|
|
305
337
|
result.capture.timestamp = timestampData;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w-r-l/verify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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>",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"LICENSE"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"fflate": "^0.8.
|
|
42
|
+
"fflate": "^0.8.3",
|
|
43
43
|
"pkijs": "3.3.3",
|
|
44
44
|
"asn1js": "3.0.5",
|
|
45
45
|
"pvutils": "1.1.3"
|