pub struct TlsConfig {
pub trust_server_certificate: bool,
pub root_certificates: Vec<CertificateDer<'static>>,
pub client_auth: Option<ClientAuth>,
pub server_name: Option<String>,
pub min_protocol_version: TlsVersion,
pub max_protocol_version: TlsVersion,
pub strict_mode: bool,
pub alpn_protocols: Vec<Vec<u8>>,
}Expand description
TLS configuration for SQL Server connections.
Fields§
§trust_server_certificate: boolWhether to trust the server certificate without validation.
Warning: This is insecure and should only be used for testing.
root_certificates: Vec<CertificateDer<'static>>Custom root certificates to trust.
If empty, the system root certificates are used.
client_auth: Option<ClientAuth>Client authentication credentials for mutual TLS (TDS 8.0 client cert auth).
server_name: Option<String>Server hostname for certificate validation.
If not set, the connection hostname is used.
min_protocol_version: TlsVersionMinimum TLS version to accept.
max_protocol_version: TlsVersionMaximum TLS version to accept.
strict_mode: boolWhether to use TDS 8.0 strict mode (TLS before any TDS traffic).
alpn_protocols: Vec<Vec<u8>>Application-layer protocol negotiation (ALPN) protocols.
Implementations§
Source§impl TlsConfig
impl TlsConfig
Sourcepub fn trust_server_certificate(self, trust: bool) -> Self
pub fn trust_server_certificate(self, trust: bool) -> Self
Trust the server certificate without validation.
Warning: This is insecure and should only be used for testing.
Sourcepub fn add_root_certificate(self, cert: CertificateDer<'static>) -> Self
pub fn add_root_certificate(self, cert: CertificateDer<'static>) -> Self
Add a custom root certificate to trust.
Sourcepub fn with_root_certificates(self, certs: Vec<CertificateDer<'static>>) -> Self
pub fn with_root_certificates(self, certs: Vec<CertificateDer<'static>>) -> Self
Set custom root certificates, replacing any existing ones.
Sourcepub fn with_client_auth(
self,
certs: Vec<CertificateDer<'static>>,
key: PrivateKeyDer<'static>,
) -> Self
pub fn with_client_auth( self, certs: Vec<CertificateDer<'static>>, key: PrivateKeyDer<'static>, ) -> Self
Set client certificate and key for mutual TLS.
Sourcepub fn with_server_name(self, name: impl Into<String>) -> Self
pub fn with_server_name(self, name: impl Into<String>) -> Self
Set the server name for certificate validation.
Sourcepub fn min_protocol_version(self, version: TlsVersion) -> Self
pub fn min_protocol_version(self, version: TlsVersion) -> Self
Set the minimum TLS version.
Sourcepub fn max_protocol_version(self, version: TlsVersion) -> Self
pub fn max_protocol_version(self, version: TlsVersion) -> Self
Set the maximum TLS version.
Sourcepub fn strict_mode(self, enabled: bool) -> Self
pub fn strict_mode(self, enabled: bool) -> Self
Enable TDS 8.0 strict mode.
Sourcepub fn with_alpn_protocols(self, protocols: Vec<Vec<u8>>) -> Self
pub fn with_alpn_protocols(self, protocols: Vec<Vec<u8>>) -> Self
Set ALPN protocols.
Sourcepub fn has_client_auth(&self) -> bool
pub fn has_client_auth(&self) -> bool
Check if client certificate authentication is configured.
Sourcepub fn add_root_certificate_der(self, der_bytes: Vec<u8>) -> Self
pub fn add_root_certificate_der(self, der_bytes: Vec<u8>) -> Self
Add a root certificate from DER-encoded bytes.
This is a convenience method that avoids requiring a direct
dependency on the rustls crate. For PEM-encoded certificates,
parse them first using the rustls-pemfile crate.
Sourcepub fn with_client_auth_der(
self,
cert_chain_der: Vec<Vec<u8>>,
private_key_der: Vec<u8>,
) -> Self
pub fn with_client_auth_der( self, cert_chain_der: Vec<Vec<u8>>, private_key_der: Vec<u8>, ) -> Self
Set client certificate and key from DER-encoded bytes.
This is a convenience method that avoids requiring a direct
dependency on the rustls crate.
cert_chain_der- DER-encoded certificate chainprivate_key_der- DER-encoded private key (PKCS#8 format)