@blamejs/pki 0.6.24 → 0.6.25

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 CHANGED
@@ -4,6 +4,14 @@ 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.25 — 2026-09-02
8
+
9
+ pki.path.build can search from a trust anchor toward the leaf, not only from the leaf toward an anchor.
10
+
11
+ ### Added
12
+
13
+ - pki.path.build accepts opts.direction: "forward" (default), "reverse" (search from a trust anchor toward the leaf, RFC 4158 sec. 3.1), or "auto" (pick by first-hop fan-out). Every direction hands each assembled path to pki.path.validate, so the direction changes only search order, never which paths are accepted; the anchor is excluded from the returned path. Reverse building is pool-only and does not combine with fetchAia.
14
+
7
15
  ## v0.6.24 — 2026-09-02
8
16
 
9
17
  A caller option of an unexpected type now yields the module's typed error, not a native TypeError.
package/README.md CHANGED
@@ -230,7 +230,7 @@ comment blocks, is at [pkijs.com](https://pkijs.com).
230
230
  | `pki.cmc` | Build and interpret CMC messages (RFC 5272). `build(spec, signer)` assembles a Full PKI Request across all three request arms (PKCS#10, CRMF, other) and signs it through `pki.cms.sign` under `id-cct-PKIData`. A PKCS#10 (`tcr`) request is verified against its own proof-of-possession before signing, so a request whose self-signature does not verify under its subject public key is refused rather than signed into a message a CA would reject. Body-part identifiers are unique across the whole message and never the reserved 0; a caller's clash is refused rather than renumbered, since a control may already reference it. An Identity Proof V2 witness is computed over the `reqSequence` bytes exactly as emitted (§6.2.1 step 1) rather than a re-serialization, a POP Link Witness is emitted only alongside the POP Link Random control §6.3.1.1 requires beside it, and a renewal carries neither Identification nor Identity Proof in either version. `verify(response, sent)` takes what the CA returned plus the state the client retained and reduces it to one terminal outcome: `issued`, `pending`, `confirm-required`, `pop-required`, or `rejected`. It binds the exchange first — Transaction Identifier, the Sender and Recipient Nonce echo compared in constant time and by full value so a truncation cannot match, and the Data Return echo — with each check applying only if the client sent that half, and, once sent, an absent or differing echo being a refusal, which is the replay defense. `bodyPartIDs` extends the same rule to what the response is about: a status reporting on a body part the request never sent is refused, which the transaction and nonce cannot catch, because a server can echo both correctly while answering about a different message. Several status controls are permitted and the worst governs, so a failure cannot hide behind an earlier success; the absence of any status control is success, per §6.1.2. The carrier's signature must verify (§3.2.1.3.4): a conforming SignedData carries its own signer certificate, so the ordinary build-then-verify flow needs nothing extra and the verdict reports `signatureVerified: true`. Where the signer is found nowhere the posture is fail-closed with a named opt-out — supply `certs` with the responder's certificate, or `allowUnverified: true`, in which case the verdict reports `signatureVerified: false`. Doing neither is refused, the opt-out never excuses a signature that is present and wrong, and a carrier with no signer at all is refused outright. The response's own `cmsSequence` and `otherMsgs` come back raw, since a request whose only arm was the other-message form has no certificate to return and §4.1 puts its answer there. Nothing is trusted: issued certificates are read from the CMS certificate bag (§4.2) and surfaced raw for `pki.path.validate`, and a Publish Trust Anchors control is surfaced with `trusted: false` rather than added to a store — `build`, `verify` |
231
231
  | `pki.schema.cmc` | Decode CMC messages (RFC 5272 as updated by RFC 6402): a Full PKI Request (`PKIData`) or Full PKI Response (`PKIResponse`) riding inside a CMS SignedData, reached by the encapsulated content type (`id-cct-PKIData` / `id-cct-PKIResponse`). Controls are surfaced in wire order with their values raw, so an unrecognized one is data rather than a fault. Tagged requests decode across all three arms. The status verdicts (`CMCStatusInfo` v1 and `CMCStatusInfoV2`) are collected as an ordered list, and the RFC 6402 two-module `OtherStatusInfo` ambiguity — `pendInfo` and `extendedFailInfo` are both untagged SEQUENCEs in the 1988 module, told apart only by their first element — is resolved by inspection and refused when it cannot be told apart. Body-part identity is unique across the whole message rather than per sequence, 0 is reserved as the reference to the enclosing PKIData, and the `reqSequence` bytes are surfaced exactly as they appeared so an Identity Proof witness is computed over the wire bytes. A companion decoder for CMS content rather than an auto-routed format — `parse`, `parsePkiData`, `parsePkiResponse` |
232
232
  | `pki.schema.engine` | The declarative ASN.1 structure-schema engine every format parser composes — `walk`, `encode`, `embeddedDer`, and the schema combinators |
233
- | `pki.path` | Certification-path validation (RFC 5280 §6). `validate` runs the §6.1 state machine over an ordered path and a trust anchor: signature chaining across RSA, ECDSA, EdDSA, ML-DSA, SLH-DSA and hybrid composite ML-DSA (a composite is accepted only when both its post-quantum and traditional components verify), validity windows, name chaining, basic constraints and path length, key usage, name constraints, and the certificate-policy tree. It returns a structured verdict with per-check reason codes and enforces a `pki.trust` anchor's per-purpose distrust-after dates and delegator purposes through `checkPurpose` — an anchor that carries either one with no purpose named to select by is refused as a configuration fault rather than validated as though it carried none. The verdict says what was established. `revocationChecked` takes the weakest outcome on the path: `false` with no checker supplied, `"determined"` when every certificate got an explicit good or revoked answer, `"waived"` when `softFail` turned an undetermined one into a pass, and `"undetermined"` when one could not be answered at all — which includes a checker that throws, a fault `softFail` does not waive because `softFail` opts into an undetermined answer, not into a broken checker. `anchorConstraints` names the purpose the anchor was judged under and whether each of its two constraints applied. `crlChecker` supplies CRL-based revocation, covering partitioned and sharded CRLs, whose §6.3.3 Distribution Point ↔ IDP correspondence lets corresponding shards accumulate reason coverage until all eight revocation reasons are covered, and delta CRLs, merged onto the complete CRL they may be combined with (§5.2.4) so a held certificate its delta releases reads good, while a delta that merges with nothing still reports what it lists and still withholds good. `ocspChecker` supplies OCSP-based revocation (RFC 6960: CertID binding, responder authorization, signature, currency) over the same pluggable hook. `build(leaf, opts)` is the discovering complement (RFC 4158): from a leaf, an untrusted pool of candidate CA certificates, and a trust store, it finds the ordered leaf-to-anchor path `validate` accepts, using name chaining plus the RFC 4158 §3.5 sort hints (an AKI/SKI match, an anchor-adjacent issuer, CA plus keyCertSign, validity at the check time — ordering hints, never filters), a depth-first search with backtracking so the first accepted path wins, and a bounded search (chain-length cap, candidate-expansion cap, identity-tuple visited set) so a cross-certificate cycle or Bridge-CA fan-out terminates deterministically. Every accept flows through `validate`, and its verdict is cross-checked against `openssl verify`. Opt-in AIA `caIssuers` fetching (`opts.fetchAia: true`) discovers a missing intermediate from a certificate's Authority Information Access URL (§4.2.2.1) over `pki.transport`, triggered only on a pool miss and bounded against SSRF and amplification: HTTPS only, a total fetch budget that caps fetching silently rather than throwing, a per-cert URL cap, a build-wide URL dedupe, a response-size and certificate-count cap, no redirect following, and every fault a silent skip. The TLS trust (`opts.tls`) stays distinct from the PKI `trustAnchors`, and every fetched certificate remains untrusted pool material that still flows through `validate` (never a trust anchor). It is off by default, so the default build is byte-identical offline. Pure and re-entrant — `validate`, `build`, `crlChecker`, `ocspChecker` |
233
+ | `pki.path` | Certification-path validation (RFC 5280 §6). `validate` runs the §6.1 state machine over an ordered path and a trust anchor: signature chaining across RSA, ECDSA, EdDSA, ML-DSA, SLH-DSA and hybrid composite ML-DSA (a composite is accepted only when both its post-quantum and traditional components verify), validity windows, name chaining, basic constraints and path length, key usage, name constraints, and the certificate-policy tree. It returns a structured verdict with per-check reason codes and enforces a `pki.trust` anchor's per-purpose distrust-after dates and delegator purposes through `checkPurpose` — an anchor that carries either one with no purpose named to select by is refused as a configuration fault rather than validated as though it carried none. The verdict says what was established. `revocationChecked` takes the weakest outcome on the path: `false` with no checker supplied, `"determined"` when every certificate got an explicit good or revoked answer, `"waived"` when `softFail` turned an undetermined one into a pass, and `"undetermined"` when one could not be answered at all — which includes a checker that throws, a fault `softFail` does not waive because `softFail` opts into an undetermined answer, not into a broken checker. `anchorConstraints` names the purpose the anchor was judged under and whether each of its two constraints applied. `crlChecker` supplies CRL-based revocation, covering partitioned and sharded CRLs, whose §6.3.3 Distribution Point ↔ IDP correspondence lets corresponding shards accumulate reason coverage until all eight revocation reasons are covered, and delta CRLs, merged onto the complete CRL they may be combined with (§5.2.4) so a held certificate its delta releases reads good, while a delta that merges with nothing still reports what it lists and still withholds good. `ocspChecker` supplies OCSP-based revocation (RFC 6960: CertID binding, responder authorization, signature, currency) over the same pluggable hook. `build(leaf, opts)` is the discovering complement (RFC 4158): from a leaf, an untrusted pool of candidate CA certificates, and a trust store, it finds the ordered leaf-to-anchor path `validate` accepts, using name chaining plus the RFC 4158 §3.5 sort hints (an AKI/SKI match, an anchor-adjacent issuer, CA plus keyCertSign, validity at the check time — ordering hints, never filters), a depth-first search with backtracking so the first accepted path wins, and a bounded search (chain-length cap, candidate-expansion cap, identity-tuple visited set) so a cross-certificate cycle or Bridge-CA fan-out terminates deterministically. Every accept flows through `validate`, and its verdict is cross-checked against `openssl verify`. Opt-in AIA `caIssuers` fetching (`opts.fetchAia: true`) discovers a missing intermediate from a certificate's Authority Information Access URL (§4.2.2.1) over `pki.transport`, triggered only on a pool miss and bounded against SSRF and amplification: HTTPS only, a total fetch budget that caps fetching silently rather than throwing, a per-cert URL cap, a build-wide URL dedupe, a response-size and certificate-count cap, no redirect following, and every fault a silent skip. The TLS trust (`opts.tls`) stays distinct from the PKI `trustAnchors`, and every fetched certificate remains untrusted pool material that still flows through `validate` (never a trust anchor). It is off by default, so the default build is byte-identical offline. An `opts.direction` of `"reverse"` searches from a trust anchor toward the leaf (RFC 4158 §3.1), narrower when the anchor set is small and the leaf's issuer options fan out, and `"auto"` picks the direction by first-hop fan-out; reverse building reuses the same pool, visited set, caps, and `validate` gate, so the direction changes only search order, and the anchor is excluded from the returned path. Reverse building is pool-only and does not combine with `fetchAia`. Pure and re-entrant — `validate`, `build`, `crlChecker`, `ocspChecker` |
234
234
  | `pki.x509` | Certificate issuance (RFC 5280 §4). `sign(spec, issuer, opts)` builds and signs a certificate from a `spec` of subject (a common-name string, an array of RDNs, or raw Name DER), the public key being certified, the validity window, an optional serial, and an optional `extensions` object. The `issuer` is a key alone (self-signed: issuer equals subject, signed with that key), a name plus public key plus key, or an issuing certificate plus key. The signature algorithm is resolved from the signing key through the shared registry, so RSA (PKCS#1 v1.5 or PSS via `opts.pss`), ECDSA P-256/384/521, Ed25519, Ed448, ML-DSA-44/65/87, the twelve SLH-DSA sets, and the composite arms all issue without a per-algorithm branch. It encodes basic constraints, key usage, extended key usage, subject and authority key identifiers (the SKI derived by SHA-1 of the subject key), subject alternative names, and certificate policies from the spec, taking any other extension as pre-encoded DER. It derives the version from the field set and enforces the serial bounds, the UTCTime/GeneralizedTime cutover, the DER default omissions, and the CA cross-field rules; a violation throws a typed `CertificateError`. Returns DER, or a PEM `CERTIFICATE` with `opts.pem`. Every arm is independently verified by OpenSSL. Parsing stays at `pki.schema.x509.parse` — `sign` |
235
235
  | `pki.csr` | PKCS#10 certification-request issuance (RFC 2986 / RFC 2985). `sign(spec, key, opts)` builds and signs a `CertificationRequest` from a `spec` of subject (which may be empty), the public key being certified, an optional `extensionRequest` carrying the requested v3 extensions a CA copies into the issued certificate (subject alternative names, key usage, extended key usage, basic constraints, certificate policies, subject key identifier, or an array of pre-encoded Extension DER), and an optional `challengePassword`. `key` (or `{ key }`) is the subject's own private key: the request is self-signed to prove possession of the private half of `subjectPublicKey`, and that proof is verified before the request is returned, which is what `openssl req -verify` checks. The signature algorithm is resolved from the subject key, so RSA (PKCS#1 v1.5 or PSS via `opts.pss`), ECDSA, EdDSA, ML-DSA, SLH-DSA, and the composite arms all sign without a per-algorithm branch. Returns DER, or a PEM `CERTIFICATE REQUEST` with `opts.pem`; malformed input throws a typed `CsrError`. `verify(request)` asks the same question of a request someone else produced, over its exact signed `certificationRequestInfo` bytes under the `subjectPKInfo` inside them, through the one path-validation signature engine. It answers `{ verified, subject, subjectPublicKeyInfo, attributes, certificationRequestInfoBytes }`, all re-derived from the signed bytes, so a CA issues from the fields the signature covers rather than from the object it passed in. A `verified: true` says the producer held that private key and that the subject and requested extensions are the ones they signed; who they are is the enrollment protocol's question, not this one. Parsing stays at `pki.schema.csr.parse` — `sign`, `verify` |
236
236
  | `pki.attrcert` | Attribute-certificate issuance (RFC 5755). `sign(spec, issuer, opts)` builds and signs an `AttributeCertificate` as an Attribute Authority: a `spec` of `holder` (exactly one of an entity name, a `baseCertificateID` reference, a `fromCertificate` binding, or an object digest), the validity window as GeneralizedTime, an optional serial (positive, at most 20 octets, randomly generated when omitted), the `attributes` (role, clearance, group, chargingIdentity, accessIdentity, authenticationInfo, or pre-encoded Attribute DER), and optional `extensions` (auditIdentity, targetInformation, noRevAvail, aaControls, acProxying, authorityKeyIdentifier, or pre-encoded Extension DER) each with its RFC 5755 criticality. An attribute certificate is never self-signed, so the `issuer` is the signing AA, supplied as `{ cert, key }` or `{ name, publicKey, key }`. The signature algorithm is resolved from the AA key, so RSA (PKCS#1 v1.5 or PSS via `opts.pss`), ECDSA, EdDSA, ML-DSA, SLH-DSA, and the composite arms all sign without a per-algorithm branch, and the signature is verified under the AA public key before the certificate is returned. Returns DER, or a PEM `ATTRIBUTE CERTIFICATE` with `opts.pem`; malformed input throws a typed `AttrCertError`. `verify(ac, issuer, opts)` is the receiving side, performing the RFC 5755 sec. 5 checks an attribute certificate and a named issuer can settle between them: the signature over the exact `AttributeCertificateInfo` bytes through the one path-validation signature engine, the AC naming the issuer this verifier trusts (compared as a distinguished name), the evaluation instant lying within the validity with equality at either bound succeeding as the section states, the sec. 4.3.2 targeting rule, and rejection of any critical extension this verb does not process (section 5 defines support as parsing the value AND rejecting where the value would reject, so `aaControls` and `acProxying`, whose constraints it does not evaluate, are refused when critical). It answers `{ verified, signatureValid, validityChecked, targetingChecked, holderBindingChecked, issuerPathChecked, holder, issuer, attributes, extensions, notBefore, notAfter, serialNumberHex, reason }` with the fields re-derived from the signed bytes; the holder's own certificate chain and the AC issuer's chain need certificates the verb is not given, so those slots report `false` rather than letting their absence read as a pass. Parsing stays at `pki.schema.attrcert.parse` — `sign`, `verify` |
@@ -2085,15 +2085,8 @@ function childAkiKeyId(cert) {
2085
2085
  return (d && d.value && d.value.keyIdentifier) ? d.value.keyIdentifier : null;
2086
2086
  }
2087
2087
 
2088
- function scoreCandidate(cand, childAki, anchors, time) {
2088
+ function _candBaseScore(cand, time) {
2089
2089
  var score = 0;
2090
- if (childAki) {
2091
- var d = softDecode(cand, OID.subjectKeyIdentifier);
2092
- if (d && Buffer.isBuffer(d.value) && d.value.equals(childAki)) score += 1000;
2093
- }
2094
- for (var i = 0; i < anchors.length; i++) {
2095
- if (nameMatchSoft(cand.issuer.rdns, anchors[i].name.rdns)) { score += 100; break; }
2096
- }
2097
2090
  var bc = softDecode(cand, OID.basicConstraints);
2098
2091
  if (bc && bc.value && bc.value.cA === true) score += 10;
2099
2092
  var ku = softDecode(cand, OID.keyUsage);
@@ -2106,7 +2099,44 @@ function scoreCandidate(cand, childAki, anchors, time) {
2106
2099
  return score;
2107
2100
  }
2108
2101
 
2109
- function _pushCandidates(frame, scored, stack, counter) {
2102
+ function scoreCandidate(cand, childAki, anchors, time) {
2103
+ var score = _candBaseScore(cand, time);
2104
+ if (childAki) {
2105
+ var d = softDecode(cand, OID.subjectKeyIdentifier);
2106
+ if (d && Buffer.isBuffer(d.value) && d.value.equals(childAki)) score += 1000;
2107
+ }
2108
+ for (var i = 0; i < anchors.length; i++) {
2109
+ if (nameMatchSoft(cand.issuer.rdns, anchors[i].name.rdns)) { score += 100; break; }
2110
+ }
2111
+ return score;
2112
+ }
2113
+
2114
+ function scoreCandidateReverse(cand, parentCert, leafCert, time) {
2115
+ var score = _candBaseScore(cand, time);
2116
+ if (parentCert) {
2117
+ var candAki = childAkiKeyId(cand);
2118
+ if (candAki) {
2119
+ var d = softDecode(parentCert, OID.subjectKeyIdentifier);
2120
+ if (d && intrinsic.isBuffer(d.value) && intrinsic.bufferEquals(d.value, candAki)) score += 1000;
2121
+ }
2122
+ }
2123
+ if (nameMatchSoft(leafCert.issuer.rdns, cand.subject.rdns)) score += 100;
2124
+ return score;
2125
+ }
2126
+
2127
+ function _pickBuildDirection(leafCert, pool, anchors, fetchAia) {
2128
+ if (fetchAia) return "forward";
2129
+ var fwdFirstHop = 0, revFirstHop = 0;
2130
+ for (var i = 0; i < pool.length; i++) {
2131
+ if (nameMatchSoft(pool[i].subject.rdns, leafCert.issuer.rdns)) fwdFirstHop += 1;
2132
+ for (var a = 0; a < anchors.length; a++) {
2133
+ if (nameMatchSoft(pool[i].issuer.rdns, anchors[a].name.rdns)) { revFirstHop += 1; break; }
2134
+ }
2135
+ }
2136
+ return revFirstHop < fwdFirstHop ? "reverse" : "forward";
2137
+ }
2138
+
2139
+ function _pushCandidates(frame, scored, stack, counter, down) {
2110
2140
  scored.sort(function (a, b) { return a.score - b.score; });
2111
2141
  var n = 0;
2112
2142
  for (var ci = 0; ci < scored.length; ci++) {
@@ -2116,7 +2146,9 @@ function _pushCandidates(frame, scored, stack, counter) {
2116
2146
  if (intrinsic.setHas(frame.keys, candKey)) continue;
2117
2147
  var childKeys = new Set(frame.keys);
2118
2148
  intrinsic.setAdd(childKeys, candKey);
2119
- stack.push({ chain: [cand].concat(frame.chain), hop: frame.hop + 1, keys: childKeys });
2149
+ stack.push(down
2150
+ ? { chain: intrinsic.concat(frame.chain, [cand]), hop: frame.hop + 1, keys: childKeys, anchor: frame.anchor }
2151
+ : { chain: [cand].concat(frame.chain), hop: frame.hop + 1, keys: childKeys });
2120
2152
  }
2121
2153
  return n;
2122
2154
  }
@@ -2238,6 +2270,7 @@ async function _fetchAiaIssuers(current, aia) {
2238
2270
  * @opts candidates The untrusted candidate CA pool (array of DER/PEM/parsed certs; alias `intermediates`).
2239
2271
  * @opts trustAnchors The trust store (non-empty array of `{ name, publicKey, algorithm }` tuples or self-signed root certificates).
2240
2272
  * @opts time The check date (`Date`, required); forwarded to every internal `validate` call.
2273
+ * @opts direction Search direction: `"forward"` (default, from the leaf toward an anchor), `"reverse"` (from an anchor toward the leaf, RFC 4158 sec. 3.1, narrower when the anchor set is small and the leaf fans out), or `"auto"` (pick by first-hop fan-out). Reverse building is pool-only and does not combine with `fetchAia`. Every direction hands each assembled path to `validate`, so the direction changes only search order, never which paths are accepted.
2241
2274
  * @opts maxDepth Chain-length depth cap (default `C.LIMITS.PATH_BUILD_MAX_DEPTH`).
2242
2275
  * @opts maxCandidatesConsidered Total-work cap on candidate expansions (default `C.LIMITS.PATH_BUILD_MAX_CANDIDATES`).
2243
2276
  * @opts validate `false` returns the ordered path without validating (pure-builder mode; default `true`).
@@ -2264,7 +2297,7 @@ async function _fetchAiaIssuers(current, aia) {
2264
2297
  */
2265
2298
  var _BUILD_OPTS = (function () {
2266
2299
  var o = {
2267
- aiaTimeout: 1, candidates: 1, fetchAia: 1, intermediates: 1, maxAiaFetches: 1,
2300
+ aiaTimeout: 1, candidates: 1, direction: 1, fetchAia: 1, intermediates: 1, maxAiaFetches: 1,
2268
2301
  maxAiaPerCert: 1, maxCandidatesConsidered: 1, maxDepth: 1, maxPathCerts: 1,
2269
2302
  maxResponseBytes: 1, time: 1, tls: 1, transport: 1, trustAnchors: 1, validate: 1
2270
2303
  };
@@ -2302,6 +2335,13 @@ async function build(leaf, opts) {
2302
2335
  var maxConsidered = guard.limits.cap(opts.maxCandidatesConsidered, "build: opts.maxCandidatesConsidered", poolCeiling, { E: E, code: "path/bad-input", min: 1 });
2303
2336
  var doValidate = opts.validate !== false;
2304
2337
 
2338
+ var direction = opts.direction !== undefined ? opts.direction : "forward";
2339
+ if (direction !== "forward" && direction !== "reverse" && direction !== "auto") {
2340
+ throw E("path/bad-input", "build: opts.direction must be \"forward\", \"reverse\", or \"auto\", got " + guard.text.showValue(opts.direction));
2341
+ }
2342
+ if (direction === "auto") direction = _pickBuildDirection(leafCert, pool, anchors, opts.fetchAia === true);
2343
+ if (direction === "reverse" && opts.fetchAia === true) throw E("path/bad-input", "build: opts.fetchAia is only supported with forward building; reverse building is pool-only (RFC 4158 sec. 3.1)");
2344
+
2305
2345
  var aiaCtx = null;
2306
2346
  if (opts.fetchAia === true) {
2307
2347
  if (opts.transport !== undefined && typeof opts.transport !== "function") {
@@ -2345,6 +2385,33 @@ async function build(leaf, opts) {
2345
2385
  var bestFail = null;
2346
2386
  var success = null;
2347
2387
 
2388
+ if (direction === "reverse") {
2389
+ var rstack = [];
2390
+ for (var rsi = 0; rsi < anchors.length; rsi++) intrinsic.push(rstack, { chain: [], hop: 0, keys: new Set([identityKey(leafCert)]), anchor: anchors[rsi] });
2391
+ while (rstack.length) {
2392
+ var rframe = rstack.pop();
2393
+ var frontierCert = rframe.chain.length ? rframe.chain[rframe.chain.length - 1] : null;
2394
+ var frontierName = frontierCert ? frontierCert.subject.rdns : rframe.anchor.name.rdns;
2395
+ if (nameMatchSoft(leafCert.issuer.rdns, frontierName)) {
2396
+ var rpath = intrinsic.concat(rframe.chain, [leafCert]);
2397
+ if (!doValidate) { success = { path: rpath, trustAnchor: rframe.anchor }; break; }
2398
+ anyChainAssembled = true;
2399
+ var rres = await validate(rpath, validateOpts(rframe.anchor));
2400
+ if (rres.valid) { success = { valid: true, path: rpath, trustAnchor: rframe.anchor, result: rres }; break; }
2401
+ if (!bestFail) bestFail = { path: rpath, trustAnchor: rframe.anchor, result: rres };
2402
+ }
2403
+ if (rframe.hop >= maxDepth) continue;
2404
+ var rscored = [];
2405
+ for (var rpi = 0; rpi < pool.length; rpi++) {
2406
+ if (nameMatchSoft(pool[rpi].subject.rdns, rframe.anchor.name.rdns) &&
2407
+ intrinsic.bufferEquals(pool[rpi].subjectPublicKeyInfo.bytes, rframe.anchor.publicKey)) continue;
2408
+ if (nameMatchSoft(pool[rpi].issuer.rdns, frontierName)) {
2409
+ intrinsic.push(rscored, { cand: pool[rpi], score: scoreCandidateReverse(pool[rpi], frontierCert, leafCert, opts.time) });
2410
+ }
2411
+ }
2412
+ considered += _pushCandidates(rframe, rscored, rstack, counter, true);
2413
+ }
2414
+ } else {
2348
2415
  var stack = [{ chain: [leafCert], hop: 0, keys: new Set([identityKey(leafCert)]) }];
2349
2416
  var deferredAia = [];
2350
2417
  var deferSeq = 0;
@@ -2408,6 +2475,7 @@ async function build(leaf, opts) {
2408
2475
  }
2409
2476
  considered += _pushCandidates(frame, scored, stack, counter);
2410
2477
  }
2478
+ }
2411
2479
 
2412
2480
  var aiaFetches = aiaCtx ? aiaCtx.fetches : 0;
2413
2481
  if (success) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/pki",
3
- "version": "0.6.24",
3
+ "version": "0.6.25",
4
4
  "description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
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:1037cbc5-0592-4848-bd2e-b05cbc135e0a",
5
+ "serialNumber": "urn:uuid:6fcfb870-a076-493f-9ee3-64055efa72f5",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-09-02T08:11:54.685Z",
8
+ "timestamp": "2026-09-02T09:57:46.224Z",
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.24",
22
+ "bom-ref": "@blamejs/pki@0.6.25",
23
23
  "type": "application",
24
24
  "name": "pki",
25
- "version": "0.6.24",
25
+ "version": "0.6.25",
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.24",
29
+ "purl": "pkg:npm/%40blamejs/pki@0.6.25",
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.24",
57
+ "ref": "@blamejs/pki@0.6.25",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]