@blamejs/pki 0.6.31 → 0.6.33
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 +24 -0
- package/README.md +2 -2
- package/lib/est.js +104 -6
- package/lib/http-transport.js +26 -6
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,30 @@ All notable changes to `@blamejs/pki` are documented here. The format
|
|
|
4
4
|
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this
|
|
5
5
|
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## v0.6.33 — 2026-09-04
|
|
8
|
+
|
|
9
|
+
pki.transport reports the RFC 9266 tls-exporter channel binding of a TLS 1.3 connection, so every connection the toolkit opens now carries the binding its protocol version defines.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- pki.transport.https reports tls.tlsExporter, the RFC 9266 channel binding of a TLS 1.3 connection (32 bytes, label EXPORTER-Channel-Binding, zero-length context), on its response and on the argument passed to a request body given as a function. It is null below TLS 1.3, where RFC 9266 sec. 2 also requires the RFC 7627 extended master secret that Node cannot confirm, and null when the socket cannot export. tls.tlsUnique is unchanged, so a connection carries exactly the binding its version defines.
|
|
14
|
+
|
|
15
|
+
## v0.6.32 — 2026-09-04
|
|
16
|
+
|
|
17
|
+
pki.est.simpleenroll and pki.est.simplereenroll accept a CSR builder, so an enrollment is signed over the tls-unique of the connection it is sent on (RFC 7030 sec. 3.5 channel binding).
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- pki.est.simpleenroll(baseUrl, builder, opts?) and pki.est.simplereenroll(baseUrl, builder, opts?) accept a CSR builder (tls) -> csr | Promise<csr> for RFC 7030 sec. 3.5 channel binding. The builder receives the connection's { protocol, cipher, peerCertificate, tlsUnique } after the handshake and returns the certification request to POST on it, so pki.csr.sign can embed the base64 tls-unique as spec.challengePassword. A redirect or authentication retry re-runs the builder against the new connection (RFC 7030 sec. 3.2.1). Existing calls that pass a DER or PEM request are unchanged.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- pki.est.simplereenroll performs its RFC 7030 sec. 4.2.2 subject and SubjectAltName identity check on each CSR a builder produces, inside the post-handshake callback and before that CSR is written. With a pre-built request the check still runs before the transport is called at all.
|
|
26
|
+
|
|
27
|
+
### Security
|
|
28
|
+
|
|
29
|
+
- A CSR builder combined with Digest authentication is refused (est/channel-binding-digest-unsupported) instead of sending an enrollment whose binding and Authorization header cannot both be correct: the Digest header is computed over the request body before the handshake the body must be bound to. A builder that throws fails the request (est/csr-builder-failed, with the cause attached) and a typed toolkit error it raises, such as requesting a binding on a TLS 1.3 connection where none exists, keeps its own code. No certification request is written to the wire in any of these cases, so an unbound or mis-bound enrollment is never sent. When an enrollment is retried across connections, the reported failure is the one that actually ended the attempt: a builder error is surfaced only where it caused the failure, so a later connection that fails on its own, for instance during TLS setup before the builder runs, reports that fault rather than an earlier builder error. A response is only ever read as an enrollment outcome when that request's own certification request was actually built and sent. Each request the client makes gets its own builder callback and its own state, so a callback belonging to an earlier request, including one a transport retained and ran late, can never supply the key or the error used to judge the request in flight. If an injected transport absorbs a builder failure, answers without requesting the body, or answers before the builder has finished, neither a 202 queued verdict nor an issued certificate is returned; the call fails closed instead, so enrollment progress is never reported for a request that never went out, and an issued certificate is never accepted against a key the request in flight did not carry.
|
|
30
|
+
|
|
7
31
|
## v0.6.31 — 2026-09-04
|
|
8
32
|
|
|
9
33
|
pki.transport reports the RFC 5929 tls-unique of a TLS 1.2 connection and accepts a request body built from it, so a caller can bind an EST enrollment to the TLS session it posts over (RFC 7030 sec. 3.5).
|
package/README.md
CHANGED
|
@@ -221,9 +221,9 @@ comment blocks, is at [pkijs.com](https://pkijs.com).
|
|
|
221
221
|
| `pki.schema.pkcs12` | PKCS#12 (PFX) stores (RFC 7292) from DER, BER, or PEM: key bags via the PKCS#8 parser, shrouded keys with the algorithm surfaced and the ciphertext opaque, cert / CRL / secret bags raw and byte-exact, encrypted and enveloped safes structurally via CMS, `friendlyName` and `localKeyId` decoded, and the exact MAC byte range (`macedBytes`) plus RFC 9579 PBMAC1 recognition for external verification. BER is accepted exactly where §4.1 requires it Fail-closed — `parse`, `pemDecode`, `pemEncode` |
|
|
222
222
|
| `pki.schema.cmp` | CMP messages (RFC 9810): the header (version, sender and recipient including the anonymous NULL-DN, nonces, transaction id, general info), the 27-arm body (certificate requests via the CRMF parser, an encrypted certificate's EnvelopedData via CMS, response / revocation / confirmation / error / support / polling arms structural, the rest raw), and the exact `headerBytes` and `bodyBytes` slices an external verifier reconstructs the protected part from. The CMP-before-OCSP dispatch order is enforced Fail-closed — `parse`, `pemDecode`, `pemEncode` |
|
|
223
223
|
| `pki.schema.csrattrs` | EST CSR Attributes (`CsrAttrs`, RFC 8951 §3.5 / RFC 9908) — the `AttrOrOID` items a server sends to shape an enrollment: bare OIDs, attributes with raw values, and decoded views of the RFC 9908 meaningful types (extension requests, EC and RSA key-type conventions, the certification-request-info template). Unknown types are surfaced raw; structure and the RFC 9908 semantic MUSTs are fail-closed — `parse` |
|
|
224
|
-
| `pki.est` | Enrollment over Secure Transport (RFC 7030 / 8951 / 9908 / 7616). The client verbs `cacerts`, `simpleenroll`, `simplereenroll`, `serverkeygen`, `csrattrs`, and `fullcmc` drive the RFC 7030 flow over `pki.transport` (inject your own via `opts.transport`, or take the fail-closed default): HTTPS only, an explicit trust anchor required, same-origin redirects followed while a downgrade or loop is refused, a 202 Retry-After surfaced but never slept, HTTP Basic or Digest (RFC 7616, SHA-256 / SHA-512-256; MD5 and no-qop refused by default) answered only after the server is authenticated, and the issued certificate chosen by public-key match. `serverkeygen` requests a server-generated key, cleartext or an opaque CMS EnvelopedData, with encryption bound to the CSR's key-identifier attribute over a confidentiality-bearing cipher. `csrattrs` fetches the CA's RFC 9908 attributes policy. `fullcmc` (§4.3) carries a CMC Full PKI Request and reduces the CA's answer through `pki.cmc.verify` to one terminal outcome, refusing a response that fails to echo the transaction and nonce the request carried, or that covers a key the request never asked for; a certs-only reply to a bound request is refused rather than read as an issuance. Under the verbs sit the transport-agnostic codecs they compose: the RFC 8951 base64 transfer codec (which ignores Content-Transfer-Encoding), the `multipart/mixed` splitter, the certs-only and serverkeygen response validators over CMS, the enroll-attribute builders, and the HTTP response classifier — `transferDecode`/`transferEncode`, `parseCertsOnly`, `splitMultipartMixed`, `parseServerKeygenResponse`, `findIssuedCert`, `classifyResponse`, `paths`, and the builders |
|
|
224
|
+
| `pki.est` | Enrollment over Secure Transport (RFC 7030 / 8951 / 9908 / 7616). The client verbs `cacerts`, `simpleenroll`, `simplereenroll`, `serverkeygen`, `csrattrs`, and `fullcmc` drive the RFC 7030 flow over `pki.transport` (inject your own via `opts.transport`, or take the fail-closed default): HTTPS only, an explicit trust anchor required, same-origin redirects followed while a downgrade or loop is refused, a 202 Retry-After surfaced but never slept, HTTP Basic or Digest (RFC 7616, SHA-256 / SHA-512-256; MD5 and no-qop refused by default) answered only after the server is authenticated, and the issued certificate chosen by public-key match. `serverkeygen` requests a server-generated key, cleartext or an opaque CMS EnvelopedData, with encryption bound to the CSR's key-identifier attribute over a confidentiality-bearing cipher. `csrattrs` fetches the CA's RFC 9908 attributes policy. For §3.5 channel binding, `simpleenroll` and `simplereenroll` accept a CSR builder `(tls) -> csr` instead of a CSR: it runs after the handshake with that connection's `tlsUnique`, so the request is signed over the session it is sent on, and it re-runs on any new connection a redirect or auth retry opens, recreating the CSR for that session (§3.2.1). A builder alongside Digest authentication is refused, since that header is computed over the body before the handshake. `fullcmc` (§4.3) carries a CMC Full PKI Request and reduces the CA's answer through `pki.cmc.verify` to one terminal outcome, refusing a response that fails to echo the transaction and nonce the request carried, or that covers a key the request never asked for; a certs-only reply to a bound request is refused rather than read as an issuance. Under the verbs sit the transport-agnostic codecs they compose: the RFC 8951 base64 transfer codec (which ignores Content-Transfer-Encoding), the `multipart/mixed` splitter, the certs-only and serverkeygen response validators over CMS, the enroll-attribute builders, and the HTTP response classifier — `transferDecode`/`transferEncode`, `parseCertsOnly`, `splitMultipartMixed`, `parseServerKeygenResponse`, `findIssuedCert`, `classifyResponse`, `paths`, and the builders |
|
|
225
225
|
| `pki.scep` | SCEP pkiMessage codec (RFC 8894), the client side of Simple Certificate Enrollment. `build(spec)` assembles a request: a `PKCSReq` or `RenewalReq` wraps a PKCS#10 certification request, whose own proof-of-possession it verifies first; a `CertPoll` wraps an IssuerAndSubject naming the issuing CA and the request subject; and a `GetCert` or `GetCRL` wraps an IssuerAndSerialNumber naming a certificate by its issuer and a positive serial of at most 20 octets. It encrypts the messageData to the CA as the inner EnvelopedData (`pkcsPKIEnvelope`, AES-128-CBC), and signs that under the transaction attributes RFC 8894 §3.2 defines, a messageType, a caller-unique transactionId, and a 16-byte senderNonce. The recipient CA certificate must assert `keyEncipherment`. `build` also issues the CA-side `CertRep` response (§3.3.2): a SUCCESS envelopes a certs-only SignedData of the issued certificate (or the CRL for a GetCRL) to the requester and signs it under the CA key, while a FAILURE (carrying a `failInfo`) or a PENDING omits the pkcsPKIEnvelope and is signed detached, each echoing the request's senderNonce as `recipientNonce`. `parse(bytes, opts?)` reads a `PKCSReq`, `RenewalReq`, `CertPoll`, `GetCert`, `GetCRL`, or `CertRep` back (a messageType outside the RFC 8894 registry is refused): it verifies the outer signature first and refuses a message whose signature does not check, so the transaction attributes it returns come only from a verified signer, never alongside a false verdict. Because a valid signature only proves self-consistency with the embedded certificate, pass `opts.signerCert` to authenticate a CA response against the CA certificate you hold (a public-key mismatch is refused, `signerAuthenticated` reports the result); a caller that omits it gets a crypto-only verdict and must authenticate the surfaced `signerCert` itself. It maps the messageType, pkiStatus, failInfo, and the nonces from their RFC 8894 enumerants and refuses an unknown one; given `recipientKey` it decrypts the `pkcsPKIEnvelope` to the messageData, and given `expectedSenderNonce` it refuses a response whose recipientNonce does not echo it. It reads a CA's CertRep in full. `getCACaps(baseUrl, opts?)`, `getCACert(baseUrl, opts?)`, `getNextCACert(baseUrl, opts)`, `enroll(baseUrl, opts)`, `renew(baseUrl, opts)`, `getCert(baseUrl, opts)`, and `getCrl(baseUrl, opts)` carry that codec to a live CA over HTTP (RFC 8894 §4) through an injectable transport (`pki.transport.https` by default): `getCACaps` reports the CA's advertised capabilities and never lowers the client's algorithm choice on the unauthenticated response, `getCACert` pins the CA certificate to an out-of-band `expectedFingerprint` a returned certificate must match, `getNextCACert` fetches the CA's next (rollover) certificate and verifies the SignedData response against the current CA certificate (`caCertificate`) before returning it, refusing a response signed by any other key, and `enroll` and `renew` POST a PKCSReq or RenewalReq, authenticate the CertRep against the CA certificate and its nonce echo, select the issued certificate by public-key match, throw on a FAILURE with the CA's failInfo, and poll a PENDING response with CertPoll requests until the CA answers or a bounded poll-count and total-wait budget is spent. `getCert` and `getCrl` retrieve an already-issued certificate or a CA CRL by issuer and serial number, authenticated the same way; RFC 8894 §2.6, §2.7, and §3.3.4 recommend these queries only where HTTP certificate-store access (RFC 4387), LDAP, or a CRL distribution point is unavailable, so prefer those where a CA offers them. A PKIOperation goes over HTTP POST by default; `httpMethod: "GET"` carries it base64-encoded in the URL query for a legacy CA that accepts only GET (RFC 8894 §4.1). Every verb reaches an https CA through a forward proxy with `opts.proxy = { url, auth?, tls? }`: a `CONNECT` tunnel is opened to the proxy and the origin TLS is negotiated inside it, so the proxy carries the enrollment without being able to read it or substitute the origin certificate. Basic proxy authentication (RFC 7617) is sent only over an `https://` proxy, where it rides the authenticated TLS-to-proxy channel; an `http://` proxy is tunnel-only, and credentials over a plaintext proxy are refused rather than exposed (see `pki.transport`) — `build`, `parse`, `parseCapabilities`, `getCACaps`, `getCACert`, `getNextCACert`, `enroll`, `renew`, `getCert`, `getCrl` |
|
|
226
|
-
| `pki.transport` | The shared, fail-closed `node:https` transport the enrollment clients drive. `pki.transport.https(defaults)` returns a `transport(request) → { status, headers, body, tls }`, where `tls` carries the negotiated `protocol`, `cipher`, raw `peerCertificate`, and
|
|
226
|
+
| `pki.transport` | The shared, fail-closed `node:https` transport the enrollment clients drive. `pki.transport.https(defaults)` returns a `transport(request) → { status, headers, body, tls }`, where `tls` carries the negotiated `protocol`, `cipher`, raw `peerCertificate`, and one channel binding per TLS version: on TLS 1.2 the RFC 5929 `tlsUnique` that `pki.est.challengePasswordFromTlsUnique` links to an EST enrollment (RFC 7030 §3.5), and on TLS 1.3 the RFC 9266 `tlsExporter` (32 bytes under the label `EXPORTER-Channel-Binding`, zero-length context). Each is `null` on the version that does not define it, and `tlsExporter` is withheld below TLS 1.3 because RFC 9266 §2 also requires the RFC 7627 extended master secret, which Node gives no way to confirm. Since `tlsUnique` on the response arrives after the body was sent, a request `body` may instead be a function `(tls) -> bytes` the transport invokes after the handshake and before it writes the body, so the caller builds a channel-bound CSR from `tlsUnique` on the same connection it posts over. It may return a promise, so the CSR can be signed with `pki.csr.sign` while the connection is held open; a callback that throws, rejects, or returns anything other than bytes or a string fails the request closed rather than posting an empty enrollment. This is the toolkit's only socket choke point: an explicit trust anchor (or an opt-in to the system store) is required, `rejectUnauthorized` is always on, TLS is floored at 1.2, the response body is capped while it streams, and a stalled socket times out. The EST, ACME, and CMP clients reuse it verbatim. A `request.proxy = { url, auth?, tls? }` reaches the origin through a forward proxy: a `CONNECT` tunnel is opened to the proxy and the origin TLS is negotiated inside it under the identical origin trust policy, so the proxy cannot read the origin's encrypted session or substitute an authenticated origin certificate. Basic proxy credentials are sent only over an `https://` proxy, whose own certificate is verified against `proxy.tls`, so they ride an authenticated channel; a plaintext `http://` proxy is tunnel-only and carrying `auth` on one is refused (`proxy-auth-requires-tls`) rather than exposing the credentials to the proxy hop. A malformed option, a failed CONNECT, an unverified proxy certificate, or an unaccepted credential fails closed. The SCEP, EST, ACME, and CMP clients each thread it through as `opts.proxy`. If you inject your own transport, return `tls` too: `pki.est.serverkeygen` asserts the negotiated cipher can protect the delivered private key, and a transport that reports no cipher is trusted rather than refused, so omitting the field silently skips that check — `https` |
|
|
227
227
|
| `pki.jose` | Flattened JWS (RFC 7515) and JWK thumbprints (RFC 7638). `sign` and `verify` run a Flattened JWS against declarative profiles (ACME outer, EAB inner, keyChange inner) that carry the required and forbidden header rules as data. `base64url` is the strict RFC 4648 §5 codec, rejecting padding, non-alphabet characters, and non-canonical trailing bits. `parseJson` is a bounded reader that refuses duplicate members at any depth. `thumbprint` is the RFC 7638 / 8037 / 9964 canonical digest. The algorithm registry binds each `alg` to its key type (ES/RS/PS/EdDSA/ML-DSA), leaving no code path for `alg:none`, an RS256→HS256 key confusion, or an all-zero ECDSA signature; `assertPublicJwk` refuses a JWK carrying private material, so an exported private key is never published. `opts.key` names the key a message must be signed under and governs: where the profile also permits an embedded header `jwk`, the two must be the same key — compared as RFC 7638 thumbprints, so member order cannot make equal keys differ — and a disagreement is refused rather than resolved in the message's favor. `keySource` reports which key answered, since a signature checked against a key you named is a different claim from one checked against the key the message carried — `sign`, `verify`, `base64url`, `parseJson`, `thumbprint`, `assertPublicJwk` |
|
|
228
228
|
| `pki.acme` | ACME (RFC 8555 / 8737 / 8738 / 9773). `client(directoryUrl, opts)` is a stateful client driving a live CA directory over `pki.transport`: `newAccount`, `newOrder`, `newAuthz`, `getOrder`, `getAuthorization`, `getChallenge`, `respondToChallenge`, `finalize`, `pollOrder`, `pollAuthorization`, and `downloadCertificate` walk the issuance flow, with `newAuthz` pre-authorizing a single identifier (§7.4.1) and `downloadCertificate` binding the issued certificate to the order — its key, its identifiers, or both; at least one is required by default and the result reports `boundToKey` / `boundToIdentifiers` — before choosing among alternate chains (`Link rel="alternate"`, §7.4.2, via a `selectChain` predicate bounded by `maxAlternates`). `revokeCert` (account-key or certificate-key signed), `keyChange`, `updateAccount` (change the account contacts, §7.3.2), `listOrders` (the account's orders list, following the §7.1.2.1 `Link rel="next"` pagination bounded by a page cap and confined to the orders origin), `deactivateAccount`, `deactivateAuthorization`, `renewalInfo` (ARI), `renewalWindow` (the RFC 9773 §4.2/4.3 renewal decision), and `scheduleRenewal` (the §4.1 auto-sleeping renewal loop that sleeps until the selected instant and refetches until it is time to renew, stopping at the certificate's notAfter) complete the lifecycle. Every URL is HTTPS only, an explicit trust anchor is required, each request carries a fresh single-use nonce with a bounded badNonce retry (and, when `opts.resignKeys` supplies caller-approved alternative account-key algorithms, a bounded RFC 8555 §6.2 badSignatureAlgorithm re-sign that the CA's advertised list can only filter, never widen, so it cannot force a weaker algorithm), reads are POST-as-GET, polling is bounded and sleeps on a Retry-After via an injectable sleeper capped by a poll count and a total-wait budget, and every response body is size-capped. The transport is injectable via `opts.transport`. Over the message layer it composes resource-object validators (closed status enums, conditional-required fields, unknown fields ignored), the three §7.1.6 state machines, the request builders (newAccount with External Account Binding, newOrder with `replaces`, finalize with a CSR identifier-set match and account-key-reuse rejection, challenge responses, deactivation, revokeCert in both key modes, the keyChange nested JWS, POST-as-GET), the http-01 / dns-01 / tls-alpn-01 challenge computations, the dns and ip identifier validators, and the ARI certID with serial sign-padding preserved — `client`, `validate`, `identify`, `assertTransition`, the builders, `keyAuthorization`, `http01`, `dns01`, `tlsAlpn01Extension`, `verifyTlsAlpn01`, `ariCertId` |
|
|
229
229
|
| `pki.schema.smime` | S/MIME ESS signed-attribute values (RFC 5035 / RFC 8551). `parseSigningCertificate` and `parseSigningCertificateV2` bind a signature to its signing certificate (cert hash, hash algorithm, issuer `GeneralNames` and serial); `parseSmimeCapabilities` decodes the ordered capability list; `decodeAttribute` dispatches a CMS attribute by OID, enforcing the single-value rule and deferring on unknown types. A companion decoder for CMS signed attributes rather than an auto-routed format — `parseSigningCertificate`, `parseSigningCertificateV2`, `parseSmimeCapabilities`, `decodeAttribute` |
|
package/lib/est.js
CHANGED
|
@@ -881,7 +881,8 @@ function _drive(method, url, body, headers, opts, transport, budgets) {
|
|
|
881
881
|
return hh;
|
|
882
882
|
}
|
|
883
883
|
function step() {
|
|
884
|
-
|
|
884
|
+
var hopBody = (typeof body === "function" && budgets.onAttempt) ? budgets.onAttempt() : body;
|
|
885
|
+
return transport({ method: method, url: url.href, headers: _headersFor(url), body: hopBody, tls: _tlsFor(url), proxy: budgets.proxy, timeout: budgets.timeout, maxResponseBytes: budgets.maxResponseBytes }).then(function (res) {
|
|
885
886
|
res = res || {};
|
|
886
887
|
var blen = _bodyLen(res);
|
|
887
888
|
if (blen > budgets.maxResponseBytes) throw E("est/response-too-large", "the response body (" + blen + " bytes) exceeds the " + budgets.maxResponseBytes + "-byte cap (RFC 7030 sec. 6)");
|
|
@@ -944,7 +945,7 @@ function _drive(method, url, body, headers, opts, transport, budgets) {
|
|
|
944
945
|
return step();
|
|
945
946
|
}
|
|
946
947
|
|
|
947
|
-
function _client(op, method, baseUrl, body, headers, opts, proxySnap) {
|
|
948
|
+
function _client(op, method, baseUrl, body, headers, opts, proxySnap, onAttempt) {
|
|
948
949
|
var base;
|
|
949
950
|
try { base = new URL(String(baseUrl)); }
|
|
950
951
|
catch (e) { throw E("est/bad-url", "the EST base URL did not parse: " + guard.text.showValue(baseUrl), e); }
|
|
@@ -964,6 +965,7 @@ function _client(op, method, baseUrl, body, headers, opts, proxySnap) {
|
|
|
964
965
|
maxResponseBytes: guard.limits.cap(opts.maxResponseBytes, "maxResponseBytes", constants.LIMITS.HTTP_MAX_RESPONSE_BYTES, { E: E, code: "est/bad-input", min: 1, max: constants.LIMITS.HTTP_MAX_RESPONSE_BYTES }),
|
|
965
966
|
maxRedirects: guard.limits.cap(opts.maxRedirects, "maxRedirects", 5, { E: E, code: "est/bad-input", min: 0, max: 32 }),
|
|
966
967
|
maxStaleRetries: guard.limits.cap(opts.auth && opts.auth.maxStaleRetries, "maxStaleRetries", 1, { E: E, code: "est/bad-input", min: 0, max: 8 }),
|
|
968
|
+
onAttempt: typeof onAttempt === "function" ? onAttempt : null,
|
|
967
969
|
};
|
|
968
970
|
_authScheme(opts);
|
|
969
971
|
return _drive(method, url, body, Object.assign({}, headers), opts, transport, budgets);
|
|
@@ -1395,11 +1397,74 @@ function _tryDecodeCmcFault(res, sent) {
|
|
|
1395
1397
|
}).then(null, function () { return null; });
|
|
1396
1398
|
}
|
|
1397
1399
|
|
|
1400
|
+
function _isTypedError(e) {
|
|
1401
|
+
try { return !!(e && e.isPkiError === true); }
|
|
1402
|
+
catch (_re) { return false; }
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
function _causedBy(e, target) {
|
|
1406
|
+
if (!target) return false;
|
|
1407
|
+
var cur = e, depth = 0;
|
|
1408
|
+
while (cur && depth < 8) {
|
|
1409
|
+
if (cur === target) return true;
|
|
1410
|
+
try { cur = cur.cause; }
|
|
1411
|
+
catch (_ce) { return false; }
|
|
1412
|
+
depth += 1;
|
|
1413
|
+
}
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
var ENROLL_HEADERS = { accept: "application/pkcs7-mime", "content-type": "application/pkcs10" };
|
|
1418
|
+
|
|
1419
|
+
function _enrollBound(op, baseUrl, builder, opts, proxySnap) {
|
|
1420
|
+
if (_authScheme(opts) === "digest") {
|
|
1421
|
+
throw E("est/channel-binding-digest-unsupported",
|
|
1422
|
+
"Digest authentication cannot be combined with a channel-bound CSR builder: the Authorization header " +
|
|
1423
|
+
"is computed over the request body before the handshake, while the bound body exists only after it " +
|
|
1424
|
+
"(RFC 7030 sec. 3.5). Use Basic authentication or a pre-built CSR.");
|
|
1425
|
+
}
|
|
1426
|
+
var current = null;
|
|
1427
|
+
function hopBody() {
|
|
1428
|
+
var attempt = { spki: null, error: null, done: false };
|
|
1429
|
+
current = attempt;
|
|
1430
|
+
return function (channel) {
|
|
1431
|
+
return guard.async.deferred(function () { return builder(channel); })
|
|
1432
|
+
.then(null, function (e) {
|
|
1433
|
+
if (_isTypedError(e)) throw e;
|
|
1434
|
+
throw E("est/csr-builder-failed", "the CSR builder threw", e);
|
|
1435
|
+
})
|
|
1436
|
+
.then(function (built) {
|
|
1437
|
+
var der = _csrDer(built);
|
|
1438
|
+
if (op === "simplereenroll") reenrollGuard(opts.oldCert, der);
|
|
1439
|
+
attempt.spki = csr.parse(der).subjectPublicKeyInfo;
|
|
1440
|
+
attempt.done = true;
|
|
1441
|
+
return transferEncode(der);
|
|
1442
|
+
})
|
|
1443
|
+
.then(null, function (e) { attempt.error = e; attempt.done = true; throw e; });
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
return _client(op, "POST", baseUrl, hopBody, ENROLL_HEADERS, opts, proxySnap, hopBody)
|
|
1447
|
+
.then(function (res) {
|
|
1448
|
+
if (current && current.error) throw current.error;
|
|
1449
|
+
if (!current || !current.done) {
|
|
1450
|
+
throw E("est/csr-builder-failed",
|
|
1451
|
+
"the response was accepted without a completed channel-bound certification request, so no CSR " +
|
|
1452
|
+
"was sent on this attempt (RFC 7030 sec. 3.5); a transport must request the body and await it");
|
|
1453
|
+
}
|
|
1454
|
+
return _certsResult(op, res, opts, current.spki);
|
|
1455
|
+
},
|
|
1456
|
+
function (e) {
|
|
1457
|
+
var failed = current && current.error;
|
|
1458
|
+
throw _causedBy(e, failed) ? failed : e;
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1398
1462
|
function _enroll(op, baseUrl, csrInput, opts, proxySnap) {
|
|
1463
|
+
if (typeof csrInput === "function") return _enrollBound(op, baseUrl, csrInput, opts, proxySnap);
|
|
1399
1464
|
var csrDer = _csrDer(csrInput);
|
|
1400
1465
|
var spki = csr.parse(csrDer).subjectPublicKeyInfo;
|
|
1401
1466
|
var body = transferEncode(csrDer);
|
|
1402
|
-
return _client(op, "POST", baseUrl, body,
|
|
1467
|
+
return _client(op, "POST", baseUrl, body, ENROLL_HEADERS, opts, proxySnap)
|
|
1403
1468
|
.then(function (res) { return _certsResult(op, res, opts, spki); });
|
|
1404
1469
|
}
|
|
1405
1470
|
|
|
@@ -1447,7 +1512,7 @@ function cacerts(baseUrl, opts) {
|
|
|
1447
1512
|
|
|
1448
1513
|
/**
|
|
1449
1514
|
* @primitive pki.est.simpleenroll
|
|
1450
|
-
* @signature pki.est.simpleenroll(baseUrl, csr, opts?) -> Promise<{ certificate, chain, certificates } | { retry, retryAfterSeconds }>
|
|
1515
|
+
* @signature pki.est.simpleenroll(baseUrl, csr | builder, opts?) -> Promise<{ certificate, chain, certificates } | { retry, retryAfterSeconds }>
|
|
1451
1516
|
* @since 0.3.16
|
|
1452
1517
|
* @status stable
|
|
1453
1518
|
* @spec RFC 7030, RFC 5272
|
|
@@ -1463,6 +1528,21 @@ function cacerts(baseUrl, opts) {
|
|
|
1463
1528
|
* 401 is answered once with HTTP Basic only when `opts.username`/`password` are supplied and
|
|
1464
1529
|
* the transport already authenticated the server.
|
|
1465
1530
|
*
|
|
1531
|
+
* For RFC 7030 sec. 3.5 channel binding, pass a BUILDER `(tls) -> csr | Promise<csr>` in place of a
|
|
1532
|
+
* CSR. The transport runs it after the handshake with that connection's
|
|
1533
|
+
* `{ protocol, cipher, peerCertificate, tlsUnique }`, so the request is signed over the tls-unique of
|
|
1534
|
+
* the connection it is POSTed on, which is what links identity and proof-of-possession. Every new
|
|
1535
|
+
* connection that carries a request body re-runs the builder and the CSR is recreated for that session
|
|
1536
|
+
* (sec. 3.2.1), so a redirect or a Basic-auth retry re-signs; reuse one key pair across invocations,
|
|
1537
|
+
* since only the binding changes. A 303 is the exception, because it turns the follow-up into a GET
|
|
1538
|
+
* that carries no request body: the certification request stays the one posted, and bound, on the POST
|
|
1539
|
+
* connection, and the GET only collects the result.
|
|
1540
|
+
* On TLS 1.3 `tlsUnique` is `null`, as RFC 5929 defines no tls-unique there. A builder cannot be combined
|
|
1541
|
+
* with Digest authentication (`est/channel-binding-digest-unsupported`): that Authorization header is
|
|
1542
|
+
* computed over the body before the handshake the body must be bound to. A builder that throws fails the
|
|
1543
|
+
* request `est/csr-builder-failed` and a typed toolkit error it raises keeps its own code; either way no
|
|
1544
|
+
* CSR is sent. `simplereenroll` runs its identity check on each built CSR before that CSR is written.
|
|
1545
|
+
*
|
|
1466
1546
|
* @opts
|
|
1467
1547
|
* - `transport` / `tls` / `label` / `timeout` / `maxResponseBytes` / `maxRedirects` / `proxy` / `now`, as in pki.est.cacerts.
|
|
1468
1548
|
* - `strict`: reject an enroll response that carries more than the single issued certificate.
|
|
@@ -1474,6 +1554,18 @@ function cacerts(baseUrl, opts) {
|
|
|
1474
1554
|
* var r = await pki.est.simpleenroll("https://ca.example", req,
|
|
1475
1555
|
* { transport: function () { return Promise.resolve({ status: 202, headers: { "retry-after": "60" }, body: "" }); } });
|
|
1476
1556
|
* r.retry && r.retryAfterSeconds; // 60
|
|
1557
|
+
* // channel binding: a builder signs the CSR over the connection's own tls-unique. A transport
|
|
1558
|
+
* // stands in for the CA here, so it must request and await the body the way a real one does.
|
|
1559
|
+
* var bound = await pki.est.simpleenroll("https://ca.example",
|
|
1560
|
+
* async function (tls) {
|
|
1561
|
+
* return pki.csr.sign({ subject: "device.example", subjectPublicKey: signerSpki,
|
|
1562
|
+
* challengePassword: tls.tlsUnique.toString("base64") }, { key: signerKeyPkcs8 });
|
|
1563
|
+
* },
|
|
1564
|
+
* { transport: async function (request) {
|
|
1565
|
+
* await request.body({ protocol: "TLSv1.2", cipher: null, peerCertificate: null, tlsUnique: Buffer.alloc(12, 1) });
|
|
1566
|
+
* return { status: 202, headers: { "retry-after": "60" }, body: "" };
|
|
1567
|
+
* } });
|
|
1568
|
+
* bound.retry; // true
|
|
1477
1569
|
*/
|
|
1478
1570
|
function simpleenroll(baseUrl, csrInput, opts) {
|
|
1479
1571
|
opts = opts || {};
|
|
@@ -1486,7 +1578,7 @@ function simpleenroll(baseUrl, csrInput, opts) {
|
|
|
1486
1578
|
|
|
1487
1579
|
/**
|
|
1488
1580
|
* @primitive pki.est.simplereenroll
|
|
1489
|
-
* @signature pki.est.simplereenroll(baseUrl, csr, opts?) -> Promise<{ certificate, chain, certificates } | { retry, retryAfterSeconds }>
|
|
1581
|
+
* @signature pki.est.simplereenroll(baseUrl, csr | builder, opts?) -> Promise<{ certificate, chain, certificates } | { retry, retryAfterSeconds }>
|
|
1490
1582
|
* @since 0.3.16
|
|
1491
1583
|
* @status stable
|
|
1492
1584
|
* @spec RFC 7030
|
|
@@ -1500,6 +1592,12 @@ function simpleenroll(baseUrl, csrInput, opts) {
|
|
|
1500
1592
|
* `est/reenroll-san-mismatch`) and the transport is never called. A missing `opts.oldCert`
|
|
1501
1593
|
* is `est/bad-input`.
|
|
1502
1594
|
*
|
|
1595
|
+
* Given a channel-binding BUILDER instead of a CSR (see `pki.est.simpleenroll`), the identity check
|
|
1596
|
+
* runs on each CSR the builder produces, inside the post-handshake callback and before that CSR is
|
|
1597
|
+
* written, so a mismatch still aborts the request without sending it. The connection is opened in that
|
|
1598
|
+
* case, since the builder needs the handshake's tls-unique; a redirect or auth retry rebuilds the CSR
|
|
1599
|
+
* and re-checks it.
|
|
1600
|
+
*
|
|
1503
1601
|
* @opts
|
|
1504
1602
|
* - `oldCert` -- REQUIRED, the DER certificate being renewed (the re-enroll identity check).
|
|
1505
1603
|
* - every option of pki.est.simpleenroll (transport, tls, label, budgets, strict, credentials).
|
|
@@ -1515,7 +1613,7 @@ function simplereenroll(baseUrl, csrInput, opts) {
|
|
|
1515
1613
|
return Promise.resolve().then(function () {
|
|
1516
1614
|
_knownOpts(opts, SIMPLEREENROLL_OPTS, "simplereenroll");
|
|
1517
1615
|
if (!opts.oldCert) throw E("est/bad-input", "simplereenroll requires opts.oldCert (the certificate being renewed, RFC 7030 sec. 4.2.2)");
|
|
1518
|
-
reenrollGuard(opts.oldCert, _csrDer(csrInput));
|
|
1616
|
+
if (typeof csrInput !== "function") reenrollGuard(opts.oldCert, _csrDer(csrInput));
|
|
1519
1617
|
return _enroll("simplereenroll", baseUrl, csrInput, opts, proxySnap);
|
|
1520
1618
|
});
|
|
1521
1619
|
}
|
package/lib/http-transport.js
CHANGED
|
@@ -19,11 +19,19 @@
|
|
|
19
19
|
* into the socket layer: the transport owns socket lifecycle, the TLS trust policy,
|
|
20
20
|
* the streaming size cap, and the timeout budget; the caller owns HTTP status,
|
|
21
21
|
* content-type, redirect, and authentication decisions. `tls` reports the negotiated
|
|
22
|
-
* channel, `{ protocol, cipher, peerCertificate, tlsUnique }`, facts a caller
|
|
23
|
-
* recover from the response bytes.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
* channel, `{ protocol, cipher, peerCertificate, tlsUnique, tlsExporter }`, facts a caller
|
|
23
|
+
* cannot recover from the response bytes. The two bindings are complementary, one per version,
|
|
24
|
+
* so a caller reads whichever the negotiated protocol defines. `tlsUnique` is the RFC 5929
|
|
25
|
+
* channel binding (the first TLS Finished) on a TLS 1.2 connection, which
|
|
26
|
+
* `pki.est.challengePasswordFromTlsUnique` base64-encodes into an EST challengePassword
|
|
27
|
+
* (RFC 7030 sec. 3.5); it is `null` on TLS 1.3, where RFC 5929 defines no tls-unique.
|
|
28
|
+
* `tlsExporter` is the RFC 9266 binding on a TLS 1.3 connection: 32 bytes exported under the
|
|
29
|
+
* label `EXPORTER-Channel-Binding` with a zero-length context, the value both peers derive.
|
|
30
|
+
* It is `null` below TLS 1.3, where RFC 9266 sec. 2 additionally requires the RFC 7627 extended
|
|
31
|
+
* master secret, which node gives no way to confirm, so the binding is withheld rather than
|
|
32
|
+
* offered unproven; it is also `null` if the socket cannot export. No shipped verb consumes
|
|
33
|
+
* tls-exporter yet: RFC 7030 sec. 3.5 binds tls-unique specifically, so a caller must not put a
|
|
34
|
+
* tls-exporter value in that challengePassword. An INJECTED substitute should return these too:
|
|
27
35
|
* `pki.est.serverkeygen` asserts the negotiated cipher can protect the private key it
|
|
28
36
|
* is about to accept, and a transport that reports no cipher is trusted instead of
|
|
29
37
|
* refused (so a loopback test channel works), which means omitting the field silently
|
|
@@ -93,6 +101,17 @@ function _stripIpv6Brackets(s) {
|
|
|
93
101
|
return (s.length >= 2 && s.charAt(0) === "[" && s.charAt(s.length - 1) === "]") ? s.slice(1, s.length - 1) : s;
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
var TLS_EXPORTER_LABEL = "EXPORTER-Channel-Binding";
|
|
105
|
+
var TLS_EXPORTER_LENGTH = 32;
|
|
106
|
+
|
|
107
|
+
function _tlsExporter(socket, proto) {
|
|
108
|
+
if (proto !== "TLSv1.3" || !socket || typeof socket.exportKeyingMaterial !== "function") return null;
|
|
109
|
+
var out;
|
|
110
|
+
try { out = socket.exportKeyingMaterial(TLS_EXPORTER_LENGTH, TLS_EXPORTER_LABEL, Buffer.alloc(0)); }
|
|
111
|
+
catch (_ee) { return null; }
|
|
112
|
+
return (Buffer.isBuffer(out) && out.length === TLS_EXPORTER_LENGTH) ? out : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
96
115
|
function _tlsInfo(socket) {
|
|
97
116
|
var proto = socket && socket.getProtocol ? socket.getProtocol() : null;
|
|
98
117
|
var cipher = socket && socket.getCipher ? socket.getCipher() : null;
|
|
@@ -101,7 +120,8 @@ function _tlsInfo(socket) {
|
|
|
101
120
|
var tlsUnique = (socket && socket.getFinished && socket.getPeerFinished && proto === "TLSv1.2")
|
|
102
121
|
? (reused ? socket.getPeerFinished() : socket.getFinished()) : null;
|
|
103
122
|
if (tlsUnique != null && tlsUnique.length === 0) tlsUnique = null;
|
|
104
|
-
|
|
123
|
+
var tlsExporter = _tlsExporter(socket, proto);
|
|
124
|
+
return { protocol: proto, cipher: cipher, peerCertificate: peer && peer.raw ? peer.raw : null, tlsUnique: tlsUnique, tlsExporter: tlsExporter };
|
|
105
125
|
}
|
|
106
126
|
|
|
107
127
|
function _pemifyAnchor(a) {
|
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.5",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:aa5ec092-0f56-46b7-bfb3-469fc4202b37",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-09-
|
|
8
|
+
"timestamp": "2026-09-04T18:56:11.300Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/pki@0.6.
|
|
22
|
+
"bom-ref": "@blamejs/pki@0.6.33",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "pki",
|
|
25
|
-
"version": "0.6.
|
|
25
|
+
"version": "0.6.33",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/pki@0.6.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/pki@0.6.33",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/pki@0.6.
|
|
57
|
+
"ref": "@blamejs/pki@0.6.33",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|