@blamejs/pki 0.6.14 → 0.6.16

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/lib/acme.js +59 -815
  3. package/lib/asn1-der.js +7 -245
  4. package/lib/attrcert-sign.js +12 -260
  5. package/lib/attrcert-verify.js +1 -7
  6. package/lib/byte-reader.js +0 -8
  7. package/lib/byte-writer.js +0 -11
  8. package/lib/cbor-det.js +0 -54
  9. package/lib/cmc-build.js +15 -357
  10. package/lib/cmc-verify.js +6 -239
  11. package/lib/cmp-build.js +41 -317
  12. package/lib/cmp-session.js +73 -760
  13. package/lib/cmp-verify.js +32 -488
  14. package/lib/cms-compress.js +3 -32
  15. package/lib/cms-decrypt.js +29 -294
  16. package/lib/cms-encrypt.js +14 -234
  17. package/lib/cms-sign.js +29 -324
  18. package/lib/cms-verify.js +9 -500
  19. package/lib/composite-kem.js +2 -102
  20. package/lib/composite-sig.js +1 -77
  21. package/lib/constants.js +0 -249
  22. package/lib/crl-sign.js +9 -237
  23. package/lib/crl-verify.js +1 -10
  24. package/lib/crmf-sign.js +19 -198
  25. package/lib/crmf-verify.js +1 -12
  26. package/lib/csr-sign.js +3 -34
  27. package/lib/csr-verify.js +1 -12
  28. package/lib/ct.js +28 -253
  29. package/lib/edwards-point.js +10 -44
  30. package/lib/est.js +28 -764
  31. package/lib/framework-error.js +4 -182
  32. package/lib/guard-all.js +1 -58
  33. package/lib/guard-async.js +1 -36
  34. package/lib/guard-bytes.js +6 -650
  35. package/lib/guard-compress.js +5 -102
  36. package/lib/guard-crypto.js +1 -40
  37. package/lib/guard-der.js +2 -93
  38. package/lib/guard-encoding.js +2 -60
  39. package/lib/guard-header.js +1 -36
  40. package/lib/guard-identifier.js +7 -531
  41. package/lib/guard-intrinsic.js +1 -150
  42. package/lib/guard-json.js +10 -73
  43. package/lib/guard-limits.js +1 -77
  44. package/lib/guard-list.js +1 -49
  45. package/lib/guard-name.js +3 -209
  46. package/lib/guard-parsed.js +7 -335
  47. package/lib/guard-range.js +1 -71
  48. package/lib/guard-secret.js +1 -102
  49. package/lib/guard-text.js +1 -64
  50. package/lib/guard-time.js +1 -97
  51. package/lib/hpke.js +3 -105
  52. package/lib/http-digest.js +14 -142
  53. package/lib/http-retry-after.js +1 -47
  54. package/lib/http-transport.js +21 -131
  55. package/lib/inspect.js +30 -284
  56. package/lib/ip-utils.js +6 -47
  57. package/lib/jose.js +7 -142
  58. package/lib/key.js +2 -67
  59. package/lib/lint.js +9 -194
  60. package/lib/merkle.js +1 -27
  61. package/lib/mime.js +9 -82
  62. package/lib/ocsp-request-verify.js +1 -14
  63. package/lib/ocsp-verify.js +1 -82
  64. package/lib/ocsp.js +11 -169
  65. package/lib/oid.js +5 -337
  66. package/lib/path-validate.js +103 -1492
  67. package/lib/pbes2.js +2 -89
  68. package/lib/pkcs12-build.js +31 -379
  69. package/lib/pki-build.js +64 -290
  70. package/lib/rc2.js +2 -18
  71. package/lib/rfc3339.js +4 -27
  72. package/lib/scep.js +140 -286
  73. package/lib/schema-all.js +0 -122
  74. package/lib/schema-attrcert.js +4 -146
  75. package/lib/schema-c509.js +153 -802
  76. package/lib/schema-cmc.js +5 -220
  77. package/lib/schema-cmp.js +2 -223
  78. package/lib/schema-cms.js +13 -427
  79. package/lib/schema-crl.js +5 -68
  80. package/lib/schema-crmf.js +6 -167
  81. package/lib/schema-csr.js +1 -54
  82. package/lib/schema-csrattrs.js +2 -87
  83. package/lib/schema-engine.js +0 -152
  84. package/lib/schema-ocsp.js +0 -117
  85. package/lib/schema-pkcs12.js +2 -93
  86. package/lib/schema-pkcs8.js +3 -35
  87. package/lib/schema-pkix.js +24 -655
  88. package/lib/schema-smime.js +0 -54
  89. package/lib/schema-tsp.js +3 -99
  90. package/lib/schema-x509.js +4 -63
  91. package/lib/shbs.js +11 -95
  92. package/lib/sign-scheme.js +2 -97
  93. package/lib/sigstore.js +9 -169
  94. package/lib/sleep.js +2 -8
  95. package/lib/smime.js +15 -408
  96. package/lib/tls-cert-compress.js +0 -62
  97. package/lib/trust.js +19 -185
  98. package/lib/tsp-sign.js +16 -270
  99. package/lib/validator-all.js +1 -30
  100. package/lib/validator-attcert.js +2 -46
  101. package/lib/validator-cose.js +2 -153
  102. package/lib/validator-keydesc.js +1 -37
  103. package/lib/validator-sig.js +1 -46
  104. package/lib/validator-tls.js +1 -88
  105. package/lib/validator-tpm.js +19 -122
  106. package/lib/verify-seam.js +1 -24
  107. package/lib/webauthn-mds.js +3 -400
  108. package/lib/webauthn.js +12 -833
  109. package/lib/webcrypto.js +5 -485
  110. package/lib/x509-sign.js +4 -108
  111. package/package.json +1 -1
  112. package/sbom.cdx.json +6 -6
@@ -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
  }