@blamejs/pki 0.6.13 → 0.6.15
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/CHANGELOG.md +22 -1
- package/README.md +1 -1
- package/index.js +1 -1
- package/lib/acme.js +59 -815
- package/lib/asn1-der.js +7 -245
- package/lib/attrcert-sign.js +12 -260
- package/lib/attrcert-verify.js +1 -7
- package/lib/byte-reader.js +0 -8
- package/lib/byte-writer.js +0 -11
- package/lib/cbor-det.js +0 -54
- package/lib/cmc-build.js +15 -357
- package/lib/cmc-verify.js +6 -239
- package/lib/cmp-build.js +41 -317
- package/lib/cmp-session.js +73 -760
- package/lib/cmp-verify.js +32 -488
- package/lib/cms-compress.js +3 -32
- package/lib/cms-decrypt.js +29 -294
- package/lib/cms-encrypt.js +14 -234
- package/lib/cms-sign.js +29 -324
- package/lib/cms-verify.js +9 -500
- package/lib/composite-kem.js +2 -102
- package/lib/composite-sig.js +1 -77
- package/lib/constants.js +0 -249
- package/lib/crl-sign.js +9 -237
- package/lib/crl-verify.js +1 -10
- package/lib/crmf-sign.js +19 -198
- package/lib/crmf-verify.js +1 -12
- package/lib/csr-sign.js +3 -34
- package/lib/csr-verify.js +1 -12
- package/lib/ct.js +28 -253
- package/lib/edwards-point.js +10 -44
- package/lib/est.js +28 -764
- package/lib/framework-error.js +4 -182
- package/lib/guard-all.js +1 -58
- package/lib/guard-async.js +1 -36
- package/lib/guard-bytes.js +6 -650
- package/lib/guard-compress.js +5 -102
- package/lib/guard-crypto.js +1 -40
- package/lib/guard-der.js +2 -93
- package/lib/guard-encoding.js +2 -60
- package/lib/guard-header.js +1 -36
- package/lib/guard-identifier.js +7 -531
- package/lib/guard-intrinsic.js +1 -150
- package/lib/guard-json.js +10 -73
- package/lib/guard-limits.js +1 -77
- package/lib/guard-list.js +1 -49
- package/lib/guard-name.js +3 -209
- package/lib/guard-parsed.js +7 -335
- package/lib/guard-range.js +1 -71
- package/lib/guard-secret.js +1 -102
- package/lib/guard-text.js +1 -64
- package/lib/guard-time.js +1 -97
- package/lib/hpke.js +3 -105
- package/lib/http-digest.js +14 -142
- package/lib/http-retry-after.js +1 -47
- package/lib/http-transport.js +21 -131
- package/lib/inspect.js +30 -284
- package/lib/ip-utils.js +6 -47
- package/lib/jose.js +7 -142
- package/lib/key.js +2 -67
- package/lib/lint.js +9 -194
- package/lib/merkle.js +1 -27
- package/lib/mime.js +9 -82
- package/lib/ocsp-request-verify.js +1 -14
- package/lib/ocsp-verify.js +1 -82
- package/lib/ocsp.js +11 -169
- package/lib/oid.js +5 -337
- package/lib/path-validate.js +103 -1492
- package/lib/pbes2.js +2 -89
- package/lib/pkcs12-build.js +31 -379
- package/lib/pki-build.js +64 -290
- package/lib/rc2.js +2 -18
- package/lib/rfc3339.js +4 -27
- package/lib/scep.js +59 -233
- package/lib/schema-all.js +0 -122
- package/lib/schema-attrcert.js +4 -146
- package/lib/schema-c509.js +153 -802
- package/lib/schema-cmc.js +5 -220
- package/lib/schema-cmp.js +2 -223
- package/lib/schema-cms.js +13 -427
- package/lib/schema-crl.js +5 -68
- package/lib/schema-crmf.js +6 -167
- package/lib/schema-csr.js +1 -54
- package/lib/schema-csrattrs.js +2 -87
- package/lib/schema-engine.js +0 -152
- package/lib/schema-ocsp.js +0 -117
- package/lib/schema-pkcs12.js +2 -93
- package/lib/schema-pkcs8.js +3 -35
- package/lib/schema-pkix.js +24 -655
- package/lib/schema-smime.js +0 -54
- package/lib/schema-tsp.js +3 -99
- package/lib/schema-x509.js +4 -63
- package/lib/shbs.js +11 -95
- package/lib/sign-scheme.js +2 -97
- package/lib/sigstore.js +9 -169
- package/lib/sleep.js +2 -8
- package/lib/smime.js +15 -408
- package/lib/tls-cert-compress.js +0 -62
- package/lib/trust.js +19 -185
- package/lib/tsp-sign.js +16 -270
- package/lib/validator-all.js +1 -30
- package/lib/validator-attcert.js +2 -46
- package/lib/validator-cose.js +2 -153
- package/lib/validator-keydesc.js +1 -37
- package/lib/validator-sig.js +1 -46
- package/lib/validator-tls.js +1 -88
- package/lib/validator-tpm.js +19 -122
- package/lib/verify-seam.js +1 -24
- package/lib/webauthn-mds.js +3 -400
- package/lib/webauthn.js +12 -833
- package/lib/webcrypto.js +5 -485
- package/lib/x509-sign.js +4 -108
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/lib/tls-cert-compress.js
CHANGED
|
@@ -53,8 +53,6 @@
|
|
|
53
53
|
var C = require("./constants");
|
|
54
54
|
var guard = require("./guard-all");
|
|
55
55
|
var intrinsic = require("./guard-intrinsic");
|
|
56
|
-
// Own-key membership through an operation taken at load. Written out, the question reads two
|
|
57
|
-
// replaceable properties to answer one thing, and here it decides which algorithms are supported.
|
|
58
56
|
var _hasOwn = intrinsic.hasOwn;
|
|
59
57
|
var frameworkError = require("./framework-error");
|
|
60
58
|
var validator = require("./validator-all");
|
|
@@ -64,55 +62,29 @@ var zlib = require("zlib");
|
|
|
64
62
|
var TlsError = frameworkError.TlsError;
|
|
65
63
|
function _err(code, message, cause) { return new TlsError(code, message, cause); }
|
|
66
64
|
|
|
67
|
-
// RFC 8879 sec. 7.3 -- the CertificateCompressionAlgorithm registry. The wire value is
|
|
68
|
-
// what travels; the name is what this toolkit's guard dispatches on. 0 is Reserved and
|
|
69
|
-
// 16384..65535 are Experimental Use, but neither needs a row: anything absent here is
|
|
70
|
-
// refused the same way, and adding a row for a value we cannot decompress would be the
|
|
71
|
-
// fail-open. Every name here is checked against the decompression guard at load, so a
|
|
72
|
-
// runtime without one of the three cannot advertise it.
|
|
73
65
|
var ALG_BY_NUMBER = { 1: "zlib", 2: "brotli", 3: "zstd" };
|
|
74
66
|
var ALG_BY_NAME = {};
|
|
75
67
|
Object.keys(ALG_BY_NUMBER).forEach(function (n) { ALG_BY_NAME[ALG_BY_NUMBER[n]] = Number(n); });
|
|
76
68
|
|
|
77
|
-
// The compressors, paired with the guard's decompressors. RFC 8879 sec. 4 binds each
|
|
78
|
-
// algorithm to its format: zlib -> RFC 1950, brotli -> RFC 7932, zstd -> RFC 8478.
|
|
79
69
|
var COMPRESS = { zlib: zlib.deflateSync, brotli: zlib.brotliCompressSync, zstd: zlib.zstdCompressSync };
|
|
80
70
|
|
|
81
|
-
// Each codec takes its compression level through a DIFFERENT option: zlib as a top-level
|
|
82
|
-
// `level`, brotli and zstd as numbered entries in `params`. Passing `{ level: n }` to the
|
|
83
|
-
// latter two is silently ignored by node, so a caller asking for a level would quietly get the
|
|
84
|
-
// default. Each is mapped to the option its codec actually reads.
|
|
85
71
|
var LEVEL_OPT = {
|
|
86
72
|
zlib: function (n) { return { level: n }; },
|
|
87
73
|
brotli: function (n) { var p = {}; p[zlib.constants.BROTLI_PARAM_QUALITY] = n; return { params: p }; },
|
|
88
74
|
zstd: function (n) { var p = {}; p[zlib.constants.ZSTD_c_compressionLevel] = n; return { params: p }; },
|
|
89
75
|
};
|
|
90
76
|
|
|
91
|
-
// The names that are both registered by RFC 8879 and reachable through the decompression
|
|
92
|
-
// guard on this runtime. An algorithm the guard cannot decompress must never be offered
|
|
93
|
-
// or accepted: advertising one would mean accepting a message we then cannot open.
|
|
94
77
|
var SUPPORTED = guard.compress.algorithms().filter(function (n) {
|
|
95
78
|
return _hasOwn(ALG_BY_NAME, n) && typeof COMPRESS[n] === "function";
|
|
96
79
|
});
|
|
97
80
|
|
|
98
|
-
// The minimum Certificate message size and the widest opaque<..2^24-1> vector, both owned
|
|
99
|
-
// by validator-tls, alongside the rest of the framing rule set. A declared
|
|
100
|
-
// uncompressed_length below the minimum cannot be a Certificate message, and refusing it
|
|
101
|
-
// also keeps a zero-length declaration away from the decompression cap, which is a positive
|
|
102
|
-
// integer by contract.
|
|
103
81
|
var MIN_CERT_MSG_BYTES = validator.tls.MIN_CERT_MSG_BYTES;
|
|
104
82
|
var MAX_VECTOR_24 = validator.tls.MAX_VECTOR_24;
|
|
105
83
|
|
|
106
|
-
// The fault codes validator-tls raises for each framing violation it owns.
|
|
107
84
|
var FRAMING_CODES = { truncated: "tls/truncated", framing: "tls/bad-framing", trailing: "tls/trailing-data" };
|
|
108
85
|
|
|
109
|
-
// The fixed part of a CompressedCertificate: uint16 algorithm + uint24 uncompressed_length +
|
|
110
|
-
// the uint24 length prefix of the compressed body (RFC 8879 sec. 4).
|
|
111
86
|
var HEADER_BYTES = 8;
|
|
112
87
|
|
|
113
|
-
// Resolve the caller's policy cap, which may only tighten the protocol ceiling DOWNWARD.
|
|
114
|
-
// A cap that could be raised would let an option undo the framing limit RFC 8879 sec. 5
|
|
115
|
-
// requires be applied "as if no compression were used".
|
|
116
88
|
function _resolveCap(opts) {
|
|
117
89
|
var cap = C.LIMITS.TLS_CERT_MSG_MAX_BYTES;
|
|
118
90
|
if (opts.maxOutputBytes !== undefined) {
|
|
@@ -125,10 +97,6 @@ function _resolveCap(opts) {
|
|
|
125
97
|
return cap;
|
|
126
98
|
}
|
|
127
99
|
|
|
128
|
-
// The algorithm names the caller will accept, defaulting to everything supported. This is
|
|
129
|
-
// the peer's `compress_certificate` advertisement: RFC 8879 sec. 4 requires the algorithm
|
|
130
|
-
// to be one the receiver offered, so accepting an unadvertised one would decompress bytes
|
|
131
|
-
// under a codec we never agreed to.
|
|
132
100
|
function _resolveAllowed(opts) {
|
|
133
101
|
if (opts.allowedAlgorithms === undefined) return SUPPORTED.slice();
|
|
134
102
|
var list = opts.allowedAlgorithms;
|
|
@@ -200,8 +168,6 @@ function _resolveAllowed(opts) {
|
|
|
200
168
|
function decompressCertificate(bytes, opts) {
|
|
201
169
|
opts = opts || {};
|
|
202
170
|
var view = guard.bytes.view(bytes, TlsError, "tls/bad-input", "the compressed certificate message");
|
|
203
|
-
// The CompressedCertificate travels as a handshake message body, framed by RFC 8446 sec. 4
|
|
204
|
-
// with a uint24 length, so one longer than that ceiling could not have been sent at all.
|
|
205
171
|
if (view.length > C.LIMITS.TLS_CERT_MSG_MAX_BYTES) {
|
|
206
172
|
throw _err("tls/too-large", "the compressed certificate message is " + view.length +
|
|
207
173
|
" bytes, over the " + C.LIMITS.TLS_CERT_MSG_MAX_BYTES + "-byte handshake framing limit");
|
|
@@ -209,20 +175,12 @@ function decompressCertificate(bytes, opts) {
|
|
|
209
175
|
var cap = _resolveCap(opts);
|
|
210
176
|
var allowed = _resolveAllowed(opts);
|
|
211
177
|
|
|
212
|
-
// Framing decode + bounds live in validator-tls (the type's rule set); which algorithms
|
|
213
|
-
// are acceptable, the output cap, and the length agreement are this codec's policy and
|
|
214
|
-
// stay here. Note the currency split the two families use: the validator takes the error
|
|
215
|
-
// CLASS, the guard below takes the `_err` FACTORY.
|
|
216
178
|
var framed = validator.tls.compressedCertificate(view, TlsError, FRAMING_CODES);
|
|
217
179
|
var algorithm = framed.algorithm;
|
|
218
180
|
var name = ALG_BY_NUMBER[algorithm];
|
|
219
181
|
if (!name) {
|
|
220
182
|
throw _err("tls/unsupported-algorithm", "compression algorithm " + algorithm + " is not in the RFC 8879 registry");
|
|
221
183
|
}
|
|
222
|
-
// SUPPORTED is the RFC 8879 registry intersected with what the decompression guard can
|
|
223
|
-
// actually open safely, so this fires wherever one of the three is dropped -- which is the
|
|
224
|
-
// long-term-support Node, where zstd cannot report a truncated frame. Covered there by the
|
|
225
|
-
// dropped-algorithm vector; unreachable on a runtime where all three qualify.
|
|
226
184
|
if (SUPPORTED.indexOf(name) === -1) {
|
|
227
185
|
throw _err("tls/unsupported-algorithm", "compression algorithm " + algorithm + " (" + name + ") is not decompressible on this runtime");
|
|
228
186
|
}
|
|
@@ -238,12 +196,8 @@ function decompressCertificate(bytes, opts) {
|
|
|
238
196
|
if (uncompressedLength > cap) {
|
|
239
197
|
throw _err("tls/too-large", "uncompressed_length " + uncompressedLength + " exceeds the " + cap + "-byte limit");
|
|
240
198
|
}
|
|
241
|
-
// The declared length IS the cap: a stream that expands past what the message itself
|
|
242
|
-
// claims is refused mid-decompression rather than after the memory is committed.
|
|
243
199
|
var message = guard.compress.bounded(name, Buffer.from(body), uncompressedLength, _err,
|
|
244
200
|
{ tooLarge: "tls/too-large", failed: "tls/decompress-failed" }, "the compressed certificate message");
|
|
245
|
-
// RFC 8879 sec. 5: if the length after decompression does not match the declared one,
|
|
246
|
-
// the message is invalid. The cap above only bounds the OVER direction.
|
|
247
201
|
if (message.length !== uncompressedLength) {
|
|
248
202
|
throw _err("tls/length-mismatch", "the decompressed message is " + message.length +
|
|
249
203
|
" bytes but uncompressed_length declared " + uncompressedLength);
|
|
@@ -305,10 +259,6 @@ function parseCertificateMessage(bytes, opts) {
|
|
|
305
259
|
throw _err("tls/bad-input", "opts.certificateType must be \"X509\" or \"RawPublicKey\"");
|
|
306
260
|
}
|
|
307
261
|
var view = guard.bytes.view(bytes, TlsError, "tls/bad-input", "the certificate message");
|
|
308
|
-
// A Certificate message is a handshake message body, framed by RFC 8446 sec. 4 with a uint24
|
|
309
|
-
// length, so one longer than that ceiling could not have appeared on the wire. This entry point
|
|
310
|
-
// is public and reachable without going through decompression, so it applies the bound itself
|
|
311
|
-
// rather than inheriting the one the compression paths enforce.
|
|
312
262
|
if (view.length > C.LIMITS.TLS_CERT_MSG_MAX_BYTES) {
|
|
313
263
|
throw _err("tls/too-large", "the certificate message is " + view.length +
|
|
314
264
|
" bytes, over the " + C.LIMITS.TLS_CERT_MSG_MAX_BYTES + "-byte handshake framing limit");
|
|
@@ -379,11 +329,6 @@ function compressCertificate(certificateMessage, opts) {
|
|
|
379
329
|
} catch (e) {
|
|
380
330
|
throw _err("tls/bad-input", "the certificate message could not be compressed (check opts.level)", e);
|
|
381
331
|
}
|
|
382
|
-
// The CompressedCertificate is itself a handshake message body, so the WHOLE emitted message --
|
|
383
|
-
// not just the message it carries -- must fit the RFC 8446 sec. 4 uint24 framing. Incompressible
|
|
384
|
-
// content near the ceiling grows by the 8-byte header, so bounding only the input would emit a
|
|
385
|
-
// message that cannot be framed and no peer could receive. Checked BEFORE the writer so this
|
|
386
|
-
// stays one verdict rather than surfacing as the body vector's own bound.
|
|
387
332
|
var wireLength = HEADER_BYTES + stream.length;
|
|
388
333
|
if (wireLength > C.LIMITS.TLS_CERT_MSG_MAX_BYTES) {
|
|
389
334
|
throw _err("tls/too-large", "the compressed certificate message would be " + wireLength +
|
|
@@ -394,14 +339,7 @@ function compressCertificate(certificateMessage, opts) {
|
|
|
394
339
|
w.u24(view.length);
|
|
395
340
|
w.vector(3, 1, MAX_VECTOR_24, stream, "tls/bad-framing");
|
|
396
341
|
var wire = w.build();
|
|
397
|
-
// Self-check: a produced message must be one this decoder accepts, and must recover the
|
|
398
|
-
// input byte-for-byte. This is what stops a codec-level defect from shipping a message
|
|
399
|
-
// that only a permissive peer can read.
|
|
400
342
|
var back = decompressCertificate(wire, { allowedAlgorithms: [name] });
|
|
401
|
-
// Coverage residual -- unreachable while the codec is correct, which is the point: this
|
|
402
|
-
// fires only if a compressor and its decompressor disagree, and there is no input that
|
|
403
|
-
// makes them. It stays as the assertion that a message this toolkit emits is one this
|
|
404
|
-
// toolkit accepts, so a future codec defect surfaces here rather than at a peer.
|
|
405
343
|
if (!back.certificateMessage.equals(view)) {
|
|
406
344
|
throw _err("tls/bad-input", "the compressed certificate message did not round-trip to the input");
|
|
407
345
|
}
|