@blamejs/pki 0.6.7 → 0.6.9
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 +29 -0
- package/README.md +1 -1
- package/lib/acme.js +20 -3
- package/lib/cmp-build.js +9 -5
- package/lib/cmp-session.js +7 -0
- package/lib/cmp-verify.js +19 -0
- package/lib/est.js +16 -6
- package/lib/guard-text.js +11 -12
- package/lib/path-validate.js +6 -1
- package/lib/scep.js +1 -1
- package/lib/schema-cmp.js +10 -11
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,35 @@ 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.9 — 2026-08-31
|
|
8
|
+
|
|
9
|
+
pki.cmp.verify holds a received PKIMessage to the RFC 9483 sec. 3.5 header rules, and pki.path.build and pki.est read a response body an injected transport returns as any BufferSource, not only a Node Buffer.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- pki.cmp.verify holds a received PKIMessage to the RFC 9483 sec. 3.5 receiving-side header rules once its protection verifies: the pvno must be cmp2000(2) or cmp2021(3), the transactionID must be present, and the senderNonce must be present and carry at least 128 bits. A message failing any of these is a fail-closed verdict (cmp/unsupported-version, cmp/bad-transaction-id, cmp/bad-sender-nonce). A cmp1999(1) message stays valid RFC 9810 syntax that pki.cmp.parse still decodes; the profile refuses it only on receipt. pki.cmp.session applies these checks to every response and additionally refuses a waiting ip/cp/kup CertResponse that carries failInfo (RFC 9483 sec. 4.4). A conformant peer is unaffected; a peer that omits a required header field is now refused.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- pki.path.build's opt-in AIA caIssuers fetch reads a certificate an injected transport returns as any BufferSource (a Uint8Array, a raw ArrayBuffer, a DataView), not only a Node Buffer. A typed-array body was coerced to a comma-joined string and failed to parse, silently dropping an AIA-discoverable intermediate from the built path; it is now re-viewed through the byte guard and parsed from its bytes.
|
|
18
|
+
- Every pki.est network verb reads a response body an injected transport returns as any BufferSource, not only a Node Buffer or a string. The transfer decode, the multipart splitter, the response-size checks, and the error diagnostic take the raw bytes through the byte guard, so a cacerts, enrollment, or serverkeygen response delivered in a typed array is parsed and sized from its bytes.
|
|
19
|
+
|
|
20
|
+
## v0.6.8 — 2026-08-31
|
|
21
|
+
|
|
22
|
+
pki.cmp.build assembles the ccr cross-certification request body (RFC 9810 sec. 5.3.11), and the ACME client accepts a response body an injected transport returns as any BufferSource, not only a Node Buffer.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- pki.cmp.build assembles the ccr cross-certification request body (RFC 9810 sec. 5.3.11): a CertReqMessages under PKIBody [13], the request one certification authority sends to have another certify its existing public key. It carries the same certificate template and proof-of-possession as an ir or cr, and refuses the private-key-transport encryptedKey proof-of-possession, since a ccr does not send the requesting CA's private key. It is a CertReqMessages at the sec. 5.3.11 normative floor, so it requires no Appendix D.6 profile field and does not enforce the optional D.6 single-request cardinality: a multi-request ccr builds and round-trips, and a producer that follows App. D.6 sends one cross-certificate per message by its own policy.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- pki.schema.cmp.parse and pki.cmp.build no longer enforce the App. D.6 single-CertResponse cardinality on a ccp cross-certification response. A CertRepMessage is SIZE (1..MAX) and App. D.6 is optional, so a multi-response ccp is parsed and built at the RFC 9810 sec. 5.3.12 normative floor, matching the new ccr treatment. The sec. 5.3.12 no-private-key restriction is unchanged.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- The ACME and SCEP clients read a response body an injected transport returns as any BufferSource (a Uint8Array, a raw ArrayBuffer, a DataView), not only a Node Buffer or a string. Both the response-size check and the body decode take its raw bytes through the byte guard, so a BufferSource response is measured and parsed from its bytes rather than from a comma-joined string, and the size check accepts the same forms the decode does.
|
|
35
|
+
|
|
7
36
|
## v0.6.7 — 2026-08-31
|
|
8
37
|
|
|
9
38
|
pki.scep gains the SCEP HTTP client verbs (RFC 8894): getCACaps, getCACert, enroll, and renew drive a certificate enrollment against a SCEP CA over the shipped pkiMessage codec.
|
package/README.md
CHANGED
|
@@ -235,7 +235,7 @@ comment blocks, is at [pkijs.com](https://pkijs.com).
|
|
|
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` |
|
|
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, and `agreeMAC` is not built, since it needs the RFC 2875 static Diffie-Hellman secret against a CA certificate the requester already holds. 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
|
-
| `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), `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, or `opts.mac`, a PBMAC1 shared-secret HMAC (RFC 9481 / 9579, PBKDF2-derived). 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 }`. 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`. Parsing stays at `pki.schema.cmp.parse` — `build`, `transfer`, `wellKnownUrl`, `verify`, `session` |
|
|
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, or `opts.mac`, a PBMAC1 shared-secret HMAC (RFC 9481 / 9579, PBKDF2-derived). 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 }`. 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`. Parsing stays at `pki.schema.cmp.parse` — `build`, `transfer`, `wellKnownUrl`, `verify`, `session` |
|
|
239
239
|
| `pki.crl` | CRL issuance and verification (RFC 5280 §5). `sign(spec, issuer, opts)` builds and signs a `CertificateList` from a `spec` of `thisUpdate` and `nextUpdate`, an optional `crlNumber`, a `revoked` array (each entry a `serialNumber` and `revocationDate` with an optional `reason` or `invalidityDate`), and an optional `extensions` object (authority key identifier, issuing distribution point, delta-CRL indicator, freshest CRL, authority information access) or an array of pre-encoded Extension DER, with an `issuer` of `{ cert, key }` or `{ name, publicKey, key }`. The signature algorithm is resolved from the issuer 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. The version is derived from the extension set (v2 when any CRL or entry extension is present, else v1), the outer `signatureAlgorithm` matches `tbsCertList.signature`, an empty revocation list omits the field rather than emitting an empty SEQUENCE, `reasonCode` is an ENUMERATED and `invalidityDate` is always GeneralizedTime, the RFC fixes per-extension criticality, and the produced signature is verified under the issuer key before return. `verify(crl, issuer)` checks a CRL signature through the one path-validation signature engine, algorithm-confusion and EdDSA low-order gates included; handed a certificate rather than a bare key it also asks what only a certificate can answer — that the certificate is the issuer the CRL names, and that its `keyUsage`, when present, asserts `cRLSign` — so a CRL minted under an end-entity certificate of the same CA does not verify as that CA's. `isRevoked(crl, serialNumber, opts)` looks a serial up, and first checks that the CRL is one a serial can be looked up in at all — it is handed a serial and nothing else, so a CRL that speaks for part of its issuer's certificates is refused rather than answered from. A delta CRL lists changes since a base, so an entry recording a release reads as a revocation when read alone; an indirect CRL carries other issuers' entries, whose serials are unrelated to yours; and any other `issuingDistributionPoint` narrows the CRL to one distribution point, one kind of certificate, or a subset of revocation reasons, none of which a serial can be matched against. A CRL speaks for a span as well as a set, so `opts.time` states the instant the question is asked at and a list that has stopped speaking for it — `nextUpdate` passed, `thisUpdate` later, or no `nextUpdate` stated at all — is refused rather than read as a clean bill of health; without `opts.time` the lookup is structural and an absent serial means only that it is not on that list. `pki.path.crlChecker` is the verb for all of them: it is handed the certificate, merges a delta with its base, performs the §6.3.3 correspondence, and decides currency against the material it fetched. Returns DER, or a PEM `X509 CRL` with `opts.pem`; malformed input throws a typed `CrlError`. Parsing stays at `pki.schema.crl.parse` — `sign`, `verify`, `isRevoked` |
|
|
240
240
|
| `pki.key` | Key-material lifecycle (RFC 5958 / RFC 8018). `encrypt(privateKey, password, opts)` wraps a PKCS#8 private key (DER, PEM, or an extractable `CryptoKey`) into an `EncryptedPrivateKeyInfo` under PBES2 (PBKDF2 with AES-CBC-Pad), where `opts` selects the `cipher` (`aes-256-cbc` default, `aes-192-cbc`, `aes-128-cbc`), the `prf` (`hmacWithSHA256` default, SHA-384/512, SHA-1), the `iterations` (default 600000), and the `salt`. The plaintext is validated as PKCS#8 before encryption, a default `prf` and `keyLength` are omitted so the parameters are byte-exact with OpenSSL, and the output is re-parsed before return. `decrypt(encrypted, password, opts)` recovers the inner `PrivateKeyInfo`, re-validated through `pki.schema.pkcs8.parse`: only PBES2 / PBKDF2 / AES-CBC is accepted (PBES1, PBMAC1, and scrypt are refused), the salt and iteration count are bounded before any derivation (`opts.maxIterations` lowers the cap), and a malformed parameter set or wrong-length IV is a distinct typed error. Because a MAC-less PBES2-CBC decrypt must not become a padding oracle (RFC 8018 §8), a wrong password and a valid-pad-but-not-a-key both surface the one uniform `key/decrypt-failed`. `export(key, opts)` and `import(input, opts)` move a private key as PKCS#8 or a public key as SubjectPublicKeyInfo. The key may come from the platform's WebCrypto or from a separately installed copy of this toolkit, and is exported through whichever holds its material; a non-extractable key, or one whose implementation keeps its material out of reach, is refused with that as the reason. Encoding is delegated to WebCrypto, so RSA carries an explicit NULL, EC a named curve, and Ed25519/Ed448/X25519/X448 omit parameters, and an ambiguous RSA or EC import requires `opts.algorithm`. `generate(algorithm, opts)` produces a key pair over RSA, ECDSA/ECDH, the Edwards and Montgomery curves, and the FIPS post-quantum ML-DSA and ML-KEM; `publicFromPrivate(privateKey)` derives the public key. Returns DER or PEM, with a typed `KeyError` on failure. Parsing stays at `pki.schema.pkcs8.parse` — `encrypt`, `decrypt`, `export`, `import`, `generate`, `publicFromPrivate` |
|
|
241
241
|
| `pki.pkcs12` | PKCS#12 (.p12/.pfx) issuance and reading (RFC 7292 / RFC 9579). `build(spec, opts)` assembles a store from the OpenSSL-style `{ key, cert, ca?, friendlyName?, localKeyId? }` or the full `{ safeContents: [...] }`, where each element is a plaintext or PBES2-encrypted `SafeContents` of key, shroudedKey, cert, crl, secret, or nested `safeContents` bags. Keys and certs are validated before wrapping, and `friendlyName` (BMPString) and `localKeyId` are single-value. Integrity is a classic Appendix B HMAC (the default, for maximum interoperability) or an RFC 9579 PBMAC1 (`opts.mac.algorithm`) over SHA-256/384/512, with shrouded keys and cert safes encrypted under RFC 8018 PBES2 (AES-128/192/256-CBC). Every password is encoded the PKCS#12 way — BMPString+NULL for the classic MAC, UTF-8 for the PBES2 bags and PBMAC1 — which is what OpenSSL and NSS consume, so a file it emits opens in both, cross-checked bidirectionally. The MAC covers the exact AuthenticatedSafe byte range, a DEFAULT-1 `MacData.iterations` is rejected up front, and the store is re-parsed before return. `verifyMac(pfx, password, opts)` recomputes a classic or PBMAC1 MAC over `macedBytes` and constant-time-compares it, throwing on a MAC-less or public-key-integrity store. Public-key integrity (`opts.integrity.mode: "public-key"`) wraps the AuthenticatedSafe in a CMS SignedData instead of a MAC, signed by any `pki.cms.sign` signer and carrying no MacData (§4); privacy stays independent, so `password` still PBES2-encrypts the bags. Public-key privacy wraps a SafeContents as a CMS EnvelopedData (AES-CBC, `id-envelopedData`, never GCM) encrypted to recipient public keys through the `pki.cms.encrypt` recipient model, via per-safe `recipients` or the `opts.recipientCerts` convenience, restricted to certificate recipients (RSA-OAEP, ECDH, X25519, X448, ML-KEM) since a password or KEK recipient could not be reopened by `open`. All four integrity-by-privacy combinations are permitted (§3.1). `open(pfx, password, opts)` reads a store back: it verifies the MAC first, so a wrong password is the MAC verdict rather than a decrypt error, then PBES2-decrypts every privacy safe and shrouded key bag and returns `{ integrityMode, macVerified, signers, keys, certs, crls, secrets }` — keys as re-validated PKCS#8 DER, certs, CRLs and secrets as raw DER, all with `friendlyName` and `localKeyId`, nested safes recursively. A MAC-less store is refused unless `opts.allowUnauthenticated`. A public-key-integrity store is verified through its CMS SignedData signature first (`pkcs12/signature-invalid` on failure), with the signer surfaced in `signers` but never trust-chained, which remains the caller's `pki.path.validate` step. A legacy-PBE store's Appendix C 3DES and RC2 bags are decrypted, RC2 through an in-tree RFC 2268 cipher, so an `openssl pkcs12 -legacy` or NSS store opens; the legacy RC4 schemes are refused. An `id-envelopedData` safe is decrypted with `opts.recipientKey` after the integrity gate (`pkcs12/no-recipient-key` when absent), every recipient-side fault and every post-integrity decrypt failure collapsing to the uniform `pkcs12/decrypt-failed`, and `opts.keys: 'crypto'` imports each key to a `CryptoKey`. It reads what OpenSSL and NSS produce. Returns DER or a PEM `PKCS12`, with a typed `Pkcs12Error` on failure. Parsing stays at `pki.schema.pkcs12.parse` — `build`, `verifyMac`, `open` |
|
package/lib/acme.js
CHANGED
|
@@ -2357,11 +2357,27 @@ function client(directoryUrl, opts) {
|
|
|
2357
2357
|
return t;
|
|
2358
2358
|
}
|
|
2359
2359
|
|
|
2360
|
-
function _bodyText(res) {
|
|
2360
|
+
function _bodyText(res) {
|
|
2361
|
+
var b = res.body;
|
|
2362
|
+
if (Buffer.isBuffer(b)) return b.toString("utf8");
|
|
2363
|
+
if (b == null) return "";
|
|
2364
|
+
if (typeof b === "string") return b;
|
|
2365
|
+
// A BufferSource (Uint8Array, ArrayBuffer) from an injected transport: read its raw bytes rather than
|
|
2366
|
+
// String()-coercing it into its "123,45,..." toString.
|
|
2367
|
+
return guard.bytes.snapshotSource(b, E, "acme/bad-response", "the response body").toString("utf8");
|
|
2368
|
+
}
|
|
2361
2369
|
// The RAW bytes for jose.parseJson, so its FATAL UTF-8 validation runs on the wire body -- _bodyText's
|
|
2362
2370
|
// lossy utf8 decode (replacement chars) would let a malformed RFC 8259 response slip through. A string
|
|
2363
2371
|
// body (an injected test transport) carries no malformed UTF-8, so encoding it is lossless.
|
|
2364
|
-
function _jsonInput(res) {
|
|
2372
|
+
function _jsonInput(res) {
|
|
2373
|
+
var b = res.body;
|
|
2374
|
+
if (Buffer.isBuffer(b)) return b;
|
|
2375
|
+
if (b == null) return Buffer.alloc(0);
|
|
2376
|
+
if (typeof b === "string") return Buffer.from(b, "utf8");
|
|
2377
|
+
// A BufferSource (Uint8Array, ArrayBuffer) from an injected transport: normalize its raw bytes so
|
|
2378
|
+
// jose.parseJson runs its fatal UTF-8 validation on the wire body, not on its "123,45,..." toString.
|
|
2379
|
+
return guard.bytes.snapshotSource(b, E, "acme/bad-response", "the response body");
|
|
2380
|
+
}
|
|
2365
2381
|
function _requireKid() { if (!kid) throw E("acme/no-account", "no account is set -- call newAccount before an authenticated request (RFC 8555 sec. 6.2)"); return kid; }
|
|
2366
2382
|
function _harvestNonce(v) {
|
|
2367
2383
|
if (typeof v !== "string" || v === "") return;
|
|
@@ -2402,7 +2418,8 @@ function client(directoryUrl, opts) {
|
|
|
2402
2418
|
// Measure an injected string body as UTF-8 -- the exact bytes _jsonInput re-encodes it to before the
|
|
2403
2419
|
// decoder sees it -- so a non-ASCII body (e.g. multi-byte emoji, ~half the byte count under latin1)
|
|
2404
2420
|
// cannot slip past the cap and reach the JSON parser.
|
|
2405
|
-
var blen =
|
|
2421
|
+
var blen = res.body == null ? 0 : (typeof res.body === "string" ? Buffer.byteLength(res.body, "utf8")
|
|
2422
|
+
: (Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) : guard.bytes.lengthOf(guard.bytes.source(res.body, E, "acme/bad-response", "the response body"))));
|
|
2406
2423
|
if (blen > budgets.maxResponseBytes) throw E("acme/response-too-large", "the response body (" + blen + " bytes) exceeds the " + budgets.maxResponseBytes + "-byte cap");
|
|
2407
2424
|
if ((method === "GET" || method === "HEAD") && res.status >= 300 && res.status < 400) {
|
|
2408
2425
|
if (redirects >= budgets.maxRedirects) throw E("acme/too-many-redirects", "the redirect budget of " + budgets.maxRedirects + " was exceeded");
|
package/lib/cmp-build.js
CHANGED
|
@@ -92,17 +92,18 @@ var KNOWN_HEADER_KEYS = {
|
|
|
92
92
|
transactionID: 1, senderNonce: 1, recipNonce: 1, freeText: 1, generalInfo: 1,
|
|
93
93
|
};
|
|
94
94
|
var KNOWN_BODY_KEYS = {
|
|
95
|
-
ir: 1, cr: 1, kur: 1, krr: 1, p10cr: 1, certConf: 1, pollReq: 1, genm: 1, rr: 1, // request-side
|
|
95
|
+
ir: 1, cr: 1, kur: 1, krr: 1, ccr: 1, p10cr: 1, certConf: 1, pollReq: 1, genm: 1, rr: 1, // request-side
|
|
96
96
|
ip: 1, cp: 1, kup: 1, ccp: 1, krp: 1, rp: 1, genp: 1, error: 1, pollRep: 1, pkiconf: 1, // CA/responder-side
|
|
97
97
|
nested: 1, // an RA wrapper of complete, independently-protected PKIMessages (RFC 9810 sec. 5.1.3.5)
|
|
98
98
|
};
|
|
99
99
|
// The PKIBody arm -> its EXPLICIT context tag number (schema-cmp.js BODY_ARMS). rr is [11], not [15].
|
|
100
100
|
var BODY_TAG = {
|
|
101
|
-
ir: 0, cr: 2, p10cr: 4, kur: 7, krr: 9, rr: 11, genm: 21, certConf: 24, pollReq: 25,
|
|
101
|
+
ir: 0, cr: 2, p10cr: 4, kur: 7, krr: 9, ccr: 13, rr: 11, genm: 21, certConf: 24, pollReq: 25,
|
|
102
102
|
ip: 1, cp: 3, kup: 8, krp: 10, rp: 12, ccp: 14, pkiconf: 19, genp: 22, error: 23, pollRep: 26,
|
|
103
103
|
nested: 20, // NestedMessageContent (schema-cmp.js BODY_ARMS [20])
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
// arms whose content is a CertReqMessages via pki.crmf.build (RFC 9810 sec. 5.3.7 krr, sec. 5.3.11 ccr).
|
|
106
|
+
var CRMF_BODY = { ir: 1, cr: 1, kur: 1, krr: 1, ccr: 1 };
|
|
106
107
|
var CERT_REP_ARM = { ip: 1, cp: 1, kup: 1, ccp: 1 }; // arms carrying a CertRepMessage
|
|
107
108
|
// Protection has two mutually exclusive forms, and the signature parameters are read only by the
|
|
108
109
|
// signature one: under PBMAC1 a requested pss or digestAlgorithm selects nothing and the message
|
|
@@ -517,7 +518,6 @@ function _encodeCertResponse(cr, state) {
|
|
|
517
518
|
function _encodeCertRepMessage(spec, state, arm) {
|
|
518
519
|
if (!spec || typeof spec !== "object" || Buffer.isBuffer(spec)) throw _err("cmp/bad-cert-rep", arm + " must be an object { caPubs?, response }");
|
|
519
520
|
if (!Array.isArray(spec.response)) throw _err("cmp/bad-cert-rep", arm + ".response must be an array of CertResponse");
|
|
520
|
-
if (arm === "ccp" && spec.response.length !== 1) throw _err("cmp/bad-cert-rep", "a ccp CertRepMessage carries exactly one CertResponse (RFC 9810 App. D)");
|
|
521
521
|
var children = [];
|
|
522
522
|
if (spec.caPubs != null) { // caPubs [1] PRECEDES response (the optional-first x509-version shape)
|
|
523
523
|
if (!Array.isArray(spec.caPubs) || !spec.caPubs.length) throw _err("cmp/bad-cert-rep", arm + ".caPubs must be a non-empty array of certificate DERs");
|
|
@@ -897,7 +897,11 @@ function _collectExtraCerts(opts, protCertDer) {
|
|
|
897
897
|
* `{ header, body }`: `header` carries the `sender` / `recipient` GeneralNames plus optional transaction
|
|
898
898
|
* metadata (`transactionID`, `senderNonce`, `messageTime`, `freeText`, `generalInfo`, ...); `body` is a
|
|
899
899
|
* single-key object naming the arm. Request-side: `{ ir }` / `{ cr }` / `{ kur }` / `{ krr }` (key recovery,
|
|
900
|
-
* RFC 9810 sec. 5.3.7
|
|
900
|
+
* RFC 9810 sec. 5.3.7) / `{ ccr }` (cross-certification, RFC 9810 sec. 5.3.11: the requesting CA keeps its
|
|
901
|
+
* private key, so a ccr carrying the private-key-transport encryptedKey proof-of-possession is refused; a
|
|
902
|
+
* ccr is a CertReqMessages at the normative floor and the optional App. D.6 single-request cardinality is
|
|
903
|
+
* not enforced); each
|
|
904
|
+
* a `CertReqMessages` spec
|
|
901
905
|
* delegated to `pki.crmf.build`; the proof-of-possession key is `key` on the arm spec), `{ p10cr }` (a PKCS#10
|
|
902
906
|
* CertificationRequest DER), `{ certConf }`, `{ pollReq }`, `{ genm }`, `{ rr }`. CA/responder-side: `{ ip }` /
|
|
903
907
|
* `{ cp }` / `{ kup }` / `{ ccp }` (a `CertRepMessage`: `caPubs` plus `response` of `CertResponse` each with a
|
package/lib/cmp-session.js
CHANGED
|
@@ -847,6 +847,13 @@ function session(opts) {
|
|
|
847
847
|
if (!resp) return { state: "unexpected", reason: "a " + arm + " carried no CertResponse for certReqId " + activeCertReqId };
|
|
848
848
|
var code = resp.status && resp.status.status ? resp.status.status.code : null;
|
|
849
849
|
var isGrantLeg = _isGranted(code);
|
|
850
|
+
// RFC 9483 sec. 4.4: a "waiting" CertResponse must not carry failInfo -- a wait is not a failure. Refuse
|
|
851
|
+
// a contradictory failInfo (mirroring the _classifyError waiting check). A granting status carrying
|
|
852
|
+
// failInfo is already refused upstream: the parser rejects failInfo alongside a certifiedKeyPair (RFC 9810
|
|
853
|
+
// sec. 5.3.4), and a grant with no certificate is refused as a missing issued certificate.
|
|
854
|
+
if (code === 3 && resp.status && resp.status.failInfo != null) {
|
|
855
|
+
return { state: "unexpected", reason: "a waiting " + arm + " CertResponse must not carry failInfo (RFC 9483 sec. 4.4)" };
|
|
856
|
+
}
|
|
850
857
|
// Accumulate the AUTHENTICATED caPubs of EVERY ip/cp/kup leg (waiting AND granting): a CA may deliver the
|
|
851
858
|
// issuing chain in a `waiting` response and omit it from the grant, so the leaf's issuer must survive the poll.
|
|
852
859
|
// Bound + validate + dedup the caPubs AS ACCUMULATED, not only when _finish is reached: an authenticated CA
|
package/lib/cmp-verify.js
CHANGED
|
@@ -523,6 +523,19 @@ function _bufEq(a, x) {
|
|
|
523
523
|
return _compare(a, x) === 0;
|
|
524
524
|
}
|
|
525
525
|
function _headerChecks(m, opts) {
|
|
526
|
+
// RFC 9483 sec. 3.5: the pvno MUST be cmp2000(2) or cmp2021(3) (failInfo unsupportedVersion). The parser
|
|
527
|
+
// accepts cmp1999(1) as valid RFC 9810 sec. 5.1.1 syntax; the lightweight profile refuses it on receipt.
|
|
528
|
+
if (m.header.pvno !== 2 && m.header.pvno !== 3) {
|
|
529
|
+
return { code: "cmp/unsupported-version", reason: "the header pvno is " + m.header.pvno + "; a received PKIMessage MUST carry cmp2000(2) or cmp2021(3) (RFC 9483 sec. 3.5)" };
|
|
530
|
+
}
|
|
531
|
+
// RFC 9483 sec. 3.5: the transactionID MUST be present (failInfo badDataFormat).
|
|
532
|
+
if (!guard.bytes.isByteSource(m.header.transactionID)) {
|
|
533
|
+
return { code: "cmp/bad-transaction-id", reason: "the header transactionID is absent; a received PKIMessage MUST carry one (RFC 9483 sec. 3.5)" };
|
|
534
|
+
}
|
|
535
|
+
// RFC 9483 sec. 3.5: the senderNonce MUST be present and MUST contain at least 128 bits (failInfo badSenderNonce).
|
|
536
|
+
if (!guard.bytes.isByteSource(m.header.senderNonce) || guard.bytes.lengthOf(m.header.senderNonce) < 16) {
|
|
537
|
+
return { code: "cmp/bad-sender-nonce", reason: "the header senderNonce is absent or shorter than 128 bits (RFC 9483 sec. 3.5)" };
|
|
538
|
+
}
|
|
526
539
|
if (opts.transactionID != null && !_bufEq(m.header.transactionID, opts.transactionID)) {
|
|
527
540
|
return { code: "cmp/transaction-id-mismatch", reason: "header.transactionID does not equal the expected value (RFC 9810 sec. 5.1.1)" };
|
|
528
541
|
}
|
|
@@ -1110,6 +1123,12 @@ async function _verify(message, opts) {
|
|
|
1110
1123
|
* signature path the authenticated header `sender` field MUST match the signer certificate subject (RFC 9483
|
|
1111
1124
|
* sec. 3.1), so a certificate the anchor trusts cannot sign under another party's sender name.
|
|
1112
1125
|
*
|
|
1126
|
+
* On a protection-verified message the RFC 9483 sec. 3.5 receiving-side header rules apply: the `pvno` MUST be
|
|
1127
|
+
* cmp2000(2) or cmp2021(3) (a cmp1999(1) message stays valid RFC 9810 syntax `pki.schema.cmp.parse` decodes,
|
|
1128
|
+
* refused only on receipt), the `transactionID` MUST be present, and the `senderNonce` MUST be present and
|
|
1129
|
+
* carry at least 128 bits; a violation is a `{ valid: false }` verdict carrying `cmp/unsupported-version`,
|
|
1130
|
+
* `cmp/bad-transaction-id`, or `cmp/bad-sender-nonce`.
|
|
1131
|
+
*
|
|
1113
1132
|
* Returns a verdict (never a bare boolean): `{ valid, trusted, protectionType, protectionAlg, signer,
|
|
1114
1133
|
* transactionID, senderNonce, recipNonce, header, body, code?, reason? }`. `valid` is whether the
|
|
1115
1134
|
* protection is cryptographically intact under the declared algorithm; `trusted` is whether a MAC secret
|
package/lib/est.js
CHANGED
|
@@ -784,7 +784,17 @@ function classifyResponse(status, headers, body, opts) {
|
|
|
784
784
|
// toString(enc, start, end) bounds the decode WITHOUT constructing a subarray
|
|
785
785
|
// view, so a detached body reads as "" here rather than throwing a raw
|
|
786
786
|
// TypeError that would mask the est/http-error verdict.
|
|
787
|
-
var text
|
|
787
|
+
var text;
|
|
788
|
+
if (Buffer.isBuffer(body)) {
|
|
789
|
+
text = body.toString("utf8", 0, 512);
|
|
790
|
+
} else if (guard.bytes.isByteSource(body)) {
|
|
791
|
+
// A byte source from an injected transport (a Uint8Array / ArrayBuffer): decode a bounded prefix through
|
|
792
|
+
// the byte guard rather than String()-coercing it to a "48,130,..." comma list.
|
|
793
|
+
try { text = guard.bytes.source(body, EstError, "est/bad-input", "the EST error body").toString("utf8", 0, 512); }
|
|
794
|
+
catch (_e) { /* allow:swallow-unverified a detached / unreadable error body reads as an empty snippet rather than masking the est/http-error verdict with a raw TypeError */ text = ""; }
|
|
795
|
+
} else {
|
|
796
|
+
text = String(body || "").slice(0, 512);
|
|
797
|
+
}
|
|
788
798
|
throw E("est/http-error", "EST server returned HTTP " + status + (text ? ": " + text : ""));
|
|
789
799
|
}
|
|
790
800
|
return { status: "unexpected", httpStatus: status };
|
|
@@ -1142,7 +1152,7 @@ function _drive(method, url, body, headers, opts, transport, budgets) {
|
|
|
1142
1152
|
// Measure an injected string body as UTF-8 -- the byte width the body is decoded/transfer-decoded at,
|
|
1143
1153
|
// and what the real socket transport counts -- so a non-ASCII body (multi-byte chars are ~half the
|
|
1144
1154
|
// count under latin1) cannot undercount past the DoS cap and reach body handling.
|
|
1145
|
-
var blen = Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) :
|
|
1155
|
+
var blen = res.body == null ? 0 : (typeof res.body === "string" ? Buffer.byteLength(res.body, "utf8") : (Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) : guard.bytes.lengthOf(guard.bytes.source(res.body, EstError, "est/bad-input", "the response body"))));
|
|
1146
1156
|
if (blen > budgets.maxResponseBytes) throw E("est/response-too-large", "the response body (" + blen + " bytes) exceeds the " + budgets.maxResponseBytes + "-byte cap (RFC 7030 sec. 6)");
|
|
1147
1157
|
// The transport contract returns lowercased headers, but the injectable seam only promises
|
|
1148
1158
|
// { status, headers, body }; normalize here so a redirect Location / WWW-Authenticate from an
|
|
@@ -1292,7 +1302,7 @@ function _certsResult(op, res, opts, csrSpki) {
|
|
|
1292
1302
|
if (verdict.status !== "ok") throw E("est/http-error", "an EST " + op + " response must be HTTP 200 or 202 (RFC 7030 sec. 4.1.3 / 4.2.3), got " + res.status);
|
|
1293
1303
|
// Measure the body as UTF-8 for parity with the transport cap above (this check only distinguishes empty
|
|
1294
1304
|
// from non-empty, where the encoding is immaterial, but the shape is kept uniform so no site undercounts).
|
|
1295
|
-
var bodyLen = Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) :
|
|
1305
|
+
var bodyLen = res.body == null ? 0 : (typeof res.body === "string" ? Buffer.byteLength(res.body, "utf8") : (Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) : guard.bytes.lengthOf(guard.bytes.source(res.body, EstError, "est/bad-input", "the response body"))));
|
|
1296
1306
|
if (bodyLen === 0) throw E("est/empty-body", "a 200 " + op + " response carried an empty body (RFC 7030 sec. 4.1.3 / 4.2.3)");
|
|
1297
1307
|
var parsed = parseCertsOnly(transferDecode(res.body));
|
|
1298
1308
|
if (op === "cacerts") return { certificates: parsed.certificates, crls: parsed.crls };
|
|
@@ -1856,7 +1866,7 @@ function _fullcmcResult(res, opts, wanted, sent) {
|
|
|
1856
1866
|
"an EST /fullcmc response must be HTTP 200 or 202 (RFC 7030 sec. 4.3.2), got " + res.status);
|
|
1857
1867
|
}
|
|
1858
1868
|
|
|
1859
|
-
var bodyLen = Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) :
|
|
1869
|
+
var bodyLen = res.body == null ? 0 : (typeof res.body === "string" ? Buffer.byteLength(res.body, "utf8") : (Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) : guard.bytes.lengthOf(guard.bytes.source(res.body, EstError, "est/bad-input", "the response body"))));
|
|
1860
1870
|
if (bodyLen === 0) throw E("est/empty-body", "a 200 /fullcmc response carried an empty body (RFC 7030 sec. 4.3.2)");
|
|
1861
1871
|
var der = transferDecode(res.body);
|
|
1862
1872
|
|
|
@@ -2255,7 +2265,7 @@ async function _serverkeygenResult(res, opts, derived) {
|
|
|
2255
2265
|
// A 202 is an enrollment posture (RFC 7030 sec. 4.4 treats /serverkeygen as an enroll): surfaced, never slept.
|
|
2256
2266
|
if (verdict.status === "retry") return { retry: true, retryAfterSeconds: verdict.retryAfterSeconds, retryAfterDate: verdict.retryAfterDate };
|
|
2257
2267
|
if (verdict.status !== "ok") throw E("est/http-error", "an EST serverkeygen response must be HTTP 200 or 202 (RFC 7030 sec. 4.4.2), got " + res.status);
|
|
2258
|
-
var bodyLen = Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) :
|
|
2268
|
+
var bodyLen = res.body == null ? 0 : (typeof res.body === "string" ? Buffer.byteLength(res.body, "utf8") : (Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) : guard.bytes.lengthOf(guard.bytes.source(res.body, EstError, "est/bad-input", "the response body"))));
|
|
2259
2269
|
if (bodyLen === 0) throw E("est/empty-body", "a 200 serverkeygen response carried an empty body (RFC 7030 sec. 4.4.2)");
|
|
2260
2270
|
_assertConfidentialCipher(res);
|
|
2261
2271
|
// parseServerKeygenResponse does the per-part transfer-decode; the recipient coherence is bound to the CSR.
|
|
@@ -2357,7 +2367,7 @@ function _csrattrsResult(res, opts) {
|
|
|
2357
2367
|
// A 202 is nonconforming for a policy GET (sec. 4.5.2 lists only 200 / 204 / 404).
|
|
2358
2368
|
if (verdict.status === "retry") throw E("est/http-error", "a /csrattrs response must be HTTP 200, 204, or 404, not 202 (RFC 7030 sec. 4.5.2)");
|
|
2359
2369
|
if (verdict.status !== "ok") throw E("est/http-error", "an EST csrattrs response must be HTTP 200 / 204 / 404 (RFC 7030 sec. 4.5.2), got " + res.status);
|
|
2360
|
-
var bodyLen = Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) :
|
|
2370
|
+
var bodyLen = res.body == null ? 0 : (typeof res.body === "string" ? Buffer.byteLength(res.body, "utf8") : (Buffer.isBuffer(res.body) ? guard.bytes.lengthOf(res.body) : guard.bytes.lengthOf(guard.bytes.source(res.body, EstError, "est/bad-input", "the response body"))));
|
|
2361
2371
|
// An empty HTTP body is distinct from a valid EMPTY CsrAttrs (`30 00` / base64 `MAA=`), which parses as {items:[]}.
|
|
2362
2372
|
if (bodyLen === 0) throw E("est/empty-body", "a 200 csrattrs response carried an empty body (RFC 7030 sec. 4.5.2)");
|
|
2363
2373
|
var attrs = csrattrsFmt.parse(transferDecode(res.body));
|
package/lib/guard-text.js
CHANGED
|
@@ -34,15 +34,14 @@ var intrinsic = require("./guard-intrinsic");
|
|
|
34
34
|
// UTF-8 rule all still run and all still pass.
|
|
35
35
|
// _byteLength measures the string arm against the cap. One returning 0 admits a string
|
|
36
36
|
// of any size, which is the allocation-DoS this guard exists to bound.
|
|
37
|
-
// _isInteger decides whether the cap itself is usable
|
|
38
|
-
// an input takes.
|
|
37
|
+
// _isInteger decides whether the cap itself is usable; guard.bytes.isByteSource decides
|
|
38
|
+
// whether an input takes the byte arm or the string arm.
|
|
39
39
|
// The two method captures are uncurried, so their call sites read no property of them; see
|
|
40
40
|
// guard-intrinsic for why capturing a method and then reading `.call` on it reopens the hole.
|
|
41
41
|
var _toString = intrinsic.uncurry(Buffer.prototype.toString);
|
|
42
42
|
var _decode = intrinsic.uncurry(TextDecoder.prototype.decode);
|
|
43
43
|
// Already plain functions rather than methods, so these are invoked directly.
|
|
44
44
|
var _byteLength = Buffer.byteLength;
|
|
45
|
-
var _isBuffer = Buffer.isBuffer;
|
|
46
45
|
var _isInteger = Number.isInteger;
|
|
47
46
|
var _TextDecoder = TextDecoder;
|
|
48
47
|
|
|
@@ -58,10 +57,10 @@ var LATIN1 = "latin1";
|
|
|
58
57
|
// tooLarge: code for the over-cap reject,
|
|
59
58
|
// badDecode: code for a fatal-charset (bad-UTF-8) reject
|
|
60
59
|
// (required only when fatal is set),
|
|
61
|
-
// badInput: code for a non-
|
|
60
|
+
// badInput: code for a non-byte-source/non-string reject,
|
|
62
61
|
// label: human phrase for the message }
|
|
63
62
|
// @enforced-by behavioral -- cap-before-copy has no rename-proof code shape; the
|
|
64
|
-
// over-cap RED vectors + the detached re-view through guard.bytes.
|
|
63
|
+
// over-cap RED vectors + the detached re-view through guard.bytes.source (itself
|
|
65
64
|
// enforced) are the guard.
|
|
66
65
|
function decode(input, maxBytes, ErrorClass, spec) {
|
|
67
66
|
// maxBytes is an authoring input: an undefined / NaN / fractional cap makes
|
|
@@ -72,12 +71,12 @@ function decode(input, maxBytes, ErrorClass, spec) {
|
|
|
72
71
|
throw new TypeError("guard.text.decode: maxBytes must be a non-negative integer");
|
|
73
72
|
}
|
|
74
73
|
var charset = spec.charset || LATIN1;
|
|
75
|
-
if (
|
|
76
|
-
// Re-view through the byte guard first so a
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
// instead of being decoded as an empty string. Then cap, then decode.
|
|
80
|
-
input = bytes.
|
|
74
|
+
if (bytes.isByteSource(input)) {
|
|
75
|
+
// Re-view through the byte guard first so any byte source (a Buffer, a Uint8Array or other typed array, a
|
|
76
|
+
// DataView, or a raw ArrayBuffer -- a caller-injected transport may return any of these) is normalized to a
|
|
77
|
+
// usable view, and a detached backing ArrayBuffer (a transferred / structuredClone'd view, which reads as
|
|
78
|
+
// zero-length) fails closed here instead of being decoded as an empty string. Then cap, then decode.
|
|
79
|
+
input = bytes.source(input, ErrorClass, spec.badInput, spec.label);
|
|
81
80
|
// Measured through the byte guard's captured intrinsic getter, never `input.length`. On a typed
|
|
82
81
|
// array `length` is an accessor on the prototype and it is configurable, so a replacement
|
|
83
82
|
// returning 0 lets a buffer of any size past the cap and straight into the decode -- the
|
|
@@ -96,7 +95,7 @@ function decode(input, maxBytes, ErrorClass, spec) {
|
|
|
96
95
|
if (byteLen > maxBytes) throw new ErrorClass(spec.tooLarge, spec.label + " exceeds the size cap");
|
|
97
96
|
return input;
|
|
98
97
|
}
|
|
99
|
-
throw new ErrorClass(spec.badInput, spec.label + " expects a string or Buffer");
|
|
98
|
+
throw new ErrorClass(spec.badInput, spec.label + " expects a string or a byte source (Buffer / TypedArray / DataView / ArrayBuffer)");
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
// Frozen for the reason the family header gives: a boundary reads its guard off this object at the
|
package/lib/path-validate.js
CHANGED
|
@@ -3352,7 +3352,12 @@ async function _aiaFetchOne(uri, aia) {
|
|
|
3352
3352
|
var res = await aia.transport({ method: "GET", url: uri, tls: aia.tls, timeout: aia.timeout, maxResponseBytes: aia.maxResponseBytes, blockPrivateAddresses: true });
|
|
3353
3353
|
res = res || {};
|
|
3354
3354
|
if (res.status !== 200) throw E("path/aia-status", "an AIA fetch returned HTTP " + res.status + " (only 200 is a cert source; no redirect following)");
|
|
3355
|
-
|
|
3355
|
+
// A binary view from an injected transport (Buffer / Uint8Array / ArrayBuffer / DataView) is re-viewed
|
|
3356
|
+
// through the byte guard, as the request path does; only a genuine string body falls back to a latin1
|
|
3357
|
+
// decode -- a typed array is never String()-coerced to "48,130,..." garbage that then fails to parse.
|
|
3358
|
+
var body = guard.bytes.isByteSource(res.body)
|
|
3359
|
+
? guard.bytes.source(res.body, PathError, "path/aia-bad-body", "the AIA response body")
|
|
3360
|
+
: Buffer.from(res.body == null ? "" : String(res.body), "latin1");
|
|
3356
3361
|
if (body.length === 0) throw E("path/aia-empty", "an AIA fetch returned an empty body");
|
|
3357
3362
|
// Belt for an INJECTED transport that ignores maxResponseBytes (the real transport streaming-aborts at the cap).
|
|
3358
3363
|
if (body.length > aia.maxResponseBytes) throw E("path/aia-too-large", "an AIA response exceeds the " + aia.maxResponseBytes + "-byte cap");
|
package/lib/scep.js
CHANGED
|
@@ -613,7 +613,7 @@ function _responseLen(body) {
|
|
|
613
613
|
if (body == null) return 0;
|
|
614
614
|
if (typeof body === "string") return Buffer.byteLength(body, "utf8");
|
|
615
615
|
if (Buffer.isBuffer(body)) return guard.bytes.lengthOf(body);
|
|
616
|
-
return guard.bytes.lengthOf(guard.bytes.
|
|
616
|
+
return guard.bytes.lengthOf(guard.bytes.source(body, ScepError, "scep/bad-response", "the response body"));
|
|
617
617
|
}
|
|
618
618
|
// Map opts.tls to the transport request.tls shape. rejectUnauthorized is NOT set -- the transport forces
|
|
619
619
|
// it on for an https connection.
|
package/lib/schema-cmp.js
CHANGED
|
@@ -599,13 +599,14 @@ var BODY = schema.decode(function (n, ctx) {
|
|
|
599
599
|
if (CRMF_ARMS[n.tagNumber]) {
|
|
600
600
|
// ccr [13] cross-certification: RFC 9810 Appendix D.6 profiles its template
|
|
601
601
|
// with signingAlg present and version "v1 or v3" (both overriding RFC 4211
|
|
602
|
-
// sec. 5 for this one arm)
|
|
603
|
-
//
|
|
602
|
+
// sec. 5 for this one arm). Those relaxations are allowed. The D.6 profile
|
|
603
|
+
// also expects exactly one CertReqMsg, but sec. 5.3.11 defines a ccr as a
|
|
604
|
+
// CertReqMessages (SIZE (1..MAX)) and App. D is OPTIONAL, so the base parser
|
|
605
|
+
// does not enforce the single-request cardinality (an App. D.6 producer keeps
|
|
606
|
+
// to one by its own policy, sending multiple cross-certificates in separate
|
|
607
|
+
// messages); only the no-private-key restriction below is normative.
|
|
604
608
|
var isCcr = n.tagNumber === 13;
|
|
605
609
|
out.decoded = crmf.walkCertReqMessages(inner, { allowSigningAlg: isCcr, allowV1Version: isCcr });
|
|
606
|
-
if (isCcr && out.decoded.messages.length !== 1) {
|
|
607
|
-
throw ctx.E("cmp/bad-body", "a cross-certification request (ccr) must contain exactly one CertReqMsg (RFC 9810 Appendix D.6)");
|
|
608
|
-
}
|
|
609
610
|
} else if (DECODED_ARMS[n.tagNumber]) {
|
|
610
611
|
var match = schema.walk(DECODED_ARMS[n.tagNumber], inner, ctx);
|
|
611
612
|
out.decoded = match.result;
|
|
@@ -704,12 +705,10 @@ var PKI_MESSAGE = schema.seq([
|
|
|
704
705
|
// meaning. Reject a ccp that carries one; never surface the key
|
|
705
706
|
// material. The field stays legal in the enrollment responses (ip/cp/kup).
|
|
706
707
|
if (body.arm === "ccp" && body.decoded && body.decoded.response) {
|
|
707
|
-
// RFC 9810 Appendix D.6
|
|
708
|
-
//
|
|
709
|
-
//
|
|
710
|
-
|
|
711
|
-
throw ctx.E("cmp/bad-body", "a cross-certification response (ccp) must contain exactly one CertResponse (RFC 9810 Appendix D.6)");
|
|
712
|
-
}
|
|
708
|
+
// RFC 9810 Appendix D.6 profiles a one-way ccp as exactly one CertResponse (the mirror of the ccr
|
|
709
|
+
// one-CertReqMsg profile), but sec. 5.3.12 defines a ccp as a CertRepMessage (SIZE (1..MAX)) and App. D
|
|
710
|
+
// is OPTIONAL, so the base parser does not enforce the single-response cardinality; only the
|
|
711
|
+
// no-private-key restriction is normative.
|
|
713
712
|
for (var c = 0; c < body.decoded.response.length; c++) {
|
|
714
713
|
var ckpCcp = body.decoded.response[c].certifiedKeyPair;
|
|
715
714
|
if (ckpCcp && ckpCcp.privateKey !== null) {
|
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:2f668b08-8394-4a54-b202-eac9892a6e2f",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-08-
|
|
8
|
+
"timestamp": "2026-08-31T15:15:24.682Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/pki@0.6.
|
|
22
|
+
"bom-ref": "@blamejs/pki@0.6.9",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "pki",
|
|
25
|
-
"version": "0.6.
|
|
25
|
+
"version": "0.6.9",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/pki@0.6.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/pki@0.6.9",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/pki@0.6.
|
|
57
|
+
"ref": "@blamejs/pki@0.6.9",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|