pub struct TlsConfig {
pub mode: SslMode,
pub ca_pem_path: Option<PathBuf>,
pub sni_hostname: Option<String>,
pub client_cert_pem_path: Option<PathBuf>,
pub client_key_pem_path: Option<PathBuf>,
}Expand description
TLS/SSL configuration for PostgreSQL connections.
Fields§
§mode: SslModeSSL mode controlling connection security level.
ca_pem_path: Option<PathBuf>Path to PEM file containing trusted CA certificates.
If None and verification is enabled (VerifyCa/VerifyFull),
the Mozilla root certificates (webpki-roots) are used.
sni_hostname: Option<String>Override SNI hostname sent during TLS handshake.
Useful when:
- Connecting via IP address but certificate has a DNS name
- Using a load balancer with different internal/external names
If None, the connection host is used for SNI.
client_cert_pem_path: Option<PathBuf>Path to PEM file containing client certificate chain.
Required for mutual TLS (mTLS) authentication.
Must be paired with client_key_pem_path.
client_key_pem_path: Option<PathBuf>Path to PEM file containing client private key.
Required for mutual TLS (mTLS) authentication.
Must be paired with client_cert_pem_path.
Supports PKCS#8, PKCS#1 (RSA), and SEC1 (EC) formats.
Implementations§
Source§impl TlsConfig
impl TlsConfig
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
Create a configuration with TLS disabled.
§Example
use pgwire_replication::config::TlsConfig;
let tls = TlsConfig::disabled();
assert!(!tls.mode.requires_tls());Sourcepub fn require() -> Self
pub fn require() -> Self
Create a configuration requiring TLS without certificate verification.
Warning: This mode is vulnerable to MITM attacks.
Use verify_ca() or verify_full() for production.
§Example
use pgwire_replication::config::TlsConfig;
let tls = TlsConfig::require();
assert!(tls.mode.requires_tls());
assert!(!tls.mode.verifies_certificate());Sourcepub fn verify_ca(ca_path: Option<PathBuf>) -> Self
pub fn verify_ca(ca_path: Option<PathBuf>) -> Self
Create a configuration with certificate chain verification.
§Arguments
ca_path- Path to CA certificate PEM file, orNonefor system roots
§Example
use pgwire_replication::config::TlsConfig;
// Using system/Mozilla roots
let tls = TlsConfig::verify_ca(None);
// Using custom CA
let tls = TlsConfig::verify_ca(Some("/path/to/ca.pem".into()));Sourcepub fn verify_full(ca_path: Option<PathBuf>) -> Self
pub fn verify_full(ca_path: Option<PathBuf>) -> Self
Create a configuration with full verification (chain + hostname).
Recommended for production.
§Arguments
ca_path- Path to CA certificate PEM file, orNonefor system roots
§Example
use pgwire_replication::config::TlsConfig;
let tls = TlsConfig::verify_full(Some("/etc/ssl/certs/ca.pem".into()));
assert!(tls.mode.verifies_hostname());Sourcepub fn with_sni_hostname(self, hostname: impl Into<String>) -> Self
pub fn with_sni_hostname(self, hostname: impl Into<String>) -> Self
Set SNI hostname override.
§Example
use pgwire_replication::config::TlsConfig;
let tls = TlsConfig::verify_full(None)
.with_sni_hostname("db.example.com");Sourcepub fn with_client_cert(
self,
cert_path: impl Into<PathBuf>,
key_path: impl Into<PathBuf>,
) -> Self
pub fn with_client_cert( self, cert_path: impl Into<PathBuf>, key_path: impl Into<PathBuf>, ) -> Self
Configure client certificate for mutual TLS.
§Example
use pgwire_replication::config::TlsConfig;
let tls = TlsConfig::verify_full(Some("/ca.pem".into()))
.with_client_cert("/client.pem", "/client.key");