Expand description
Certificate wrapping, renewal logic, and subject validation.
This module provides the Certificate type that wraps a TLS certificate
chain (as DER-encoded bytes) together with its private key and metadata
extracted from the leaf certificate (SANs, validity period, hash).
§Key concepts
- Renewal window: a certificate is considered due for renewal when the remaining fraction of
its total lifetime drops below a configurable ratio (default
DEFAULT_RENEWAL_WINDOW_RATIO= 1/3). An emergency renewal is also triggered when fewer than 24 hours remain. - Subject qualification: helper functions such as
subject_qualifies_for_certandsubject_qualifies_for_public_certvalidate domain names before attempting certificate issuance, catching common typos and misconfigurations early. - Wildcard matching:
match_wildcardimplements RFC 6125 / RFC 2818 wildcard rules for certificate lookups.
Structs§
- Certificate
- A TLS certificate chain together with its private key and parsed metadata.
Enums§
- Private
KeyKind - Indicates which variant of
PrivateKeyDerthe stored raw bytes represent.
Constants§
- DEFAULT_
RENEWAL_ WINDOW_ RATIO - The default ratio of remaining lifetime to total lifetime at which a certificate is considered due for renewal.
Functions§
- currently_
in_ renewal_ window - Returns
trueif the current time is within (or past) the renewal window. - extract_
names_ from_ der - Extract subject names from a DER-encoded certificate without requiring
the full
Certificatestruct. - hash_
certificate_ chain - Compute the SHA-256 hash of the entire certificate chain (all DER bytes concatenated) and return it as a lowercase hex string.
- managed_
cert_ in_ storage_ needs_ renewal - Check whether a managed certificate stored in
storageneeds renewal. - match_
wildcard - Returns
trueifsubject(a candidate DNS name) matcheswildcard(a reference DNS name), using DNS wildcard matching logic. - reload_
managed_ certificate - Reload a managed certificate from storage, replacing the old version in cache.
- subject_
is_ internal - Returns
trueifsubjectis an internal-facing hostname or address that cannot receive a certificate from a public CA. - subject_
is_ ip - Returns
trueifsubjectis an IP address (either IPv4 or IPv6). - subject_
qualifies_ for_ cert - Returns
trueifsubjectlooks like it could be a valid certificate subject name. - subject_
qualifies_ for_ public_ cert - Returns
trueif the subject name appears eligible for a certificate from a public CA such as Let’s Encrypt.