From e45e600de9eb06a4fe47a3b12513dde900043a24 Mon Sep 17 00:00:00 2001 From: Justin Miron Date: Sat, 22 Jan 2022 20:36:29 +0000 Subject: [PATCH 1/4] Make rustls-tls an optional feature for reqwest. rustls-tls includes a dependency that has a license considered copyleft (MPL-2.0). To make this library more sound to use under the MIT license, make rustls-tls an optional feature. This removes the ability to specify client certs when the `rustls-tls` feature is disabled. However, tls is enabled with reqwests defaults by default. --- Cargo.toml | 6 +++++- src/client.rs | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0d849ff..4c48cf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ base64 = "0.13.0" consulrs_derive = { version = "0.1.0", path = "consulrs_derive" } derive_builder = "0.10.2" http = "0.2.5" -reqwest = { version = "0.11.4", default-features = false, features = ["rustls-tls"] } +reqwest = { version = "0.11.4", default-features = false } rustify = "0.5.2" rustify_derive = "0.5.2" serde = "1.0.130" @@ -38,3 +38,7 @@ test-log = { version = "0.2.8", features = ["trace"] } tokio = { version = "1.12.0", features = ["full"] } tokio-test = "0.4.2" tracing-subscriber = {version = "0.2.17", default-features = false, features = ["env-filter", "fmt"]} + +[features] +default = ["reqwest/default-tls"] +rustls-tls = ["reqwest/rustls-tls"] diff --git a/src/client.rs b/src/client.rs index 1dc6053..7b8813f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -80,7 +80,8 @@ impl ConsulClient { http_client = http_client.add_root_certificate(cert); } - // Add client certificate + // Add support for client certificates if rustls-tls is enabled. + #[cfg(feature = "rustls-tls")] if let (Some(cert), Some(key)) = (&settings.client_cert, &settings.client_key) { let cert_content = std::fs::read_to_string(&cert).map_err(|e| ClientError::FileReadError { @@ -122,8 +123,8 @@ impl ConsulClient { /// /// * `address`: CONSUL_HTTP_ADDR /// * `ca_certs`: CONSUL_CACERT / CONSUL_CAPATH -/// * `client_cert`: CONSUL_CLIENT_CERT -/// * `client_key`: CONSUL_CLIENT_KEY +/// * `client_cert`: CONSUL_CLIENT_CERT, requires `rustls-tls` feature. +/// * `client_key`: CONSUL_CLIENT_KEY, requires `rustls-tls` feature. /// * `token`: CONSUL_HTTP_TOKEN /// * `verify`: CONSUL_HTTP_SSL_VERIFY /// @@ -136,8 +137,10 @@ pub struct ConsulClientSettings { pub address: String, #[builder(default = "self.default_ca_certs()")] pub ca_certs: Vec, + #[cfg(feature = "rustls-tls")] #[builder(default = "self.default_client_cert()")] pub client_cert: Option, + #[cfg(feature = "rustls-tls")] #[builder(default = "self.default_client_key()")] pub client_key: Option, #[builder(setter(into), default = "self.default_token()")] @@ -182,6 +185,7 @@ impl ConsulClientSettingsBuilder { paths } + #[cfg(feature = "rustls-tls")] fn default_client_cert(&self) -> Option { match env::var("CONSUL_CLIENT_CERT") { Ok(s) => { @@ -195,6 +199,7 @@ impl ConsulClientSettingsBuilder { } } + #[cfg(feature = "rustls-tls")] fn default_client_key(&self) -> Option { match env::var("CONSUL_CLIENT_KEY") { Ok(s) => { From 13fd34aed69c315bc536805bfcad15f4500d7891 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 22 Feb 2023 09:34:40 -0500 Subject: [PATCH 2/4] Update Cargo.toml Co-authored-by: Gabi Moldovan <15640520+gabi-250@users.noreply.github.com> --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4c48cf1..75d033e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,4 @@ tracing-subscriber = {version = "0.2.17", default-features = false, features = [ [features] default = ["reqwest/default-tls"] -rustls-tls = ["reqwest/rustls-tls"] +rustls-tls = ["reqwest/rustls-tls", "rustify/rustls-tls"] From 7313d2a0c694c540131085a4e6c1e667b537dce2 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 22 Feb 2023 09:34:46 -0500 Subject: [PATCH 3/4] Update Cargo.toml Co-authored-by: Gabi Moldovan <15640520+gabi-250@users.noreply.github.com> --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 75d033e..50b3ea5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ consulrs_derive = { version = "0.1.0", path = "consulrs_derive" } derive_builder = "0.10.2" http = "0.2.5" reqwest = { version = "0.11.4", default-features = false } -rustify = "0.5.2" +rustify = { version = "0.5.2", default-features = false } rustify_derive = "0.5.2" serde = "1.0.130" serde_json = "1.0.66" From e8bfaaf30fa00e0d5569351a8a74b402faf6933c Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 22 Feb 2023 09:34:51 -0500 Subject: [PATCH 4/4] Update Cargo.toml Co-authored-by: Gabi Moldovan <15640520+gabi-250@users.noreply.github.com> --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 50b3ea5..a384408 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,5 +40,5 @@ tokio-test = "0.4.2" tracing-subscriber = {version = "0.2.17", default-features = false, features = ["env-filter", "fmt"]} [features] -default = ["reqwest/default-tls"] +default = ["reqwest/default-tls", "rustify/default"] rustls-tls = ["reqwest/rustls-tls", "rustify/rustls-tls"]