@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.
- package/CHANGELOG.md +411 -0
- package/README.md +67 -16
- package/bin/pki.js +716 -30
- package/examples/issue-a-certificate.js +90 -0
- package/examples/post-quantum.js +66 -0
- package/examples/read-a-certificate.js +56 -0
- package/examples/revoke-and-check.js +86 -0
- package/examples/sign-and-verify-cms.js +63 -0
- package/index.js +18 -5
- package/lib/acme.js +223 -74
- package/lib/alt-sig.js +441 -0
- package/lib/asn1-der.js +48 -25
- package/lib/attrcert-sign.js +27 -19
- package/lib/cbor-det.js +24 -14
- package/lib/cmc-build.js +9 -2
- package/lib/cmc-verify.js +14 -3
- package/lib/cmp-build.js +17 -5
- package/lib/cmp-session.js +24 -11
- package/lib/cmp-verify.js +28 -19
- package/lib/cms-compress.js +3 -1
- package/lib/cms-decrypt.js +102 -7
- package/lib/cms-encrypt.js +59 -7
- package/lib/cms-sign.js +31 -9
- package/lib/cms-verify.js +22 -18
- package/lib/composite-kem.js +30 -18
- package/lib/composite-sig.js +29 -14
- package/lib/constants.js +28 -0
- package/lib/crl-sign.js +111 -19
- package/lib/crmf-sign.js +167 -15
- package/lib/csr-sign.js +117 -6
- package/lib/ct.js +939 -48
- package/lib/est.js +29 -16
- package/lib/framework-error.js +12 -0
- package/lib/guard-async.js +1 -1
- package/lib/guard-bytes.js +103 -20
- package/lib/guard-crypto.js +205 -3
- package/lib/guard-encoding.js +6 -1
- package/lib/guard-identifier.js +55 -8
- package/lib/guard-intrinsic.js +43 -0
- package/lib/guard-json.js +122 -9
- package/lib/guard-limits.js +12 -1
- package/lib/guard-list.js +63 -8
- package/lib/guard-name.js +167 -20
- package/lib/guard-range.js +43 -5
- package/lib/guard-text.js +41 -0
- package/lib/guard-verdict.js +39 -8
- package/lib/hpke.js +688 -42
- package/lib/http-transport.js +156 -4
- package/lib/identity-match.js +4 -4
- package/lib/inspect.js +448 -2
- package/lib/jose.js +93 -25
- package/lib/key.js +18 -13
- package/lib/lint.js +165 -1
- package/lib/merkle.js +233 -27
- package/lib/ocsp.js +27 -14
- package/lib/oid.js +14 -4
- package/lib/path-validate.js +143 -61
- package/lib/pkcs12-build.js +7 -2
- package/lib/pki-build.js +31 -7
- package/lib/possession.js +575 -0
- package/lib/related-cert.js +708 -0
- package/lib/revocation-fetch.js +6 -6
- package/lib/scep.js +15 -5
- package/lib/schema-c509.js +5 -2
- package/lib/schema-cmc.js +1 -1
- package/lib/schema-cmp.js +8 -8
- package/lib/schema-cms.js +2 -15
- package/lib/schema-csr.js +69 -0
- package/lib/schema-engine.js +10 -3
- package/lib/schema-pkix.js +267 -4
- package/lib/schema-tsp.js +7 -6
- package/lib/sign-scheme.js +22 -9
- package/lib/sigstore.js +684 -168
- package/lib/sleep.js +8 -1
- package/lib/smime.js +22 -1
- package/lib/tlog.js +1235 -0
- package/lib/tls-cert-compress.js +25 -8
- package/lib/tsp-sign.js +120 -35
- package/lib/tuf.js +1395 -0
- package/lib/validator-tpm.js +4 -1
- package/lib/verify-seam.js +7 -1
- package/lib/webauthn-mds.js +41 -4
- package/lib/webauthn.js +43 -25
- package/lib/webcrypto.js +48 -46
- package/lib/x509-sign.js +225 -19
- package/package.json +2 -1
- 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
|
|
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);
|