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() -> TlsConfig
pub fn disabled() -> TlsConfig
Create a configuration with TLS disabled.
§Example
use pgwire_replication::config::TlsConfig;
let tls = TlsConfig::disabled();
assert!(!tls.mode.requires_tls());Sourcepub fn require() -> TlsConfig
pub fn require() -> TlsConfig
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>) -> TlsConfig
pub fn verify_ca(ca_path: Option<PathBuf>) -> TlsConfig
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>) -> TlsConfig
pub fn verify_full(ca_path: Option<PathBuf>) -> TlsConfig
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>) -> TlsConfig
pub fn with_sni_hostname(self, hostname: impl Into<String>) -> TlsConfig
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>,
) -> TlsConfig
pub fn with_client_cert( self, cert_path: impl Into<PathBuf>, key_path: impl Into<PathBuf>, ) -> TlsConfig
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");Trait Implementations§
impl Eq for TlsConfig
impl StructuralPartialEq for TlsConfig
Auto Trait Implementations§
impl Freeze for TlsConfig
impl RefUnwindSafe for TlsConfig
impl Send for TlsConfig
impl Sync for TlsConfig
impl Unpin for TlsConfig
impl UnsafeUnpin for TlsConfig
impl UnwindSafe for TlsConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more