@blamejs/pki 0.7.22 → 0.7.24
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 +3 -3
- package/lib/constants.js +1 -0
- package/lib/csr-sign.js +6 -2
- package/lib/inspect.js +20 -1
- package/lib/ocsp-verify.js +8 -2
- package/lib/pki-build.js +58 -4
- package/lib/schema-pkix.js +40 -4
- package/lib/x509-sign.js +21 -0
- 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.7.24 — 2026-09-12
|
|
8
|
+
|
|
9
|
+
A certificate request can name every extension its subject owns.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- The pki.csr.sign extensionRequest takes msCertificateTemplate, msEnrollCertType, msApplicationPolicies, subjectInfoAccess and subjectDirectoryAttributes, with the same spec shapes and the same rules pki.x509.sign applies, because one encoder serves both verbs: the same spec yields identical bytes and criticality in the request and in the certificate, and a fault is reported with a csr/* code.
|
|
14
|
+
- A request naming an extension the issuing CA assigns as a spec key is refused by name rather than encoded and ignored: authorityKeyIdentifier names the CA's key, precertificatePoison and signedCertificateTimestampList are the CA's exchange with a log, msCaVersion and msPreviousCertHash are the CA's own, and ocspNoCheck is the CA's decision about a responder. The pre-encoded Extension array is unchanged: it carries whatever well-formed extension a caller assembles, as it always has.
|
|
15
|
+
|
|
16
|
+
## v0.7.23 — 2026-09-11
|
|
17
|
+
|
|
18
|
+
Subject information access, subject directory attributes and the OCSP no-check marker are read and written.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- extensions.subjectInfoAccess takes the same { accessMethod, accessLocation } list authorityInfoAccess takes, because RFC 5280 section 4.2.2.2 gives it section 4.2.2.1's syntax. The two access methods that section defines are the registered names id-ad-caRepository and id-ad-timeStamping; the latter is a different object identifier from the extended-key-usage timeStamping, and naming the wrong one is the mistake this spelling avoids.
|
|
23
|
+
- extensions.subjectDirectoryAttributes takes a list of { type, values } with each value as pre-encoded DER, which is the form its reader surfaces (RFC 5280 section 4.2.1.8). Both extensions are emitted non-critical, which those sections require of a conforming CA, and a pre-encoded instance marked critical is refused on both signers.
|
|
24
|
+
- extensions.ocspNoCheck marks an OCSP responder certificate so a client does not ask about its own revocation (RFC 6960 section 4.2.2.2.1). The value is NULL, which that section requires, and the extension is emitted non-critical, which it says it should be.
|
|
25
|
+
- All three join the shared certificate-extension decoders. pki.lint.certificate reads them, so a malformed value is graded lint/rfc5280/extension-undecodable instead of passing unexamined, and pki.inspect prints the access method and location, the attribute and its value, and the no-check marker, where it previously printed a hex dump. That brings the set of certificate extensions the toolkit decodes and the set it can issue to the same twenty-six.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- pki.ocsp.verify authorized a delegated responder whose ocspNoCheck extension carried something other than NULL. The extension is what lets a client stop asking whether the responder itself is revoked, and the delegation gate tested only that it was present, so a responder certificate carrying a malformed marker was accepted and could return a good verdict. The gate now decodes the extension, as it already did for the key usage and extended key usage beside it, and a responder whose marker is not the NULL RFC 6960 section 4.2.2.2.1 requires is unauthorized. A conforming responder certificate is unaffected.
|
|
30
|
+
|
|
7
31
|
## v0.7.22 — 2026-09-11
|
|
8
32
|
|
|
9
33
|
A CRL can name its issuer's other identities.
|
package/README.md
CHANGED
|
@@ -208,7 +208,7 @@ comment blocks, is at [pkijs.com](https://pkijs.com).
|
|
|
208
208
|
| `pki.webcrypto` | A W3C `SubtleCrypto` engine over `node:crypto` — `sign`/`verify`/`encrypt`/`decrypt`/`deriveBits`/`digest`/`generateKey`/`importKey`/`exportKey` across RSA, ECDSA, ECDH, Ed25519/Ed448, AES, HMAC, HKDF, PBKDF2 and SHA, plus post-quantum ML-DSA-44/65/87, SLH-DSA, and ML-KEM-512/768/1024 key generation with certificate and PKCS#8 import. The RFC 9935 seed / expandedKey / both private-key CHOICE is validated fail-closed, so an OpenSSL-legacy bare seed or an internally inconsistent key is rejected with a typed error. `encapsulateBits` and `decapsulateBits` are the ML-KEM key-establishment pair the CMS `KEMRecipientInfo` arm rides on, with the FIPS 203 §7.3 ciphertext-length check enforced here so a direct caller inherits it. Cross-implementation use is undefined in the specification, so a `CryptoKey` from a different WebCrypto implementation is refused here with a typed fault naming its origin; the `pki.*` verbs adopt such a key instead, whether it came from the platform or from a separately installed copy of this toolkit |
|
|
209
209
|
| `pki.tls` | RFC 8879 certificate compression and the RFC 8446 §4.4.2 Certificate message it carries, which is the handshake's largest payload. `decompressCertificate` decodes a `CompressedCertificate` and returns the algorithm, the declared uncompressed length, the recovered message raw, and its per-entry certificate DER. Decompression carries the two-sided bound §5 requires: capped at the message's own declared length so a bomb is refused mid-stream, then compared to that declaration exactly, which catches the under-length direction a cap alone cannot see. An algorithm outside the RFC 8879 registry, one the runtime cannot decompress, or one the receiver never advertised is refused before any decompressor is handed the bytes; an empty compressed body is a framing violation (`tls/bad-framing`); and trailing bytes, after the message or after the compressed frame, are refused (`tls/trailing-data`), so one chain has exactly one encoding. `compressCertificate` is the inverse and round-trips its own output before returning. `parseCertificateMessage` decodes the RFC 8446 §4.4.2 message on its own, surfacing each entry's certificate DER ready for `pki.schema.x509.parse` alongside its raw extensions; a separate extension negotiates `certificate_type`, so it is declared, never guessed. All three registered algorithms (zlib, brotli, zstd) are implemented, each offered only where the running Node decompresses it safely — one whose decompressor answers a truncated frame with a short result instead of a fault is dropped at startup rather than advertised with a truncation it cannot detect. Structure only: no handshake is spoken and no certificate verified — `decompressCertificate`, `compressCertificate`, `parseCertificateMessage` |
|
|
210
210
|
| `pki.schema` | The schema family. `parse` detects which PKI format a DER or PEM input encodes and routes it to the right parser; `all` enumerates the registered formats; the engine and per-format members are grouped here |
|
|
211
|
-
| `pki.schema.x509` | Certificates (RFC 5280) parsed into structured, validated fields with
|
|
211
|
+
| `pki.schema.x509` | Certificates (RFC 5280) parsed into structured, validated fields. Each extension is surfaced by name with its `extnValue` bytes; the shared extension decoders that read those bytes are what `pki.lint.certificate`, `pki.inspect` and `pki.path.validate` consume, and they cover the RFC 3739 / ETSI EN 319 412-5 qualified-certificate `qcStatements` (EU-qualified declaration, reliance limit, QSCD flag, certificate type, retention, PDS URLs, country of qualification), the Microsoft Active Directory Certificate Services enrollment extensions (certificate template, CA version, previous-CA-certificate hash, application policies), subject information access, subject directory attributes, and the RFC 6960 OCSP no-check responder marker. Unknown statements stay opaque, fail-closed Fail-closed — `parse`, `pemDecode`, `pemEncode` |
|
|
212
212
|
| `pki.schema.c509` | C509 certificates (draft-ietf-cose-cbor-encoded-cert), the compact CBOR profile of X.509, decoded fail-closed under deterministic CBOR. `encode` is the byte-exact inverse: a DER X.509 v3 certificate forward-transforms to a compact type-3 C509 whose reconstruction reproduces the original DER byte for byte, so the original signature still verifies. A `parse` result re-emits its native array in canonical deterministic CBOR, with the registry integer shorthands, the C509 compressions, and the compact draft-20 per-extension value forms: the scalar extensions (keyUsage, basicConstraints, extended key usage, subject key identifier, inhibitAnyPolicy, OCSP No Check, TLS Feature), the general-name-bearing extensions (subjectAltName, issuer alternative name, name constraints, CRL distribution points, freshest CRL, authority and subject information access, and the full authority key identifier) over one shared GeneralNames codec, certificate policies with their CPS-URI and UserNotice qualifiers, policy mappings and policy constraints, subject directory attributes, and the RFC 3779 resource-delegation extensions (IP address blocks and AS identifiers) with their RFC 8360 v2 twins, whose addresses ride either the delta-coded integer form or the byte-string form the specification mandates once an address exceeds eight octets. A value the compact form cannot carry exactly falls back to the byte-string form with its bytes intact; a certificate outside the invertible set throws a typed `C509Error`. Called explicitly, since it is CBOR rather than DER and so is not auto-routed |
|
|
213
213
|
| `pki.schema.crl` | X.509 CRLs (RFC 5280 §5): revoked serials with real-`Date` revocation times, named and partly decoded extensions Fail-closed — `parse`, `pemDecode`, `pemEncode` |
|
|
214
214
|
| `pki.schema.csr` | PKCS#10 certification requests (RFC 2986): subject DN, public key, requested attributes, signature Fail-closed — `parse`, `pemDecode`, `pemEncode` |
|
|
@@ -231,8 +231,8 @@ comment blocks, is at [pkijs.com](https://pkijs.com).
|
|
|
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
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`. When `opts.userInitialPolicySet` names acceptable certificate-policy OIDs and more than one path validates, build returns the accepted path whose user-constrained policy set best satisfies that set (RFC 4158 §4) rather than the first accepted path, the ranking bounded by the same candidate cap and a malformed set refused with `path/bad-input`; an `anyPolicy` entry is unconstrained and returns the first accepted path. In a mesh of cross-certified domains, where many candidates chain by name to the same place, a candidate is ranked by how many leading relative distinguished names it shares with the name the search is heading for (§3.5.16 and the §3.5.19 reverse method), so a certificate in the target's own domain is tried before one from a cross-certified domain, and forward building sorts a candidate under every candidate that can complete the path when its path length constraint cannot cover the certificates already below it (§3.5.7), an ordering that outranks the other hints rather than competing with them. No candidate is removed and an unbounded search still reaches every path the pool holds; a bounded one spends `maxCandidatesConsidered` on whichever branches the order steers it to. Pure and re-entrant — `validate`, `build`, `crlChecker`, `ocspChecker` |
|
|
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. `randomSerial()` draws the same 20-octet CSPRNG serial the signer uses when the spec names none, so a serial can be reserved or logged before the certificate is issued. 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; the AKI optionally naming the issuing certificate by name and serial), subject alternative names, certificate policies with their RFC 5280 section 4.2.1.4 qualifiers (a CPS pointer and a user notice), name constraints, authority information access, CRL distribution points, the freshest CRL, issuer alternative names, the policy machinery path validation acts on (policy constraints, inhibit anyPolicy, policy mappings), the RFC 3739 qualified-certificate statements including the ETSI EN 319 412-5 set, the RFC 6962 certificate-transparency pair (the precertificate poison and the embedded SCT list),
|
|
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, the RFC 3739 qualified-certificate statements, 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` |
|
|
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. `randomSerial()` draws the same 20-octet CSPRNG serial the signer uses when the spec names none, so a serial can be reserved or logged before the certificate is issued. 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; the AKI optionally naming the issuing certificate by name and serial), subject alternative names, certificate policies with their RFC 5280 section 4.2.1.4 qualifiers (a CPS pointer and a user notice), name constraints, authority information access, CRL distribution points, the freshest CRL, issuer alternative names, the policy machinery path validation acts on (policy constraints, inhibit anyPolicy, policy mappings), the RFC 3739 qualified-certificate statements including the ETSI EN 319 412-5 set, the RFC 6962 certificate-transparency pair (the precertificate poison and the embedded SCT list), the Active Directory Certificate Services enrollment extensions (certificate template, legacy template name, CA version, previous-CA-certificate hash, application policies), subject information access, subject directory attributes, and the RFC 6960 OCSP no-check responder marker, from the spec. That is every extension the shared certificate-extension decoders read, so any certificate `pki.lint.certificate` and `pki.inspect` can read in full the toolkit can also issue; any other extension is taken as pre-encoded DER. `extensions.nameConstraints` takes `{ permitted, excluded }` lists of GeneralName-form objects, restricting what the CA being issued may itself issue; each base is held to the rule for a constraint base, and the extension is emitted critical as §4.2.1.10 requires. 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
|
+
| `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, the RFC 3739 qualified-certificate statements, the Microsoft certificate template and application policies, subject information access, subject directory attributes, or an array of pre-encoded Extension DER; an extension the issuing CA assigns, such as the authority key identifier or the OCSP no-check marker, is refused by name rather than requested), 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` |
|
|
237
237
|
| `pki.crmf` | Certificate-request-message issuance (RFC 4211). `build(spec, key, opts)` assembles a `CertReqMessages` from a `spec` of `certReqId` (default 0, with the RFC 9483 `-1` sentinel allowed), a `certTemplate` of the requested fields (`subject`, `publicKey` as the SPKI DER of the key being certified, `validity`, requested `extensions`, an optional `version` 2), optional `controls` and `regInfo` (regToken, authenticator, utf8Pairs, oldCertID, protocolEncrKey, or pre-encoded `AttributeTypeAndValue` DER), and an optional `pop` selector. `key` (or `{ key }`) is the requester's private key: the message carries a `POPOSigningKey` proof of possession signed with the private half of `certTemplate.publicKey` and verified before the message is returned, exactly as a PKCS#10 CSR proves possession. A complete template signs the `CertRequest`; an incomplete one signs a `POPOSigningKeyInput`. The signature algorithm is resolved from the requested public 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. `key` is optional for a `raVerified` proof. A key that cannot sign, which is where an ML-KEM enrollment sits, takes a `POPOPrivKey` proof instead (RFC 4211 sec. 4.2, sec. 4.3): `pop.type` of `keyEncipherment` or `keyAgreement` with `pop.method: 'subsequentMessage'` declares whether an encrypted certificate (`encrCert`) or a challenge (`challengeResp`) completes the proof over the enrolling protocol's next exchange, and `pop.method: 'encryptedKey'` encloses the requester's private key for the CA in a CMS `EnvelopedData` under `id-ct-encKeyWithID`, requiring `pop.privateKey`, `pop.recipients`, the `pop.identifier` sec. 4.2.1 makes mandatory, and `pop.archive: true` because RFC 9810 sec. 5.2.8.3.1 permits the method only where archival is intended. The enclosed key must be the private half of `certTemplate.publicKey`, or the proof demonstrates possession of a key the request never asked to have certified. The `thisMessage` and `dhMAC` alternatives the specification deprecates are refused with their successors named. `pop.method: 'agreeMAC'` completes the four: `pop.key` is the requester's finite-field Diffie-Hellman private key, as a PKCS#8 DER, a PEM `PRIVATE KEY` block or a `KeyObject`, and `pop.caCert` the authority's certificate it already holds; the two agree a static secret (RFC 2875 sec. 3), and the key derived from it MACs the DER `certReq` under `id-dhPop-static-HMAC-SHA1`. Either key may name its group in the PKCS#3 or the X9.42 encoding. `pop.key` must be the private half of `certTemplate.publicKey`, and the template must name both a subject and a public key. Pass an array of specs for a batch; the CA-assigned template fields are never emitted. Returns DER, or a PEM block with `opts.pem`; malformed input throws a typed `CrmfError`. `verifyPop(messages)` is the receiving side: for each `CertReqMsg` it verifies the `POPOSigningKey` signature over the bytes RFC 4211 sec. 4.1 names — the DER of `poposkInput` when present, of `certReq` when not — through the one path-validation signature engine, and answers `{ verified, messages: [{ verified, method, cryptographicallyVerified, certReqId, subject, subjectBound, publicKey, reason }] }` with the fields re-derived from the message's own bytes. Each verdict reports only what its preimage covers: `publicKey` is the key possession was proven for, and `subject` is the requested name when the `certReq` was signed. A `poposkInput` preimage covers the key and the sender alone, so any subject beside it is unsigned and is withheld with `subjectBound: false`. A `raVerified` proof is an RA's out-of-band assertion and a `keyEncipherment` or `keyAgreement` proof completes over a later exchange, so each is reported unverified with its `method` named instead of guessed. Parsing stays at `pki.schema.crmf.parse` — `build`, `verifyPop` |
|
|
238
238
|
| `pki.cmp` | CMP message building, transfer, and verification (RFC 9810). `build(message, opts)` assembles a protected `PKIMessage`. `message.header` carries the `sender` and `recipient` GeneralNames (including the anonymous NULL-DN) plus optional transaction metadata; `message.body` is a single-key object naming the arm — request-side `ir`, `cr`, `kur`, `krr` (key recovery, §5.3.7), `ccr` (cross-certification, §5.3.11: a `CertReqMessages` at the normative floor, where the requesting CA keeps its private key so a private-key-transport encryptedKey proof-of-possession is refused, and the optional App. D.6 single-request cardinality is not enforced), `p10cr`, `certConf`, `pollReq`, `genm`, `rr`, responder-side `ip`, `cp`, `kup`, `ccp`, `rp`, `genp`, `error`, `pollRep`, `krp`, `pkiconf`, and the registration-authority `nested` wrapper of complete PKIMessages (RFC 9810 §5.1.3.5). Protection is exactly one of `opts.{ key, cert }`, a signature under the sender key with the algorithm resolved from the signer certificate so RSA (PKCS#1 v1.5 / PSS), ECDSA, EdDSA, ML-DSA, SLH-DSA, and the composite arms all sign without a per-algorithm branch, `opts.mac`, a PBMAC1 shared-secret HMAC (RFC 9481 / 9579, PBKDF2-derived), or `opts.kem`, a KEM-based MAC for a client whose key can only establish secrets (RFC 9810 §5.1.3.4): the ciphertext a peer encapsulated to its ML-KEM key is decapsulated, the key is derived under HKDF-SHA256 with a context bound to the transaction identifier of the message that carried the ciphertext, and `pki.cmp.verify` checks it from the shared secret. Protection covers the exact DER of the virtual `ProtectedPart` and is self-verified before the message is returned, and `protectionAlg` is derived rather than caller-set, so the message the parser accepts is coherent by construction. A `p10cr` request's PKCS#10 proof-of-possession is verified before the message is protected, so one whose self-signature does not verify under its subject public key is refused rather than sent. `transfer(url, message, opts)` carries a built message to a CMP endpoint over `pki.transport` (RFC 9811): one POST of the DER PKIMessage, with the response classified fail-closed — 200 only for success, a non-200 2xx or an un-followed 3xx refused, a 4xx or 5xx carrying a CMP error PKIMessage forwarded as the integrity-protected verdict — and protection surfaced rather than verified. `wellKnownUrl(base, opts)` builds the §3.4 `/.well-known/cmp` request-URIs. `verify(message, opts)` checks the protection on an incoming message, either a signature through the same certification-path engine `pki.crl.verify` and `pki.ocsp.verify` use, with the EdDSA low-order-point and algorithm-confusion gates, or a PBMAC1 MAC recomputed from `opts.sharedSecret` and the message's own PBKDF2 parameters and constant-time compared, over the exact `ProtectedPart` reconstructed from the parser's raw slices. It is fail-closed on an unprotected message, a legacy or KEM MAC algorithm, an omitted keyLength, or a SHA-1 PRF, and returns a `{ valid, trusted, protectionType, signer, ... }` verdict. With `opts.trustAnchors` the signer certificate is fully path-validated (RFC 5280 §6.1 plus the RFC 9483 §3.2 `keyUsage.digitalSignature` gate) at a trusted current time, or an explicit `opts.time` for historical verification and never the message's self-asserted `messageTime`, before it is reported trusted; without one the verdict is crypto-only and the signer certificate is surfaced to anchor. `session(opts)` returns a stateful enrollment session whose `enroll(request)` drives a full `ir` / `cr` / `kur` / `p10cr` transaction over the shared transport, composing `build`, `transfer`, and `verify`. Every response is protection-verified, signer-trusted, and bound to the exchange (a stable `transactionID`, a fresh-`senderNonce` and echoed-`recipNonce` chain) before its body is read, with a bounded `pollReq` / `pollRep` loop for a `waiting` status and a `certConf` / `pkiConf` (or implicit) confirmation carrying an explicit `hashAlg` for a signature algorithm that does not convey its hash. It returns a terminal `{ outcome, certificate, chain, status, trusted, confirmed, implicitConfirm, transactionID, polls, transcript }`. A certification authority can take longer to answer than a process is held open, so a `poll-timeout` carries a `resumeToken` and `resumePoll(token)` continues the same transaction in a later process: the token is plain JSON naming the transaction, the nonce the next request echoes, the polled request and the arm its grant arrives on, and the key the grant must certify. It carries no secret and grants nothing, since the protection material and the endpoint come from the session built to resume with, and the resumed poll verifies, nonce-binds, and key-binds every response. Its fields are what the resumed exchange is held to, so store it where the enrollment's own state is stored: someone who can rewrite it can widen what the resumed session accepts, as far as that session's trust anchors and the authority's protection allow and no further. The same session also drives the other two RFC 9483 operations under that shell: `revoke(request)` sends an `rr` naming a certificate as `{ certificate }` or `{ certDetails }` with an optional CRLReason `reason`, and returns `revoked` / `rejected` / `poll-timeout`; `info(request)` sends a `genm` for one of the four support messages — `{ caCerts }`, `{ rootCaCert }`, `{ certReqTemplate }`, `{ crlUpdate }` — and returns `answered` with the decoded `value` and a `present` flag, since an absent response value is how each says nothing is available. A session revokes its own certificate: the signature over the request is the proof of authorization (§4.2), so the named certificate must be `opts.cert` and a PBMAC1 session is refused. The signature flavor requires `opts.trustAnchors` to authenticate the CA; a verified rejection or error and an exhausted poll budget are terminal verdicts, while a tampered, untrusted, or desynchronized response is a typed throw. Returns DER, or a PEM `CMP` block with `opts.pem`; malformed input throws a typed `CmpError`. `openKeyPackage(container, opts)` opens a private key the CA generated centrally and delivered in the `privateKey` field of a granted `CertifiedKeyPair` (RFC 9483 §4.1.6): a CMS `SignedData` over an RFC 5958 `AsymmetricKeyPackage`, sealed in a CMS `EnvelopedData`. `opts.key` (with `opts.cert`) opens the key transport and key agreement containers a signature-protected request selects, `opts.password` the password container a MAC-protected request selects. The authority is authorized before any key material is returned: its certificate must chain to an anchor in `opts.trustAnchors` AND assert the `id-kp-cmKGA` extended key usage, since a certificate with no `extendedKeyUsage` permits every purpose and so authorizes nothing; `opts.authorizedBySharedSecret` states §4.1.6's exemption for an entity that authorizes by the secret that protected its request. Returns `{ keys, kga, trusted }`, where each key is a PKCS#8 `PrivateKeyInfo` ready for `pki.key.import`; `keys` is the whole RFC 5958 `AsymmetricKeyPackage` (`SIZE (1..MAX)`), while a session enrollment requires the sequence of one §4.1.6 profiles it to. Both CMS layers are read as a ContentInfo or as the bare structure, told apart by what the SEQUENCE opens with. `session(opts)` drives the whole exchange under `opts.acceptCentralKeyGeneration`: the request omits `certTemplate.publicKey`, carries no proof of possession, and goes out as `cmp2021`; the session opens the delivered container with the credential it enrolled under and surfaces it as `deliveredKey`, having first checked that the issued certificate certifies the delivered key. Without the option, such a request and such a grant are both refused. Parsing stays at `pki.schema.cmp.parse` — `build`, `transfer`, `wellKnownUrl`, `verify`, `openKeyPackage`, `session` |
|
package/lib/constants.js
CHANGED
|
@@ -205,6 +205,7 @@ var NAMES = Object.assign(Object.create(null), {
|
|
|
205
205
|
issuingDistributionPoint: "X509v3 Issuing Distribution Point", cRLReason: "X509v3 CRL Reason Code",
|
|
206
206
|
invalidityDate: "Invalidity Date", certificateIssuer: "X509v3 Certificate Issuer",
|
|
207
207
|
signedCertificateTimestampList: "CT Precertificate SCTs", precertificatePoison: "CT Precertificate Poison",
|
|
208
|
+
subjectDirectoryAttributes: "X509v3 Subject Directory Attributes", ocspNoCheck: "OCSP No Check",
|
|
208
209
|
},
|
|
209
210
|
KEY_USAGE: {
|
|
210
211
|
digitalSignature: "Digital Signature", nonRepudiation: "Non Repudiation", keyEncipherment: "Key Encipherment",
|
package/lib/csr-sign.js
CHANGED
|
@@ -70,8 +70,12 @@ function _challengePassword(pw) {
|
|
|
70
70
|
* (a common-name string, an array of RDNs, or raw Name DER; MAY be empty), `subjectPublicKey` (the SPKI
|
|
71
71
|
* DER of the key being certified), and optional `extensionRequest` (requested v3 extensions, as an object
|
|
72
72
|
* of subjectAltName / keyUsage / extendedKeyUsage / basicConstraints / certificatePolicies /
|
|
73
|
-
* subjectKeyIdentifier / qcStatements
|
|
74
|
-
*
|
|
73
|
+
* subjectKeyIdentifier / qcStatements / msCertificateTemplate / msEnrollCertType /
|
|
74
|
+
* msApplicationPolicies / subjectInfoAccess / subjectDirectoryAttributes and the rest of the
|
|
75
|
+
* subject-owned set `pki.x509.sign` takes, or an array of pre-encoded Extension DER) and
|
|
76
|
+
* `challengePassword`. An extension the issuing CA assigns (authorityKeyIdentifier, the
|
|
77
|
+
* certificate-transparency pair, the CA version and previous-certificate hash, ocspNoCheck) is not a
|
|
78
|
+
* request and is refused by name. `key` (or
|
|
75
79
|
* `{ key }`) is the subject's own PKCS#8 private key / WebCrypto CryptoKey, so the request is self-signed
|
|
76
80
|
* to prove possession of the private half of `subjectPublicKey`, and that proof is verified before the
|
|
77
81
|
* request is returned. The signature algorithm is resolved from the subject key (RSA PKCS#1 v1.5 or PSS,
|
package/lib/inspect.js
CHANGED
|
@@ -301,7 +301,10 @@ var EXT_RENDERERS = Object.assign(Object.create(null), {
|
|
|
301
301
|
cRLDistributionPoints: _renderCrlDp,
|
|
302
302
|
freshestCRL: _renderCrlDp,
|
|
303
303
|
authorityInfoAccess: function (decoded, inner) {
|
|
304
|
-
var LABEL = Object.assign(Object.create(null), {
|
|
304
|
+
var LABEL = Object.assign(Object.create(null), {
|
|
305
|
+
caIssuers: "CA Issuers", ocsp: "OCSP",
|
|
306
|
+
"id-ad-caRepository": "CA Repository", "id-ad-timeStamping": "Time Stamping",
|
|
307
|
+
});
|
|
305
308
|
return (decoded || []).map(function (ad) {
|
|
306
309
|
var m = null;
|
|
307
310
|
try { m = oid.name(ad.accessMethod); } catch (_e) { /* allow:swallow-unverified display best-effort: an unregistered accessMethod OID falls back to the raw dotted OID below (inspection is best-effort, never a verdict) */ }
|
|
@@ -352,6 +355,22 @@ var EXT_RENDERERS = Object.assign(Object.create(null), {
|
|
|
352
355
|
precertificatePoison: function (decoded, inner) {
|
|
353
356
|
return inner + "Precertificate Poison (this is a precertificate, not a certificate)";
|
|
354
357
|
},
|
|
358
|
+
/** @internal RFC 5280 sec. 4.2.2.2 gives subjectInfoAccess sec. 4.2.2.1's AccessDescription
|
|
359
|
+
* syntax, so it renders through the same rows; only the access methods it names differ. */
|
|
360
|
+
subjectInfoAccess: function (decoded, inner) {
|
|
361
|
+
return EXT_RENDERERS.authorityInfoAccess(decoded, inner);
|
|
362
|
+
},
|
|
363
|
+
/** @internal Each Attribute value is raw DER, so it renders through the same best-effort value
|
|
364
|
+
* fallback every other opaque value uses rather than a second reading of the same bytes. */
|
|
365
|
+
subjectDirectoryAttributes: function (decoded, inner) {
|
|
366
|
+
return (decoded || []).map(function (a) {
|
|
367
|
+
var lines = (a.values || []).map(function (v) { return _fallback(v, inner + " "); });
|
|
368
|
+
return inner + (a.name || a.type) + ":" + (lines.length ? "\n" + lines.join("\n") : "");
|
|
369
|
+
}).join("\n");
|
|
370
|
+
},
|
|
371
|
+
ocspNoCheck: function (decoded, inner) {
|
|
372
|
+
return inner + "OCSP No Check (this is an OCSP responder certificate; do not check its revocation)";
|
|
373
|
+
},
|
|
355
374
|
subjectKeyIdentifier: function (decoded, inner) {
|
|
356
375
|
return inner + _hexColon(Buffer.isBuffer(decoded) ? decoded : (decoded.bytes || Buffer.alloc(0)), { upper: true });
|
|
357
376
|
},
|
package/lib/ocsp-verify.js
CHANGED
|
@@ -34,7 +34,6 @@ function ocspKeyValue(spkiDer) {
|
|
|
34
34
|
function makeOcspVerify(deps) {
|
|
35
35
|
var verifyWithSpki = deps.verifyWithSpki;
|
|
36
36
|
var decodeExt = deps.decodeExt;
|
|
37
|
-
var findExt = deps.findExt;
|
|
38
37
|
var unrecognizedCriticalExtension = deps.unrecognizedCriticalExtension;
|
|
39
38
|
var validateCriticalExtensionStructure = deps.validateCriticalExtensionStructure;
|
|
40
39
|
var compositeKeyUsageCheck = deps.compositeKeyUsageCheck;
|
|
@@ -112,7 +111,14 @@ function makeOcspVerify(deps) {
|
|
|
112
111
|
if (ku && ku.value.digitalSignature !== true) continue;
|
|
113
112
|
if (unrecognizedCriticalExtension(rc, false)) continue;
|
|
114
113
|
if (validateCriticalExtensionStructure(rc)) continue;
|
|
115
|
-
|
|
114
|
+
/** @internal RFC 6960 sec. 4.2.2.2.1 gives this extension a value that SHALL be NULL, and its
|
|
115
|
+
* presence is what lets a client stop asking whether the responder itself is revoked. A
|
|
116
|
+
* malformed value is not that marker, so this decodes the extension, as the key usage and
|
|
117
|
+
* extended key usage checks above do. */
|
|
118
|
+
var noCheck;
|
|
119
|
+
try { noCheck = decodeExt(rc, OID_OCSP_NOCHECK); }
|
|
120
|
+
catch (_e) { continue; }
|
|
121
|
+
if (!noCheck) continue;
|
|
116
122
|
if (compositeSig.COMPOSITE_ALGS[rc.subjectPublicKeyInfo.algorithm.oid] && !compositeKeyUsageCheck(rc).ok) continue;
|
|
117
123
|
return ocspResponderSpki(rc, issuer);
|
|
118
124
|
}
|
package/lib/pki-build.js
CHANGED
|
@@ -12,6 +12,7 @@ var _isArray = intrinsic.isArray;
|
|
|
12
12
|
var _bufferFrom = intrinsic.bufferFrom;
|
|
13
13
|
var _bufferEquals = intrinsic.bufferEquals;
|
|
14
14
|
var oid = require("./oid");
|
|
15
|
+
var C = require("./constants");
|
|
15
16
|
var pkix = require("./schema-pkix");
|
|
16
17
|
var ipUtils = require("./ip-utils");
|
|
17
18
|
var _packIpLiteral = ipUtils.packIpLiteral;
|
|
@@ -274,6 +275,7 @@ var AKI_KEYS = intrinsic.assign(intrinsic.create(null), { keyIdentifier: 1, auth
|
|
|
274
275
|
* are proprietary, so the toolkit's own readers in schema-pkix define the shape the builder emits. */
|
|
275
276
|
var MS_TEMPLATE_KEYS = intrinsic.assign(intrinsic.create(null), { templateID: 1, templateMajorVersion: 1, templateMinorVersion: 1 });
|
|
276
277
|
var MS_CA_VERSION_KEYS = intrinsic.assign(intrinsic.create(null), { caKeyIndex: 1, certIndex: 1 });
|
|
278
|
+
var SDA_ATTR_KEYS = intrinsic.assign(intrinsic.create(null), { type: 1, values: 1 });
|
|
277
279
|
/** @internal The fields each typed statementInfo defines, by statement id. A key outside its
|
|
278
280
|
* statement's set is refused rather than ignored: a misspelled field would otherwise be dropped and
|
|
279
281
|
* the certificate would carry a statement the caller did not write. */
|
|
@@ -735,13 +737,16 @@ function makeBuilder(ctx) {
|
|
|
735
737
|
}
|
|
736
738
|
/** @internal AuthorityInfoAccessSyntax (RFC 5280 sec. 4.2.2.1): SEQUENCE SIZE (1..MAX) OF
|
|
737
739
|
* AccessDescription { accessMethod OBJECT IDENTIFIER, accessLocation GeneralName }. */
|
|
738
|
-
|
|
740
|
+
/** @internal Sec. 4.2.2.1 and sec. 4.2.2.2 define the same SEQUENCE SIZE (1..MAX) OF
|
|
741
|
+
* AccessDescription, so one encoder serves both and is told which structure it is writing: a fault
|
|
742
|
+
* in a subjectInfoAccess must not be reported against authorityInfoAccess. */
|
|
743
|
+
function extAccessDescriptions(list, label, clause) {
|
|
739
744
|
if (!_isArray(list) || !list.length) {
|
|
740
|
-
throw E("bad-input", "
|
|
745
|
+
throw E("bad-input", label + " must name at least one { accessMethod, accessLocation } (" + clause + ")");
|
|
741
746
|
}
|
|
742
|
-
var dense = reqDenseArray(list,
|
|
747
|
+
var dense = reqDenseArray(list, label);
|
|
743
748
|
return b.sequence(_mapIntrinsic(dense, function (d, i) {
|
|
744
|
-
var who = "
|
|
749
|
+
var who = label + " entry " + i;
|
|
745
750
|
if (!d || typeof d !== "object" || _isArray(d) || _isBufferChk(d)) {
|
|
746
751
|
throw E("bad-input", who + " must be an object { accessMethod, accessLocation }");
|
|
747
752
|
}
|
|
@@ -758,6 +763,41 @@ function makeBuilder(ctx) {
|
|
|
758
763
|
return b.sequence([b.oid(_resolveOid(d.accessMethod, who + " accessMethod")), encodeGeneralName(d.accessLocation)]);
|
|
759
764
|
}));
|
|
760
765
|
}
|
|
766
|
+
function extAuthorityInfoAccess(list) {
|
|
767
|
+
return extAccessDescriptions(list, "authorityInfoAccess", "RFC 5280 sec. 4.2.2.1");
|
|
768
|
+
}
|
|
769
|
+
function extSubjectInfoAccess(list) {
|
|
770
|
+
return extAccessDescriptions(list, "subjectInfoAccess", "RFC 5280 sec. 4.2.2.2");
|
|
771
|
+
}
|
|
772
|
+
/** @internal SubjectDirectoryAttributes ::= SEQUENCE SIZE (1..MAX) OF Attribute (RFC 5280
|
|
773
|
+
* sec. 4.2.1.8). The reader surfaces each value as its raw DER, so the spec supplies it the same
|
|
774
|
+
* way and the two directions describe one structure. */
|
|
775
|
+
function extSubjectDirectoryAttributes(list) {
|
|
776
|
+
if (!_isArray(list) || !list.length) {
|
|
777
|
+
throw E("bad-input", "subjectDirectoryAttributes must name at least one { type, values } (RFC 5280 sec. 4.2.1.8)");
|
|
778
|
+
}
|
|
779
|
+
var dense = reqDenseArray(list, "subjectDirectoryAttributes");
|
|
780
|
+
return b.sequence(_mapIntrinsic(dense, function (a, i) {
|
|
781
|
+
var who = "subjectDirectoryAttributes entry " + i;
|
|
782
|
+
if (!a || typeof a !== "object" || _isArray(a) || _isBufferChk(a)) {
|
|
783
|
+
throw E("bad-input", who + " must be an object { type, values }");
|
|
784
|
+
}
|
|
785
|
+
guard.identifier.assertKnownKeys(a, SDA_ATTR_KEYS, E, "bad-input", function (k) {
|
|
786
|
+
return "unknown " + who + " field " + _stringify(k) + " (accepted: type, values)";
|
|
787
|
+
});
|
|
788
|
+
if (!_isArray(a.values) || !a.values.length) throw E("bad-input", who + " requires a non-empty values array of pre-encoded DER");
|
|
789
|
+
/** @internal The reader caps an Attribute's values, so the writer is held to the same ceiling
|
|
790
|
+
* and cannot emit an attribute this toolkit's own decoder refuses. */
|
|
791
|
+
if (a.values.length > C.LIMITS.ATTRIBUTE_MAX_VALUES) {
|
|
792
|
+
throw E("bad-input", who + " carries " + a.values.length + " values, exceeding the " + C.LIMITS.ATTRIBUTE_MAX_VALUES + " an Attribute may hold");
|
|
793
|
+
}
|
|
794
|
+
var vals = _mapIntrinsic(reqDenseArray(a.values, who + " values"), function (v, j) {
|
|
795
|
+
return b.raw(guard.der.tlv(guard.bytes.source(v, ErrorClass, ctx.prefix + "/bad-input", who + " value " + j),
|
|
796
|
+
rawErr, ctx.prefix + "/bad-input", who + " value " + j));
|
|
797
|
+
});
|
|
798
|
+
return b.sequence([b.oid(_resolveOid(a.type, who + " type")), b.set(vals)]);
|
|
799
|
+
}));
|
|
800
|
+
}
|
|
761
801
|
/** @internal One DistributionPoint (RFC 5280 sec. 4.2.1.13). distributionPoint [0] wraps a
|
|
762
802
|
* DistributionPointName whose fullName is [0] IMPLICIT GeneralNames; reasons is [1] IMPLICIT
|
|
763
803
|
* ReasonFlags; cRLIssuer is [2] IMPLICIT GeneralNames. A DistributionPoint must not consist of
|
|
@@ -1088,7 +1128,15 @@ function makeBuilder(ctx) {
|
|
|
1088
1128
|
nameConstraints: 1, authorityInfoAccess: 1, cRLDistributionPoints: 1, freshestCRL: 1,
|
|
1089
1129
|
policyConstraints: 1, inhibitAnyPolicy: 1, policyMappings: 1, policyMappingsCritical: 1,
|
|
1090
1130
|
issuerAltName: 1, qcStatements: 1, qcStatementsCritical: 1,
|
|
1131
|
+
msCertificateTemplate: 1, msEnrollCertType: 1, msApplicationPolicies: 1,
|
|
1132
|
+
subjectInfoAccess: 1, subjectDirectoryAttributes: 1,
|
|
1091
1133
|
};
|
|
1134
|
+
/** @internal RFC 2985 sec. 5.4.2 has the attribute carry "certificate extensions the requester
|
|
1135
|
+
* wishes to be included". What the issuing CA assigns is not a wish: the authority key
|
|
1136
|
+
* identifier names the CA's key, the precertificate poison and SCT list are the CA's exchange
|
|
1137
|
+
* with a log, the CA version and previous-certificate hash are the CA's own, and the OCSP
|
|
1138
|
+
* no-check marker is the CA's decision about a responder. Those stay out of this table so a
|
|
1139
|
+
* request naming one is refused rather than written and ignored. */
|
|
1092
1140
|
function requestedExtensions(extSpec, spki) {
|
|
1093
1141
|
var EXT_DECODERS = ctx.EXT_DECODERS;
|
|
1094
1142
|
if (_isArray(extSpec)) {
|
|
@@ -1134,6 +1182,11 @@ function makeBuilder(ctx) {
|
|
|
1134
1182
|
if (extSpec.policyMappings != null) guard.list.append(out, ext(O("policyMappings"), !!extSpec.policyMappingsCritical, extPolicyMappings(extSpec.policyMappings)));
|
|
1135
1183
|
if (extSpec.issuerAltName != null) guard.list.append(out, ext(O("issuerAltName"), false, encodeGeneralNames(reqDenseArray(extSpec.issuerAltName, "issuerAltName"))));
|
|
1136
1184
|
if (extSpec.qcStatements != null) guard.list.append(out, ext(O("qcStatements"), !!extSpec.qcStatementsCritical, extQcStatements(extSpec.qcStatements)));
|
|
1185
|
+
if (extSpec.msCertificateTemplate != null) guard.list.append(out, ext(O("msCertificateTemplate"), false, extMsCertificateTemplate(extSpec.msCertificateTemplate)));
|
|
1186
|
+
if (extSpec.msEnrollCertType != null) guard.list.append(out, ext(O("msEnrollCertType"), false, extMsEnrollCertType(extSpec.msEnrollCertType)));
|
|
1187
|
+
if (extSpec.msApplicationPolicies != null) guard.list.append(out, ext(O("msApplicationPolicies"), false, extCertPolicies(extSpec.msApplicationPolicies)));
|
|
1188
|
+
if (extSpec.subjectInfoAccess != null) guard.list.append(out, ext(O("subjectInfoAccess"), false, extSubjectInfoAccess(extSpec.subjectInfoAccess)));
|
|
1189
|
+
if (extSpec.subjectDirectoryAttributes != null) guard.list.append(out, ext(O("subjectDirectoryAttributes"), false, extSubjectDirectoryAttributes(extSpec.subjectDirectoryAttributes)));
|
|
1137
1190
|
if (!out.length) throw E("bad-input", "the requested extensions object must request at least one extension");
|
|
1138
1191
|
return b.sequence(out);
|
|
1139
1192
|
}
|
|
@@ -1206,6 +1259,7 @@ function makeBuilder(ctx) {
|
|
|
1206
1259
|
extKeyUsage: extKeyUsage, extExtKeyUsage: extExtKeyUsage, validateBcSpec: validateBcSpec,
|
|
1207
1260
|
extBasicConstraints: extBasicConstraints, pathLen: pathLen, extSki: extSki, extAki: extAki, AKI_KEYS: AKI_KEYS,
|
|
1208
1261
|
extSan: extSan, extCertPolicies: extCertPolicies, ext: ext,
|
|
1262
|
+
extSubjectInfoAccess: extSubjectInfoAccess, extSubjectDirectoryAttributes: extSubjectDirectoryAttributes,
|
|
1209
1263
|
extMsCertificateTemplate: extMsCertificateTemplate, extMsCaVersion: extMsCaVersion,
|
|
1210
1264
|
extMsPreviousCertHash: extMsPreviousCertHash, extMsEnrollCertType: extMsEnrollCertType,
|
|
1211
1265
|
spkiKeyId: spkiKeyId, skiKeyId: skiKeyId,
|
package/lib/schema-pkix.js
CHANGED
|
@@ -942,14 +942,17 @@ function certExtensionDecoders(ns) {
|
|
|
942
942
|
return schema.walk(generalNames(ns, { decodeValue: true, code: C }), n, ns).result;
|
|
943
943
|
}
|
|
944
944
|
|
|
945
|
-
|
|
945
|
+
/** @internal Sec. 4.2.2.1 and sec. 4.2.2.2 define the same SEQUENCE SIZE (1..MAX) OF
|
|
946
|
+
* AccessDescription, so one reader serves both and takes the structure's own name and clause: a
|
|
947
|
+
* fault in a SubjectInfoAccess must not be reported against AuthorityInfoAccess. */
|
|
948
|
+
function accessDescriptions(buf, what, clause) {
|
|
946
949
|
var C = ns.prefix + "/bad-extension-value";
|
|
947
|
-
var descs = seqChildren(buf, C,
|
|
948
|
-
if (descs.length < 1) throw ns.E(C, "
|
|
950
|
+
var descs = seqChildren(buf, C, what);
|
|
951
|
+
if (descs.length < 1) throw ns.E(C, what + " must contain at least one AccessDescription (" + clause + ", SIZE(1..MAX))");
|
|
949
952
|
var GN = generalName(ns, { decodeValue: true, code: C });
|
|
950
953
|
return _map(descs, function (d) {
|
|
951
954
|
if (d.tagClass !== "universal" || d.tagNumber !== _T.SEQUENCE || !d.children || d.children.length !== 2) {
|
|
952
|
-
throw ns.E(C, "AccessDescription must be a SEQUENCE { accessMethod, accessLocation } (
|
|
955
|
+
throw ns.E(C, "AccessDescription must be a SEQUENCE { accessMethod, accessLocation } (" + clause + ")");
|
|
953
956
|
}
|
|
954
957
|
var method;
|
|
955
958
|
try { method = asn1.read.oid(d.children[0]); }
|
|
@@ -958,6 +961,36 @@ function certExtensionDecoders(ns) {
|
|
|
958
961
|
return { accessMethod: method, accessLocation: { tag: loc.tagNumber, value: loc.value } };
|
|
959
962
|
});
|
|
960
963
|
}
|
|
964
|
+
function authorityInfoAccess(buf) {
|
|
965
|
+
return accessDescriptions(buf, "AuthorityInfoAccessSyntax", "RFC 5280 sec. 4.2.2.1");
|
|
966
|
+
}
|
|
967
|
+
function subjectInfoAccess(buf) {
|
|
968
|
+
return accessDescriptions(buf, "SubjectInfoAccessSyntax", "RFC 5280 sec. 4.2.2.2");
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/** @internal SubjectDirectoryAttributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
|
|
972
|
+
* (RFC 5280 sec. 4.2.1.8), read through the shared Attribute sub-schema. */
|
|
973
|
+
function subjectDirectoryAttributes(buf) {
|
|
974
|
+
var C = ns.prefix + "/bad-extension-value";
|
|
975
|
+
var kids = seqChildren(buf, C, "SubjectDirectoryAttributes");
|
|
976
|
+
if (kids.length < 1) throw ns.E(C, "SubjectDirectoryAttributes must contain at least one Attribute (RFC 5280 sec. 4.2.1.8, SIZE(1..MAX))");
|
|
977
|
+
var A = attribute(ns);
|
|
978
|
+
return _map(kids, function (k) {
|
|
979
|
+
try { return schema.walk(A, k, ns).result; }
|
|
980
|
+
catch (e) { throw ns.E(C, "SubjectDirectoryAttributes member must be an Attribute SEQUENCE { type, values } (RFC 5280 sec. 4.2.1.8)", e); }
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** @internal RFC 6960 sec. 4.2.2.2.1: "The value of the extension SHALL be NULL." The extension is
|
|
985
|
+
* a marker, so a successful read carries no value and anything other than a bare NULL is refused. */
|
|
986
|
+
function ocspNoCheck(buf) {
|
|
987
|
+
var C = ns.prefix + "/bad-extension-value";
|
|
988
|
+
var n = decodeTop(buf, C, "OCSPNoCheck");
|
|
989
|
+
if (n.tagClass !== "universal" || n.tagNumber !== _T.NULL || n.length !== 0) {
|
|
990
|
+
throw ns.E(C, "the ocspNoCheck extension value SHALL be NULL (RFC 6960 sec. 4.2.2.2.1)");
|
|
991
|
+
}
|
|
992
|
+
return null;
|
|
993
|
+
}
|
|
961
994
|
|
|
962
995
|
function extKeyUsage(buf) {
|
|
963
996
|
var C = ns.prefix + "/bad-extension-value";
|
|
@@ -1203,6 +1236,9 @@ function certExtensionDecoders(ns) {
|
|
|
1203
1236
|
byOid[O("cRLDistributionPoints")] = crlDistributionPoints;
|
|
1204
1237
|
byOid[O("freshestCRL")] = crlDistributionPoints;
|
|
1205
1238
|
byOid[O("authorityInfoAccess")] = authorityInfoAccess;
|
|
1239
|
+
byOid[O("subjectInfoAccess")] = subjectInfoAccess;
|
|
1240
|
+
byOid[O("subjectDirectoryAttributes")] = subjectDirectoryAttributes;
|
|
1241
|
+
byOid[O("ocspNoCheck")] = ocspNoCheck;
|
|
1206
1242
|
byOid[O("msCertificateTemplate")] = msCertificateTemplate;
|
|
1207
1243
|
byOid[O("msEnrollCertType")] = msEnrollCertType;
|
|
1208
1244
|
byOid[O("msCaVersion")] = msCaVersion;
|
package/lib/x509-sign.js
CHANGED
|
@@ -58,6 +58,7 @@ var KNOWN_EXT_KEYS = intrinsic.assign(intrinsic.create(null), {
|
|
|
58
58
|
precertificatePoison: 1, signedCertificateTimestampList: 1,
|
|
59
59
|
msCertificateTemplate: 1, msEnrollCertType: 1, msCaVersion: 1, msPreviousCertHash: 1,
|
|
60
60
|
msApplicationPolicies: 1,
|
|
61
|
+
subjectInfoAccess: 1, subjectDirectoryAttributes: 1, ocspNoCheck: 1,
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
var _b = pkiBuild.makeBuilder({ ErrorClass: CertificateError, prefix: "x509", O: O, NS: NS, NAME_SCHEMA: NAME_SCHEMA, SPKI_SCHEMA: SPKI_SCHEMA, EXT_DECODERS: EXT_DECODERS });
|
|
@@ -232,6 +233,16 @@ function _buildExtensions(extSpec, ctx) {
|
|
|
232
233
|
if (extSpec.msCaVersion != null) guard.list.append(out, _ext(O("msCaVersion"), false, _b.extMsCaVersion(extSpec.msCaVersion)));
|
|
233
234
|
if (extSpec.msPreviousCertHash != null) guard.list.append(out, _ext(O("msPreviousCertHash"), false, _b.extMsPreviousCertHash(extSpec.msPreviousCertHash)));
|
|
234
235
|
if (extSpec.msApplicationPolicies != null) guard.list.append(out, _ext(O("msApplicationPolicies"), false, _extCertPolicies(extSpec.msApplicationPolicies)));
|
|
236
|
+
/** @internal Sections 4.2.2.2 and 4.2.1.8 both require a conforming CA to mark these non-critical,
|
|
237
|
+
* which `assertCertCriticality` also holds the pre-encoded form to. */
|
|
238
|
+
if (extSpec.subjectInfoAccess != null) guard.list.append(out, _ext(O("subjectInfoAccess"), false, _b.extSubjectInfoAccess(extSpec.subjectInfoAccess)));
|
|
239
|
+
if (extSpec.subjectDirectoryAttributes != null) guard.list.append(out, _ext(O("subjectDirectoryAttributes"), false, _b.extSubjectDirectoryAttributes(extSpec.subjectDirectoryAttributes)));
|
|
240
|
+
/** @internal RFC 6960 sec. 4.2.2.2.1 marks an OCSP responder certificate so a client does not ask
|
|
241
|
+
* about its revocation: the value SHALL be NULL, and the section says it should be non-critical. */
|
|
242
|
+
if (extSpec.ocspNoCheck != null) {
|
|
243
|
+
if (extSpec.ocspNoCheck !== true) throw _err("x509/bad-input", "ocspNoCheck is a flag, so it is true or omitted");
|
|
244
|
+
guard.list.append(out, _ext(O("ocspNoCheck"), false, asn1.build.nullValue()));
|
|
245
|
+
}
|
|
235
246
|
return out;
|
|
236
247
|
}
|
|
237
248
|
|
|
@@ -400,6 +411,16 @@ function _hasCriticalSan(extSpec) {
|
|
|
400
411
|
* know an unknown syntax. `pki.path.validate` does not process this extension, so it is emitted
|
|
401
412
|
* non-critical unless `qcStatementsCritical` is set.
|
|
402
413
|
*
|
|
414
|
+
* `extensions.subjectInfoAccess` takes the same `{ accessMethod, accessLocation }` list
|
|
415
|
+
* `authorityInfoAccess` takes, since RFC 5280 sec. 4.2.2.2 gives it sec. 4.2.2.1's syntax; the two
|
|
416
|
+
* access methods that section defines are the registered names `id-ad-caRepository` and
|
|
417
|
+
* `id-ad-timeStamping`, the latter being a different OID from the extended-key-usage `timeStamping`.
|
|
418
|
+
* `extensions.subjectDirectoryAttributes` takes a list of `{ type, values }` with each value as
|
|
419
|
+
* pre-encoded DER, the form its reader surfaces (sec. 4.2.1.8). Both are emitted non-critical, which
|
|
420
|
+
* those sections require. `extensions.ocspNoCheck: true` marks an OCSP responder certificate so a
|
|
421
|
+
* client does not ask about its revocation (RFC 6960 sec. 4.2.2.2.1): the value is NULL, as that
|
|
422
|
+
* section requires, and it is emitted non-critical, which the section says it should be.
|
|
423
|
+
*
|
|
403
424
|
* The Active Directory Certificate Services enrollment extensions are written from the same spec.
|
|
404
425
|
* `extensions.msCertificateTemplate` takes `{ templateID, templateMajorVersion, templateMinorVersion }`,
|
|
405
426
|
* the versions optional and each a DWORD, a minor version requiring a major one;
|
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:afc45867-a237-46a4-91ea-4cb590b54d06",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-09-
|
|
8
|
+
"timestamp": "2026-09-12T00:45:51.621Z",
|
|
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.7.
|
|
22
|
+
"bom-ref": "@blamejs/pki@0.7.24",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "pki",
|
|
25
|
-
"version": "0.7.
|
|
25
|
+
"version": "0.7.24",
|
|
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.7.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/pki@0.7.24",
|
|
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.7.
|
|
57
|
+
"ref": "@blamejs/pki@0.7.24",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|