Expand description
TLS termination and protocol (HTTP/1.1 vs HTTP/2) selection for the listeners.
This is the single place that knows how to load a PEM cert/key, build a
rustls [ServerConfig] (with ALPN and a min_version floor), turn it into
a [tokio_rustls::TlsAcceptor], and serve a connection over the negotiated
protocol. Both the data-plane listener (server::listener) and the optional
Admin API TLS reuse build_acceptor + serve_connection, so cert
handling lives in exactly one module.
Everything is pinned to the rustls ring provider, matching the rest of
the dependency tree (see install_crypto_provider).
StructsΒ§
- Client
Cert Identity - Verified identity of an mTLS client, read from its leaf certificate.
- SniCert
Resolver π - Resolves the server certificate by ClientHello SNI hostname (exact or single-label wildcard), falling back to the default cert. Enables multi-domain TLS termination on one listener.
EnumsΒ§
- TlsError
- Failure loading a cert/key or building the rustls config. Every variant carries enough detail (the offending path or message) for a fail-fast startup error.
FunctionsΒ§
- build_
acceptor - Builds a [
TlsAcceptor] ready to wrap accepted TCP streams. Fail-fast: any cert/key/config error surfaces here at startup. - build_
connection - Builds (but does not drive) a connection future for
io, ready to be either.awaited directly or handed to a graceful-shutdown watcher. - build_
reloadable - Builds a hot-reloadable TLS config: the initial
ServerConfigwrapped in an [ArcSwap] sospawn_cert_watchercan swap it in on cert rotation. Fail-fast: a bad cert/key at startup surfaces here. - build_
server_ config - Builds a rustls [
ServerConfig] fromtls, enforcingmin_versionand advertising ALPNh2+http/1.1whenhttp2_enabled(elsehttp/1.1only). Uses an explicit ring provider so the version floor is honored regardless of global-provider install ordering. - certified_
key π - Loads a cert chain + key into a validated [
CertifiedKey] (same load + key-match checkwith_single_certperforms). - client_
cert_ identity - The verified client identity on an mTLS connection, or
Noneif the client presented no certificate (anonymous client in optional mode, or mTLS not enabled). Read after the handshake. - current_
acceptor - A [
TlsAcceptor] over the current config. Call this per connection (itβs an atomic load +Arcclone) so reloads take effect for new connections. - install_
crypto_ provider - Installs the process-level rustls ring
CryptoProviderexactly once. - load_
cert_ chain - Loads the PEM certificate chain at
path. Errors if the file is missing or contains no certificates. - load_
client_ πca_ roots - Loads a PEM CA bundle at
pathinto a [RootCertStore] for verifying client certificates (mTLS). Errors if the file is missing or yields no usable certificates. - load_
private_ key - Loads the PEM private key at
path(PKCS#8, PKCS#1, or SEC1). Errors if the file is missing or contains no private key. - parse_
client_ πidentity - Extracts the subject CN and SAN DNS names from a DER-encoded certificate.
Panic-free: any parse error yields
(None, empty). - serve_
connection - Serves a single (already-handshaked,
TokioIo-wrapped) connection. - spawn_
cert_ watcher - Watches the cert/key files and hot-reloads
sharedwhen they change.
Type AliasesΒ§
- Shared
TlsConfig - A live TLS
ServerConfigthat can be atomically swapped for cert rotation. New connections read the current config; in-flight ones are unaffected.