Skip to content

Commit 0dc418d

Browse files
authored
Merge pull request #988 from Matt3o12/main
feat(rumqttc): add use-rustls-no-provider feature
2 parents 7605cc2 + a571e58 commit 0dc418d

File tree

8 files changed

+75
-60
lines changed

8 files changed

+75
-60
lines changed

rumqttc/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
* `use-rustls-no-provider` feature flag to allow choosing crypto backend without being forced to compile `aws_lc_rs`
12+
1113
### Changed
1214
### Deprecated
1315
### Removed

rumqttc/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ rustdoc-args = ["--cfg", "docsrs"]
1717

1818
[features]
1919
default = ["use-rustls"]
20-
use-rustls = ["dep:tokio-rustls", "dep:rustls-webpki", "dep:rustls-pemfile", "dep:rustls-native-certs"]
20+
use-rustls = ["use-rustls-no-provider", "tokio-rustls/default"]
21+
use-rustls-no-provider = ["dep:tokio-rustls", "dep:rustls-webpki", "dep:rustls-pemfile", "dep:rustls-native-certs"]
2122
use-native-tls = ["dep:tokio-native-tls", "dep:native-tls"]
2223
websocket = ["dep:async-tungstenite", "dep:ws_stream_tungstenite", "dep:http"]
2324
proxy = ["dep:async-http-proxy"]
@@ -33,7 +34,7 @@ thiserror = "2.0.8"
3334

3435
# Optional
3536
# rustls
36-
tokio-rustls = { version = "0.26.0", optional = true }
37+
tokio-rustls = { version = "0.26.0", optional = true, default-features = false }
3738
rustls-webpki = { version = "0.102.8", optional = true }
3839
rustls-pemfile = { version = "2.2.0", optional = true }
3940
rustls-native-certs = { version = "0.8.1", optional = true }

rumqttc/src/eventloop.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::time::Duration;
1818
#[cfg(unix)]
1919
use {std::path::Path, tokio::net::UnixStream};
2020

21-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
21+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
2222
use crate::tls;
2323

2424
#[cfg(feature = "websocket")]
@@ -46,7 +46,7 @@ pub enum ConnectionError {
4646
#[cfg(feature = "websocket")]
4747
#[error("Websocket Connect: {0}")]
4848
WsConnect(#[from] http::Error),
49-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
49+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
5050
#[error("TLS: {0}")]
5151
Tls(#[from] tls::Error),
5252
#[error("I/O: {0}")]
@@ -387,7 +387,7 @@ async fn network_connect(
387387
let (domain, port) = match options.transport() {
388388
#[cfg(feature = "websocket")]
389389
Transport::Ws => split_url(&options.broker_addr)?,
390-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
390+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
391391
Transport::Wss(_) => split_url(&options.broker_addr)?,
392392
_ => options.broker_address(),
393393
};
@@ -416,7 +416,7 @@ async fn network_connect(
416416
options.max_incoming_packet_size,
417417
options.max_outgoing_packet_size,
418418
),
419-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
419+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
420420
Transport::Tls(tls_config) => {
421421
let socket =
422422
tls::tls_connect(&options.broker_addr, options.port, &tls_config, tcp_stream)
@@ -450,7 +450,7 @@ async fn network_connect(
450450
options.max_outgoing_packet_size,
451451
)
452452
}
453-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
453+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
454454
Transport::Wss(tls_config) => {
455455
let mut request = options.broker_addr.as_str().into_client_request()?;
456456
request

rumqttc/src/lib.rs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extern crate log;
100100

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

103-
#[cfg(any(feature = "use-rustls", feature = "websocket"))]
103+
#[cfg(any(feature = "use-rustls-no-provider", feature = "websocket"))]
104104
use std::sync::Arc;
105105

106106
use std::time::Duration;
@@ -112,7 +112,7 @@ pub mod mqttbytes;
112112
mod state;
113113
pub mod v5;
114114

115-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
115+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
116116
mod tls;
117117

118118
#[cfg(feature = "websocket")]
@@ -140,18 +140,18 @@ pub use client::{
140140
pub use eventloop::{ConnectionError, Event, EventLoop};
141141
pub use mqttbytes::v4::*;
142142
pub use mqttbytes::*;
143-
#[cfg(feature = "use-rustls")]
143+
#[cfg(feature = "use-rustls-no-provider")]
144144
use rustls_native_certs::load_native_certs;
145145
pub use state::{MqttState, StateError};
146-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
146+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
147147
pub use tls::Error as TlsError;
148148
#[cfg(feature = "use-native-tls")]
149149
pub use tokio_native_tls;
150150
#[cfg(feature = "use-native-tls")]
151151
use tokio_native_tls::native_tls::TlsConnector;
152-
#[cfg(feature = "use-rustls")]
152+
#[cfg(feature = "use-rustls-no-provider")]
153153
pub use tokio_rustls;
154-
#[cfg(feature = "use-rustls")]
154+
#[cfg(feature = "use-rustls-no-provider")]
155155
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
156156

157157
#[cfg(feature = "proxy")]
@@ -226,15 +226,18 @@ impl From<Unsubscribe> for Request {
226226
#[derive(Clone)]
227227
pub enum Transport {
228228
Tcp,
229-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
229+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
230230
Tls(TlsConfiguration),
231231
#[cfg(unix)]
232232
Unix,
233233
#[cfg(feature = "websocket")]
234234
#[cfg_attr(docsrs, doc(cfg(feature = "websocket")))]
235235
Ws,
236-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
237-
#[cfg_attr(docsrs, doc(cfg(all(feature = "use-rustls", feature = "websocket"))))]
236+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
237+
#[cfg_attr(
238+
docsrs,
239+
doc(cfg(all(feature = "use-rustls-no-provider", feature = "websocket")))
240+
)]
238241
Wss(TlsConfiguration),
239242
}
240243

@@ -250,13 +253,13 @@ impl Transport {
250253
Self::Tcp
251254
}
252255

253-
#[cfg(feature = "use-rustls")]
256+
#[cfg(feature = "use-rustls-no-provider")]
254257
pub fn tls_with_default_config() -> Self {
255258
Self::tls_with_config(Default::default())
256259
}
257260

258261
/// Use secure tcp with tls as transport
259-
#[cfg(feature = "use-rustls")]
262+
#[cfg(feature = "use-rustls-no-provider")]
260263
pub fn tls(
261264
ca: Vec<u8>,
262265
client_auth: Option<(Vec<u8>, Vec<u8>)>,
@@ -271,7 +274,7 @@ impl Transport {
271274
Self::tls_with_config(config)
272275
}
273276

274-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
277+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
275278
pub fn tls_with_config(tls_config: TlsConfiguration) -> Self {
276279
Self::Tls(tls_config)
277280
}
@@ -289,8 +292,11 @@ impl Transport {
289292
}
290293

291294
/// Use secure websockets with tls as transport
292-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
293-
#[cfg_attr(docsrs, doc(cfg(all(feature = "use-rustls", feature = "websocket"))))]
295+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
296+
#[cfg_attr(
297+
docsrs,
298+
doc(cfg(all(feature = "use-rustls-no-provider", feature = "websocket")))
299+
)]
294300
pub fn wss(
295301
ca: Vec<u8>,
296302
client_auth: Option<(Vec<u8>, Vec<u8>)>,
@@ -305,24 +311,30 @@ impl Transport {
305311
Self::wss_with_config(config)
306312
}
307313

308-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
309-
#[cfg_attr(docsrs, doc(cfg(all(feature = "use-rustls", feature = "websocket"))))]
314+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
315+
#[cfg_attr(
316+
docsrs,
317+
doc(cfg(all(feature = "use-rustls-no-provider", feature = "websocket")))
318+
)]
310319
pub fn wss_with_config(tls_config: TlsConfiguration) -> Self {
311320
Self::Wss(tls_config)
312321
}
313322

314-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
315-
#[cfg_attr(docsrs, doc(cfg(all(feature = "use-rustls", feature = "websocket"))))]
323+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
324+
#[cfg_attr(
325+
docsrs,
326+
doc(cfg(all(feature = "use-rustls-no-provider", feature = "websocket")))
327+
)]
316328
pub fn wss_with_default_config() -> Self {
317329
Self::Wss(Default::default())
318330
}
319331
}
320332

321333
/// TLS configuration method
322334
#[derive(Clone, Debug)]
323-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
335+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
324336
pub enum TlsConfiguration {
325-
#[cfg(feature = "use-rustls")]
337+
#[cfg(feature = "use-rustls-no-provider")]
326338
Simple {
327339
/// ca certificate
328340
ca: Vec<u8>,
@@ -339,7 +351,7 @@ pub enum TlsConfiguration {
339351
/// password for use with der
340352
client_auth: Option<(Vec<u8>, String)>,
341353
},
342-
#[cfg(feature = "use-rustls")]
354+
#[cfg(feature = "use-rustls-no-provider")]
343355
/// Injected rustls ClientConfig for TLS, to allow more customisation.
344356
Rustls(Arc<ClientConfig>),
345357
#[cfg(feature = "use-native-tls")]
@@ -350,7 +362,7 @@ pub enum TlsConfiguration {
350362
NativeConnector(TlsConnector),
351363
}
352364

353-
#[cfg(feature = "use-rustls")]
365+
#[cfg(feature = "use-rustls-no-provider")]
354366
impl Default for TlsConfiguration {
355367
fn default() -> Self {
356368
let mut root_cert_store = RootCertStore::empty();
@@ -365,7 +377,7 @@ impl Default for TlsConfiguration {
365377
}
366378
}
367379

368-
#[cfg(feature = "use-rustls")]
380+
#[cfg(feature = "use-rustls-no-provider")]
369381
impl From<ClientConfig> for TlsConfiguration {
370382
fn from(config: ClientConfig) -> Self {
371383
TlsConfiguration::Rustls(Arc::new(config))
@@ -788,12 +800,12 @@ impl std::convert::TryFrom<url::Url> for MqttOptions {
788800
// Encrypted connections are supported, but require explicit TLS configuration. We fall
789801
// back to the unencrypted transport layer, so that `set_transport` can be used to
790802
// configure the encrypted transport layer with the provided TLS configuration.
791-
#[cfg(feature = "use-rustls")]
803+
#[cfg(feature = "use-rustls-no-provider")]
792804
"mqtts" | "ssl" => (Transport::tls_with_default_config(), 8883),
793805
"mqtt" | "tcp" => (Transport::Tcp, 1883),
794806
#[cfg(feature = "websocket")]
795807
"ws" => (Transport::Ws, 8000),
796-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
808+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
797809
"wss" => (Transport::wss_with_default_config(), 8000),
798810
_ => return Err(OptionError::Scheme),
799811
};
@@ -927,7 +939,7 @@ mod test {
927939
use super::*;
928940

929941
#[test]
930-
#[cfg(all(feature = "use-rustls", feature = "websocket"))]
942+
#[cfg(all(feature = "use-rustls-no-provider", feature = "websocket"))]
931943
fn no_scheme() {
932944
let mut mqttoptions = MqttOptions::new("client_a", "a3f8czas.iot.eu-west-1.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=MyCreds%2F20201001%2Feu-west-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20201001T130812Z&X-Amz-Expires=7200&X-Amz-Signature=9ae09b49896f44270f2707551581953e6cac71a4ccf34c7c3415555be751b2d1&X-Amz-SignedHeaders=host", 443);
933945

rumqttc/src/proxy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::NetworkOptions;
44

55
use std::io;
66

7-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
7+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
88
use crate::{tls, TlsConfiguration};
99

1010
#[derive(Clone, Debug)]
@@ -18,7 +18,7 @@ pub struct Proxy {
1818
#[derive(Clone, Debug)]
1919
pub enum ProxyType {
2020
Http,
21-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
21+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
2222
Https(TlsConfiguration),
2323
}
2424

@@ -35,7 +35,7 @@ pub enum ProxyError {
3535
#[error("Proxy connect: {0}.")]
3636
Proxy(#[from] async_http_proxy::HttpError),
3737

38-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
38+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
3939
#[error("Tls connect: {0}.")]
4040
Tls(#[from] tls::Error),
4141
}
@@ -53,7 +53,7 @@ impl Proxy {
5353
Box::new(socket_connect(proxy_addr, network_options).await?);
5454
let mut tcp = match self.ty {
5555
ProxyType::Http => tcp,
56-
#[cfg(any(feature = "use-rustls", feature = "use-native-tls"))]
56+
#[cfg(any(feature = "use-rustls-no-provider", feature = "use-native-tls"))]
5757
ProxyType::Https(tls_config) => {
5858
tls::tls_connect(&self.addr, self.port, &tls_config, tcp).await?
5959
}

rumqttc/src/tls.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#[cfg(feature = "use-rustls")]
1+
#[cfg(feature = "use-rustls-no-provider")]
22
use rustls_pemfile::Item;
3-
#[cfg(feature = "use-rustls")]
3+
#[cfg(feature = "use-rustls-no-provider")]
44
use tokio_rustls::rustls::{
55
self,
66
pki_types::{InvalidDnsNameError, ServerName},
77
ClientConfig, RootCertStore,
88
};
9-
#[cfg(feature = "use-rustls")]
9+
#[cfg(feature = "use-rustls-no-provider")]
1010
use tokio_rustls::TlsConnector as RustlsConnector;
1111

12-
#[cfg(feature = "use-rustls")]
12+
#[cfg(feature = "use-rustls-no-provider")]
1313
use std::convert::TryFrom;
14-
#[cfg(feature = "use-rustls")]
14+
#[cfg(feature = "use-rustls-no-provider")]
1515
use std::io::{BufReader, Cursor};
16-
#[cfg(feature = "use-rustls")]
16+
#[cfg(feature = "use-rustls-no-provider")]
1717
use std::sync::Arc;
1818

1919
use crate::framed::AsyncReadWrite;
@@ -36,27 +36,27 @@ pub enum Error {
3636
/// I/O related error
3737
#[error("I/O: {0}")]
3838
Io(#[from] io::Error),
39-
#[cfg(feature = "use-rustls")]
39+
#[cfg(feature = "use-rustls-no-provider")]
4040
/// Certificate/Name validation error
4141
#[error("Web Pki: {0}")]
4242
WebPki(#[from] webpki::Error),
4343
/// Invalid DNS name
44-
#[cfg(feature = "use-rustls")]
44+
#[cfg(feature = "use-rustls-no-provider")]
4545
#[error("DNS name")]
4646
DNSName(#[from] InvalidDnsNameError),
47-
#[cfg(feature = "use-rustls")]
47+
#[cfg(feature = "use-rustls-no-provider")]
4848
/// Error from rustls module
4949
#[error("TLS error: {0}")]
5050
TLS(#[from] rustls::Error),
51-
#[cfg(feature = "use-rustls")]
51+
#[cfg(feature = "use-rustls-no-provider")]
5252
/// No valid CA cert found
5353
#[error("No valid CA certificate provided")]
5454
NoValidCertInChain,
55-
#[cfg(feature = "use-rustls")]
55+
#[cfg(feature = "use-rustls-no-provider")]
5656
/// No valid client cert found
5757
#[error("No valid certificate for client authentication in chain")]
5858
NoValidClientCertInChain,
59-
#[cfg(feature = "use-rustls")]
59+
#[cfg(feature = "use-rustls-no-provider")]
6060
/// No valid key found
6161
#[error("No valid key in chain")]
6262
NoValidKeyInChain,
@@ -65,7 +65,7 @@ pub enum Error {
6565
NativeTls(#[from] NativeTlsError),
6666
}
6767

68-
#[cfg(feature = "use-rustls")]
68+
#[cfg(feature = "use-rustls-no-provider")]
6969
pub async fn rustls_connector(tls_config: &TlsConfiguration) -> Result<RustlsConnector, Error> {
7070
let config = match tls_config {
7171
TlsConfiguration::Simple {
@@ -170,7 +170,7 @@ pub async fn tls_connect(
170170
tcp: Box<dyn AsyncReadWrite>,
171171
) -> Result<Box<dyn AsyncReadWrite>, Error> {
172172
let tls: Box<dyn AsyncReadWrite> = match tls_config {
173-
#[cfg(feature = "use-rustls")]
173+
#[cfg(feature = "use-rustls-no-provider")]
174174
TlsConfiguration::Simple { .. } | TlsConfiguration::Rustls(_) => {
175175
let connector = rustls_connector(tls_config).await?;
176176
let domain = ServerName::try_from(addr)?.to_owned();

0 commit comments

Comments
 (0)