@blamejs/pki 0.8.30 → 0.8.48

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 (87) hide show
  1. package/CHANGELOG.md +411 -0
  2. package/README.md +67 -16
  3. package/bin/pki.js +716 -30
  4. package/examples/issue-a-certificate.js +90 -0
  5. package/examples/post-quantum.js +66 -0
  6. package/examples/read-a-certificate.js +56 -0
  7. package/examples/revoke-and-check.js +86 -0
  8. package/examples/sign-and-verify-cms.js +63 -0
  9. package/index.js +18 -5
  10. package/lib/acme.js +223 -74
  11. package/lib/alt-sig.js +441 -0
  12. package/lib/asn1-der.js +48 -25
  13. package/lib/attrcert-sign.js +27 -19
  14. package/lib/cbor-det.js +24 -14
  15. package/lib/cmc-build.js +9 -2
  16. package/lib/cmc-verify.js +14 -3
  17. package/lib/cmp-build.js +17 -5
  18. package/lib/cmp-session.js +24 -11
  19. package/lib/cmp-verify.js +28 -19
  20. package/lib/cms-compress.js +3 -1
  21. package/lib/cms-decrypt.js +102 -7
  22. package/lib/cms-encrypt.js +59 -7
  23. package/lib/cms-sign.js +31 -9
  24. package/lib/cms-verify.js +22 -18
  25. package/lib/composite-kem.js +30 -18
  26. package/lib/composite-sig.js +29 -14
  27. package/lib/constants.js +28 -0
  28. package/lib/crl-sign.js +111 -19
  29. package/lib/crmf-sign.js +167 -15
  30. package/lib/csr-sign.js +117 -6
  31. package/lib/ct.js +939 -48
  32. package/lib/est.js +29 -16
  33. package/lib/framework-error.js +12 -0
  34. package/lib/guard-async.js +1 -1
  35. package/lib/guard-bytes.js +103 -20
  36. package/lib/guard-crypto.js +205 -3
  37. package/lib/guard-encoding.js +6 -1
  38. package/lib/guard-identifier.js +55 -8
  39. package/lib/guard-intrinsic.js +43 -0
  40. package/lib/guard-json.js +122 -9
  41. package/lib/guard-limits.js +12 -1
  42. package/lib/guard-list.js +63 -8
  43. package/lib/guard-name.js +167 -20
  44. package/lib/guard-range.js +43 -5
  45. package/lib/guard-text.js +41 -0
  46. package/lib/guard-verdict.js +39 -8
  47. package/lib/hpke.js +688 -42
  48. package/lib/http-transport.js +156 -4
  49. package/lib/identity-match.js +4 -4
  50. package/lib/inspect.js +448 -2
  51. package/lib/jose.js +93 -25
  52. package/lib/key.js +18 -13
  53. package/lib/lint.js +165 -1
  54. package/lib/merkle.js +233 -27
  55. package/lib/ocsp.js +27 -14
  56. package/lib/oid.js +14 -4
  57. package/lib/path-validate.js +143 -61
  58. package/lib/pkcs12-build.js +7 -2
  59. package/lib/pki-build.js +31 -7
  60. package/lib/possession.js +575 -0
  61. package/lib/related-cert.js +708 -0
  62. package/lib/revocation-fetch.js +6 -6
  63. package/lib/scep.js +15 -5
  64. package/lib/schema-c509.js +5 -2
  65. package/lib/schema-cmc.js +1 -1
  66. package/lib/schema-cmp.js +8 -8
  67. package/lib/schema-cms.js +2 -15
  68. package/lib/schema-csr.js +69 -0
  69. package/lib/schema-engine.js +10 -3
  70. package/lib/schema-pkix.js +267 -4
  71. package/lib/schema-tsp.js +7 -6
  72. package/lib/sign-scheme.js +22 -9
  73. package/lib/sigstore.js +684 -168
  74. package/lib/sleep.js +8 -1
  75. package/lib/smime.js +22 -1
  76. package/lib/tlog.js +1235 -0
  77. package/lib/tls-cert-compress.js +25 -8
  78. package/lib/tsp-sign.js +120 -35
  79. package/lib/tuf.js +1395 -0
  80. package/lib/validator-tpm.js +4 -1
  81. package/lib/verify-seam.js +7 -1
  82. package/lib/webauthn-mds.js +41 -4
  83. package/lib/webauthn.js +43 -25
  84. package/lib/webcrypto.js +48 -46
  85. package/lib/x509-sign.js +225 -19
  86. package/package.json +2 -1
  87. package/sbom.cdx.json +6 -6
package/lib/sleep.js CHANGED
@@ -3,10 +3,17 @@
3
3
  "use strict";
4
4
  // @internal
5
5
 
6
+ var intrinsic = require("./guard-intrinsic");
7
+ /** @internal The constructor is captured at load like every operation the toolkit decides with. A
8
+ * replacement reached here settles the wait itself, so a backoff a caller asked for does not happen.
9
+ * `setTimeout` is deliberately NOT captured: the delay this splits is observed through the global, and
10
+ * capturing it would make the split unobservable. */
11
+ var _Promise = intrinsic.Promise;
12
+
6
13
  var SETTIMEOUT_MAX_MS = 2147483647;
7
14
 
8
15
  function sleep(ms) {
9
- return new Promise(function (resolve) {
16
+ return new _Promise(function (resolve) {
10
17
  (function step(remaining) {
11
18
  if (remaining <= SETTIMEOUT_MAX_MS) { setTimeout(resolve, remaining); return; }
12
19
  setTimeout(function () { step(remaining - SETTIMEOUT_MAX_MS); }, SETTIMEOUT_MAX_MS);
package/lib/smime.js CHANGED
@@ -62,7 +62,7 @@ var ENCRYPT_OPTS = Object.assign(Object.create(null), {
62
62
  entity: 1, contentType: 1, protectHeaders: 1, headers: 1, hcp: 1,
63
63
  contentEncryptionAlgorithm: 1, oaepHash: 1, keyIdentifier: 1, ukm: 1,
64
64
  });
65
- var DECRYPT_OPTS = Object.assign(Object.create(null), { recipientIndex: 1, maxIterations: 1, strictSmimeType: 1, legacyHeaderProtection: 1 });
65
+ var DECRYPT_OPTS = Object.assign(Object.create(null), { recipientIndex: 1, maxIterations: 1, strictSmimeType: 1, legacyHeaderProtection: 1, allowUnauthenticatedRsa15: 1 });
66
66
  var COMPRESS_OPTS = Object.assign(Object.create(null), { entity: 1, contentType: 1, level: 1 });
67
67
  var DECOMPRESS_OPTS = Object.assign(Object.create(null), { maxOutputBytes: 1 });
68
68
 
@@ -84,6 +84,19 @@ function _isPkcs7(type, kind) {
84
84
 
85
85
  var MICALG = Object.assign(Object.create(null), { sha1: "sha-1", sha224: "sha-224", sha256: "sha-256", sha384: "sha-384", sha512: "sha-512", md5: "md5", shake128: "shake128", shake256: "shake256" });
86
86
 
87
+ /** @internal The content, copied before the caller's options are read. Every verb that builds an entity
88
+ * settles its options first, and settling them COPIES them, which reads the caller's own object: a
89
+ * property there is caller code that runs before the content would otherwise have been read, and over a
90
+ * view of the content it would replace what the verb goes on to sign, encrypt or compress, after the
91
+ * verb had accepted the content it was handed. So the copy has to come before the option copy, not at
92
+ * the entity builders below, which run too late.
93
+ * The test is the one the byte readers themselves apply, so a value they would refuse is still refused
94
+ * where they refuse it and no diagnostic moves ahead of the option check. */
95
+ function _fixedContent(content) {
96
+ if (!nodeUtil.types.isUint8Array(content)) return content;
97
+ return guard.bytes.snapshot(content, SmimeError, "smime/bad-input", "content");
98
+ }
99
+
87
100
  function _entityBytes(content, opts) {
88
101
  var raw = guard.bytes.view(content, SmimeError, "smime/bad-input", "content");
89
102
  if (opts.entity) return mime.canonicalize(raw, SmimeError, "smime/bad-mime");
@@ -637,6 +650,7 @@ function _base64Body(der) {
637
650
  * var msg = await pki.smime.sign(Buffer.from("hello"), [{ cert: signerCertDer, key: signerKeyPkcs8 }]);
638
651
  */
639
652
  async function sign(content, signers, opts) {
653
+ content = _fixedContent(content);
640
654
  opts = opts || {};
641
655
  opts = _knownOpts(opts, SIGN_OPTS, "sign");
642
656
  signers = _snapshotSignersFitForMail(signers);
@@ -859,6 +873,7 @@ function _cmsEncryptOpts(opts) {
859
873
  * var enc = await pki.smime.encrypt(Buffer.from("secret"), [{ cert: recipientCertDer }]);
860
874
  */
861
875
  async function encrypt(content, recipients, opts) {
876
+ content = _fixedContent(content);
862
877
  opts = opts || {};
863
878
  opts = _knownOpts(opts, ENCRYPT_OPTS, "encrypt");
864
879
  var hp = opts.protectHeaders === true;
@@ -902,6 +917,7 @@ async function encrypt(content, recipients, opts) {
902
917
  * @opts recipientIndex forwarded to cms.decrypt: explicitly select the recipient by index.
903
918
  * @opts maxIterations forwarded to cms.decrypt: lower the PBKDF2 iteration cap (downward only).
904
919
  * @opts strictSmimeType reject a header `smime-type` that disagrees with the CMS body (`smime/smime-type-mismatch`).
920
+ * @opts allowUnauthenticatedRsa15 forwarded to cms.decrypt: read a body that uses RSAES-PKCS1-v1_5 key transport over a content with no integrity tag, refused by default with `cms/unauthenticated-rsa-v15`. An `openssl smime -encrypt` message is exactly that combination when no algorithm is named.
905
921
  * @opts legacyHeaderProtection opt in to detecting a LEGACY RFC 8551 header-protected message (RFC 9788 sec. 4.10): an encrypted Cryptographic Payload that is a bare `message/rfc822` wrap with no `hp=` parameter. When set, a precisely-identified legacy message surfaces the inner headers under `headerProtection.legacy = { headers, mode: "cipher", fromMismatch, confidential }`, with `headers` an ordered `[{ name, value }]` array (retaining repeated fields) and the `confidential` set derived from the actual visible outer Header Section. They are not placed under `protectedHeaders`, and `present` stays `false`, since a legacy message is structurally indistinguishable from a forwarded `message/rfc822` (a heuristic; cross-check `legacy.fromMismatch`). Anything not precisely identified reports `legacy: null`. Off by default.
906
922
  * @example
907
923
  * var rsa = { name: "RSA-OAEP", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" };
@@ -929,6 +945,10 @@ async function decrypt(message, keyMaterial, opts) {
929
945
  var cmsOpts = {};
930
946
  if (opts.recipientIndex !== undefined) cmsOpts.recipientIndex = opts.recipientIndex;
931
947
  if (opts.maxIterations !== undefined) cmsOpts.maxIterations = opts.maxIterations;
948
+ /** @internal Forwarded rather than re-decided here: an S/MIME body is a CMS structure and the rule about
949
+ * RSAES-PKCS1-v1_5 over an unauthenticated content belongs to the verb that opens it. An
950
+ * `openssl smime -encrypt` or `openssl cms -encrypt` message is exactly that combination by default. */
951
+ if (opts.allowUnauthenticatedRsa15 !== undefined) cmsOpts.allowUnauthenticatedRsa15 = opts.allowUnauthenticatedRsa15;
932
952
  var res = await cms.decrypt(der, keyMaterial, cmsOpts);
933
953
  return Object.assign({
934
954
  content: res.content, smimeType: smimeType, authenticated: res.authenticated,
@@ -960,6 +980,7 @@ async function decrypt(message, keyMaterial, opts) {
960
980
  * var z = await pki.smime.compress(Buffer.from("compress this message"));
961
981
  */
962
982
  async function compress(content, opts) {
983
+ content = _fixedContent(content);
963
984
  opts = opts || {};
964
985
  opts = _knownOpts(opts, COMPRESS_OPTS, "compress");
965
986
  var entity = _entityBytes(content, opts);