Skip to content

Commit

Permalink
Expose and forward rustls default features
Browse files Browse the repository at this point in the history
tls12 and logging are rustls features we enable by default,
as does rustls, exposing them explicitly allows users
to disable them by disabling hyper-rustls default features.

Make sure tests run with tls12 by enabling it in dev-dependencies,
because windows tests (at least in CI) seem to run with an outdated
version of curl that doesn't support TLS 1.3.
  • Loading branch information
g2p committed Nov 8, 2021
1 parent 5ff82f0 commit 413b73a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@ homepage = "https://github.com/ctz/hyper-rustls"
repository = "https://github.com/ctz/hyper-rustls"

[dependencies]
log = "0.4.4"
http = "0.2"
hyper = { version = "0.14", default-features = false, features = ["client"] }
rustls = "0.20"
log = { version = "0.4.4", optional = true }
rustls-native-certs = { version = "0.6", optional = true }
rustls = { version = "0.20", default-features = false }
tokio = "1.0"
tokio-rustls = "0.23"
tokio-rustls = { version = "0.23", default-features = false }
webpki-roots = { version = "0.22", optional = true }

[dev-dependencies]
async-stream = "0.3.0"
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }
hyper = { version = "0.14", features = ["full"] }
futures-util = { version = "0.3.1", default-features = false }
hyper = { version = "0.14", features = ["full"] }
rustls = { version = "0.20", default-features = false, features = ["tls12"] }
rustls-pemfile = "0.2.1"
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }

[features]
default = ["native-tokio", "http1"]
default = ["native-tokio", "http1", "tls12", "logging"]
http1 = ["hyper/http1"]
http2 = ["hyper/http2"]
webpki-tokio = ["tokio-runtime", "webpki-roots"]
native-tokio = ["tokio-runtime", "rustls-native-certs"]
tokio-runtime = ["hyper/runtime"]
tls12 = ["tokio-rustls/tls12", "rustls/tls12"]
logging = ["log", "tokio-rustls/logging", "rustls/logging"]

[[example]]
name = "client"
Expand Down
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub trait ConfigBuilderExt {
impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
#[cfg(feature = "rustls-native-certs")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))]
#[cfg_attr(not(feature = "logging"), allow(unused_variables))]
fn with_native_roots(self) -> ClientConfig {
let mut roots = rustls::RootCertStore::empty();
let mut valid_count = 0;
Expand All @@ -32,13 +33,13 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
match roots.add(&cert) {
Ok(_) => valid_count += 1,
Err(err) => {
log::trace!("invalid cert der {:?}", cert.0);
log::debug!("certificate parsing failed: {:?}", err);
crate::log::trace!("invalid cert der {:?}", cert.0);
crate::log::debug!("certificate parsing failed: {:?}", err);
invalid_count += 1
}
}
}
log::debug!(
crate::log::debug!(
"with_native_roots processed {} valid and {} invalid certs",
valid_count, invalid_count
);
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ mod config;
mod connector;
mod stream;

#[cfg(feature = "logging")]
mod log {
pub use log::{debug, trace};
}

#[cfg(not(feature = "logging"))]
mod log {
macro_rules! trace ( ($($tt:tt)*) => {{}} );
macro_rules! debug ( ($($tt:tt)*) => {{}} );
pub(crate) use {debug, trace};
}

pub use crate::config::ConfigBuilderExt;
pub use crate::connector::builder::ConnectorBuilder as HttpsConnectorBuilder;
pub use crate::connector::HttpsConnector;
Expand Down

0 comments on commit 413b73a

Please sign in to comment.