@blamejs/pki 0.7.27 → 0.7.29
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 +21 -0
- package/README.md +1 -1
- package/lib/cmp-build.js +1 -1
- package/lib/cmp-verify.js +31 -7
- package/lib/key.js +37 -27
- package/lib/oid.js +5 -4
- package/package.json +2 -2
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,27 @@ 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.29 — 2026-09-12
|
|
8
|
+
|
|
9
|
+
Every decision pki.key makes is taken with operations bound when the module loads.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- pki.key.import, pki.key.generate, pki.key.decrypt, pki.key.encrypt, pki.key.export, pki.key.publicFromPrivate and the key-pair correspondence check read Array.isArray, Math.floor, isFinite, String, String.prototype.toUpperCase and String.prototype.indexOf, Buffer.from, Object.assign, Object.create and Object.prototype.hasOwnProperty as bound at module load. Replacing any of them afterwards changes nothing the module decides: a non-array usages is still refused, a fractional or infinite maxIterations is still refused, an Ed25519 import still receives signing usages, and an unrestricted RSASSA-PSS pair still corresponds when an inherited saltLength is planted on Object.prototype. Behavior on an untouched runtime is unchanged.
|
|
14
|
+
|
|
15
|
+
## v0.7.28 — 2026-09-12
|
|
16
|
+
|
|
17
|
+
pki.cmp.verify names a MAC algorithm it does not compute as what it is, not as a failed signature.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- pki.oid resolves the RFC 9481 section 6.2 identifiers aes128-GMAC, aes192-GMAC, aes256-GMAC, kmacWithSHAKE128 and kmacWithSHAKE256.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- pki.cmp.verify classifies the protectionAlg before checking it. A protectionAlg naming id-PasswordBasedMac, id-DHBasedMac, or one of the bare symmetric MACs of RFC 9481 section 6.2 (hmacWithSHA1 through hmacWithSHA512, aes128/192/256-GMAC, KMACWithSHAKE128/256) returns { valid: false, protectionType: "mac", code: "cmp/unsupported-algorithm" } with a reason naming the algorithm and its section, whatever credential the caller supplied. A symmetric MAC applied without a key derivation keys the shared secret directly, with no work factor, so one captured message is an offline oracle against a low-entropy secret; PBMAC1 exists to close that, and this verifier computes PBMAC1, KEM-based MAC and signature protection only. An identifier no table knows still reaches the signature path, which section 5.1.3.3 leaves open-ended, and still fails closed there.
|
|
26
|
+
- The message pki.cmp.build raises for a mac.algorithm other than pbmac1 states the profile decision (RFC 9481 section 6.1.2) rather than calling the alternative deferred.
|
|
27
|
+
|
|
7
28
|
## v0.7.27 — 2026-09-12
|
|
8
29
|
|
|
9
30
|
pki lint detects a certificate, a CRL or an OCSP response and runs the matching profile.
|
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, 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
|
-
| `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
|
|
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 MAC algorithm it does not compute (reported as MAC-protected under that algorithm, never as a failed signature), 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` |
|
|
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, issuer alternative name, issuing distribution point, delta-CRL indicator, freshest CRL, authority information access, which is every extension RFC 5280 §5.2 defines) 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/cmp-build.js
CHANGED
|
@@ -752,7 +752,7 @@ function _resolveProtection(opts, message) {
|
|
|
752
752
|
var m = opts.mac;
|
|
753
753
|
if (!m || typeof m !== "object" || Buffer.isBuffer(m)) throw _err("cmp/bad-input", "opts.mac must be an object { secret, salt?, iterationCount?, prf?, keyLength? }");
|
|
754
754
|
guard.identifier.assertKnownKeys(m, KNOWN_MAC_KEYS, _err, "cmp/bad-input", "unknown opts.mac field ");
|
|
755
|
-
if (m.algorithm != null && m.algorithm !== "pbmac1") throw _err("cmp/unsupported-algorithm", "opts.mac.algorithm " + guard.text.showValue(m.algorithm) + " is not supported
|
|
755
|
+
if (m.algorithm != null && m.algorithm !== "pbmac1") throw _err("cmp/unsupported-algorithm", "opts.mac.algorithm " + guard.text.showValue(m.algorithm) + " is not supported; MAC protection is computed under pbmac1 (RFC 9481 sec. 6.1.2), the one password-based MAC in the RFC 9481 profile");
|
|
756
756
|
var secret = m.secret;
|
|
757
757
|
if (typeof secret !== "string" || !secret) {
|
|
758
758
|
if (!Buffer.isBuffer(secret) || !secret.length) throw _err("cmp/bad-input", "opts.mac.secret must be a non-empty string or Buffer");
|
package/lib/cmp-verify.js
CHANGED
|
@@ -74,10 +74,30 @@ var PBMAC1_KEYLEN_MIN = 20;
|
|
|
74
74
|
var PBMAC1_KEYLEN_MAX = 1024;
|
|
75
75
|
var PRF_HLEN = intrinsic.assign(intrinsic.create(null), { "SHA-256": 32, "SHA-384": 48, "SHA-512": 64 });
|
|
76
76
|
|
|
77
|
+
/** @internal The MAC protection identifiers RFC 9810 sec. 5.1.3 and RFC 9481 sec. 6 name that this
|
|
78
|
+
* verifier does NOT compute, keyed by OID, each with the reason its verdict carries. A message
|
|
79
|
+
* carrying one is MAC-protected under a flavor that is not verified here, and its verdict says so:
|
|
80
|
+
* it is never the signature case, which sec. 5.1.3.3 leaves open-ended and which an OID absent from
|
|
81
|
+
* this table falls through to. The two legacy identifiers sit outside the RFC 9481 profile. A bare
|
|
82
|
+
* symmetric MAC keys the shared secret directly, with no derivation and no work factor, so one
|
|
83
|
+
* captured message is an offline oracle against a low-entropy secret; PBMAC1 exists to close that,
|
|
84
|
+
* and RFC 9481 sec. 6.2.2 forbids AES-GMAC beside PBKDF2 outright. */
|
|
77
85
|
var UNSUPPORTED_MAC_OIDS = _create(null);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
function _unsupportedMacs(why, bySection) {
|
|
87
|
+
intrinsic.forEach(intrinsic.keys(bySection), function (section) {
|
|
88
|
+
intrinsic.forEach(bySection[section], function (name) {
|
|
89
|
+
UNSUPPORTED_MAC_OIDS[oid.byName(name)] = { name: name, why: why + " (" + section + ")" };
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
_unsupportedMacs("is not in the RFC 9481 algorithm profile", {
|
|
94
|
+
"RFC 9481 sec. 6.1.1": ["passwordBasedMac"],
|
|
95
|
+
"RFC 9810 sec. 5.1.3.2": ["dhBasedMac"],
|
|
96
|
+
});
|
|
97
|
+
_unsupportedMacs("is a symmetric-key MAC applied without a key derivation", {
|
|
98
|
+
"RFC 9481 sec. 6.2.1": ["hmacWithSHA1", "hmacWithSHA224", "hmacWithSHA256", "hmacWithSHA384", "hmacWithSHA512"],
|
|
99
|
+
"RFC 9481 sec. 6.2.2": ["aes128-GMAC", "aes192-GMAC", "aes256-GMAC"],
|
|
100
|
+
"RFC 9481 sec. 6.2.3": ["kmacWithSHAKE128", "kmacWithSHAKE256"],
|
|
81
101
|
});
|
|
82
102
|
|
|
83
103
|
var _engine = null;
|
|
@@ -823,8 +843,9 @@ async function _verify(message, opts) {
|
|
|
823
843
|
|
|
824
844
|
var protectedPart = b.sequence([b.raw(m.headerBytes), b.raw(m.bodyBytes)]);
|
|
825
845
|
|
|
826
|
-
|
|
827
|
-
|
|
846
|
+
var unsupportedMac = UNSUPPORTED_MAC_OIDS[protectionAlg.oid];
|
|
847
|
+
if (unsupportedMac !== undefined) {
|
|
848
|
+
return _fail(m, "mac", protectionAlg, "cmp/unsupported-algorithm", "the " + unsupportedMac.name + " protection algorithm " + unsupportedMac.why + "; this verifier computes PBMAC1, KEM-based MAC and signature protection");
|
|
828
849
|
}
|
|
829
850
|
|
|
830
851
|
var isMac = protectionAlg.oid === oid.byName("pbmac1");
|
|
@@ -1171,8 +1192,11 @@ function openKeyPackage(container, opts) {
|
|
|
1171
1192
|
* `pki.schema.cmp.parse` result (the protection is always recomputed from the parser-surfaced raw
|
|
1172
1193
|
* `headerBytes` / `bodyBytes`, so a mutated display field on a parsed object cannot desync the crypto).
|
|
1173
1194
|
* The protection flavor is read from the header `protectionAlg` alone: `id-PBMAC1` selects the MAC path,
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1195
|
+
* `id-KemBasedMac` the KEM path, and a signature `AlgorithmIdentifier` the signature path. An
|
|
1196
|
+
* unprotected message fails closed, and so does a MAC identifier this verifier does not compute
|
|
1197
|
+
* (`id-PasswordBasedMac`, `id-DHBasedMac`, and the bare symmetric MACs of RFC 9481 sec. 6.2: the SHA-2
|
|
1198
|
+
* HMACs, AES-GMAC and KMAC), each reported as `protectionType: "mac"` with `cmp/unsupported-algorithm`
|
|
1199
|
+
* rather than as a failed signature. On the
|
|
1176
1200
|
* signature path the authenticated header `sender` field MUST match the signer certificate subject (RFC 9483
|
|
1177
1201
|
* sec. 3.1), so a certificate the anchor trusts cannot sign under another party's sender name.
|
|
1178
1202
|
*
|
package/lib/key.js
CHANGED
|
@@ -29,6 +29,16 @@ var webcrypto = require("./webcrypto");
|
|
|
29
29
|
var compositeKem = require("./composite-kem");
|
|
30
30
|
var frameworkError = require("./framework-error");
|
|
31
31
|
var guard = require("./guard-all");
|
|
32
|
+
var intrinsic = require("./guard-intrinsic");
|
|
33
|
+
var _assign = intrinsic.assign;
|
|
34
|
+
var _create = intrinsic.create;
|
|
35
|
+
var _isArray = intrinsic.isArray;
|
|
36
|
+
var _bufferFrom = intrinsic.bufferFrom;
|
|
37
|
+
var _floor = intrinsic.floor;
|
|
38
|
+
var _isFinite = intrinsic.isFinite;
|
|
39
|
+
var _String = intrinsic.String;
|
|
40
|
+
var _toUpperCase = intrinsic.toUpperCase;
|
|
41
|
+
var _strIndexOf = intrinsic.stringIndexOf;
|
|
32
42
|
|
|
33
43
|
var b = asn1.build;
|
|
34
44
|
var subtle = webcrypto.webcrypto.subtle;
|
|
@@ -37,16 +47,16 @@ var PemError = frameworkError.PemError;
|
|
|
37
47
|
function O(n) { return oid.byName(n); }
|
|
38
48
|
function _err(code, msg, cause) { return new KeyError(code, msg, cause); }
|
|
39
49
|
|
|
40
|
-
var CIPHER_NAME =
|
|
50
|
+
var CIPHER_NAME = _assign(_create(null), { "aes-128-cbc": "aes128-CBC", "aes-192-cbc": "aes192-CBC", "aes-256-cbc": "aes256-CBC" });
|
|
41
51
|
|
|
42
|
-
var INFER_ALG =
|
|
52
|
+
var INFER_ALG = _create(null);
|
|
43
53
|
["Ed25519", "Ed448", "X25519", "X448"].forEach(function (n) { INFER_ALG[O(n)] = { name: n }; });
|
|
44
54
|
[["id-ml-dsa-44", "ML-DSA-44"], ["id-ml-dsa-65", "ML-DSA-65"], ["id-ml-dsa-87", "ML-DSA-87"],
|
|
45
55
|
["id-ml-kem-512", "ML-KEM-512"], ["id-ml-kem-768", "ML-KEM-768"], ["id-ml-kem-1024", "ML-KEM-1024"]
|
|
46
56
|
].forEach(function (r) { INFER_ALG[O(r[0])] = { name: r[1] }; });
|
|
47
57
|
["sha2-128s", "sha2-128f", "sha2-192s", "sha2-192f", "sha2-256s", "sha2-256f",
|
|
48
58
|
"shake-128s", "shake-128f", "shake-192s", "shake-192f", "shake-256s", "shake-256f"
|
|
49
|
-
].forEach(function (s) { INFER_ALG[O("id-slh-dsa-" + s)] = { name: ("SLH-DSA-" + s)
|
|
59
|
+
].forEach(function (s) { INFER_ALG[O("id-slh-dsa-" + s)] = { name: _toUpperCase("SLH-DSA-" + s) }; });
|
|
50
60
|
|
|
51
61
|
function _isCryptoKey(x) { return webcrypto.isCryptoKeyLike(x); }
|
|
52
62
|
function _algName(a) { return typeof a === "string" ? a : (a && a.name); }
|
|
@@ -89,7 +99,7 @@ async function _toPrivateKeyDer(input) {
|
|
|
89
99
|
* var enc = await pki.key.encrypt(der, "s3cr3t", { pem: true });
|
|
90
100
|
* var back = await pki.key.decrypt(enc, "s3cr3t");
|
|
91
101
|
*/
|
|
92
|
-
var _ENCRYPT_OPTS =
|
|
102
|
+
var _ENCRYPT_OPTS = _assign(_create(null), { cipher: 1, iterations: 1, pem: 1, prf: 1, salt: 1 });
|
|
93
103
|
|
|
94
104
|
async function encrypt(privateKey, password, opts) {
|
|
95
105
|
opts = guard.identifier.optionsObject(opts, _err, "key/bad-input", "pki.key.encrypt options");
|
|
@@ -148,14 +158,14 @@ async function encrypt(privateKey, password, opts) {
|
|
|
148
158
|
* var enc = await pki.key.encrypt(await pki.key.export(pair.privateKey), "s3cr3t", { pem: true });
|
|
149
159
|
* var der = await pki.key.decrypt(enc, "s3cr3t");
|
|
150
160
|
*/
|
|
151
|
-
var _DECRYPT_OPTS =
|
|
161
|
+
var _DECRYPT_OPTS = _assign(_create(null), { maxIterations: 1, pem: 1 });
|
|
152
162
|
|
|
153
163
|
async function decrypt(encrypted, password, opts) {
|
|
154
164
|
opts = guard.identifier.optionsObject(opts, _err, "key/bad-input", "pki.key.decrypt options");
|
|
155
165
|
guard.identifier.assertKnownKeys(opts, _DECRYPT_OPTS, _err, "key/bad-input",
|
|
156
166
|
"pki.key.decrypt has an unknown option (the PBKDF2 cap here is `maxIterations`; " +
|
|
157
167
|
"`iterations` is the encrypt-side count): ");
|
|
158
|
-
if (opts.maxIterations != null && (typeof opts.maxIterations !== "number" || !
|
|
168
|
+
if (opts.maxIterations != null && (typeof opts.maxIterations !== "number" || !_isFinite(opts.maxIterations) || opts.maxIterations < 1 || _floor(opts.maxIterations) !== opts.maxIterations)) {
|
|
159
169
|
throw _err("key/bad-input", "maxIterations must be a positive integer");
|
|
160
170
|
}
|
|
161
171
|
var input = pkix.coerceToDer(encrypted, { pemLabel: "ENCRYPTED PRIVATE KEY", PemError: PemError, ErrorClass: KeyError, prefix: "key" });
|
|
@@ -204,7 +214,7 @@ function _decryptPbes2(encAlg, ciphertext, password, opts) {
|
|
|
204
214
|
* var pair = await pki.key.generate("Ed25519");
|
|
205
215
|
* var spkiPem = await pki.key.export(pair.publicKey, { format: "pem" });
|
|
206
216
|
*/
|
|
207
|
-
var _EXPORT_OPTS =
|
|
217
|
+
var _EXPORT_OPTS = _assign(_create(null), { format: 1, label: 1 });
|
|
208
218
|
|
|
209
219
|
async function export_(key, opts) {
|
|
210
220
|
opts = guard.identifier.optionsObject(opts, _err, "key/bad-input", "pki.key.export options");
|
|
@@ -247,7 +257,7 @@ async function export_(key, opts) {
|
|
|
247
257
|
* var spki = await pki.key.export(pair.publicKey);
|
|
248
258
|
* var pub = await pki.key.import(spki); // Ed25519 -- algorithm inferred
|
|
249
259
|
*/
|
|
250
|
-
var _IMPORT_OPTS =
|
|
260
|
+
var _IMPORT_OPTS = _assign(_create(null), { algorithm: 1, extractable: 1, password: 1, usages: 1 });
|
|
251
261
|
|
|
252
262
|
async function import_(input, opts) {
|
|
253
263
|
opts = guard.identifier.optionsObject(opts, _err, "key/bad-input", "pki.key.import options");
|
|
@@ -260,7 +270,7 @@ async function import_(input, opts) {
|
|
|
260
270
|
}
|
|
261
271
|
var algorithm = opts.algorithm != null ? opts.algorithm : _inferAlgorithm(detected);
|
|
262
272
|
var isPublic = detected.format === "spki";
|
|
263
|
-
if (opts.usages != null && !
|
|
273
|
+
if (opts.usages != null && !_isArray(opts.usages)) throw _err("key/bad-input", "opts.usages must be an array of key-usage strings");
|
|
264
274
|
var usages = opts.usages || _importUsages(_algName(algorithm), isPublic);
|
|
265
275
|
var extractable = opts.extractable != null ? opts.extractable : false;
|
|
266
276
|
try {
|
|
@@ -291,14 +301,14 @@ async function import_(input, opts) {
|
|
|
291
301
|
* var pair = await pki.key.generate("Ed25519");
|
|
292
302
|
* var pkcs8 = await pki.key.export(pair.privateKey);
|
|
293
303
|
*/
|
|
294
|
-
var _GENERATE_OPTS =
|
|
304
|
+
var _GENERATE_OPTS = _assign(_create(null), { extractable: 1, usages: 1 });
|
|
295
305
|
|
|
296
306
|
async function generate(algorithm, opts) {
|
|
297
307
|
opts = guard.identifier.optionsObject(opts, _err, "key/bad-input", "pki.key.generate options");
|
|
298
308
|
guard.identifier.assertKnownKeys(opts, _GENERATE_OPTS, _err, "key/bad-input",
|
|
299
309
|
"pki.key.generate has an unknown option (the WebCrypto spelling is `extractable`): ");
|
|
300
310
|
var extractable = opts.extractable != null ? opts.extractable : true;
|
|
301
|
-
if (opts.usages != null && !
|
|
311
|
+
if (opts.usages != null && !_isArray(opts.usages)) throw _err("key/bad-input", "opts.usages must be an array of key-usage strings");
|
|
302
312
|
var usages = opts.usages || _generateUsages(_algName(algorithm));
|
|
303
313
|
var pair;
|
|
304
314
|
try { pair = await subtle.generateKey(algorithm, extractable, usages); }
|
|
@@ -333,7 +343,7 @@ async function generate(algorithm, opts) {
|
|
|
333
343
|
* var pair = await pki.key.generate("Ed25519");
|
|
334
344
|
* var spki = await pki.key.publicFromPrivate(await pki.key.export(pair.privateKey));
|
|
335
345
|
*/
|
|
336
|
-
var _PUBLIC_FROM_PRIVATE_OPTS =
|
|
346
|
+
var _PUBLIC_FROM_PRIVATE_OPTS = _assign(_create(null), { pem: 1 });
|
|
337
347
|
|
|
338
348
|
/** @internal The composite ML-KEM OID a private key names, or null when it names anything else. Read
|
|
339
349
|
* from the AlgorithmIdentifier alone: a key that is not well formed enough to state one is left to the
|
|
@@ -399,17 +409,17 @@ async function publicFromPrivate(privateKey, opts) {
|
|
|
399
409
|
* correspondence that succeeds, and does not stop the key from being usable with the certificate.
|
|
400
410
|
* A caller needing structural consistency has a different question, and this is not it.
|
|
401
411
|
*/
|
|
402
|
-
var _PAIR_DIGEST =
|
|
403
|
-
var _PAIR_AGREE =
|
|
404
|
-
var _PAIR_KEM =
|
|
412
|
+
var _PAIR_DIGEST = _assign(_create(null), { rsa: "sha256", ec: "sha256" });
|
|
413
|
+
var _PAIR_AGREE = _assign(_create(null), { x25519: 1, x448: 1 });
|
|
414
|
+
var _PAIR_KEM = _assign(_create(null),
|
|
405
415
|
{ "ml-kem-512": 1, "ml-kem-768": 1, "ml-kem-1024": 1 });
|
|
406
416
|
/** @internal RFC 4055 sec. 1.2: ONE RSA key pair may be identified either by `rsaEncryption` or by
|
|
407
417
|
* `id-RSASSA-PSS`, and a delivered private key and the certificate that certifies it need not have
|
|
408
418
|
* chosen the same one. The key engine reports those two encodings as different types, so comparing
|
|
409
419
|
* types alone would call a usable pair no pair at all. They name one algorithm and are exercised
|
|
410
420
|
* together, under PSS, which is the padding the restricted encoding permits. */
|
|
411
|
-
var _PAIR_RSA =
|
|
412
|
-
var _PAIR_PROBE =
|
|
421
|
+
var _PAIR_RSA = _assign(_create(null), { rsa: 1, "rsa-pss": 1 });
|
|
422
|
+
var _PAIR_PROBE = _bufferFrom("pki.js key pair correspondence", "utf8");
|
|
413
423
|
|
|
414
424
|
function _sameKeyFamily(priv, pub) {
|
|
415
425
|
if (priv.asymmetricKeyType === pub.asymmetricKeyType) return true;
|
|
@@ -443,7 +453,7 @@ function _pairSignOptions(priv, pub) {
|
|
|
443
453
|
var salt = _pssSalt(privDetails.saltLength, pubDetails.saltLength);
|
|
444
454
|
/** @internal Null-prototype, because the engine READS this object by name. A plain object would
|
|
445
455
|
* let an inherited `saltLength` reach the signature as a restriction neither half stated. */
|
|
446
|
-
var options =
|
|
456
|
+
var options = _create(null);
|
|
447
457
|
options.padding = nodeCrypto.constants.RSA_PKCS1_PSS_PADDING;
|
|
448
458
|
if (salt != null) options.saltLength = salt;
|
|
449
459
|
return { digest: digest, options: options };
|
|
@@ -457,12 +467,12 @@ var _PSS_PINS = ["hashAlgorithm", "mgf1HashAlgorithm", "saltLength"];
|
|
|
457
467
|
* object would let an inherited `saltLength` or `hashAlgorithm` answer as a restriction the key never
|
|
458
468
|
* carried, and refuse a genuine pair. */
|
|
459
469
|
function _pssRestrictionOf(key, isPss) {
|
|
460
|
-
var out =
|
|
470
|
+
var out = _create(null);
|
|
461
471
|
var details = isPss ? key.asymmetricKeyDetails : null;
|
|
462
472
|
if (details == null) return out;
|
|
463
473
|
for (var i = 0; i < _PSS_PINS.length; i++) {
|
|
464
474
|
var name = _PSS_PINS[i];
|
|
465
|
-
if (
|
|
475
|
+
if (intrinsic.hasOwn(details, name) && details[name] != null) out[name] = details[name];
|
|
466
476
|
}
|
|
467
477
|
return out;
|
|
468
478
|
}
|
|
@@ -492,7 +502,7 @@ async function correspondsTo(privateKey, spkiDer) {
|
|
|
492
502
|
var priv, pub;
|
|
493
503
|
try { priv = nodeCrypto.createPrivateKey({ key: privDer, format: "der", type: "pkcs8" }); }
|
|
494
504
|
catch (e) { throw _err("key/bad-input", "the private key could not be read", e); }
|
|
495
|
-
try { pub = nodeCrypto.createPublicKey({ key:
|
|
505
|
+
try { pub = nodeCrypto.createPublicKey({ key: _bufferFrom(spkiDer), format: "der", type: "spki" }); }
|
|
496
506
|
catch (e) { throw _err("key/bad-input", "the public key could not be read", e); }
|
|
497
507
|
if (!_sameKeyFamily(priv, pub)) return false;
|
|
498
508
|
var kind = guard.text.keyOf(priv.asymmetricKeyType);
|
|
@@ -521,8 +531,8 @@ async function correspondsTo(privateKey, spkiDer) {
|
|
|
521
531
|
if (how === null) {
|
|
522
532
|
throw _err("key/unsupported-algorithm", "the two halves pin incompatible RSASSA-PSS parameters, so no operation exercises them together and whether they are a pair cannot be decided");
|
|
523
533
|
}
|
|
524
|
-
var signKey = how.options ?
|
|
525
|
-
var verifyKey = how.options ?
|
|
534
|
+
var signKey = how.options ? _assign(_create(null), { key: priv }, how.options) : priv;
|
|
535
|
+
var verifyKey = how.options ? _assign(_create(null), { key: pub }, how.options) : pub;
|
|
526
536
|
return nodeCrypto.verify(how.digest, _PAIR_PROBE, verifyKey,
|
|
527
537
|
nodeCrypto.sign(how.digest, _PAIR_PROBE, signKey)) === true;
|
|
528
538
|
} catch (e) {
|
|
@@ -569,17 +579,17 @@ function _inferAlgorithm(detected) {
|
|
|
569
579
|
}
|
|
570
580
|
|
|
571
581
|
function _importUsages(name, isPublic) {
|
|
572
|
-
var n =
|
|
582
|
+
var n = _toUpperCase(_String(name == null ? "" : name));
|
|
573
583
|
if (n === "X25519" || n === "X448" || n === "ECDH") return isPublic ? [] : ["deriveBits", "deriveKey"];
|
|
574
|
-
if (n
|
|
584
|
+
if (_strIndexOf(n, "ML-KEM") === 0) return isPublic ? ["encapsulateBits"] : ["decapsulateBits"];
|
|
575
585
|
if (n === "RSA-OAEP") return isPublic ? ["encrypt"] : ["decrypt"];
|
|
576
586
|
return isPublic ? ["verify"] : ["sign"];
|
|
577
587
|
}
|
|
578
588
|
|
|
579
589
|
function _generateUsages(name) {
|
|
580
|
-
var n =
|
|
590
|
+
var n = _toUpperCase(_String(name == null ? "" : name));
|
|
581
591
|
if (n === "X25519" || n === "X448" || n === "ECDH") return ["deriveBits", "deriveKey"];
|
|
582
|
-
if (n
|
|
592
|
+
if (_strIndexOf(n, "ML-KEM") === 0) return ["encapsulateBits", "decapsulateBits"];
|
|
583
593
|
if (n === "RSA-OAEP") return ["encrypt", "decrypt"];
|
|
584
594
|
return ["sign", "verify"];
|
|
585
595
|
}
|
package/lib/oid.js
CHANGED
|
@@ -303,12 +303,13 @@ var FAMILIES = Object.assign(Object.create(null), {
|
|
|
303
303
|
"id-TA-RSA-PSS-SHA-256": 4, "id-TA-RSA-v1-5-SHA-512": 5, "id-TA-RSA-PSS-SHA-512": 6 } },
|
|
304
304
|
|
|
305
305
|
nistAes: { base: [2, 16, 840, 1, 101, 3, 4, 1], of: {
|
|
306
|
-
"aes128-CBC": 2, "aes128-wrap": 5, "aes128-GCM": 6, "aes128-CCM": 7,
|
|
307
|
-
"aes192-CBC": 22, "aes192-wrap": 25, "aes192-GCM": 26, "aes192-CCM": 27,
|
|
308
|
-
"aes256-CBC": 42, "aes256-wrap": 45, "aes256-GCM": 46, "aes256-CCM": 47 } },
|
|
306
|
+
"aes128-CBC": 2, "aes128-wrap": 5, "aes128-GCM": 6, "aes128-CCM": 7, "aes128-GMAC": 9,
|
|
307
|
+
"aes192-CBC": 22, "aes192-wrap": 25, "aes192-GCM": 26, "aes192-CCM": 27, "aes192-GMAC": 29,
|
|
308
|
+
"aes256-CBC": 42, "aes256-wrap": 45, "aes256-GCM": 46, "aes256-CCM": 47, "aes256-GMAC": 49 } },
|
|
309
309
|
|
|
310
310
|
nistHash: { base: [2, 16, 840, 1, 101, 3, 4, 2], of: {
|
|
311
|
-
sha256: 1, sha384: 2, sha512: 3, "sha3-256": 8, "sha3-512": 10, shake128: 11, shake256: 12
|
|
311
|
+
sha256: 1, sha384: 2, sha512: 3, "sha3-256": 8, "sha3-512": 10, shake128: 11, shake256: 12,
|
|
312
|
+
kmacWithSHAKE128: 19, kmacWithSHAKE256: 20 } },
|
|
312
313
|
|
|
313
314
|
nistSig: { base: [2, 16, 840, 1, 101, 3, 4, 3], of: {
|
|
314
315
|
"id-rsassa-pkcs1-v1_5-with-sha3-224": 13, "id-rsassa-pkcs1-v1_5-with-sha3-256": 14,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blamejs/pki",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.29",
|
|
4
4
|
"description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "blamejs contributors",
|
|
@@ -84,6 +84,6 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"c8": "12.0.0",
|
|
86
86
|
"esbuild": "0.28.2",
|
|
87
|
-
"eslint": "10.
|
|
87
|
+
"eslint": "10.10.0"
|
|
88
88
|
}
|
|
89
89
|
}
|
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:3c9a8588-ff6f-477c-92fd-33c03ea2c98b",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-09-
|
|
8
|
+
"timestamp": "2026-09-12T05:32:15.338Z",
|
|
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.29",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "pki",
|
|
25
|
-
"version": "0.7.
|
|
25
|
+
"version": "0.7.29",
|
|
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.29",
|
|
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.29",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|