rustls-mitm
SNI-based certificate resolver for rustls that generates per-host TLS certificates on the fly, enabling man-in-the-middle TLS interception.
How it works
rustls-mitm provides a ResolvesServerCert implementation that intercepts TLS handshakes: when a client connects, the resolver reads the hostname from the SNI extension in the ClientHello, generates a leaf certificate for that hostname signed by your CA, and caches it in an LRU cache for subsequent connections.
This is runtime-agnostic and crypto-provider-agnostic — it works with any async runtime (tokio, async-std, etc.) and any rustls CryptoProvider (ring, aws-lc-rs, etc.).
Usage
use Arc;
use ;
use TlsAcceptor;
// Load or generate a CA
let ca = from_pem_files?;
// Build a rustls ServerConfig with the MITM resolver
let mut config = new.into_server_config;
// Set ALPN if needed (e.g. for HTTP)
config.alpn_protocols = vec!;
// Use with any TLS acceptor — tokio-rustls, async-rustls, sync rustls, etc.
let acceptor = from;
Generating a CA
use CertificateAuthority;
let ca = generate?;
ca.to_pem_files?;
Clients must trust this CA certificate for interception to work transparently.
Custom cache capacity
The resolver caches generated certificates in an LRU cache (default: 1024 entries):
let resolver = with_cache_capacity;
let config = resolver.into_server_config;