@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
@@ -1,19 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // Copyright (c) blamejs contributors
3
3
  "use strict";
4
- //
5
- // @internal -- the pki.cms.compress / pki.cms.decompress implementation. The operator-facing
4
+ // @internal
6
5
  // @module pki.cms + the @primitive blocks live in cms-verify.js, which re-exports these (the
7
- // cms-encrypt.js / cms-decrypt.js model).
8
- //
9
- // CMS CompressedData (RFC 3274) -- the size-transform content type. compress ZLIB-compresses
10
- // (RFC 1950 / RFC 1951) the content and wraps it as a CompressedData ContentInfo; decompress parses
11
- // one (over the shipped strict schema-cms parser), enforces version 0 + id-alg-zlibCompress +
12
- // absent-or-NULL params (RFC 3274 sec. 2), and BOUNDED-inflates the eContent. There is NO crypto
13
- // here -- CompressedData provides no integrity / confidentiality / authentication (RFC 8551 sec.
14
- // 2.4.5); it is purely a size transform. The one load-bearing defense is the decompression-bomb
15
- // cap: inflate stops at C.LIMITS.COMPRESS_MAX_BYTES before the output is materialized (a
16
- // resource-exhaustion defense, CWE-409), and every zlib fault collapses to a uniform typed error.
17
6
 
18
7
  var zlib = require("zlib");
19
8
  var oid = require("./oid");
@@ -29,12 +18,8 @@ function O(n) { return oid.byName(n); }
29
18
  function _err(code, message, cause) { return new CmsError(code, message, cause); }
30
19
 
31
20
  var OID_ZLIB = O("id-alg-zlibCompress");
32
- // The NULL params DER (0x05 0x00) -- the one non-absent encoding RFC 3274 sec. 2 permits (MAY be NULL).
33
21
  var NULL_PARAMS_DER = Buffer.from([0x05, 0x00]);
34
22
 
35
- // Compress `content` and wrap it as a CMS CompressedData ContentInfo (RFC 3274 sec. 1.1): version 0,
36
- // compressionAlgorithm = id-alg-zlibCompress with ABSENT parameters, encapContentInfo = { eContentType
37
- // (default id-data), eContent = the RFC 1950 ZLIB stream }.
38
23
  async function compress(content, opts) {
39
24
  opts = opts || {};
40
25
  var raw = guard.bytes.source(content, CmsError, "cms/bad-input", "content");
@@ -48,29 +33,25 @@ async function compress(content, opts) {
48
33
  catch (e) { throw _err("cms/bad-input", "the content could not be compressed (check opts.level)", e); }
49
34
  var cd = b.sequence([
50
35
  b.integer(0),
51
- b.sequence([b.oid(OID_ZLIB)]), // compressionAlgorithm, params ABSENT (RFC 3274 sec. 2)
36
+ b.sequence([b.oid(OID_ZLIB)]),
52
37
  b.sequence([b.oid(ctOid), b.explicit(0, b.octetString(stream))]),
53
38
  ]);
54
39
  var ci = b.sequence([b.oid(O("compressedData")), b.explicit(0, cd)]);
55
40
  return opts.pem ? schemaCms.pemEncode(ci, "CMS") : ci;
56
41
  }
57
42
 
58
- // Parse a CMS CompressedData and recover its content. Requires contentTypeName == compressedData,
59
- // version 0 (enforced by the parser), compressionAlgorithm == id-alg-zlibCompress with absent-or-NULL
60
- // params, and a present eContent; then BOUNDED-inflates. Every failure is a typed CmsError.
61
43
  async function decompress(input, opts) {
62
44
  opts = opts || {};
63
45
  var cap = C.LIMITS.COMPRESS_MAX_BYTES;
64
46
  if (opts.maxOutputBytes !== undefined) {
65
47
  var mo = opts.maxOutputBytes;
66
48
  if (typeof mo !== "number" || !isFinite(mo) || mo <= 0 || Math.floor(mo) !== mo) throw _err("cms/bad-input", "opts.maxOutputBytes must be a positive integer");
67
- if (mo < cap) cap = mo; // a caller may tighten the cap DOWNWARD only, never loosen it
49
+ if (mo < cap) cap = mo;
68
50
  }
69
51
  var parsed = schemaCms.parse(_toDer(input));
70
52
  if (parsed.contentTypeName !== "compressedData") throw _err("cms/unsupported-content-type", "input is not a CMS CompressedData (got " + parsed.contentTypeName + ")");
71
53
  var alg = parsed.compressionAlgorithm;
72
54
  if (alg.oid !== OID_ZLIB) throw _err("cms/unsupported-algorithm", "unsupported compressionAlgorithm " + (alg.name || alg.oid) + " (only id-alg-zlibCompress, RFC 3274 sec. 2)");
73
- // RFC 3274 sec. 2: the parameters SHOULD be omitted but MAY be NULL. Reject any other encoding.
74
55
  if (alg.parameters != null && Buffer.compare(alg.parameters, NULL_PARAMS_DER) !== 0) throw _err("cms/bad-algorithm-parameters", "id-alg-zlibCompress parameters must be absent or NULL (RFC 3274 sec. 2)");
75
56
  var eci = parsed.encapContentInfo;
76
57
  if (eci.eContent == null) throw _err("cms/no-encapsulated-content", "the CompressedData carries no encapsulated content (a detached CompressedData cannot be decompressed)");
@@ -79,8 +60,6 @@ async function decompress(input, opts) {
79
60
  content: content,
80
61
  contentType: eci.eContentType,
81
62
  contentTypeName: oid.name(eci.eContentType) || eci.eContentType,
82
- // Coverage residual: reaching here requires alg.oid === id-alg-zlibCompress (line above), which is
83
- // always a registered name, so the `|| alg.oid` fallback is a defensive belt, never selected.
84
63
  compressionAlgorithm: alg.name || alg.oid,
85
64
  };
86
65
  }
@@ -91,14 +70,6 @@ function _toDer(input) {
91
70
  throw _err("cms/bad-input", "input must be a DER Buffer, Uint8Array, or PEM string");
92
71
  }
93
72
 
94
- // Inflate the RFC 1950 ZLIB stream through the shared bounded-decompression guard, which applies
95
- // the output cap at the decompressor (so a bomb is refused mid-stream, before it is allocated) and
96
- // requires the whole octet string to be exactly one compressed frame (so trailing bytes cannot give
97
- // one content a second encoding). This module keeps its own verdict codes: a cap breach is
98
- // cms/decompress-too-large, every other fault the uniform cms/decompress-failed.
99
- //
100
- // `_err` is a factory and the guard calls it as one. Handing it CmsError instead would throw
101
- // "class cannot be invoked without new" on the rejection path, turning a refusal into a crash.
102
73
  function _inflateBounded(stream, cap) {
103
74
  var view = guard.bytes.view(stream, CmsError, "cms/decompress-failed", "the compressed content");
104
75
  return guard.compress.bounded("zlib", view, cap, _err,