@w-r-l/verify 0.1.0 → 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 +69 -9
- package/lib/cli.js +18 -2
- package/lib/format-legal.js +721 -0
- package/lib/format.js +86 -10
- package/lib/key-resolver.js +12 -2
- package/lib/verify.js +29 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Verify the cryptographic integrity of [WRL](https://github.com/benpeter/web-resource-ledger) WACZ capture bundles -- offline, zero-install.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
6
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## What it checks
|
|
@@ -20,19 +20,31 @@ Exit code `0` means all applicable checks passed. Exit code `1` means one or mor
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
-
### Remote capture
|
|
23
|
+
### Remote capture
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npx @w-r-l/verify https://
|
|
26
|
+
npx @w-r-l/verify "https://api.webresourceledger.com/v1/captures/cap_abc123def456..."
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
The signing key is fetched
|
|
29
|
+
The signing key is fetched from the server automatically. Individual captures are publicly accessible -- no authentication or tokens are needed.
|
|
30
|
+
|
|
31
|
+
### Remote capture via server-side verify endpoint
|
|
32
|
+
|
|
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:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx @w-r-l/verify https://api.webresourceledger.com/v1/verify/cap_abc123def456...
|
|
37
|
+
```
|
|
38
|
+
|
|
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)
|
|
30
42
|
|
|
31
43
|
### Local file
|
|
32
44
|
|
|
33
45
|
```bash
|
|
34
46
|
# Fetch the key from the operator
|
|
35
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
47
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com
|
|
36
48
|
|
|
37
49
|
# Or provide the key directly
|
|
38
50
|
npx @w-r-l/verify capture.wacz --key <base64-encoded-public-key>
|
|
@@ -51,10 +63,31 @@ npx @w-r-l/verify capture.wacz --trust-embedded
|
|
|
51
63
|
|
|
52
64
|
Uses the key embedded in the WACZ. This proves the archive is internally consistent, but not that it came from a trusted operator.
|
|
53
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
|
+
|
|
54
87
|
### JSON output
|
|
55
88
|
|
|
56
89
|
```bash
|
|
57
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
90
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com --json
|
|
58
91
|
```
|
|
59
92
|
|
|
60
93
|
Outputs a single JSON object to stdout. All human messages go to stderr in JSON mode.
|
|
@@ -79,7 +112,7 @@ Outputs a single JSON object to stdout. All human messages go to stderr in JSON
|
|
|
79
112
|
"keyResolution": {
|
|
80
113
|
"keyId": "a1b2c3d4",
|
|
81
114
|
"source": "origin",
|
|
82
|
-
"origin": "https://
|
|
115
|
+
"origin": "https://api.webresourceledger.com",
|
|
83
116
|
"endpoint": "/.well-known/signing-keys"
|
|
84
117
|
},
|
|
85
118
|
"source": "capture.wacz",
|
|
@@ -96,7 +129,7 @@ On errors, `verified` is `null` (not `false`) and an `error` field is present:
|
|
|
96
129
|
### Additional trusted roots
|
|
97
130
|
|
|
98
131
|
```bash
|
|
99
|
-
npx @w-r-l/verify capture.wacz --origin https://
|
|
132
|
+
npx @w-r-l/verify capture.wacz --origin https://api.webresourceledger.com --trust-root /path/to/extra-root.pem
|
|
100
133
|
```
|
|
101
134
|
|
|
102
135
|
The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to add PEM certificates for other timestamp authorities. Can be specified multiple times.
|
|
@@ -109,6 +142,7 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
|
|
|
109
142
|
--key-file <path> Read public key from file
|
|
110
143
|
--trust-embedded Use the embedded key (insecure)
|
|
111
144
|
--trust-root <path> Additional trusted root certificate (PEM)
|
|
145
|
+
--legal Produce a structured plain-text legal report (WRL-LEGAL-1.0)
|
|
112
146
|
--json Output machine-readable JSON to stdout
|
|
113
147
|
--no-color Disable colored output
|
|
114
148
|
-h, --help Show this help message
|
|
@@ -117,10 +151,36 @@ The tool bundles the DigiCert Trusted Root G4 certificate. Use `--trust-root` to
|
|
|
117
151
|
|
|
118
152
|
`--origin`, `--key`, `--key-file`, and `--trust-embedded` are mutually exclusive.
|
|
119
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
|
+
|
|
120
156
|
## Requirements
|
|
121
157
|
|
|
122
158
|
Node.js 20 or later.
|
|
123
159
|
|
|
160
|
+
## Releasing
|
|
161
|
+
|
|
162
|
+
Releases are published to npm automatically when a `verify/v*` tag is pushed.
|
|
163
|
+
|
|
164
|
+
**Steps:**
|
|
165
|
+
|
|
166
|
+
1. Generate the changelog (review and edit before proceeding):
|
|
167
|
+
```bash
|
|
168
|
+
./scripts/changelog-verify.sh patch # or minor, major
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
2. Bump version, commit, and create tag:
|
|
172
|
+
```bash
|
|
173
|
+
cd packages/verify && npm version patch -m "chore(verify): release %s"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
3. Push the commit and tag:
|
|
177
|
+
```bash
|
|
178
|
+
git push origin main --follow-tags
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The CI workflow runs tests and publishes to npm with provenance attestation.
|
|
182
|
+
If the version already exists on npm, the publish step exits cleanly.
|
|
183
|
+
|
|
124
184
|
## License
|
|
125
185
|
|
|
126
|
-
[
|
|
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.
|
|
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
|
@@ -43,11 +43,13 @@ function bold(text, color) { return color ? `${ANSI_BOLD}${text}${ANSI_RESET}`
|
|
|
43
43
|
// ---------------------------------------------------------------------------
|
|
44
44
|
|
|
45
45
|
const CHECK_LABELS = {
|
|
46
|
-
artifactHashes:
|
|
47
|
-
bundleHash:
|
|
48
|
-
signature:
|
|
49
|
-
timestamp:
|
|
50
|
-
|
|
46
|
+
artifactHashes: 'File integrity',
|
|
47
|
+
bundleHash: 'Bundle integrity',
|
|
48
|
+
signature: 'Digital signature',
|
|
49
|
+
timestamp: 'Timestamp imprint',
|
|
50
|
+
qualifiedTimestamp: 'Qualified timestamp',
|
|
51
|
+
timeVerification: 'Time verification',
|
|
52
|
+
timestampChain: 'Timestamp chain',
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
// Fixed display order
|
|
@@ -55,7 +57,7 @@ const CHECK_ORDER = [
|
|
|
55
57
|
'artifactHashes',
|
|
56
58
|
'bundleHash',
|
|
57
59
|
'signature',
|
|
58
|
-
'
|
|
60
|
+
'timeVerification',
|
|
59
61
|
'timestampChain',
|
|
60
62
|
];
|
|
61
63
|
|
|
@@ -65,10 +67,75 @@ const CHECK_ORDER = [
|
|
|
65
67
|
* @param {string} name
|
|
66
68
|
* @returns {string}
|
|
67
69
|
*/
|
|
68
|
-
function checkLabel(name) {
|
|
70
|
+
export function checkLabel(name) {
|
|
69
71
|
return CHECK_LABELS[name] ?? name;
|
|
70
72
|
}
|
|
71
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
|
+
|
|
72
139
|
// ---------------------------------------------------------------------------
|
|
73
140
|
// Human-readable formatter
|
|
74
141
|
// ---------------------------------------------------------------------------
|
|
@@ -84,7 +151,8 @@ function checkLabel(name) {
|
|
|
84
151
|
* signature?: string,
|
|
85
152
|
* publicKey?: string,
|
|
86
153
|
* signedAt?: string,
|
|
87
|
-
* timestamp?: { genTime: string, tsa: string }
|
|
154
|
+
* timestamp?: { genTime: string, tsa: string },
|
|
155
|
+
* qualifiedTimestamp?: { genTime: string, tsa: string }
|
|
88
156
|
* },
|
|
89
157
|
* keyResolution?: {
|
|
90
158
|
* keyId: string,
|
|
@@ -99,13 +167,16 @@ function checkLabel(name) {
|
|
|
99
167
|
export function formatHuman(result, opts = {}) {
|
|
100
168
|
const color = shouldColor(opts);
|
|
101
169
|
|
|
170
|
+
// Merge timestamp checks before ordering
|
|
171
|
+
const merged = mergeTimestampChecks(result.checks);
|
|
172
|
+
|
|
102
173
|
// Sort checks into fixed display order, preserving any extras at the end
|
|
103
174
|
const orderedChecks = [];
|
|
104
175
|
for (const name of CHECK_ORDER) {
|
|
105
|
-
const c =
|
|
176
|
+
const c = merged.find(ch => ch.name === name);
|
|
106
177
|
if (c) orderedChecks.push(c);
|
|
107
178
|
}
|
|
108
|
-
for (const c of
|
|
179
|
+
for (const c of merged) {
|
|
109
180
|
if (!CHECK_ORDER.includes(c.name)) orderedChecks.push(c);
|
|
110
181
|
}
|
|
111
182
|
|
|
@@ -150,6 +221,11 @@ export function formatHuman(result, opts = {}) {
|
|
|
150
221
|
process.stdout.write(` TSA ${tsa}\n`);
|
|
151
222
|
}
|
|
152
223
|
|
|
224
|
+
const qtsa = result.capture?.qualifiedTimestamp?.tsa;
|
|
225
|
+
if (qtsa) {
|
|
226
|
+
process.stdout.write(` QTSA ${qtsa} (eIDAS)\n`);
|
|
227
|
+
}
|
|
228
|
+
|
|
153
229
|
const kr = result.keyResolution;
|
|
154
230
|
if (kr?.keyId) {
|
|
155
231
|
let keySource;
|
package/lib/key-resolver.js
CHANGED
|
@@ -86,6 +86,15 @@ async function fetchBytes(url, { timeoutMs = KEY_FETCH_TIMEOUT_MS, maxBytes = MA
|
|
|
86
86
|
clearTimeout(timer);
|
|
87
87
|
|
|
88
88
|
if (!response.ok) {
|
|
89
|
+
if (response.status === 401) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`HTTP 401 fetching ${url}\n\n` +
|
|
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`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
89
98
|
throw new Error(`HTTP ${response.status} fetching ${url}`);
|
|
90
99
|
}
|
|
91
100
|
|
|
@@ -127,7 +136,8 @@ async function fetchBytes(url, { timeoutMs = KEY_FETCH_TIMEOUT_MS, maxBytes = MA
|
|
|
127
136
|
export async function fetchWaczFromCaptureUrl(captureUrl) {
|
|
128
137
|
const origin = originFromUrl(captureUrl);
|
|
129
138
|
const captureId = captureIdFromUrl(captureUrl);
|
|
130
|
-
|
|
139
|
+
|
|
140
|
+
const waczUrl = `${origin}/v1/captures/${captureId}/artifacts/wacz`;
|
|
131
141
|
|
|
132
142
|
process.stderr.write(`Fetching capture from ${waczUrl}\n`);
|
|
133
143
|
|
|
@@ -407,7 +417,7 @@ export async function resolveKey(options) {
|
|
|
407
417
|
`insecure -- an attacker who modifies the capture can also replace the\n` +
|
|
408
418
|
`embedded key.\n\n` +
|
|
409
419
|
`Specify one of:\n` +
|
|
410
|
-
` --origin https://
|
|
420
|
+
` --origin https://api.webresourceledger.com Fetch key from the operator\n` +
|
|
411
421
|
` --key <base64> Provide key directly\n` +
|
|
412
422
|
` --key-file <path> Read key from file\n\n` +
|
|
413
423
|
`The embedded keyId is: ${embeddedKeyId}`
|
package/lib/verify.js
CHANGED
|
@@ -233,7 +233,32 @@ export async function verifyWacz(waczBytes, publicKeyBytes, options = {}) {
|
|
|
233
233
|
// For v0.1.0: no timestamp check at all (3 checks, not 4)
|
|
234
234
|
|
|
235
235
|
// ---------------------------------------------------------------------------
|
|
236
|
-
// Check 5:
|
|
236
|
+
// Check 5: qualifiedTimestamp (v0.2.0 only, when present)
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
let qualifiedTimestampData = null;
|
|
239
|
+
if (version === '0.2.0') {
|
|
240
|
+
const sigs = signedData?.signatures ?? [];
|
|
241
|
+
const qtsEntry = sigs.find(s => s.type === 'rfc3161_qualified');
|
|
242
|
+
|
|
243
|
+
if (!qtsEntry) {
|
|
244
|
+
// Absent = not requested. Do NOT push a skip check -- simply omit.
|
|
245
|
+
} else {
|
|
246
|
+
try {
|
|
247
|
+
const result = verifyTimestamp(qtsEntry.token, signedData.hash);
|
|
248
|
+
if (result.valid) {
|
|
249
|
+
checks.push({ name: 'qualifiedTimestamp', status: 'pass' });
|
|
250
|
+
qualifiedTimestampData = { genTime: result.genTime, tsa: qtsEntry.tsa };
|
|
251
|
+
} else {
|
|
252
|
+
checks.push({ name: 'qualifiedTimestamp', status: 'fail', detail: 'Qualified timestamp structurally invalid' });
|
|
253
|
+
}
|
|
254
|
+
} catch {
|
|
255
|
+
checks.push({ name: 'qualifiedTimestamp', status: 'fail', detail: 'Qualified timestamp structurally invalid' });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// Check 6: timestampChain (CLI only -- CMS certificate chain validation)
|
|
237
262
|
// ---------------------------------------------------------------------------
|
|
238
263
|
if (version === '0.2.0' && tsToken && trustedRoots && trustedRoots.length > 0 && doCmsChain) {
|
|
239
264
|
try {
|
|
@@ -279,6 +304,9 @@ export async function verifyWacz(waczBytes, publicKeyBytes, options = {}) {
|
|
|
279
304
|
if (timestampData) {
|
|
280
305
|
result.capture.timestamp = timestampData;
|
|
281
306
|
}
|
|
307
|
+
if (qualifiedTimestampData) {
|
|
308
|
+
result.capture.qualifiedTimestamp = qualifiedTimestampData;
|
|
309
|
+
}
|
|
282
310
|
}
|
|
283
311
|
|
|
284
312
|
return result;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w-r-l/verify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Verify cryptographic integrity of WRL WACZ web capture bundles",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Ben Peter <bp@ben-peter.com>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/benpeter/web-resource-ledger.git",
|
|
9
|
+
"url": "git+https://github.com/benpeter/web-resource-ledger.git",
|
|
10
10
|
"directory": "packages/verify"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/benpeter/web-resource-ledger/tree/main/packages/verify#readme",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "node --test 'test/**/*.test.js'"
|
|
27
27
|
},
|
|
28
28
|
"bin": {
|
|
29
|
-
"wrl-verify": "
|
|
29
|
+
"wrl-verify": "bin/wrl-verify.js"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=20.0.0"
|