@blamejs/pki 0.8.15 → 0.8.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ 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.8.16 — 2026-09-24
8
+
9
+ A certification request is linted before it is issued, against the rows its certificate will be held to.
10
+
11
+ ### Added
12
+
13
+ - `pki.lint.csr(pem | der | parsed, opts?)` lints a PKCS#10 certification request and returns the `LintReport` shape the other lint verbs return. It never throws on the data path: bytes that are not a well-formed request produce a single `fatal` finding `lint/unparseable` carrying the strict parser's own code.
14
+ - The `rfc2986` profile covers what the request asks for: an empty subject that names no identity, an empty subject whose subjectAltName is not critical (RFC 5280 section 4.1.2.6), a request for an extension the issuer determines rather than takes from a request, a request asking for a CA certificate, a request signed under a broken digest, and a challengePassword traveling inside the request. The broken digests are named outright rather than read out of the algorithm name, because `shaWithRSAEncryption` is the original SHA, now SHA-0, and its name carries no digest to read.
15
+ - `opts.profile: "cabf-tls"` adds the CA/Browser Forum rows: a commonName no subjectAltName covers, a malformed requested dNSName, a request naming no subjectAltName, and a key below the TLS minimum. They run only when named, because a request carries no extKeyUsage and nothing in its bytes says it is for TLS. Each is the certificate profile's own row, applied to what the request asks for.
16
+ - A request carrying more than one extensionRequest attribute is reported, and each is linted as the request it states. Two parse where they sort in DER order, and a reader asking for an extension by name takes the first match, so a basicConstraints of cA FALSE in one attribute would otherwise hide a cA TRUE in the next and the answer would be decided by how the bytes happened to sort.
17
+ - A requested extension whose value does not decode under its own syntax is reported, by the RFC 5280 section 4.2 row the certificate profile already carries. It counted as a passing check before, because the shared decoder returns null for a value it cannot read and every row asking for an extension by name reads that null as absence.
18
+ - The weak-digest row reads an RSASSA-PSS request's digest from its parameters rather than its algorithm name. RFC 4055 section 3.1 makes the hashAlgorithm field default to SHA-1, so absent parameters and an empty parameter sequence both name SHA-1: the encoding that appears to say nothing names the weakest digest.
19
+ - `pki.lint.rules("rfc2986")` lists the new rows with their citations, and `pki.lint.profiles()` enumerates `rfc2986` alongside the existing names.
20
+ - `pki.lint.rules(profile, artifact)` takes an optional second argument, one of `"certificate"`, `"csr"`, `"crl"` or `"ocsp"`. `"cabf-tls"` names a set for both a certificate and a request and the two are not the same rows, so without it a reader asking about the request was given the certificate-only extKeyUsage and validity rows and none of the structural ones. Calls passing one argument are unchanged. Each id now appears once in the listing, including where two artifacts run the same rule.
21
+
22
+ ### Changed
23
+
24
+ - `md2WithRSAEncryption`, `md4WithRSAEncryption-pkcs1`, `md5WithRSAEncryption`, `sha1WithRSAEncryption`, `ecdsaWithSHA1` and `dsaWithSha1` resolve through `pki.oid`, so an artifact signed under one reads back with a name instead of a bare dotted string. The weak-digest row reads that name, so an algorithm the registry could not name passed it silently. Nothing signs or verifies from that registry: the signing and verifying paths carry their own tables and neither has a row for these, so naming one does not make it usable. A request or certificate carrying one still fails to verify.
25
+ - Every name in the OID registry resolves back to the OID it names, which is now checked. The registry is two-way and its directions did not agree about a repeated name: the first `name -> OID` registration was kept while `OID -> name` took the last, so adding a name a family already held would silently repoint every lookup of it and leave the original OID still answering with that name. X.501 and X.520 both standardize `clearance`, at 2.5.1.5.55 and 2.5.4.55, and that pair is recorded as the one intended duplicate. PKCS#1's MD4 signature is registered as `md4WithRSAEncryption-pkcs1` for the same reason: the plain name already belongs to the OIW arc's 1.3.14.3.2.4.
26
+
7
27
  ## v0.8.15 — 2026-09-24
8
28
 
9
29
  The host's own CA bundle becomes trust anchors, and says which set you got.
package/README.md CHANGED
@@ -290,7 +290,7 @@ comment blocks, is at [pkijs.com](https://pkijs.com).
290
290
  | `pki.sigstore` | Offline verifier for a Sigstore bundle, the artifact `npm publish --provenance` produces and the registry serves. `verifyBundle` composes five fail-closed legs against caller-pinned trust (Fulcio CA roots and Rekor log keys, never trusted from the bundle): the DSSE signature over its PAE preimage under the Fulcio leaf key, the ephemeral Fulcio certificate chain validated as of the Rekor log time, the RFC 9162 inclusion proof folded to a Rekor-signed tree root, the log entry bound to this exact signature, and the in-toto SLSA subject digest the caller confirms against the published artifact. It reuses the X.509 parser, the RFC 5280 path validator, and the Merkle verifier; the net-new codecs are the DSSE PAE byte-builder and a fail-closed JSON reader. `verified: true` says the artifact was signed and logged, not that a party you trust signed it — Fulcio issues to anyone who completes an OIDC flow, so who signed is decided only by `opts.identity`, and `identityChecked` reports which of its fields were compared. An identity policy naming no field, or a field name that is not one of the three, is refused rather than satisfied — either would accept every signer while reading as a policy in force. A sixth leg is opt-in: pinning the certificate-transparency logs in `opts.ctLogs` checks the receipt Fulcio embeds in the certificate it issues (RFC 6962 §3.2), verified over the certificate as it stood before the receipt was added and under the key of the log that issued it, so the verdict says the signing certificate was public when it was issued rather than handed out quietly. At least one receipt must verify against a pinned log, the verdict reports `sctChecked` and `validScts`, and an empty log set is refused rather than read as a policy that checks nothing. Both content arms are read: a DSSE-wrapped in-toto attestation, and a message signature over an artifact's own bytes, which `cosign sign-blob` produces. For that arm `opts.artifact` supplies the bytes, and they are held to the hash the Rekor `hashedrekord` entry records before the signature is checked over them; the `messageDigest` the bundle carries is covered by no signature, so it is compared against the computed digest and never used in its place. `contentType` names the arm and the verdict has one shape for both — `pae`, `parseBundle`, `verifyBundle` |
291
291
  | `pki.inspect` | Human-readable inspection, the pure-JS equivalent of `openssl x509/crl/req/cms -text`. `certificate(pem \| der \| parsed)` renders an OpenSSL-style report: version, serial, signature algorithm, issuer and subject distinguished names, validity, public-key details (curve or modulus size plus the raw point or modulus), every decoded extension with its critical flag, and the signature. `crl`, `csr`, and `cms` render the other formats the same way — a CRL like `openssl crl -text`, a CSR like `openssl req -text`, and a CMS message like `openssl cms -cmsout -print`, with a stable summary for a non-SignedData ContentInfo — and `any(input)` detects the format and routes to the right report. Built over the strict parsers and the two-way OID registry with one set of field renderers, it names extension and algorithm OIDs an OpenSSL build shows only as raw bytes. No OpenSSL dependency, and the format is stable and OpenSSL-familiar rather than pinned to one OpenSSL version. A certificate policy's user notice renders as text, both its explicit text and a notice reference with the notice numbers that identify it, rather than hex, and a malformed part falls back to a hex dump rather than throwing — `certificate`, `crl`, `csr`, `cms`, `any` |
292
292
  | `pki.webauthn` | WebAuthn and passkey verification, both halves: offline trust evaluation of a W3C WebAuthn (Level 3) registration, and signature verification of the assertion every login returns. `parseAttestationObject(bytes)` decodes the CBOR attestation object, authenticatorData, and COSE credential key over the strict `pki.cbor` codec; `parseAuthenticatorData(bytes)` reads the bare form an assertion carries through the same parser; `parseClientData(bytes, opts)` decodes the `clientDataJSON` no signature check looks inside, through the shared JSON guard since these are attacker-chosen bytes, returning the challenge decoded so a caller compares bytes rather than spellings, and checking the ceremony type, challenge, and origin when the relying party supplies what it issued. `verifyAssertion(input)` verifies an assertion signature over `authenticatorData \|\| SHA-256(clientDataJSON)` — raw bytes, no COSE_Sign1, an ES256 signature in ASN.1 DER — and applies the §7.2 step 21 counter rule when a stored `previousSignCount` is given, so a counter that fails to advance is refused as a cloned authenticator. `verify(attestationObject, clientDataHash, opts)` checks the attestation-statement signature and each format's structural bindings for packed, tpm, android-key, apple, fido-u2f, and none: the x5c leaf key, the apple nonce, the tpm `certInfo` Name and `extraData` over the `pubArea`, the android `KeyDescription`, and the fido-u2f `verificationData`. It binds the credential public key to each attestation, through the signed authenticatorData for packed and fido-u2f or a cert or `pubArea`-key equality check for android-key, apple, and tpm, and enforces each leaf's certificate requirements. The credential-key check covers the full WebAuthn COSE algorithm set — ES256/384/512, RS256/384/512, PS256/384/512, EdDSA (Ed25519), and the RFC 9864 fully-specified identifiers ESP256/384/512, Ed25519, and Ed448 — validating the public-key point on its curve, rejecting the compressed EC point form, and enforcing a minimally encoded DER ECDSA signature. The verdict field is `attestationVerified`, and `signatureVerified` for an assertion, rather than a bare `verified`, because a sound statement is a different claim from an acceptable ceremony: an attestation naming another origin's RP ID with user presence clear is perfectly sound and must not be registered. Pass `expectedRpId`, `requireUserPresence`, `requireUserVerification`, or `allowedAlgorithms` and those are checked, with `bindingChecked` reporting which ran, so a check that passed can be told from one that never happened. Pass `opts.clientDataJSON` instead of the digest and the client data is read here too: the ceremony type is checked unconditionally, since a login response replayed into a registration is what that rule stops, and the challenge, origin, and top-level origin are checked against what the relying party issued, with `clientData.checked` reporting which comparisons ran. A registration verdict also carries the `credentialId`, `credentialPublicKey`, and initial `signCount` a later login needs. A credential key declaring COSE algorithm `-65535` (RSASSA-PKCS1-v1_5 with SHA-1) is refused unless `allowedAlgorithms` names it, since every signature that credential ever makes would use SHA-1. Anchoring the trust path has two routes: `opts.metadata` resolves the roots the authenticator's own model registered, and `opts.rootCertificates` pins roots directly, which is what anchors the formats FIDO MDS does not cover, Apple's authenticators and the Google hardware-attestation roots among them. `metadata` governs when both are given, and `anchoredTo` names every route that anchored the path, joined with `+` when more than one did: `"metadata"`, `"rootCertificates"`, and `"safetyNetRoots"` for the android-safetynet chain, which anchors through the roots that format requires whether or not either other route was asked for. It is `null` only when nothing anchored the path. `verifyMetadataBlob(blob, opts)` reads a FIDO Metadata Service (MDS v3) BLOB, the signed catalogue of registered authenticator models, verifying its JWS and chaining its signer to an operator-supplied FIDO root before the payload is parsed, with sequence-number rollback and `nextUpdate` freshness checks. Passing the result as `opts.metadata` to `verify` resolves the authenticator's registered attestation roots from its identifier and requires the trust path to fully validate to one of them, refusing an unlisted or revoked model. `metadataAnchors(entry, opts)` applies the same status gate for a caller anchoring the path themselves: a model the catalogue has disqualified registers no anchors. Both of the catalogue's key spaces are covered: an aaguid, and the attestation-certificate key identifiers a U2F authenticator is listed under instead. No FIDO root is bundled, there is no trust-on-first-use, and retrieving the BLOB is out of scope. Fail-closed with typed `webauthn/*` errors — `parseAttestationObject`, `verify`, `verifyMetadataBlob`, `metadataFor`, `metadataAnchors` |
293
- | `pki.lint` | Certificate linting, the zlint or pkilint of JavaScript. `certificate(pem \| der \| parsed, opts)` walks a parsed certificate and emits graded advisory findings, each with a stable id, a severity (`fatal`, `error`, `warn`, `notice`), a source, a spec-clause citation, and a message, against the RFC 5280 profile, the post-quantum certificate profiles, and a representative CA/Browser Forum TLS BR subset: serial sign and size, validity ordering and the SC081v3 reducing validity schedule, keyCertSign coherence, extension criticality (basicConstraints, nameConstraints, policyConstraints and inhibitAnyPolicy must be critical, and keyUsage should be), nameConstraints CA-scope, unknown critical extensions, empty-subject SAN, SKI and AKI presence including the end-entity subjectKeyIdentifier, the six extensions a conforming CA must mark non-critical (reported by clause rather than as unrecognized) and the two it should (issuerAltName, cRLDistributionPoints), a policy mapping to or from anyPolicy, a unique identifier a conforming CA must not generate, a critical subjectAltName beside a non-empty subject, a critical extKeyUsage naming anyExtendedKeyUsage, a userNotice noticeRef, SAN required and CN-in-SAN, dNSName syntax, serverAuth EKU, weak keys, the post-quantum key-usage rules binding a certificate's keyUsage bits to its subject key type (ML-KEM under RFC 9935 §5, ML-DSA under RFC 9881 §5, and SLH-DSA under RFC 9909 §6 across both its pure and prehash identifiers) together with the ML-KEM encapsulation-key encoding and size, and the §4.2.1.4 certificate-policy user-notice rules (a VisibleString or BMPString explicitText, a notice past 200 characters, an empty notice, control characters, and a non-NFC UTF8String notice, each at the strength the clause states). Alone among these entries the data path never throws: hostile bytes return a `fatal` `lint/unparseable` finding carrying the strict parser's code, so a whole directory lints without a try/catch, and only config-time misuse throws a typed `LintError` — `certificate`, `crl` (the RFC 5280 §5 revocation-list profile: nextUpdate presence, update ordering, cRLNumber presence and its 20-octet ceiling, authorityKeyIdentifier presence, the criticality each profiled CRL and entry extension must carry, freshestCRL in a delta CRL, and unrecognized critical extensions), `ocsp` (the RFC 6960 response profile: an empty signature, each SingleResponse's update ordering and its relation to producedAt, an empty `certs` field, the extended revoked definition and the fixed shape of a revoked answer for a non-issued certificate, the list each extension belongs in, the criticality and value syntax of the CRL entry extensions a SingleResponse may carry, unrecognized critical extensions, the reasons unspecified and removeFromCRL, and two answers for one CertID; the RFC 5019 lightweight rows run on request), `rules`, `profiles` |
293
+ | `pki.lint` | Certificate linting, the zlint or pkilint of JavaScript. `certificate(pem \| der \| parsed, opts)` walks a parsed certificate and emits graded advisory findings, each with a stable id, a severity (`fatal`, `error`, `warn`, `notice`), a source, a spec-clause citation, and a message, against the RFC 5280 profile, the post-quantum certificate profiles, and a representative CA/Browser Forum TLS BR subset: serial sign and size, validity ordering and the SC081v3 reducing validity schedule, keyCertSign coherence, extension criticality (basicConstraints, nameConstraints, policyConstraints and inhibitAnyPolicy must be critical, and keyUsage should be), nameConstraints CA-scope, unknown critical extensions, empty-subject SAN, SKI and AKI presence including the end-entity subjectKeyIdentifier, the six extensions a conforming CA must mark non-critical (reported by clause rather than as unrecognized) and the two it should (issuerAltName, cRLDistributionPoints), a policy mapping to or from anyPolicy, a unique identifier a conforming CA must not generate, a critical subjectAltName beside a non-empty subject, a critical extKeyUsage naming anyExtendedKeyUsage, a userNotice noticeRef, SAN required and CN-in-SAN, dNSName syntax, serverAuth EKU, weak keys, the post-quantum key-usage rules binding a certificate's keyUsage bits to its subject key type (ML-KEM under RFC 9935 §5, ML-DSA under RFC 9881 §5, and SLH-DSA under RFC 9909 §6 across both its pure and prehash identifiers) together with the ML-KEM encapsulation-key encoding and size, and the §4.2.1.4 certificate-policy user-notice rules (a VisibleString or BMPString explicitText, a notice past 200 characters, an empty notice, control characters, and a non-NFC UTF8String notice, each at the strength the clause states). Alone among these entries the data path never throws: hostile bytes return a `fatal` `lint/unparseable` finding carrying the strict parser's code, so a whole directory lints without a try/catch, and only config-time misuse throws a typed `LintError` — `certificate`, `crl` (the RFC 5280 §5 revocation-list profile: nextUpdate presence, update ordering, cRLNumber presence and its 20-octet ceiling, authorityKeyIdentifier presence, the criticality each profiled CRL and entry extension must carry, freshestCRL in a delta CRL, and unrecognized critical extensions), `ocsp` (the RFC 6960 response profile: an empty signature, each SingleResponse's update ordering and its relation to producedAt, an empty `certs` field, the extended revoked definition and the fixed shape of a revoked answer for a non-issued certificate, the list each extension belongs in, the criticality and value syntax of the CRL entry extensions a SingleResponse may carry, unrecognized critical extensions, the reasons unspecified and removeFromCRL, and two answers for one CertID; the RFC 5019 lightweight rows run on request), `csr` (the artifact a CA reads before it issues: an empty subject naming no identity, an empty subject whose subjectAltName is not critical, a request for an extension the issuer determines, a request asking for a CA certificate, a broken signing digest, and a challengePassword traveling with the request; `opts.profile: "cabf-tls"` adds the certificate profile's own commonName-in-SAN, dNSName syntax, SAN-required and key-strength rows, applied to what the request asks for, and they run only when named because a request carries no extKeyUsage. It does not check the request's signature, which is a cryptographic operation `pki.csr.verify` owns), `rules`, `profiles` |
294
294
  | `pki.C` / `pki.constants` | Version-stable constants: the functional scale helpers `C.TIME.*` and `C.BYTES.*`, the codec `LIMITS`, and `version` |
295
295
  | `pki.errors` | The `PkiError` taxonomy — `defineClass` plus `ConstantsError`, `Asn1Error`, `OidError`, `PemError`, `CertificateError`, `CrlError`, `CsrError`, `Pkcs8Error`, `CmsError`, `OcspError`, `TspError`, `AttrCertError`, `CrmfError`, `Pkcs12Error`, `CmpError`, `PathError`, `CtError`, `JoseError`, `AcmeError`, `WebauthnError`, and `LintError`, each carrying a stable `code` in `domain/reason` form |
296
296
  | `pki` CLI | `pki version`, `pki oid <dotted\|name>`, `pki parse <cert>`, `pki inspect <cert>`, `pki lint <cert\|crl\|ocsp-response>`, `pki convert <file> --to der\|pem`, `pki verify <cert>... --anchor <cert>`, `pki sign <file> --cert <c> --key <k>` |
package/lib/lint.js CHANGED
@@ -34,6 +34,7 @@ var guard = require("./guard-all");
34
34
  var oid = require("./oid");
35
35
  var x509 = require("./schema-x509");
36
36
  var crlSchema = require("./schema-crl");
37
+ var csrSchema = require("./schema-csr");
37
38
  var ocspSchema = require("./schema-ocsp");
38
39
  var pkix = require("./schema-pkix");
39
40
  var schema = require("./schema-engine");
@@ -1774,6 +1775,163 @@ var RFC5019_OCSP_RULES = [
1774
1775
  var OCSP_PROFILES = Object.assign(Object.create(null), { "rfc6960": RFC6960_OCSP_RULES, "rfc5019": RFC5019_OCSP_RULES });
1775
1776
  var ALL_OCSP_RULES = RFC6960_OCSP_RULES.concat(RFC5019_OCSP_RULES);
1776
1777
 
1778
+ /** @internal The extensions an issuer determines, which a request may carry and a CA does not take
1779
+ * from one. subjectKeyIdentifier and authorityKeyIdentifier are computed from the keys, and the
1780
+ * three pointers name services the issuer operates. A request for any of them is not a fault in
1781
+ * the request, so these are reported at notice: the CA simply does not honor them. */
1782
+ var CA_DETERMINED_EXTENSIONS = [
1783
+ "authorityKeyIdentifier", "subjectKeyIdentifier", "authorityInfoAccess",
1784
+ "cRLDistributionPoints", "freshestCRL",
1785
+ ];
1786
+
1787
+ /** @internal The signature algorithms a request must not be signed under. A certification request
1788
+ * is signed by the requester's own key, and the signature is the only evidence the requester
1789
+ * holds it, so a collision-broken digest removes the one thing the structure proves. */
1790
+ var WEAK_CSR_SIG_DIGESTS = ["md2", "md4", "md5", "sha1"];
1791
+
1792
+ /** @internal Named outright, because reading the digest out of the algorithm's NAME misses the one
1793
+ * whose name does not carry it: `shaWithRSAEncryption` is the original SHA, now SHA-0, and it
1794
+ * spells neither "sha1" nor any other substring above. The set is resolved through the registry
1795
+ * rather than written as OIDs, so a name that stops resolving fails the round-trip gate in
1796
+ * oid.test.js rather than silently dropping out of this set. */
1797
+ var WEAK_CSR_SIG_OIDS = Object.create(null);
1798
+ ["shaWithRSAEncryption",
1799
+ "md2WithRSAEncryption", "md4WithRSAEncryption", "md4WithRSAEncryption-pkcs1",
1800
+ "md5WithRSAEncryption", "sha1WithRSAEncryption",
1801
+ "md4WithRSA", "md5WithRSA",
1802
+ "md2WithRSASignature", "md5WithRSASignature", "sha1WithRSASignature",
1803
+ "ecdsaWithSHA1", "dsaWithSha1",
1804
+ ].forEach(function (n) { var d = oid.byName(n); if (d) WEAK_CSR_SIG_OIDS[d] = n; });
1805
+
1806
+ /** @internal RSASSA-PSS carries its digest in the parameters rather than in the algorithm name, so
1807
+ * the name alone never reads as weak. RFC 4055 sec. 3.1 makes the hashAlgorithm `[0]` field
1808
+ * DEFAULT sha1, which means ABSENT parameters and an empty parameter SEQUENCE both name SHA-1:
1809
+ * the shape that looks like it says nothing is the one that says the weakest thing. */
1810
+ function _pssDigestName(sigAlg) {
1811
+ if (!sigAlg || sigAlg.oid !== oid.byName("rsassaPss")) return null;
1812
+ var params = sigAlg.parameters;
1813
+ if (params === null || params === undefined) return "sha1";
1814
+ var node;
1815
+ try { node = asn1.decode(params); }
1816
+ // allow:swallow-unverified parameters that do not decode are reported by the value-syntax path
1817
+ catch (_e) { return null; }
1818
+ if (!node || node.tagNumber !== asn1.TAGS.SEQUENCE || !node.children) return null;
1819
+ for (var i = 0; i < node.children.length; i++) {
1820
+ var c = node.children[i];
1821
+ if (c.tagClass !== "context" || c.tagNumber !== 0) continue;
1822
+ var inner = c.children && c.children[0];
1823
+ if (!inner || !inner.children || !inner.children[0]) return null;
1824
+ var dotted;
1825
+ try { dotted = asn1.read.oid(inner.children[0]); }
1826
+ // allow:swallow-unverified a hashAlgorithm that does not read is not a digest this names
1827
+ catch (_e2) { return null; }
1828
+ return oid.name(dotted) || dotted;
1829
+ }
1830
+ return "sha1";
1831
+ }
1832
+
1833
+ var RFC2986_CSR_RULES = [
1834
+ {
1835
+ id: "lint/rfc2986/subject-empty-no-identity", severity: "error", source: "rfc2986", citation: "RFC 5280 sec. 4.1.2.6",
1836
+ /** @internal Section 4.1.2.6 admits an empty subject only where the subjectAltName carries the
1837
+ * identity instead. A request with neither names nothing to certify, so there is no name for
1838
+ * the issuer to put in the certificate. */
1839
+ message: "a request with an empty subject must request a subjectAltName, or it names nothing to certify",
1840
+ check: function (csr, ctx) {
1841
+ if (_subjectIsNonEmpty(csr)) return null;
1842
+ var san = ctx.decode("subjectAltName");
1843
+ return (san && san.value && san.value.names && san.value.names.length) ? null : true;
1844
+ },
1845
+ },
1846
+ {
1847
+ id: "lint/rfc2986/san-not-critical-empty-subject", severity: "error", source: "rfc2986", citation: "RFC 5280 sec. 4.1.2.6 / 4.2.1.6",
1848
+ /** @internal "If the subject field contains an empty sequence, then the issuing CA MUST
1849
+ * include a subjectAltName extension that is marked as critical." A request whose only
1850
+ * identity is a non-critical SAN asks for a certificate the profile refuses. */
1851
+ message: "where the subject is empty the requested subjectAltName must be critical",
1852
+ check: function (csr, ctx) {
1853
+ if (_subjectIsNonEmpty(csr)) return null;
1854
+ var san = ctx.decode("subjectAltName");
1855
+ if (!san || !san.value || !san.value.names || !san.value.names.length) return null;
1856
+ return san.critical === true ? null : true;
1857
+ },
1858
+ },
1859
+ {
1860
+ id: "lint/rfc2986/ca-determined-extension-requested", severity: "notice", source: "rfc2986", citation: "RFC 5280 sec. 4.2.1.1 / 4.2.1.2 / 4.2.2",
1861
+ message: "the request asks for an extension the issuer determines, which a CA does not take from a request",
1862
+ check: function (csr, ctx) {
1863
+ var out = [];
1864
+ CA_DETERMINED_EXTENSIONS.forEach(function (name) {
1865
+ if (ctx.raw(name)) out.push({ context: { extension: name } });
1866
+ });
1867
+ return out.length ? out : null;
1868
+ },
1869
+ },
1870
+ {
1871
+ id: "lint/rfc2986/basic-constraints-ca-requested", severity: "warn", source: "rfc2986", citation: "RFC 5280 sec. 4.2.1.9",
1872
+ /** @internal A subscriber request asking for cA TRUE is the request that turns a subscriber
1873
+ * into an issuer if it is honored, so it is named rather than passed over. It is a warning
1874
+ * and not an error because a CA legitimately issues intermediates from a request. */
1875
+ message: "the request asks for a CA certificate (basicConstraints cA TRUE)",
1876
+ check: function (csr, ctx) {
1877
+ var bc = ctx.decode("basicConstraints");
1878
+ return (bc && bc.value && bc.value.cA === true) ? { context: { pathLenConstraint: bc.value.pathLenConstraint } } : null;
1879
+ },
1880
+ },
1881
+ {
1882
+ id: "lint/rfc2986/weak-signature-algorithm", severity: "error", source: "rfc2986", citation: "RFC 2986 sec. 4.2",
1883
+ message: "the request is signed under a digest no longer fit to carry a proof of possession",
1884
+ check: function (csr) {
1885
+ var alg = csr.signatureAlgorithm;
1886
+ if (alg && WEAK_CSR_SIG_OIDS[alg.oid]) {
1887
+ return { context: { signatureAlgorithm: WEAK_CSR_SIG_OIDS[alg.oid], from: "algorithm" } };
1888
+ }
1889
+ var pss = _pssDigestName(alg);
1890
+ var named = pss !== null ? pss : (alg && alg.name);
1891
+ if (typeof named !== "string") return null;
1892
+ var lower = named.toLowerCase();
1893
+ for (var i = 0; i < WEAK_CSR_SIG_DIGESTS.length; i++) {
1894
+ if (lower.indexOf(WEAK_CSR_SIG_DIGESTS[i]) !== -1) {
1895
+ return { context: { signatureAlgorithm: (alg && alg.name) || (alg && alg.oid),
1896
+ digest: WEAK_CSR_SIG_DIGESTS[i], from: pss !== null ? "parameters" : "algorithm" } };
1897
+ }
1898
+ }
1899
+ return null;
1900
+ },
1901
+ },
1902
+ {
1903
+ id: "lint/rfc2986/extension-request-ambiguous", severity: "error", source: "rfc2986", citation: "RFC 2985 sec. 5.4.2 / X.501 sec. 8.2",
1904
+ /** @internal An attribute type appears once in a SET OF Attributes, and extensionRequest is
1905
+ * SINGLE VALUE besides. Two of them parse when they are in DER order, and which one a reader
1906
+ * takes then depends on how the bytes happened to sort, so one request reads two ways. Every
1907
+ * one of them is linted below, and this row says the request did not ask once. */
1908
+ message: "the request carries more than one extensionRequest attribute, so what it asks for depends on which is read",
1909
+ check: function (csr) {
1910
+ var n = _csrAttributesOf(csr, "extensionRequest").length;
1911
+ return n > 1 ? { context: { count: n } } : null;
1912
+ },
1913
+ },
1914
+ {
1915
+ id: "lint/rfc2986/challenge-password-present", severity: "notice", source: "rfc2986", citation: "RFC 2985 sec. 5.4.1",
1916
+ /** @internal The attribute travels inside the request, so wherever the request is stored or
1917
+ * logged the password is too. Reported so an operator knows it is in the artifact, not
1918
+ * because the structure is wrong. */
1919
+ message: "the request carries a challengePassword, which travels and is stored with it",
1920
+ check: function (csr) { return _csrHasAttribute(csr, "challengePassword") ? true : null; },
1921
+ },
1922
+ ];
1923
+
1924
+ /** @internal The certificate rows that read only the subject, the public key and the requested
1925
+ * subjectAltName, which a request carries too. They are REUSED rather than restated so the
1926
+ * pre-issuance answer cannot drift from the post-issuance one: the row, its severity and its
1927
+ * citation are the certificate profile's own. */
1928
+ var CABF_TLS_CSR_RULE_IDS = [
1929
+ "lint/cabf-tls/san-missing",
1930
+ "lint/cabf-tls/cn-not-in-san",
1931
+ "lint/cabf-tls/dnsname-bad-syntax",
1932
+ "lint/cabf-tls/weak-key",
1933
+ ];
1934
+
1777
1935
  var PROFILES = Object.assign(Object.create(null), {
1778
1936
  "rfc5280": RFC5280_RULES,
1779
1937
  "rfc9881": RFC9881_RULES,
@@ -1783,6 +1941,133 @@ var PROFILES = Object.assign(Object.create(null), {
1783
1941
  });
1784
1942
  var ALL_RULES = RFC5280_RULES.concat(RFC9881_RULES).concat(RFC9909_RULES).concat(RFC9935_RULES).concat(CABF_TLS_RULES);
1785
1943
 
1944
+ var CABF_TLS_CSR_RULES = CABF_TLS_RULES.filter(function (r) {
1945
+ return CABF_TLS_CSR_RULE_IDS.indexOf(r.id) !== -1;
1946
+ });
1947
+ /** @internal RFC 5280 sec. 4.2 fixes each extension's syntax wherever it is carried, and a
1948
+ * requested extension whose value does not decode is the same fault in a request as in a
1949
+ * certificate. The certificate's own row reads `extensions` and the request view supplies it, so
1950
+ * the row is reused rather than restated. Without it a malformed requested value counted as a
1951
+ * passing check, because the shared decoder returns null and every row that asks by name reads
1952
+ * that null as absence. */
1953
+ var RFC5280_CSR_RULES = RFC5280_RULES.filter(function (r) {
1954
+ return r.id === "lint/rfc5280/extension-undecodable";
1955
+ });
1956
+ var CSR_STRUCTURAL_RULES = RFC2986_CSR_RULES.concat(RFC5280_CSR_RULES);
1957
+ var CSR_PROFILES = Object.assign(Object.create(null), {
1958
+ "rfc2986": CSR_STRUCTURAL_RULES,
1959
+ "cabf-tls": CSR_STRUCTURAL_RULES.concat(CABF_TLS_CSR_RULES),
1960
+ });
1961
+ var ALL_CSR_RULES = CSR_STRUCTURAL_RULES;
1962
+
1963
+ function _subjectIsNonEmpty(csr) {
1964
+ var rdns = csr.subject && csr.subject.rdns;
1965
+ return !!(Array.isArray(rdns) && rdns.length);
1966
+ }
1967
+
1968
+ function _csrAttributesOf(csr, name) {
1969
+ var dotted = oid.byName(name);
1970
+ var list = csr.attributes || [];
1971
+ var out = [];
1972
+ for (var i = 0; i < list.length; i++) { if (list[i].type === dotted) out.push(list[i]); }
1973
+ return out;
1974
+ }
1975
+ function _csrHasAttribute(csr, name) { return _csrAttributesOf(csr, name).length > 0; }
1976
+
1977
+ /** @internal A request read the way the certificate rows read a certificate: the subject and the
1978
+ * public key are the request's own, and `extensions` is what the extensionRequest attribute asked
1979
+ * for. Shaped this way so `_findRaw`, `_decodeOrNull` and the reused CABF rows run unchanged
1980
+ * against a request rather than each restating how to reach a requested extension. */
1981
+ function _csrViewWith(csr, exts) {
1982
+ var view = Object.create(null);
1983
+ view.subject = csr.subject;
1984
+ view.subjectPublicKeyInfo = csr.subjectPublicKeyInfo;
1985
+ view.signatureAlgorithm = csr.signatureAlgorithm;
1986
+ view.attributes = csr.attributes;
1987
+ view.extensions = exts;
1988
+ return view;
1989
+ }
1990
+
1991
+ /** @internal One view per extensionRequest attribute, rather than one view over all of them
1992
+ * flattened. A rule that asks for an extension BY NAME reads the first match, so flattening lets
1993
+ * a basicConstraints of cA FALSE in one attribute hide a cA TRUE in the next: the value that
1994
+ * decides the answer would be the one that happened to sort first. Each attribute is linted as
1995
+ * the request it states, and the findings are merged. A request carrying one attribute, which is
1996
+ * every conforming one, produces exactly one view and the same answer as before. */
1997
+ function _csrViews(csr) {
1998
+ var attrs = _csrAttributesOf(csr, "extensionRequest");
1999
+ if (!attrs.length) return [_csrViewWith(csr, [])];
2000
+ return attrs.map(function (attr) {
2001
+ return _csrViewWith(csr, Array.isArray(attr.extensions) ? attr.extensions : []);
2002
+ });
2003
+ }
2004
+
2005
+ /** @internal The same rule firing on two views of one request is one finding, since the rows that
2006
+ * do not read an extension see the identical request each time. */
2007
+ function _mergeCsrReports(reports) {
2008
+ var findings = [], ran = [], seen = Object.create(null), ranSeen = Object.create(null);
2009
+ reports.forEach(function (r) {
2010
+ r.findings.forEach(function (f) {
2011
+ var key = f.id + "\u0000" + JSON.stringify(f.context === undefined ? null : f.context);
2012
+ if (seen[key]) return;
2013
+ seen[key] = true;
2014
+ findings.push(f);
2015
+ });
2016
+ r.ran.forEach(function (id) { if (!ranSeen[id]) { ranSeen[id] = true; ran.push(id); } });
2017
+ });
2018
+ var counts = Object.assign(Object.create(null), { fatal: 0, error: 0, warn: 0, notice: 0, pass: 0, na: 0, ne: 0 });
2019
+ var failed = Object.create(null), failedCount = 0;
2020
+ findings.forEach(function (f) {
2021
+ counts[f.severity] = (counts[f.severity] || 0) + 1;
2022
+ if (!failed[f.id]) { failed[f.id] = true; failedCount += 1; }
2023
+ });
2024
+ /** @internal A rule that reports twice is still ONE rule that did not pass, which is what
2025
+ * `_runLints` counts, so the distinct failing ids come off the executed ones. Subtracting the
2026
+ * finding count instead understates `pass` the moment any rule reports more than once. */
2027
+ counts.pass = ran.length - failedCount > 0 ? ran.length - failedCount : 0;
2028
+ return { findings: findings, counts: counts, ran: ran };
2029
+ }
2030
+
2031
+ /** @internal A request carries no extKeyUsage, so nothing in its bytes says it is for TLS. The
2032
+ * caller names that profile or the TLS rows do not run, which is why `isTlsServerCert` here is
2033
+ * the caller's statement rather than something read off the artifact. */
2034
+ function _makeCsrCtx(view, profile) {
2035
+ var explicitTls = profile === "cabf-tls";
2036
+ return {
2037
+ profile: profile,
2038
+ explicitTlsProfile: explicitTls,
2039
+ isTlsServerCert: explicitTls,
2040
+ decode: function (name) { return _decodeOrNull(view, name); },
2041
+ raw: function (name) { return _findRaw(view, name); },
2042
+ };
2043
+ }
2044
+
2045
+ /** @internal The kind-checked door the other lint verbs use, rather than a property test of our
2046
+ * own: a parsed certificate carries a subjectPublicKeyInfo too, so a shape test admits one as a
2047
+ * request and then reads its extensions from an extensionRequest attribute it does not have,
2048
+ * reporting on a request that was never made. */
2049
+ function _derivedCsr(o) {
2050
+ if (!o || typeof o !== "object" || guard.bytes.isByteSource(o)) return null;
2051
+ // allow:swallow-unverified an object the guard refuses is not a parsed request, and the byte paths below answer for it
2052
+ try { return guard.parsed.acceptDerived(o, "csr", csrSchema.parse, _cfg, "lint/bad-input", "the certification request"); }
2053
+ catch (_e) { return null; }
2054
+ }
2055
+
2056
+ function _ingestCsr(input) {
2057
+ var derived = _derivedCsr(input);
2058
+ if (derived) return { csr: derived };
2059
+ var der;
2060
+ if (Buffer.isBuffer(input)) der = input;
2061
+ else if (typeof input === "string") {
2062
+ try { der = csrSchema.pemDecode(input); }
2063
+ catch (e) { return { fatal: { id: "lint/unparseable", severity: "fatal", source: "engine", citation: "pki.lint", message: "input is not a decodable PEM/DER certification request", context: { code: e.code } } }; }
2064
+ } else {
2065
+ throw _cfg("lint/bad-input", "pki.lint.csr input must be a parsed certification request, a DER Buffer, or a PEM string");
2066
+ }
2067
+ try { return { csr: csrSchema.parse(der) }; }
2068
+ catch (e) { return { fatal: { id: "lint/unparseable", severity: "fatal", source: "engine", citation: "RFC 2986", message: "input is not a well-formed PKCS#10 certification request", context: { code: e.code } } }; }
2069
+ }
2070
+
1786
2071
  function _selectRules(profile) {
1787
2072
  if (profile == null || profile === "all" || profile === "default") return ALL_RULES;
1788
2073
  if (!PROFILES[profile]) {
@@ -1929,6 +2214,87 @@ function _ingestCrl(input) {
1929
2214
  * report.worst; // -> "error", for the missing AKI
1930
2215
  * report.findings.map(function (f) { return f.id; }); // -> ["lint/rfc5280-crl/aki-missing"]
1931
2216
  */
2217
+ /**
2218
+ * @primitive pki.lint.csr
2219
+ * @signature pki.lint.csr(pem | der | parsed, opts?) -> LintReport
2220
+ * @since 0.8.16
2221
+ * @status stable
2222
+ * @spec RFC 2986, RFC 2985 sec. 5.4, RFC 5280 sec. 4.1.2.6, CA/Browser Forum TLS BR
2223
+ * @related pki.lint.certificate, pki.csr.verify, pki.schema.csr.parse, pki.csr.sign
2224
+ *
2225
+ * Lint a PKCS#10 certification request, which is the artifact a CA reads before it issues. `input`
2226
+ * is a PEM string, a DER `Buffer`, or an already-parsed `pki.schema.csr` object. It returns the
2227
+ * same `LintReport` shape `pki.lint.certificate` returns, and it never throws on the data path:
2228
+ * bytes that are not a well-formed request produce a single `fatal` finding `lint/unparseable`
2229
+ * carrying the strict parser's own code.
2230
+ *
2231
+ * The rows cover what the request asks for: an empty subject and whether a subjectAltName carries
2232
+ * the identity in its place, the extensions an issuer determines rather than takes from a request,
2233
+ * a request asking for a CA certificate, the digest the request is signed under, and a
2234
+ * challengePassword traveling inside it.
2235
+ *
2236
+ * This does not check the request's signature. That signature is the requester's proof that it
2237
+ * holds the private key, verifying it is a cryptographic operation rather than a profile question,
2238
+ * and `pki.csr.verify` is the verb for it. A CA runs both.
2239
+ *
2240
+ * The CA/Browser Forum rows run only under `opts.profile: "cabf-tls"`. A request carries no
2241
+ * extKeyUsage, so nothing in its bytes says it is for TLS, and the caller states that. Those rows
2242
+ * are the certificate profile's own, applied to what the request asks for, so the answer before
2243
+ * issuance is the answer after it.
2244
+ *
2245
+ * Five shapes never appear here because the strict parser refuses them first and a rule for them
2246
+ * could not fire. A version other than 0 (RFC 2986 sec. 4.1), a challengePassword or
2247
+ * extensionRequest attribute carrying more than one value, an extensionRequest carrying no
2248
+ * extensions (RFC 2985 sec. 5.4), the same extension OID twice inside one, and attributes out of
2249
+ * DER order each arrive as `lint/unparseable` carrying the parser's own code. A SECOND
2250
+ * extensionRequest attribute does parse, where the two sort in DER order, and is reported by
2251
+ * `lint/rfc2986/extension-request-ambiguous`; every one of them is read, so nothing a later
2252
+ * attribute asks for escapes the rows below.
2253
+ *
2254
+ * @opts profile `"rfc2986"` for the structural rows alone, or `"cabf-tls"` to add the TLS rows
2255
+ * (default runs the structural rows). A certificate, CRL or OCSP profile name is
2256
+ * refused rather than run against a request.
2257
+ * @opts severity Suppress findings below this floor (default `"notice"`). `counts` and `worst`
2258
+ * always reflect the complete, unfiltered result.
2259
+ * @example
2260
+ * var pair = await pki.key.generate("Ed25519");
2261
+ * var der = await pki.csr.sign({ subject: [{ commonName: "example.com" }],
2262
+ * subjectPublicKey: await pki.key.export(pair.publicKey) },
2263
+ * { key: await pki.key.export(pair.privateKey) });
2264
+ * var report = pki.lint.csr(der, { profile: "cabf-tls" });
2265
+ * report.findings.map(function (f) { return f.id; }); // -> ["lint/cabf-tls/san-missing"]
2266
+ */
2267
+ function csr(input, opts) {
2268
+ opts = guard.identifier.optionsObject(opts, _cfg, "lint/bad-input", "pki.lint options");
2269
+ guard.identifier.assertKnownKeys(opts, _CRL_OPTS, _cfg, "lint/bad-input",
2270
+ "pki.lint.csr has an unknown option: ");
2271
+ if (opts.severity != null && VALID_SEVERITY.indexOf(opts.severity) === -1) {
2272
+ throw _cfg("lint/bad-severity", "unknown severity threshold \"" + opts.severity + "\" (known: " + VALID_SEVERITY.join(", ") + ")");
2273
+ }
2274
+ var profile = opts.profile;
2275
+ var rules_;
2276
+ if (profile == null || profile === "all" || profile === "default") rules_ = ALL_CSR_RULES;
2277
+ else if (CSR_PROFILES[profile]) rules_ = CSR_PROFILES[profile];
2278
+ else if (CRL_PROFILES[profile]) throw _cfg("lint/unknown-profile", "\"" + profile + "\" is a CRL profile; lint a CRL with pki.lint.crl");
2279
+ else if (OCSP_PROFILES[profile]) throw _cfg("lint/unknown-profile", "\"" + profile + "\" is an OCSP profile; lint a response with pki.lint.ocsp");
2280
+ else if (PROFILES[profile]) throw _cfg("lint/unknown-profile", "\"" + profile + "\" is a certificate profile; lint a certificate with pki.lint.certificate");
2281
+ else throw _cfg("lint/unknown-profile", "unknown certification-request lint profile \"" + profile + "\" (known: " + Object.keys(CSR_PROFILES).join(", ") + ")");
2282
+
2283
+ var ingested = _ingestCsr(input);
2284
+ var report;
2285
+ if (ingested.fatal) {
2286
+ report = { findings: [ingested.fatal], ran: [],
2287
+ counts: Object.assign(Object.create(null), { fatal: 1, error: 0, warn: 0, notice: 0, pass: 0, na: 0, ne: 0 }) };
2288
+ } else {
2289
+ report = _mergeCsrReports(_csrViews(ingested.csr).map(function (view) {
2290
+ return _runLints(rules_, view, _makeCsrCtx(view, profile));
2291
+ }));
2292
+ }
2293
+ report.worst = _worst(report.findings);
2294
+ report.findings = _applyThreshold(report, opts.severity);
2295
+ return report;
2296
+ }
2297
+
1932
2298
  function crl(input, opts) {
1933
2299
  opts = guard.identifier.optionsObject(opts, _cfg, "lint/bad-input", "pki.lint options");
1934
2300
  guard.identifier.assertKnownKeys(opts, _CRL_OPTS, _cfg, "lint/bad-input",
@@ -2074,23 +2440,67 @@ function ocsp(input, opts) {
2074
2440
 
2075
2441
  /**
2076
2442
  * @primitive pki.lint.rules
2077
- * @signature pki.lint.rules(profile?) -> [{id, severity, source, citation}]
2443
+ * @signature pki.lint.rules(profile?, artifact?) -> [{id, severity, source, citation}]
2078
2444
  * @since 0.2.10
2079
2445
  * @status stable
2080
2446
  * @spec RFC 5280, CA/Browser Forum TLS BR
2081
2447
  *
2082
2448
  * Enumerate the rule registry (all rules, or one profile's). Each entry exposes its
2083
2449
  * stable `id`, `severity`, `source`, and spec-clause `citation` for documentation and
2084
- * corpus tooling.
2450
+ * corpus tooling. Each id appears once, including where two artifacts run the same rule.
2451
+ *
2452
+ * `artifact` says which verb's reading of a profile name to return, and is needed because
2453
+ * `"cabf-tls"` names a set for both `pki.lint.certificate` and `pki.lint.csr` and the two are not
2454
+ * the same rows: a request has no extKeyUsage and no validity period, and carries structural rows
2455
+ * a certificate does not. It is `"certificate"`, `"csr"`, `"crl"` or `"ocsp"`, and defaults to the
2456
+ * artifact that first claims the name, which is the certificate for `"cabf-tls"`.
2457
+ *
2085
2458
  * @example
2086
- * pki.lint.rules("rfc5280").length; // -> a positive count
2459
+ * pki.lint.rules("rfc5280").length; // -> a positive count
2460
+ * pki.lint.rules("cabf-tls", "csr").length; // -> the rows pki.lint.csr runs under it
2087
2461
  */
2088
- function rules(profile) {
2089
- var set = profile == null
2090
- ? ALL_RULES.concat(ALL_CRL_RULES).concat(ALL_OCSP_RULES)
2091
- : (PROFILES[profile] || CRL_PROFILES[profile] || OCSP_PROFILES[profile]
2092
- || (function () { throw _cfg("lint/unknown-profile", "unknown lint profile \"" + profile + "\""); })());
2093
- return set.map(function (r) { return { id: r.id, severity: r.severity, source: r.source, citation: r.citation }; });
2462
+ /** @internal Prototype-less, because `artifact` is the caller's string and a computed lookup on a
2463
+ * literal would answer for "constructor" and the rest of Object.prototype. */
2464
+ var BY_ARTIFACT = Object.assign(Object.create(null), {
2465
+ certificate: PROFILES, csr: CSR_PROFILES, crl: CRL_PROFILES, ocsp: OCSP_PROFILES,
2466
+ });
2467
+
2468
+ function rules(profile, artifact) {
2469
+ if (artifact != null && !Object.prototype.hasOwnProperty.call(BY_ARTIFACT, artifact)) {
2470
+ throw _cfg("lint/bad-input", "unknown lint artifact \"" + artifact +
2471
+ "\" (known: " + Object.keys(BY_ARTIFACT).join(", ") + ")");
2472
+ }
2473
+ var set;
2474
+ if (profile == null && artifact != null) {
2475
+ /** @internal An artifact without a profile asks what that VERB can run, which is the union of
2476
+ * its own profiles. Returning the whole registry would answer with a certificate's validity
2477
+ * rows and the CRL and OCSP sets, none of which a request or a response is ever held to. */
2478
+ set = [];
2479
+ Object.keys(BY_ARTIFACT[artifact]).forEach(function (name) {
2480
+ BY_ARTIFACT[artifact][name].forEach(function (r) { set.push(r); });
2481
+ });
2482
+ } else if (profile == null) {
2483
+ set = ALL_RULES.concat(ALL_CRL_RULES).concat(ALL_OCSP_RULES).concat(ALL_CSR_RULES);
2484
+ } else if (artifact != null) {
2485
+ set = BY_ARTIFACT[artifact][profile];
2486
+ if (!set) {
2487
+ throw _cfg("lint/unknown-profile", "\"" + profile + "\" is not a " + artifact +
2488
+ " lint profile (known: " + Object.keys(BY_ARTIFACT[artifact]).join(", ") + ")");
2489
+ }
2490
+ } else {
2491
+ set = PROFILES[profile] || CRL_PROFILES[profile] || OCSP_PROFILES[profile] || CSR_PROFILES[profile];
2492
+ if (!set) throw _cfg("lint/unknown-profile", "unknown lint profile \"" + profile + "\"");
2493
+ }
2494
+ /** @internal One row per id: a rule reused across artifacts, like the RFC 5280 sec. 4.2
2495
+ * extension-syntax row a request and a certificate both run, is one rule with one id, and
2496
+ * tooling that counts or registers from this list would otherwise process it twice. */
2497
+ var seen = Object.create(null), out = [];
2498
+ set.forEach(function (r) {
2499
+ if (seen[r.id]) return;
2500
+ seen[r.id] = true;
2501
+ out.push({ id: r.id, severity: r.severity, source: r.source, citation: r.citation });
2502
+ });
2503
+ return out;
2094
2504
  }
2095
2505
 
2096
2506
  /**
@@ -2104,10 +2514,18 @@ function rules(profile) {
2104
2514
  * @example
2105
2515
  * pki.lint.profiles(); // -> ["rfc5280", "rfc9881", "rfc9909", "rfc9935", "cabf-tls", "rfc5280-crl", "rfc6960", "rfc5019"]
2106
2516
  */
2107
- function profiles() { return Object.keys(PROFILES).concat(Object.keys(CRL_PROFILES)).concat(Object.keys(OCSP_PROFILES)); }
2517
+ /** @internal `cabf-tls` names the certificate profile in this list and is not repeated for the
2518
+ * request form: `pki.lint.csr` takes the same name and runs those rows against what a request
2519
+ * asks for, so one name means one set of requirements whichever artifact carries it. */
2520
+ function profiles() {
2521
+ var out = Object.keys(PROFILES).concat(Object.keys(CRL_PROFILES)).concat(Object.keys(OCSP_PROFILES));
2522
+ Object.keys(CSR_PROFILES).forEach(function (name) { if (out.indexOf(name) === -1) out.push(name); });
2523
+ return out;
2524
+ }
2108
2525
 
2109
2526
  module.exports = {
2110
2527
  certificate: certificate,
2528
+ csr: csr,
2111
2529
  crl: crl,
2112
2530
  ocsp: ocsp,
2113
2531
  rules: rules,
package/lib/oid.js CHANGED
@@ -165,8 +165,19 @@ var FAMILIES = Object.assign(Object.create(null), {
165
165
  buildConfigURI: 18, buildConfigDigest: 19, buildTrigger: 20,
166
166
  runInvocationURI: 21, sourceRepositoryVisibilityAtSigning: 22 } },
167
167
 
168
+ /** @internal md5WithRSAEncryption and sha1WithRSAEncryption are registered so the toolkit can
169
+ * NAME them, not so it can use them. Nothing signs or verifies from this registry: the signing
170
+ * and verifying paths carry their own name-keyed tables, and neither has a row for these. An
171
+ * unregistered OID reads back as an undefined name, which left a linter unable to say what a
172
+ * request from another implementation was signed under. */
168
173
  rsa: { base: [1, 2, 840, 113549, 1, 1], of: {
169
- rsaEncryption: 1, rsaesOaep: 7, mgf1: 8, pSpecified: 9, rsassaPss: 10,
174
+ /** @internal PKCS#1's MD4 signature carries the arc-qualified name because the OIW arc already
175
+ * holds the plain `md4WithRSAEncryption` for 1.3.14.3.2.4. The registry is two-way and a name
176
+ * registered twice repoints every lookup of it, so two standards using one name for two OIDs
177
+ * are told apart here rather than silently sharing an entry. */
178
+ rsaEncryption: 1, md2WithRSAEncryption: 2, "md4WithRSAEncryption-pkcs1": 3,
179
+ md5WithRSAEncryption: 4, sha1WithRSAEncryption: 5,
180
+ rsaesOaep: 7, mgf1: 8, pSpecified: 9, rsassaPss: 10,
170
181
  sha256WithRSAEncryption: 11,
171
182
  sha384WithRSAEncryption: 12, sha512WithRSAEncryption: 13 } },
172
183
 
@@ -271,8 +282,14 @@ var FAMILIES = Object.assign(Object.create(null), {
271
282
 
272
283
  ansiX962: { base: [1, 2, 840, 10045], of: {
273
284
  ecPublicKey: [2, 1], prime192v1: [3, 1, 1], prime256v1: [3, 1, 7],
285
+ ecdsaWithSHA1: [4, 1],
274
286
  ecdsaWithSHA256: [4, 3, 2], ecdsaWithSHA384: [4, 3, 3], ecdsaWithSHA512: [4, 3, 4] } },
275
287
 
288
+ /** @internal X9.57 DSA, registered for naming alone. The toolkit neither signs nor verifies DSA,
289
+ * and dsaWithSha1 is here so a request or certificate carrying it reads back with a name rather
290
+ * than a bare dotted string, which is what a linter needs to say what it refused. */
291
+ x957: { base: [1, 2, 840, 10040, 4], of: { dsa: 1, dsaWithSha1: 3 } },
292
+
276
293
  secg: { base: [1, 3, 132, 0], of: {
277
294
  sect163k1: 1, sect163r1: 2, secp256k1: 10, sect163r2: 15, sect283k1: 16, sect283r1: 17,
278
295
  sect233k1: 26, sect233r1: 27, secp192k1: 31, secp224k1: 32, secp224r1: 33,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/pki",
3
- "version": "0.8.15",
3
+ "version": "0.8.16",
4
4
  "description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
package/sbom.cdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.5",
5
- "serialNumber": "urn:uuid:fd715296-3209-4fc3-85ee-b6af7fbfdd1c",
5
+ "serialNumber": "urn:uuid:770a6573-9a63-4951-bf37-d9999705b708",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-09-24T03:48:38.286Z",
8
+ "timestamp": "2026-09-24T05:26:27.977Z",
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.8.15",
22
+ "bom-ref": "@blamejs/pki@0.8.16",
23
23
  "type": "application",
24
24
  "name": "pki",
25
- "version": "0.8.15",
25
+ "version": "0.8.16",
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.8.15",
29
+ "purl": "pkg:npm/%40blamejs/pki@0.8.16",
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.8.15",
57
+ "ref": "@blamejs/pki@0.8.16",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]