tr-fetch 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -431,15 +431,27 @@ tr-curl --cacert private-ca.pem --crlfile current.crl https://internal.example/
431
431
  | Failure and limits | `-f/--fail`, `--fail-with-body`, `--fail-early`, `--max-filesize`, `-m/--max-time` |
432
432
  | Messages | `-v/--verbose`, `-s/--silent`, `-S/--show-error`, `--no-progress-meter`, `-#/--progress-bar`, `-h/--help`, `-V/--version` |
433
433
  | TLS | `-k/--insecure`, `--cacert`, `--crlfile`, `-1/--tlsv1`, `--tlsv1.0` … `--tlsv1.3`, `--tls-max`, `--ciphers`, `--tls13-ciphers` |
434
- | trFetch | `--trfetch-options <json>` |
434
+ | trFetch | `--tr-fetch-max-crl-bytes`, `--tr-fetch-crl-url`, `--tr-fetch-ocsp-url`, `--tr-fetch-options` |
435
435
 
436
436
  `--verbose` prints the request and response headers, prefixed with `>` and
437
437
  `<` like curl, and also enables `trFetchDebug`, so the revocation diagnostics
438
- appear on stderr. `--trfetch-options` takes a JSON object of trFetch options,
439
- for example `'{"trFetchCrlCheckDepth":"full-chain"}'`. The option can be
440
- repeated, and later objects override earlier keys. `--crlfile` sets
441
- `trFetchCrlOverride`. `--cacert` replaces Node's default CA certificates for
442
- the process.
438
+ appear on stderr. `--cacert` replaces Node's default CA certificates for the
439
+ process.
440
+
441
+ The `--tr-fetch-*` options set trFetch options directly:
442
+
443
+ | Option | trFetch option |
444
+ |---|---|
445
+ | `--tr-fetch-max-crl-bytes <bytes>` | `trFetchCrlPolicy.maxCrlBytes`, a positive integer |
446
+ | `--tr-fetch-crl-url <url>` | `trFetchCrlDistributionPointOverride` |
447
+ | `--tr-fetch-ocsp-url <url>` | `trFetchOcspUriOverride` |
448
+ | `--crlfile <file>` | `trFetchCrlOverride`, read from the file |
449
+
450
+ `--tr-fetch-options` takes a JSON object of any trFetch options, for example
451
+ `'{"trFetchCrlCheckDepth":"full-chain"}'`. It can be repeated; later objects
452
+ replace earlier keys. The options above take precedence over the same
453
+ settings in it, whatever their order, and `--tr-fetch-max-crl-bytes` is merged
454
+ into its `trFetchCrlPolicy` rather than replacing it.
443
455
 
444
456
  `--insecure` cannot be implemented through trFetch, which never relaxes TLS
445
457
  verification. With `-k`, tr-curl uses plain fetch with an unverified TLS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tr-fetch",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Node.js fetch with CRL and OCSP certificate revocation checking, plus tr-curl, a curl-like test tool",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -26,6 +26,14 @@ function tlsMaxCb(value) {
26
26
  return (value === 'default') ? value : TLS_VERSIONS[value];
27
27
  }
28
28
 
29
+ function positiveBytesCb(value) {
30
+ return (/^[1-9]\d*$/.test(value) && Number.isSafeInteger(Number(value))) ? Number(value) : undefined;
31
+ }
32
+
33
+ function networkUrlCb(value) {
34
+ return (URL.canParse(value) && [ 'http:', 'https:' ].includes(new URL(value).protocol)) ? value : undefined;
35
+ }
36
+
29
37
  function jsonObjectCb(value) {
30
38
  try {
31
39
  const parsed = JSON.parse(value);
@@ -96,7 +104,10 @@ function optionDefinitions() {
96
104
  flag(undefined, 'tlsv1.3', 'Use TLSv1.3 or greater'),
97
105
  arg(undefined, 'tls-max', '<version> Maximum TLS version: 1.0, 1.1, 1.2, 1.3 or default', tlsMaxCb),
98
106
  arg(undefined, 'tls13-ciphers', '<list> TLS 1.3 cipher suites to use'),
99
- arg(undefined, 'trfetch-options', '<json> Extra trFetch options as a JSON object', jsonObjectCb, true),
107
+ arg(undefined, 'tr-fetch-max-crl-bytes', '<bytes> Largest CRL accepted (default 16777216)', positiveBytesCb),
108
+ arg(undefined, 'tr-fetch-crl-url', '<url> Fetch the server certificate\'s CRL from this URL instead', networkUrlCb),
109
+ arg(undefined, 'tr-fetch-ocsp-url', '<url> Query this OCSP responder for the server certificate instead', networkUrlCb),
110
+ arg(undefined, 'tr-fetch-options', '<json> Extra trFetch options as a JSON object', jsonObjectCb, true),
100
111
  arg('u', 'user', '<user:password> Server user and password (basic authentication)'),
101
112
  arg(undefined, 'url', '<url> URL to work with', undefined, true),
102
113
  flag('v', 'verbose', 'Make the operation more talkative, including trFetch debug output', true),
@@ -123,12 +134,30 @@ function parseArguments(argv) {
123
134
  if (value('output').length && value('remote-name')) {
124
135
  throw new UsageError('--output and --remote-name cannot be used together');
125
136
  }
126
- const trFetchOptions = Object.assign({}, ...value('trfetch-options'));
137
+ const trFetchOptions = Object.assign({}, ...value('tr-fetch-options'));
127
138
  for (const key of Object.keys(trFetchOptions)) {
128
139
  if (! /^trFetch/.test(key)) {
129
- throw new UsageError(`--trfetch-options accepts only trFetch options, not ${JSON.stringify(key)}`);
140
+ throw new UsageError(`--tr-fetch-options accepts only trFetch options, not ${JSON.stringify(key)}`);
130
141
  }
131
142
  }
143
+ // Dedicated options take precedence over the same settings given in
144
+ // --tr-fetch-options, regardless of their order.
145
+ if (value('tr-fetch-max-crl-bytes') !== undefined) {
146
+ const policy = trFetchOptions.trFetchCrlPolicy;
147
+ // Leave a malformed policy for trFetch to reject.
148
+ if ((policy === undefined) || (policy && (typeof(policy) === 'object') && ! Array.isArray(policy))) {
149
+ trFetchOptions.trFetchCrlPolicy = { ...policy, maxCrlBytes: value('tr-fetch-max-crl-bytes') };
150
+ }
151
+ }
152
+ if (value('tr-fetch-crl-url') !== undefined) {
153
+ if (value('crlfile') !== undefined) {
154
+ throw new UsageError('--tr-fetch-crl-url and --crlfile cannot be used together');
155
+ }
156
+ trFetchOptions.trFetchCrlDistributionPointOverride = value('tr-fetch-crl-url');
157
+ }
158
+ if (value('tr-fetch-ocsp-url') !== undefined) {
159
+ trFetchOptions.trFetchOcspUriOverride = value('tr-fetch-ocsp-url');
160
+ }
132
161
  const data = [ 'data', 'data-ascii', 'data-binary', 'data-raw', 'data-urlencode', 'json' ]
133
162
  .flatMap(value).sort((a, b) => a.seq - b.seq);
134
163
  if (value('head') && data.length && ! value('get')) {