Skip to main content

TlsConfigProvider

Trait TlsConfigProvider 

Source
pub trait TlsConfigProvider: Send + Sync {
    // Required methods
    fn client_config(
        &self,
    ) -> Result<Arc<dyn Any + Send + Sync>, ExtensionError>;
    fn provider_name(&self) -> &str;
    fn config_type_name(&self) -> &str;
    fn min_tls_version(&self) -> TlsVersion;
    fn supports_mtls(&self) -> bool;
    fn accepts_invalid_certs(&self) -> bool;
}
Expand description

A type-erased provider of TLS client configuration.

Extensions that make outbound HTTPS connections implement this trait to supply their TLS setup (client certificates, custom CA bundles, etc.) without coupling quack-rs to a specific TLS library.

§Downcasting

The returned Arc<dyn Any + Send + Sync> should be downcast by the consumer to the concrete config type. Use config_type_name to verify the expected type before downcasting, and handle None from downcast_ref gracefully (never use .expect() or .unwrap() in FFI callback contexts — see Pitfall L3).

use std::any::Any;
use std::sync::Arc;
use quack_rs::error::ExtensionError;

fn use_config(config: Arc<dyn Any + Send + Sync>) -> Result<(), ExtensionError> {
    // let rustls_config = config.downcast_ref::<rustls::ClientConfig>()
    //     .ok_or(ExtensionError::new("expected rustls::ClientConfig"))?;
    Ok(())
}

§Security

See the module-level documentation for security requirements. Implementations that bypass certificate validation or allow deprecated TLS versions should clearly document this and emit warnings.

Required Methods§

Source

fn client_config(&self) -> Result<Arc<dyn Any + Send + Sync>, ExtensionError>

Returns the TLS client configuration as a type-erased Arc.

Implementations should return an Arc wrapping their concrete TLS config type (e.g., Arc<rustls::ClientConfig>).

§Errors

Returns an ExtensionError if the configuration cannot be created (e.g., certificate file not found, invalid key format, expired CA).

Source

fn provider_name(&self) -> &str

Returns a human-readable name for this TLS provider.

Used in diagnostics, warning messages, and error context.

Source

fn config_type_name(&self) -> &str

Returns the concrete type name of the config returned by client_config.

This allows consumers to verify they have the right provider before attempting a downcast. For example, a rustls-based provider would return "rustls::ClientConfig".

Source

fn min_tls_version(&self) -> TlsVersion

Returns the minimum TLS protocol version this config allows.

Implementations should return TlsVersion::Tls12 or higher. Returning a deprecated version (TlsVersion::Tls10 or TlsVersion::Tls11) should trigger a warning via WarningCollector.

Source

fn supports_mtls(&self) -> bool

Returns true if this config includes a client certificate for mTLS.

Source

fn accepts_invalid_certs(&self) -> bool

Returns true if this config accepts invalid (self-signed, expired, or hostname-mismatched) server certificates.

§Security

This should return false by default. Returning true disables server certificate validation (CWE-295: Improper Certificate Validation) and should only be enabled when explicitly requested by the user (e.g., via a SET variable or connection parameter).

When this returns true, the extension should emit an ExtensionWarning with code: "TLS_NO_VERIFY", severity: High, and cwe: Some(295).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§