@blamejs/pki 0.8.16 → 0.8.17

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,25 @@ 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.17 — 2026-09-24
8
+
9
+ The CA/Browser Forum subscriber certificate profile is linted against its own tables, not a subset of them.
10
+
11
+ ### Added
12
+
13
+ - The extension presence and criticality table (section 7.1.2.7.6): `authorityInformationAccess` and `certificatePolicies` are required, `nameConstraints` is forbidden, `authorityInformationAccess` must not be critical, and a `subjectKeyIdentifier` is reported at notice as NOT RECOMMENDED. That last one is the opposite of what RFC 5280 asks of an end-entity certificate, and both ship, each under the profile that states it.
14
+ - The authorityInformationAccess table (section 7.1.2.7.7): an accessMethod outside `id-ad-ocsp` and `id-ad-caIssuers` is reported, as is an accessLocation that is not a `uniformResourceIdentifier`.
15
+ - basicConstraints (section 7.1.2.7.8): `cA` must be FALSE and `pathLenConstraint` must be absent.
16
+ - certificatePolicies (section 7.1.2.7.9): `anyPolicy` is forbidden, exactly one reserved policy identifier must be asserted, counted across all four the profile defines, which are the domain-, organization- and individual-validated identifiers and the Extended Validation one (naming none and naming two are the same fault, and the finding says which), and a policy qualifier other than `id-qt-cps` is forbidden, which includes the userNotice RFC 5280 otherwise allows.
17
+ - The extKeyUsage table (section 7.1.2.7.10): `id-kp-codeSigning`, `id-kp-emailProtection`, `id-kp-timeStamping`, `id-kp-OCSPSigning`, `anyExtendedKeyUsage` and the precertificate signing purpose are each forbidden.
18
+ - The two Key Usage tables (section 7.1.2.7.11), which differ by key type: a bit the table marks unpermitted for the certificate's own key is reported, so `keyEncipherment` is accepted on an RSA certificate and reported on an ECC one. An ECC certificate must assert `digitalSignature`, and an RSA certificate must set at least one of the bits its table permits. The section gives a table for an RSA key and a table for an ECC key and none for anything else, so a certificate on another key, a post-quantum one among them, is held to neither rather than to the RSA one by default.
19
+ - The subjectAltName table (section 7.1.2.7.12): an entry of a type outside `dNSName` and `iPAddress` is reported, a `dNSName` carrying the root zone's zero-length trailing label is reported, and the extension must be critical where the subject is an empty sequence and non-critical otherwise, which one rule measures in both directions.
20
+
21
+ ### Changed
22
+
23
+ - `pki.lint.rules("cabf-tls", "certificate")` returns twenty-five rules where it returned six.
24
+ - Selecting `opts.profile: "cabf-tls"` is documented as what it is: an assertion that the input is a TLS subscriber certificate, not a question asked of it. The section 7.1.2.7 rows then apply whatever the certificate says it is, so naming the profile for a CA certificate reports that CA against subscriber requirements. Left unnamed, those rows reach a certificate only where it asserts id-kp-serverAuth and is not a CA. The CA profiles of section 7.1.2.10 are a separate set this does not yet carry.
25
+
7
26
  ## v0.8.16 — 2026-09-24
8
27
 
9
28
  A certification request is linted before it is issued, against the rows its certificate will be held to.
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), `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` |
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 CA/Browser Forum subscriber certificate profile of §7.1.2.7 (the extension presence and criticality table, the authorityInformationAccess accessMethod and accessLocation tables, basicConstraints cA and pathLenConstraint, certificatePolicies against anyPolicy and the exactly-one reserved identifier rule and the permitted-qualifier table, the forbidden extended key purposes, the two Key Usage tables that differ by key type, and the subjectAltName GeneralName table with its criticality rule in both directions), 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
@@ -242,6 +242,7 @@ function _ecCurveName(spki) {
242
242
 
243
243
  var OID_UNOTICE = oid.byName("unotice");
244
244
  var OID_ANY_POLICY = oid.byName("anyPolicy");
245
+ var OID_CPS = oid.byName("cps");
245
246
  /** @internal The extensions RFC 5280 says a conforming CA SHOULD mark non-critical, keyed by OID
246
247
  * with the clause; the MUSTs live in the shared CERT_FIXED_CRITICALITY table. The subjectAltName
247
248
  * and extKeyUsage recommendations are conditional and have their own rules. */
@@ -544,7 +545,327 @@ function _validityCeilingDays(notBefore) {
544
545
  return VALIDITY_SCHEDULE[VALIDITY_SCHEDULE.length - 1].maxDays;
545
546
  }
546
547
 
548
+ /** @internal All FOUR reserved policy identifiers of BR sec. 7.1.6.1, one per Subscriber
549
+ * Certificate type named in sec. 7.1.2.7.1: Domain, Organization and Individual Validated under
550
+ * the baseline-requirements arc, and Extended Validation under ev-guidelines. Sec. 7.1.2.7.9:
551
+ * "the Certificate Policies extension MUST contain exactly one Reserved Certificate Policy
552
+ * Identifier", so a list short of one type reports every certificate of that type as asserting
553
+ * none. */
554
+ var CABF_RESERVED_POLICIES = ["domain-validated", "organization-validated", "individual-validated",
555
+ "ev-guidelines"]
556
+ .map(function (n) { return oid.byName(n); }).filter(function (d) { return !!d; });
557
+
558
+ /** @internal BR sec. 7.1.2.7.10. Each is MUST NOT for a Subscriber Certificate. */
559
+ var CABF_FORBIDDEN_EKU = ["codeSigning", "emailProtection", "timeStamping", "ocspSigning",
560
+ "anyExtendedKeyUsage", "precertificateSigningCert"]
561
+ .map(function (n) { var d = oid.byName(n); return d ? { name: n, oid: d } : null; })
562
+ .filter(function (e) { return !!e; });
563
+
564
+ /** @internal BR sec. 7.1.2.7.7. Only these two accessMethods are permitted; any other MUST NOT. */
565
+ var CABF_AIA_METHODS = ["ocsp", "caIssuers"].map(function (n) { return oid.byName(n); });
566
+
567
+ /** @internal BR sec. 7.1.2.7.11, the two Key Usage tables. A bit marked "Permitted: N" for the
568
+ * certificate's key type may not be set. The tables differ by key type, which is the point: the
569
+ * same bit is permitted for one and forbidden for the other. */
570
+ var CABF_KU_FORBIDDEN_RSA = ["nonRepudiation", "keyAgreement", "keyCertSign", "cRLSign",
571
+ "encipherOnly", "decipherOnly"];
572
+ var CABF_KU_FORBIDDEN_ECC = ["nonRepudiation", "keyEncipherment", "dataEncipherment",
573
+ "keyCertSign", "cRLSign", "encipherOnly", "decipherOnly"];
574
+ var CABF_KU_RSA_BITS = ["digitalSignature", "keyEncipherment", "dataEncipherment"];
575
+
576
+ /** @internal BR sec. 7.1.2.7.12: only dNSName and iPAddress are permitted in a Subscriber
577
+ * Certificate's subjectAltName. The GeneralName context tag numbers are RFC 5280 sec. 4.2.1.6's. */
578
+ var CABF_SAN_PERMITTED_TAGS = [2, 7];
579
+ var CABF_SAN_TAG_NAMES = Object.assign(Object.create(null), {
580
+ 0: "otherName", 1: "rfc822Name", 2: "dNSName", 3: "x400Address", 4: "directoryName",
581
+ 5: "ediPartyName", 6: "uniformResourceIdentifier", 7: "iPAddress", 8: "registeredID",
582
+ });
583
+
584
+ /** @internal Which of the two Key Usage tables sec. 7.1.2.7.11 gives applies to this certificate,
585
+ * or null where neither does. The section opens "The acceptable Key Usage values vary based on
586
+ * whether the Certificate's subjectPublicKeyInfo identifies an RSA public key or an ECC public
587
+ * key", and gives a table for each and none for anything else. A key outside the two, such as an
588
+ * ML-DSA one, therefore has no table to be held to, and treating everything that is not ECC as
589
+ * RSA would report it against requirements written for a different algorithm. */
590
+ function _cabfKeyUsageTable(cert) {
591
+ var spki = cert.subjectPublicKeyInfo;
592
+ var name = spki && spki.algorithm && spki.algorithm.name;
593
+ if (name === "ecPublicKey") return "ecc";
594
+ if (RSA_KEY_ALGS[name]) return "rsa";
595
+ return null;
596
+ }
597
+ function _isEccKey(cert) { return _cabfKeyUsageTable(cert) === "ecc"; }
598
+ function _subjectIsEmpty(cert) {
599
+ var rdns = cert.subject && cert.subject.rdns;
600
+ return !(Array.isArray(rdns) && rdns.length);
601
+ }
602
+
603
+ /** @internal Every policy qualifier of every PolicyInformation, as its qualifier OID. The bytes
604
+ * are re-decoded the way the display-text walk above re-decodes them. */
605
+ function _policyQualifierIds(ctx) {
606
+ var d = ctx.decode("certificatePolicies");
607
+ if (!d || !Array.isArray(d.value)) return [];
608
+ var out = [];
609
+ d.value.forEach(function (pi) {
610
+ if (!pi.qualifiersBytes || !pi.qualifiersBytes.length) return;
611
+ var quals;
612
+ // allow:swallow-unverified bytes that already decoded under the policy-qualifier door cannot throw
613
+ try { quals = asn1.decode(pi.qualifiersBytes).children; } catch (_e) { return; }
614
+ (quals || []).forEach(function (pq) {
615
+ // allow:swallow-unverified the same door already read this OID
616
+ try { out.push(asn1.read.oid(pq.children[0])); } catch (_e2) { void 0; }
617
+ });
618
+ });
619
+ return out;
620
+ }
621
+
547
622
  var CABF_TLS_RULES = [
623
+ {
624
+ id: "lint/cabf-tls/aia-missing", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.6",
625
+ message: "a subscriber certificate must carry an authorityInformationAccess extension",
626
+ appliesTo: _isTls,
627
+ check: function (cert, ctx) { return ctx.raw("authorityInfoAccess") ? null : true; },
628
+ },
629
+ {
630
+ id: "lint/cabf-tls/aia-critical", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.6",
631
+ message: "authorityInformationAccess must not be marked critical",
632
+ appliesTo: _isTls,
633
+ check: function (cert, ctx) {
634
+ var e = ctx.raw("authorityInfoAccess");
635
+ return (e && e.critical === true) ? true : null;
636
+ },
637
+ },
638
+ {
639
+ id: "lint/cabf-tls/aia-forbidden-access-method", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.7",
640
+ /** @internal The table permits id-ad-ocsp and id-ad-caIssuers and says of any other value
641
+ * "No other accessMethods may be used". */
642
+ message: "an authorityInformationAccess accessMethod other than id-ad-ocsp or id-ad-caIssuers is not permitted",
643
+ appliesTo: _isTls,
644
+ check: function (cert, ctx) {
645
+ var d = ctx.decode("authorityInfoAccess");
646
+ if (!d || !Array.isArray(d.value)) return null;
647
+ var out = [];
648
+ d.value.forEach(function (ad) {
649
+ if (CABF_AIA_METHODS.indexOf(ad.accessMethod) === -1) {
650
+ out.push({ context: { accessMethod: ad.accessMethod, name: oid.name(ad.accessMethod) || null } });
651
+ }
652
+ });
653
+ return out.length ? out : null;
654
+ },
655
+ },
656
+ {
657
+ id: "lint/cabf-tls/aia-location-not-uri", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.7",
658
+ /** @internal Each permitted accessMethod states uniformResourceIdentifier as its accessLocation
659
+ * GeneralName type, and "each accessLocation MUST be encoded as the specified GeneralName type". */
660
+ message: "an authorityInformationAccess accessLocation must be a uniformResourceIdentifier",
661
+ appliesTo: _isTls,
662
+ check: function (cert, ctx) {
663
+ var d = ctx.decode("authorityInfoAccess");
664
+ if (!d || !Array.isArray(d.value)) return null;
665
+ var out = [];
666
+ d.value.forEach(function (ad) {
667
+ if (CABF_AIA_METHODS.indexOf(ad.accessMethod) === -1) return;
668
+ var loc = ad.accessLocation;
669
+ if (!loc || loc.tag !== 6) {
670
+ out.push({ context: { accessMethod: oid.name(ad.accessMethod) || ad.accessMethod,
671
+ generalNameTag: loc ? loc.tag : null } });
672
+ }
673
+ });
674
+ return out.length ? out : null;
675
+ },
676
+ },
677
+ {
678
+ id: "lint/cabf-tls/policies-missing", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.6",
679
+ message: "a subscriber certificate must carry a certificatePolicies extension",
680
+ appliesTo: _isTls,
681
+ check: function (cert, ctx) { return ctx.raw("certificatePolicies") ? null : true; },
682
+ },
683
+ {
684
+ id: "lint/cabf-tls/policies-any-policy", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.9",
685
+ /** @internal "The anyPolicy Policy Identifier MUST NOT be present." */
686
+ message: "certificatePolicies must not assert anyPolicy",
687
+ appliesTo: _isTls,
688
+ check: function (cert, ctx) {
689
+ var d = ctx.decode("certificatePolicies");
690
+ if (!d || !Array.isArray(d.value)) return null;
691
+ return d.value.some(function (pi) { return pi.policyIdentifier === OID_ANY_POLICY; }) ? true : null;
692
+ },
693
+ },
694
+ {
695
+ id: "lint/cabf-tls/policies-reserved-identifier-count", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.9",
696
+ /** @internal "Regardless of the order of PolicyInformation values, the Certificate Policies
697
+ * extension MUST contain exactly one Reserved Certificate Policy Identifier." Exactly one, so
698
+ * naming none and naming two are the same fault and the count says which. */
699
+ message: "certificatePolicies must assert exactly one reserved certificate policy identifier",
700
+ appliesTo: _isTls,
701
+ check: function (cert, ctx) {
702
+ var d = ctx.decode("certificatePolicies");
703
+ if (!d || !Array.isArray(d.value)) return null;
704
+ var found = d.value.filter(function (pi) {
705
+ return CABF_RESERVED_POLICIES.indexOf(pi.policyIdentifier) !== -1;
706
+ });
707
+ return found.length === 1 ? null : { context: { count: found.length,
708
+ identifiers: found.map(function (pi) { return pi.policyIdentifier; }) } };
709
+ },
710
+ },
711
+ {
712
+ id: "lint/cabf-tls/policy-qualifier-forbidden", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.9",
713
+ /** @internal The permitted-qualifier table admits id-qt-cps and says of any other qualifier
714
+ * MUST NOT, which includes the userNotice RFC 5280 otherwise allows. */
715
+ message: "a certificatePolicies qualifier other than id-qt-cps is not permitted",
716
+ appliesTo: _isTls,
717
+ check: function (cert, ctx) {
718
+ var out = [];
719
+ _policyQualifierIds(ctx).forEach(function (qid) {
720
+ if (qid !== OID_CPS) out.push({ context: { qualifier: qid, name: oid.name(qid) || null } });
721
+ });
722
+ return out.length ? out : null;
723
+ },
724
+ },
725
+ {
726
+ id: "lint/cabf-tls/eku-forbidden-purpose", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.10",
727
+ message: "a key purpose the subscriber profile forbids is present in extKeyUsage",
728
+ appliesTo: _isTls,
729
+ check: function (cert, ctx) {
730
+ var d = ctx.decode("extKeyUsage");
731
+ if (!d || !Array.isArray(d.value)) return null;
732
+ var out = [];
733
+ CABF_FORBIDDEN_EKU.forEach(function (e) {
734
+ if (d.value.indexOf(e.oid) !== -1) out.push({ context: { keyPurpose: e.name, oid: e.oid } });
735
+ });
736
+ return out.length ? out : null;
737
+ },
738
+ },
739
+ {
740
+ id: "lint/cabf-tls/name-constraints-present", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.6",
741
+ message: "a subscriber certificate must not carry a nameConstraints extension",
742
+ appliesTo: _isTls,
743
+ check: function (cert, ctx) { return ctx.raw("nameConstraints") ? true : null; },
744
+ },
745
+ {
746
+ id: "lint/cabf-tls/basic-constraints-ca-true", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.8",
747
+ message: "a subscriber certificate's basicConstraints cA must be FALSE",
748
+ appliesTo: _isTls,
749
+ check: function (cert, ctx) {
750
+ var d = ctx.decode("basicConstraints");
751
+ return (d && d.value && d.value.cA === true) ? true : null;
752
+ },
753
+ },
754
+ {
755
+ id: "lint/cabf-tls/basic-constraints-path-len", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.8",
756
+ message: "a subscriber certificate's basicConstraints must not carry a pathLenConstraint",
757
+ appliesTo: _isTls,
758
+ check: function (cert, ctx) {
759
+ var d = ctx.decode("basicConstraints");
760
+ var pl = d && d.value ? d.value.pathLenConstraint : null;
761
+ return pl === null || pl === undefined ? null : { context: { pathLenConstraint: pl } };
762
+ },
763
+ },
764
+ {
765
+ id: "lint/cabf-tls/key-usage-forbidden-bit", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.11",
766
+ /** @internal The two Key Usage tables differ by key type, which is the whole point: the same
767
+ * bit is permitted for one and forbidden for the other, so the key decides which table asks. */
768
+ message: "a keyUsage bit the subscriber profile does not permit for this key type is set",
769
+ appliesTo: _isTls,
770
+ check: function (cert, ctx) {
771
+ var d = ctx.decode("keyUsage");
772
+ if (!d || !d.value) return null;
773
+ var table = _cabfKeyUsageTable(cert);
774
+ if (table === null) return null;
775
+ var forbidden = table === "ecc" ? CABF_KU_FORBIDDEN_ECC : CABF_KU_FORBIDDEN_RSA;
776
+ var out = [];
777
+ forbidden.forEach(function (bit) {
778
+ if (d.value[bit] === true) out.push({ context: { keyUsage: bit, keyType: table } });
779
+ });
780
+ return out.length ? out : null;
781
+ },
782
+ },
783
+ {
784
+ id: "lint/cabf-tls/key-usage-ecc-without-digital-signature", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.11",
785
+ /** @internal The ECC table marks digitalSignature Required: MUST, where the RSA table marks it
786
+ * SHOULD and admits a keyEncipherment-only certificate. */
787
+ message: "an ECC subscriber certificate's keyUsage must assert digitalSignature",
788
+ appliesTo: function (cert, ctx) { return _isTls(cert, ctx) && _isEccKey(cert); },
789
+ check: function (cert, ctx) {
790
+ var d = ctx.decode("keyUsage");
791
+ if (!d || !d.value) return null;
792
+ return d.value.digitalSignature === true ? null : true;
793
+ },
794
+ },
795
+ {
796
+ id: "lint/cabf-tls/key-usage-rsa-no-bit-set", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.11",
797
+ /** @internal "At least one Key Usage MUST be set for RSA Public Keys." Measured over the bits
798
+ * that table permits, since a forbidden bit being set is the row above's answer, not this one's. */
799
+ message: "an RSA subscriber certificate's keyUsage must set at least one permitted bit",
800
+ appliesTo: function (cert, ctx) { return _isTls(cert, ctx) && _cabfKeyUsageTable(cert) === "rsa"; },
801
+ check: function (cert, ctx) {
802
+ var d = ctx.decode("keyUsage");
803
+ if (!d || !d.value) return null;
804
+ var any = CABF_KU_RSA_BITS.some(function (bit) { return d.value[bit] === true; });
805
+ return any ? null : true;
806
+ },
807
+ },
808
+ {
809
+ id: "lint/cabf-tls/san-forbidden-name-type", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.12",
810
+ /** @internal The GeneralName table permits dNSName and iPAddress and marks every other type
811
+ * Permitted: N, including the uniformResourceIdentifier and rfc822Name RFC 5280 allows. */
812
+ message: "a subjectAltName entry of a type the subscriber profile does not permit is present",
813
+ appliesTo: _isTls,
814
+ check: function (cert, ctx) {
815
+ var d = ctx.decode("subjectAltName");
816
+ if (!d || !d.value || !Array.isArray(d.value.names)) return null;
817
+ var out = [];
818
+ d.value.names.forEach(function (gn) {
819
+ if (CABF_SAN_PERMITTED_TAGS.indexOf(gn.tagNumber) === -1) {
820
+ out.push({ context: { generalName: CABF_SAN_TAG_NAMES[gn.tagNumber] || null, tag: gn.tagNumber } });
821
+ }
822
+ });
823
+ return out.length ? out : null;
824
+ },
825
+ },
826
+ {
827
+ id: "lint/cabf-tls/san-criticality-mismatch", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.12",
828
+ /** @internal "If the subject field of the certificate is an empty SEQUENCE, this extension MUST
829
+ * be marked critical ... Otherwise, this extension MUST NOT be marked critical." Both
830
+ * directions are MUST, so one row measures the pair and the context says which way it failed. */
831
+ message: "subjectAltName must be critical where the subject is empty and non-critical otherwise",
832
+ appliesTo: _isTls,
833
+ check: function (cert, ctx) {
834
+ var e = ctx.raw("subjectAltName");
835
+ if (!e) return null;
836
+ var empty = _subjectIsEmpty(cert);
837
+ var critical = e.critical === true;
838
+ if (empty === critical) return null;
839
+ return { context: { subjectEmpty: empty, critical: critical } };
840
+ },
841
+ },
842
+ {
843
+ id: "lint/cabf-tls/dnsname-trailing-dot", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.12",
844
+ /** @internal "The zero-length Domain Label representing the root zone ... MUST NOT be included
845
+ * (e.g. 'example.com' MUST be encoded as 'example.com' and MUST NOT be encoded as
846
+ * 'example.com.')." */
847
+ message: "a subjectAltName dNSName must not carry the root zone's zero-length label",
848
+ appliesTo: _isTls,
849
+ check: function (cert, ctx) {
850
+ var out = [];
851
+ _sanDnsNames(ctx).forEach(function (name) {
852
+ if (typeof name === "string" && name.length > 0 && name.charAt(name.length - 1) === ".") {
853
+ out.push({ context: { dnsName: name } });
854
+ }
855
+ });
856
+ return out.length ? out : null;
857
+ },
858
+ },
859
+ {
860
+ id: "lint/cabf-tls/ski-present", severity: "notice", source: "cabf-tls", citation: "CABF TLS BR 7.1.2.7.6",
861
+ /** @internal NOT RECOMMENDED here, which is the opposite of what RFC 5280 sec. 4.2.1.2 asks of
862
+ * an end-entity certificate. Both readings ship, each under the profile that states it, so a
863
+ * caller running one profile is not told the other's answer. Graded notice because the clause
864
+ * is NOT RECOMMENDED rather than MUST NOT. */
865
+ message: "a subscriber certificate's subjectKeyIdentifier is NOT RECOMMENDED by this profile",
866
+ appliesTo: _isTls,
867
+ check: function (cert, ctx) { return ctx.raw("subjectKeyIdentifier") ? true : null; },
868
+ },
548
869
  {
549
870
  id: "lint/cabf-tls/san-missing", severity: "error", source: "cabf-tls", citation: "CABF TLS BR 7.1.4.2.1",
550
871
  message: "a TLS server certificate must include a usable subjectAltName extension",
@@ -2104,7 +2425,13 @@ function _applyThreshold(report, severity) {
2104
2425
  * raises a typed `LintError`.
2105
2426
  *
2106
2427
  * @opts profile One of `pki.lint.profiles()` (default runs every profile). Selecting
2107
- * `"cabf-tls"` lints the input AS a TLS server certificate.
2428
+ * `"cabf-tls"` lints the input AS a TLS SUBSCRIBER certificate, which is an
2429
+ * assertion about the input rather than a question asked of it: the section
2430
+ * 7.1.2.7 rows then apply whatever the certificate says it is, so naming it for
2431
+ * a CA certificate reports that CA against subscriber requirements. The CA
2432
+ * profiles of section 7.1.2.10 are a separate set this does not yet carry. Left
2433
+ * unnamed, a certificate is held to those rows only where it asserts
2434
+ * id-kp-serverAuth and is not a CA.
2108
2435
  * @opts severity Suppress findings below this floor (default `"notice"`). `counts` and
2109
2436
  * `worst` always reflect the complete, unfiltered result.
2110
2437
  * @example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/pki",
3
- "version": "0.8.16",
3
+ "version": "0.8.17",
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:770a6573-9a63-4951-bf37-d9999705b708",
5
+ "serialNumber": "urn:uuid:1b8d2783-3d1c-49be-ad22-5e029717a170",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-09-24T05:26:27.977Z",
8
+ "timestamp": "2026-09-24T06:15:30.953Z",
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.16",
22
+ "bom-ref": "@blamejs/pki@0.8.17",
23
23
  "type": "application",
24
24
  "name": "pki",
25
- "version": "0.8.16",
25
+ "version": "0.8.17",
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.16",
29
+ "purl": "pkg:npm/%40blamejs/pki@0.8.17",
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.16",
57
+ "ref": "@blamejs/pki@0.8.17",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]