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

Update to allow use of webpki-roots where rustls-native-certs fails. #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ before_script:

script:
- cargo test
- cargo test --all-features
- cargo test --no-default-features --features native-tokio
- cargo test --no-default-features --features webpki-tokio
- cargo test --no-default-features
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "$CLIPPY_RUST_VERSION" ]]; then
cargo clippy -- -D warnings;
Expand Down
25 changes: 14 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ homepage = "https://github.com/ctz/hyper-rustls"
repository = "https://github.com/ctz/hyper-rustls"

[dependencies]
bytes = "0.5.2"
ct-logs = { version = "^0.6.0", optional = true }
futures-util = "0.3.1"
hyper = { version = "0.13.0", default-features = false }
bytes = "0.5"
ct-logs = { version = "0.6", optional = true }
futures-util = "0.3"
hyper = { version = "0.13", default-features = false }
rustls = "0.16"
tokio = "0.2.4"
tokio-rustls = "0.12.1"
webpki = "^0.21.0"
rustls-native-certs = { version = "^0.1.0", optional = true }
rustls-native-certs = { version = "0.1", optional = true }
tokio = "0.2"
tokio-rustls = "0.12"
webpki = "0.21"
webpki-roots = { version = "0.18", optional = true }

[dev-dependencies]
tokio = { version = "0.2.4", features = ["io-std", "macros", "dns", "stream"] }
tokio = { version = "0.2", features = ["io-std", "macros", "dns", "stream"] }

[features]
default = ["tokio-runtime"]
tokio-runtime = ["hyper/runtime", "ct-logs", "rustls-native-certs"]
default = ["native-tokio"]
webpki-tokio = ["tokio-runtime", "webpki-roots"]
native-tokio = ["tokio-runtime", "rustls-native-certs"]
tokio-runtime = ["hyper/runtime", "ct-logs"]

[[example]]
name = "client"
Expand Down
4 changes: 2 additions & 2 deletions admin/pipelines/cargo-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ steps:
- script: cargo test
displayName: "cargo test (debug; default features)"
env: { "RUST_BACKTRACE": "1" }
- script: cargo test --all-features
displayName: "cargo test (debug; all features)"
- script: cargo test --no-default-features --features webpki-tokio
displayName: "cargo test (debug; webpi-roots feature)"
env: { "RUST_BACKTRACE": "1" }
- script: cargo test --no-default-features
displayName: "cargo build (debug; no default features)"
Expand Down
17 changes: 13 additions & 4 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct HttpsConnector<T> {
tls_config: Arc<ClientConfig>,
}

#[cfg(feature = "tokio-runtime")]
#[cfg(all(any(feature = "rustls-native-certs", feature = "webpki-roots"), feature = "tokio-runtime"))]
impl HttpsConnector<HttpConnector> {
/// Construct a new `HttpsConnector`.
///
Expand All @@ -33,8 +33,17 @@ impl HttpsConnector<HttpConnector> {
http.enforce_http(false);
let mut config = ClientConfig::new();
config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
config.root_store = rustls_native_certs::load_native_certs()
.expect("cannot access native cert store");
#[cfg(feature = "rustls-native-certs")]
{
config.root_store = rustls_native_certs::load_native_certs()
.expect("cannot access native cert store");
}
#[cfg(feature = "webpki-roots")]
{
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
}
config.ct_logs = Some(&ct_logs::LOGS);
HttpsConnector {
http,
Expand All @@ -43,7 +52,7 @@ impl HttpsConnector<HttpConnector> {
}
}

#[cfg(feature = "tokio-runtime")]
#[cfg(all(any(feature = "rustls-native-certs", feature = "webpki-roots"), feature = "tokio-runtime"))]
impl Default for HttpsConnector<HttpConnector> {
fn default() -> Self {
Self::new()
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! ## Example
//!
//! ```no_run
//! # #[cfg(feature = "tokio-runtime")]
//! # #[cfg(all(any(feature = "rustls-native-certs", feature = "webpki-roots"), feature = "tokio-runtime"))]
//! # fn main() {
//! use hyper::{Body, Client, StatusCode, Uri};
//!
Expand All @@ -22,6 +22,15 @@
//! # fn main() {}
//! ```

#[cfg(all(
feature = "tokio-runtime",
any(not(feature = "rustls-native-certs"), feature = "webpki-roots"),
any(not(feature = "webpki-roots"), feature = "rustls-native-certs")
))]
compile_error!(
"Must enable exactly one of rustls-native-certs (default) or webpki-roots with tokio-runtime! (note: use `default-features = false' in a binary crate for one or other)"
);

mod connector;
mod stream;

Expand Down