@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/csr-sign.js
CHANGED
|
@@ -16,11 +16,6 @@
|
|
|
16
16
|
* @spec RFC 2986
|
|
17
17
|
* @card Build and sign a PKCS#10 certification request (proof of possession by the subject key).
|
|
18
18
|
*/
|
|
19
|
-
//
|
|
20
|
-
// The signature algorithm resolves from the SUBJECT public key through the shared sign-scheme registry
|
|
21
|
-
// (RSA / ECDSA / EdDSA / ML-DSA / SLH-DSA / composite), so there is no per-algorithm branch here. The
|
|
22
|
-
// distinguished-name / extension / SPKI encoders + the post-sign self-check are the shared lib/pki-build
|
|
23
|
-
// primitives (the same ones pki.x509.sign composes), bound to the csr namespace.
|
|
24
19
|
|
|
25
20
|
var asn1 = require("./asn1-der");
|
|
26
21
|
var oid = require("./oid");
|
|
@@ -30,7 +25,7 @@ var pkix = require("./schema-pkix");
|
|
|
30
25
|
var pkiBuild = require("./pki-build");
|
|
31
26
|
var frameworkError = require("./framework-error");
|
|
32
27
|
var guard = require("./guard-all");
|
|
33
|
-
require("./path-validate");
|
|
28
|
+
require("./path-validate");
|
|
34
29
|
var csrVerify = require("./csr-verify");
|
|
35
30
|
|
|
36
31
|
var CsrError = frameworkError.CsrError;
|
|
@@ -47,18 +42,12 @@ var _b = pkiBuild.makeBuilder({
|
|
|
47
42
|
NAME_SCHEMA: pkix.name(NS), SPKI_SCHEMA: pkix.spki(NS), EXT_DECODERS: EXT_DECODERS,
|
|
48
43
|
});
|
|
49
44
|
|
|
50
|
-
// attributes ::= [0] IMPLICIT SET OF Attribute (RFC 2986). The IMPLICIT tag replaces the universal SET,
|
|
51
|
-
// so it is a context-constructed [0] whose DER-sorted members ARE the SET-OF; empty -> A0 00.
|
|
52
45
|
function _implicitSetOf0(members) {
|
|
53
46
|
return b.contextConstructed(0, Buffer.concat(members.slice().sort(Buffer.compare)));
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
// The requested v3 Extensions (a bare SEQUENCE OF Extension, RFC 2985 sec. 5.4.2) -- the shared builder
|
|
57
|
-
// primitive (a CSR REQUESTS extensions; no CA gates), object form or a pre-encoded Extension DER array.
|
|
58
49
|
function _buildRequestedExtensions(extSpec, subjectSpki) { return _b.requestedExtensions(extSpec, subjectSpki); }
|
|
59
50
|
|
|
60
|
-
// challengePassword ::= DirectoryString bounded 1..255 (RFC 2985 sec. 5.4.1). PrintableString when the
|
|
61
|
-
// value is in that charset, else UTF8String; never a Teletex/BMP/Universal string for a new value.
|
|
62
51
|
function _challengePassword(pw) {
|
|
63
52
|
if (typeof pw !== "string" || pw.length < 1 || pw.length > 255) throw _err("csr/bad-input", "challengePassword must be a 1..255 character string (RFC 2985 sec. 5.4.1)");
|
|
64
53
|
return asn1.isPrintableString(pw) ? b.printable(pw) : b.utf8(pw);
|
|
@@ -101,8 +90,6 @@ function _challengePassword(pw) {
|
|
|
101
90
|
* pki.schema.csr.parse(req).subject.dn; // "CN=req.example.com"
|
|
102
91
|
*/
|
|
103
92
|
function sign(spec, key, opts) {
|
|
104
|
-
// Every caller-owned argument copied at entry and released when the call settles -- see the note
|
|
105
|
-
// on the same call in x509-sign.
|
|
106
93
|
return guard.bytes.fixedCall(CsrError, "csr/bad-input", [
|
|
107
94
|
[spec, "the certification-request spec"], [key, "the signing key"], [opts, "pki.csr.sign options"],
|
|
108
95
|
], _sign);
|
|
@@ -111,10 +98,7 @@ function sign(spec, key, opts) {
|
|
|
111
98
|
function _sign(spec, key, opts) {
|
|
112
99
|
opts = opts || {};
|
|
113
100
|
if (!spec || typeof spec !== "object" || Buffer.isBuffer(spec)) throw _err("csr/bad-input", "the certification-request spec must be an object");
|
|
114
|
-
// Reject a typo'd spec field at config-time rather than silently dropping it (a misspelled `subjcet`
|
|
115
|
-
// would otherwise yield an empty-subject request).
|
|
116
101
|
guard.identifier.assertKnownKeys(spec, KNOWN_SPEC_KEYS, _err, "csr/bad-input", "unknown spec field ");
|
|
117
|
-
// The signing key is the second argument (a PKCS#8 key / CryptoKey / composite key pair), or { key }.
|
|
118
102
|
var signingKey = (key && typeof key === "object" && !Buffer.isBuffer(key) && !(key instanceof Uint8Array) && key.type == null && "key" in key) ? key.key : key;
|
|
119
103
|
if (signingKey == null) throw _err("csr/bad-input", "a signing key (the subject's private key) is required");
|
|
120
104
|
|
|
@@ -122,13 +106,11 @@ function _sign(spec, key, opts) {
|
|
|
122
106
|
_b.assertValidSpki(subjectSpki, "spec.subjectPublicKey");
|
|
123
107
|
var subjectDer = _b.encodeName(spec.subject == null ? [] : spec.subject);
|
|
124
108
|
|
|
125
|
-
// attributes: extensionRequest + challengePassword + pre-encoded opaque Attribute DER (the escape
|
|
126
|
-
// hatch). A recognized attribute may appear at most once (RFC 2985 SINGLE VALUE + producer hygiene).
|
|
127
109
|
var attrs = [], seenAttr = {};
|
|
128
110
|
function addAttr(attrType, valueTlv) {
|
|
129
111
|
if (seenAttr[attrType]) throw _err("csr/bad-input", "duplicate " + (oid.name(attrType) || attrType) + " attribute");
|
|
130
112
|
seenAttr[attrType] = true;
|
|
131
|
-
attrs.push(b.sequence([b.oid(attrType), b.set([valueTlv])]));
|
|
113
|
+
attrs.push(b.sequence([b.oid(attrType), b.set([valueTlv])]));
|
|
132
114
|
}
|
|
133
115
|
if (spec.extensionRequest != null) addAttr(O("extensionRequest"), _buildRequestedExtensions(spec.extensionRequest, subjectSpki));
|
|
134
116
|
if (spec.challengePassword != null) addAttr(O("challengePassword"), _challengePassword(spec.challengePassword));
|
|
@@ -143,13 +125,8 @@ function _sign(spec, key, opts) {
|
|
|
143
125
|
var at;
|
|
144
126
|
try { at = asn1.read.oid(n.children[0]); }
|
|
145
127
|
catch (e) { throw _err("csr/bad-input", "pre-encoded attribute [" + i + "] type is not an OBJECT IDENTIFIER", e); }
|
|
146
|
-
// A type with a dedicated typed spec field must go through that field so its value syntax is always
|
|
147
|
-
// enforced (RFC 2985 sec. 5.4): the opaque escape hatch is for UNRECOGNIZED attribute types only and
|
|
148
|
-
// must never carry a recognized type with an unvalidated value the strict parser would then reject.
|
|
149
128
|
if (at === O("extensionRequest")) throw _err("csr/bad-input", "pass requested extensions via spec.extensionRequest, not a pre-encoded extensionRequest attribute");
|
|
150
129
|
if (at === O("challengePassword")) throw _err("csr/bad-input", "pass the challenge password via spec.challengePassword, not a pre-encoded challengePassword attribute");
|
|
151
|
-
// Attribute ::= SEQUENCE { type, values SET SIZE(1..MAX) }: an empty value SET is malformed and the
|
|
152
|
-
// strict parser rejects it, so reject at build time -- a signed request must always round-trip.
|
|
153
130
|
if (!n.children[1].children || n.children[1].children.length === 0) throw _err("csr/bad-input", "pre-encoded attribute [" + i + "] value SET must contain at least one value (RFC 2986 SET SIZE(1..MAX))");
|
|
154
131
|
if (seenAttr[at]) throw _err("csr/bad-input", "duplicate " + (oid.name(at) || at) + " attribute");
|
|
155
132
|
seenAttr[at] = true;
|
|
@@ -157,14 +134,11 @@ function _sign(spec, key, opts) {
|
|
|
157
134
|
});
|
|
158
135
|
}
|
|
159
136
|
|
|
160
|
-
// Resolve the signature scheme from the SUBJECT public key (the request proves possession of its private half).
|
|
161
137
|
var scheme = signScheme.resolveSignScheme(_b.certLikeFromSpki(subjectSpki), { combinedRsaSig: true, pss: opts.pss, digestAlgorithm: opts.digestAlgorithm }, true, _signE);
|
|
162
138
|
|
|
163
|
-
// CertificationRequestInfo ::= SEQUENCE { version INTEGER(0), subject, subjectPKInfo, attributes [0] }.
|
|
164
139
|
var criDer = b.sequence([b.integer(0n), subjectDer, b.raw(subjectSpki), _implicitSetOf0(attrs)]);
|
|
165
140
|
|
|
166
141
|
return signScheme.signOverTbs(scheme, signingKey, criDer, _signE).then(function (sig) {
|
|
167
|
-
// Proof of possession: the signature MUST verify under the subject public key (what openssl req -verify checks).
|
|
168
142
|
return Promise.resolve(_b.assertSignatureVerifies(criDer, sig, subjectSpki, scheme)).then(function () {
|
|
169
143
|
var der = b.sequence([criDer, scheme.sigAlgId, b.bitString(sig, 0)]);
|
|
170
144
|
return opts.pem ? csr.pemEncode(der, "CERTIFICATE REQUEST") : der;
|
|
@@ -229,15 +203,10 @@ function _coerceCsr(request) {
|
|
|
229
203
|
*/
|
|
230
204
|
function verify(request) { return guard.async.deferred(function () { return _verify(request); }); }
|
|
231
205
|
function _verify(request) {
|
|
232
|
-
// The fields come off the structure the door re-derived from the recorded bytes, never off the
|
|
233
|
-
// argument. A caller who normalizes a parse result in place -- rewriting subject or attributes
|
|
234
|
-
// before verifying -- still holds their edited object afterwards, and a bare boolean would let
|
|
235
|
-
// them issue from it while the verdict was about something else. Handing back the verified
|
|
236
|
-
// structure means the fields a CA acts on are the fields the signature covers.
|
|
237
206
|
var parsed = _coerceCsr(request);
|
|
238
207
|
return Promise.resolve(csrVerify.verifyCsrSignature(parsed)).then(function (ok) {
|
|
239
208
|
return {
|
|
240
|
-
valid: ok === true,
|
|
209
|
+
valid: ok === true,
|
|
241
210
|
verified: ok === true,
|
|
242
211
|
subject: parsed.subject,
|
|
243
212
|
subjectPublicKeyInfo: parsed.subjectPublicKeyInfo,
|
package/lib/csr-verify.js
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (c) blamejs contributors
|
|
3
3
|
"use strict";
|
|
4
|
-
//
|
|
5
|
-
// @internal -- the single PKCS#10 proof-of-possession signature seam for an INBOUND request, shared
|
|
6
|
-
// by pki.csr.verify and by every enrollment path that accepts one, so all of them route through one
|
|
7
|
-
// signature engine and no second, weaker verifier of untrusted requests can drift. The producing
|
|
8
|
-
// side runs its own check over what it just signed (pki-build's assertSignatureVerifies, called
|
|
9
|
-
// from csr-sign), which is a different question about a key the caller already controls. The slot,
|
|
10
|
-
// the wiring assertion and the octet-alignment refusal are the shared seam (lib/verify-seam.js). It
|
|
11
|
-
// is not wired into index.js and is reached only by require.
|
|
4
|
+
// @internal
|
|
12
5
|
|
|
13
6
|
var frameworkError = require("./framework-error");
|
|
14
7
|
var seam = require("./verify-seam");
|
|
15
8
|
|
|
16
9
|
var _seam = seam.makeSeam("csr-verify", frameworkError.CsrError, "csr/bad-input");
|
|
17
10
|
|
|
18
|
-
// Verify a parsed certification request's signature over its exact certificationRequestInfo bytes
|
|
19
|
-
// under the subjectPKInfo the request carries. A CSR has no issuer: the verifying key is the one
|
|
20
|
-
// inside the signed preimage, which is what makes the signature a proof of possession and nothing
|
|
21
|
-
// more.
|
|
22
11
|
function verifyCsrSignature(parsed) {
|
|
23
12
|
return _seam.verify(parsed.signatureAlgorithm, parsed.signatureValue,
|
|
24
13
|
parsed.subjectPublicKeyInfo.bytes, parsed.certificationRequestInfoBytes);
|