2.5 KiB
2.5 KiB
helpers/has-name-match — RFC 6125 host-name match
Purpose
The helpers/has-name-match module exposes a pre-filtering / display helper around the parsed certificate data. It is independent of the path-validation algorithm: validateChain does not depend on it for correctness, and consumers can use it freely without invoking signature verify. The helper is convenient for UI display, candidate-issuer enumeration, and host-name matching outside the full path-validation path. The implementation operates exclusively on the parsed X509Certificate shape — no re-decoding, no cryptographic operations.
Features
- Pure synchronous function, no I/O.
- No allocations beyond the boolean return.
- Idempotent — same input produces the same output.
- Compatible with the rest of the
@suaveplan/x509public surface — the certificate, name, and extension types feed directly in. - Defensive — missing fields (no SAN, no AKI/SKI) return
falserather than throwing, so callers can drive their own branching logic.
Usage: Basic Example
import { hasNameMatch, chainsTo, isIssuerOf } from "@suaveplan/x509/helpers";
import { parseCertificate } from "@suaveplan/x509/certificate";
const cert = parseCertificate(derBytes);
const anchor = parseCertificate(anchorBytes);
hasNameMatch(cert, "example.com");
chainsTo(cert, anchor);
isIssuerOf(cert, anchor);
Usage: Advanced Example
import { chainsTo } from "@suaveplan/x509/helpers";
import { parseCertificate } from "@suaveplan/x509/certificate";
const candidates = await loadTrustAnchorBundle();
const candidate = candidates.find((a) => chainsTo(parsedLeaf, a));
API Reference
- Helper function as named.
- Operates on
X509Certificatevalues from@suaveplan/x509/certificate.
Implementation Notes
- The helpers are intentionally heuristic.
hasNameMatchfollows RFC 6125 paragraph 6.4 — SAN dNSName entries take precedence; CN fallback only when SAN is absent. Wildcard matching honours the leftmost-label rule. chainsToconsults the AKI and SKI extensions; missing extensions yieldfalse(the caller should fall back to a full subject/issuer-name match viaisIssuerOfplus signature verify).isIssuerOfuses the canonical name comparison fromcertificate/name; the canonical form is whitespace-collapsed and case-folded so issuer/subject equality survives encoding choice (PrintableString vs UTF8String).- None of the helpers replace
validateChain— they are pre-filters and display helpers, not validators.