Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rumqttc: Enable native tls TlsConnector support. #870

Merged
merged 24 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions rumqttc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extern crate log;

use std::fmt::{self, Debug, Formatter};

#[cfg(any(feature = "use-rustls", feature = "websocket"))]
#[cfg(any(feature = "use-rustls",feature = "use-native-tls", feature = "websocket"))]
use std::sync::Arc;

use std::time::Duration;
Expand Down Expand Up @@ -149,6 +149,10 @@ pub use tls::Error as TlsError;
pub use tokio_rustls;
#[cfg(feature = "use-rustls")]
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
#[cfg(feature = "use-native-tls")]
pub use tokio_native_tls;
#[cfg(feature = "use-native-tls")]
use tokio_native_tls::native_tls::TlsConnectorBuilder;

#[cfg(feature = "proxy")]
pub use proxy::{Proxy, ProxyAuth, ProxyType};
Expand Down Expand Up @@ -315,7 +319,7 @@ impl Transport {
}

/// TLS configuration method
#[derive(Clone, Debug)]
#[derive(Clone)]
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
pub enum TlsConfiguration {
#[cfg(feature = "use-rustls")]
Expand All @@ -339,7 +343,8 @@ pub enum TlsConfiguration {
/// Injected rustls ClientConfig for TLS, to allow more customisation.
Rustls(Arc<ClientConfig>),
#[cfg(feature = "use-native-tls")]
Native,
/// Injected rustls TlsConnectorBuilder for TLS, to allow more customisation.
Native(Arc<TlsConnectorBuilder>),
}

#[cfg(feature = "use-rustls")]
Expand All @@ -364,6 +369,13 @@ impl From<ClientConfig> for TlsConfiguration {
}
}

#[cfg(feature = "use-native-tls")]
impl From<TlsConnectorBuilder> for TlsConfiguration {
fn from(builder: TlsConnectorBuilder) -> Self {
TlsConfiguration::Native(Arc::new(builder))
}
}

/// Provides a way to configure low level network connection configurations
#[derive(Clone, Default)]
pub struct NetworkOptions {
Expand Down
4 changes: 2 additions & 2 deletions rumqttc/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub async fn native_tls_connector(

connector_builder.build()?
}
TlsConfiguration::Native => native_tls::TlsConnector::new()?,
TlsConfiguration::Native(builder) => builder.build()?,
#[allow(unreachable_patterns)]
_ => unreachable!("This cannot be called for other TLS backends than Native TLS"),
};
Expand All @@ -176,7 +176,7 @@ pub async fn tls_connect(
Box::new(connector.connect(domain, tcp).await?)
}
#[cfg(feature = "use-native-tls")]
TlsConfiguration::Native | TlsConfiguration::SimpleNative { .. } => {
TlsConfiguration::Native(_) | TlsConfiguration::SimpleNative { .. } => {
let connector = native_tls_connector(tls_config).await?;
Box::new(connector.connect(addr, tcp).await?)
}
Expand Down
Loading