Skip to content

Commit bd5da5a

Browse files
calaveraseanmonstar
authored andcommitted
feat: make Rustls the default TLS provider. (#2752)
* feat: Make Rustls the default TLS provider. This switches the default TLS provider to Rustls. It keeps the `native-tls` feature with the same configuration it had before as the default TLS provider. * fix: Fix TlsBackend default options. * fix: Remove hyper-tls from the default-tls feature. It's not used by Rustls. * fix: Update precise dependencies to run MSRV. * fix: Make explicit the dependency version for aws-lc-sys. This allows Reqwest to build on nightly with a version of aws-lc-sys that works and still maintains MSRV. * fix: Use aws-lc-rs as provider when both ring and aws-lc-rs are enabled. This should be a corner case since only one feature should be enable at a time, but some checks enable all features. Favor aws-lc-rs when all features are enabled. * fix: Fix feature config formatting. * fix: Reverse precise dep ordering. This ensures that the MSRV for all dependencies are met. * fix: Pin hyper-rustls precise version. * fix: Build `default_rustls_crypto_provider` only when rustls is enabled. * fix: Make rustls-tls feature work without default-tls. * fix: Remove unused dependency. Update the MSRV check to use precise dependency versions. * fix: Install Crypto Provider to run the HTTP3 tests. Since both Ring and AWS-LC-RS are supported, we need to explicitly install the correct Crypto Provider before configuring the server. * fix: Update nightly run with the precise version of aws-lc-sys. * fix: Use prebuilt NASM compiled code on Windows. See: https://github.com/aws/aws-lc-rs/blob/f0a6350abb247b413ffbf8ae8d8e1eb3bb1d4e66/aws-lc-sys/README.md?plain=1#L37 * fix: Update the precise version of aws-lc-rs for nightly builds. * fix: Update all Windows targets to use prebuilt nasm binaries. * fix: Set LIBCLANG_PATH for windows builds. * fix: Install clang and nasm on Windows i686. * fix: Run macman.exe after adding it to the path. * fix: Add clang and nasm for Windows x86_64 GNU.
1 parent 74e6f84 commit bd5da5a

File tree

6 files changed

+152
-80
lines changed

6 files changed

+152
-80
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ jobs:
5656

5757
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
5858

59+
env:
60+
AWS_LC_SYS_PREBUILT_NASM: ${{ matrix.aws_lc_sys_prebuilt_nasm || 0 }}
61+
5962
# The build matrix does not yet support 'allow failures' at job level.
6063
# See `jobs.nightly` for the active nightly job definition.
6164
strategy:
@@ -103,24 +106,28 @@ jobs:
103106
os: windows-latest
104107
target: x86_64-pc-windows-msvc
105108
features: "--features blocking,gzip,brotli,zstd,deflate,json,multipart,stream"
109+
aws_lc_sys_prebuilt_nasm: 1
106110
- name: windows / stable-i686-msvc
107111
os: windows-latest
108112
target: i686-pc-windows-msvc
109113
features: "--features blocking,gzip,brotli,zstd,deflate,json,multipart,stream"
114+
aws_lc_sys_prebuilt_nasm: 1
110115
- name: windows / stable-x86_64-gnu
111116
os: windows-latest
112117
rust: stable-x86_64-pc-windows-gnu
113118
target: x86_64-pc-windows-gnu
114119
features: "--features blocking,gzip,brotli,zstd,deflate,json,multipart,stream"
115120
package_name: mingw-w64-x86_64-gcc
116121
mingw64_path: "C:\\msys64\\mingw64\\bin"
122+
aws_lc_sys_prebuilt_nasm: 1
117123
- name: windows / stable-i686-gnu
118124
os: windows-latest
119125
rust: stable-i686-pc-windows-gnu
120126
target: i686-pc-windows-gnu
121127
features: "--features blocking,gzip,brotli,zstd,deflate,json,multipart,stream"
122128
package_name: mingw-w64-i686-gcc
123129
mingw64_path: "C:\\msys64\\mingw32\\bin"
130+
aws_lc_sys_prebuilt_nasm: 1
124131

125132
- name: "feat.: default-tls disabled"
126133
features: "--no-default-features"
@@ -182,6 +189,26 @@ jobs:
182189
if: matrix.mingw64_path
183190
shell: bash
184191

192+
- name: Install i686 Clang & NASM
193+
if: ${{ matrix.target == 'i686-pc-windows-gnu' }}
194+
run: pacman.exe -Sy --noconfirm mingw-w64-i686-clang mingw-w64-i686-nasm
195+
shell: bash
196+
197+
- name: Install x86_64 Clang & NASM
198+
if: ${{ matrix.target == 'x86_64-pc-windows-gnu' }}
199+
run: pacman.exe -Sy --noconfirm mingw-w64-x86_64-clang mingw-w64-x86_64-nasm
200+
shell: bash
201+
202+
- name: Add libclang to the environment for windows i686-gnu
203+
run: echo "LIBCLANG_PATH=C:\msys64\mingw32\bin" >> $env:GITHUB_ENV
204+
if: ${{ matrix.target == 'i686-pc-windows-gnu' }}
205+
shell: bash
206+
207+
- name: Add libclang to the environment for windows x86_64-gnu
208+
run: echo "LIBCLANG_PATH=C:\msys64\mingw64\bin" >> $env:GITHUB_ENV
209+
if: ${{ matrix.target == 'x86_64-pc-windows-gnu' }}
210+
shell: bash
211+
185212
- name: Update gcc
186213
if: matrix.package_name
187214
run: pacman.exe -Sy --noconfirm ${{ matrix.package_name }}
@@ -219,7 +246,7 @@ jobs:
219246
- uses: Swatinem/rust-cache@v2
220247

221248
- name: check --feature-powerset
222-
run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --skip http3,__tls,__rustls,__rustls-ring,native-tls-vendored,trust-dns
249+
run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --skip http3,__tls,__rustls,__rustls-ring,__rustls-aws-lc-rs,native-tls-vendored,trust-dns
223250
env:
224251
RUSTFLAGS: "-D dead_code -D unused_imports"
225252

@@ -284,6 +311,8 @@ jobs:
284311
cargo clean
285312
cargo update -Z minimal-versions
286313
cargo update -p proc-macro2 --precise 1.0.87
314+
cargo update -p aws-lc-rs --precise 1.13.1
315+
cargo update -p aws-lc-sys --precise 0.29.0
287316
cargo update -p openssl-sys
288317
cargo update -p openssl
289318
cargo check
@@ -314,6 +343,23 @@ jobs:
314343
with:
315344
toolchain: ${{ steps.metadata.outputs.msrv }}
316345

346+
- name: Fix dependency versions
347+
run: |
348+
cargo update
349+
cargo update -p log --precise 0.4.18
350+
cargo update -p tokio --precise 1.29.1
351+
cargo update -p tokio-util --precise 0.7.11
352+
cargo update -p idna_adapter --precise 1.1.0
353+
cargo update -p hashbrown --precise 0.15.0
354+
cargo update -p native-tls --precise 0.2.13
355+
cargo update -p once_cell --precise 1.20.3
356+
cargo update -p tracing-core --precise 0.1.33
357+
cargo update -p hyper-rustls --precise 0.27.2
358+
cargo update -p tokio-rustls --precise 0.26.0
359+
cargo update -p rustls --precise 0.23.19
360+
cargo update -p aws-lc-rs --precise 1.13.1
361+
cargo update -p aws-lc-sys --precise 0.29.0
362+
317363
- uses: Swatinem/rust-cache@v2
318364

319365
- name: Check

Cargo.toml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ features = [
3636
[features]
3737
default = ["default-tls", "charset", "http2", "system-proxy"]
3838

39-
# Note: this doesn't enable the 'native-tls' feature, which adds specific
40-
# functionality for it.
41-
default-tls = ["dep:hyper-tls", "dep:native-tls-crate", "__tls", "dep:tokio-native-tls"]
39+
default-tls = ["rustls-tls"]
4240

4341
http2 = ["h2", "hyper/http2", "hyper-util/http2", "hyper-rustls?/http2"]
4442

45-
# Enables native-tls specific functionality not available by default.
46-
native-tls = ["default-tls"]
43+
native-tls = ["dep:hyper-tls", "dep:native-tls-crate", "__tls", "dep:tokio-native-tls"]
4744
native-tls-alpn = ["native-tls", "native-tls-crate?/alpn", "hyper-tls?/alpn"]
4845
native-tls-vendored = ["native-tls", "native-tls-crate?/vendored"]
4946

@@ -54,9 +51,9 @@ rustls-tls-manual-roots-no-provider = ["__rustls"]
5451
rustls-tls-webpki-roots-no-provider = ["dep:webpki-roots", "hyper-rustls?/webpki-tokio", "__rustls"]
5552
rustls-tls-native-roots-no-provider = ["dep:rustls-native-certs", "hyper-rustls?/native-tokio", "__rustls"]
5653

57-
rustls-tls-manual-roots = ["rustls-tls-manual-roots-no-provider", "__rustls-ring"]
58-
rustls-tls-webpki-roots = ["rustls-tls-webpki-roots-no-provider", "__rustls-ring"]
59-
rustls-tls-native-roots = ["rustls-tls-native-roots-no-provider", "__rustls-ring"]
54+
rustls-tls-manual-roots = ["rustls-tls-manual-roots-no-provider", "__rustls-aws-lc-rs"]
55+
rustls-tls-webpki-roots = ["rustls-tls-webpki-roots-no-provider", "__rustls-aws-lc-rs"]
56+
rustls-tls-native-roots = ["rustls-tls-native-roots-no-provider", "__rustls-aws-lc-rs"]
6057

6158
blocking = ["dep:futures-channel", "futures-channel?/sink", "dep:futures-util", "futures-util?/io", "futures-util?/sink", "tokio/sync"]
6259

@@ -104,6 +101,7 @@ __tls = ["dep:rustls-pki-types", "tokio/io-util"]
104101
# Equivalent to rustls-tls-manual-roots but shorter :)
105102
__rustls = ["dep:hyper-rustls", "dep:tokio-rustls", "dep:rustls", "__tls"]
106103
__rustls-ring = ["hyper-rustls?/ring", "tokio-rustls?/ring", "rustls?/ring", "quinn?/ring"]
104+
__rustls-aws-lc-rs = ["hyper-rustls?/aws-lc-rs", "tokio-rustls?/aws-lc-rs", "rustls?/aws-lc-rs", "quinn?/aws-lc-rs"]
107105

108106
[dependencies]
109107
base64 = "0.22"
@@ -142,12 +140,12 @@ pin-project-lite = "0.2.11"
142140
rustls-pki-types = { version = "1.9.0", features = ["std"], optional = true }
143141
mime = { version = "0.3.16", optional = true }
144142

145-
## default-tls
143+
# native-tls
146144
hyper-tls = { version = "0.6", optional = true }
147145
native-tls-crate = { version = "0.2.10", optional = true, package = "native-tls" }
148146
tokio-native-tls = { version = "0.3.0", optional = true }
149147

150-
# rustls-tls
148+
# default-tls and rustls-tls
151149
hyper-rustls = { version = "0.27.0", default-features = false, optional = true, features = ["http1", "tls12"] }
152150
rustls = { version = "0.23.4", optional = true, default-features = false, features = ["std", "tls12"] }
153151
tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["tls12"] }

src/async_impl/client.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use http::header::{
5151
use http::uri::Scheme;
5252
use http::Uri;
5353
use hyper_util::client::legacy::connect::HttpConnector;
54-
#[cfg(feature = "default-tls")]
54+
#[cfg(feature = "native-tls")]
5555
use native_tls_crate::TlsConnector;
5656
use pin_project_lite::pin_project;
5757
#[cfg(feature = "http3")]
@@ -487,8 +487,8 @@ impl ClientBuilder {
487487

488488
#[cfg(feature = "__tls")]
489489
match config.tls {
490-
#[cfg(feature = "default-tls")]
491-
TlsBackend::Default => {
490+
#[cfg(feature = "native-tls")]
491+
TlsBackend::NativeTls => {
492492
let mut tls = TlsConnector::builder();
493493

494494
#[cfg(all(feature = "native-tls-alpn", not(feature = "http3")))]
@@ -554,7 +554,7 @@ impl ClientBuilder {
554554
tls.max_protocol_version(Some(protocol));
555555
}
556556

557-
ConnectorBuilder::new_default_tls(
557+
ConnectorBuilder::new_native_tls(
558558
http,
559559
tls,
560560
proxies.clone(),
@@ -578,7 +578,7 @@ impl ClientBuilder {
578578
)?
579579
}
580580
#[cfg(feature = "native-tls")]
581-
TlsBackend::BuiltNativeTls(conn) => ConnectorBuilder::from_built_default_tls(
581+
TlsBackend::BuiltNativeTls(conn) => ConnectorBuilder::from_built_native_tls(
582582
http,
583583
conn,
584584
proxies.clone(),
@@ -725,13 +725,7 @@ impl ClientBuilder {
725725
// If not, we use ring.
726726
let provider = rustls::crypto::CryptoProvider::get_default()
727727
.map(|arc| arc.clone())
728-
.unwrap_or_else(|| {
729-
#[cfg(not(feature = "__rustls-ring"))]
730-
panic!("No provider set");
731-
732-
#[cfg(feature = "__rustls-ring")]
733-
Arc::new(rustls::crypto::ring::default_provider())
734-
});
728+
.unwrap_or_else(default_rustls_crypto_provider);
735729

736730
// Build TLS config
737731
let signature_algorithms = provider.signature_verification_algorithms;
@@ -2014,7 +2008,7 @@ impl ClientBuilder {
20142008
#[cfg(feature = "native-tls")]
20152009
#[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
20162010
pub fn use_native_tls(mut self) -> ClientBuilder {
2017-
self.config.tls = TlsBackend::Default;
2011+
self.config.tls = TlsBackend::NativeTls;
20182012
self
20192013
}
20202014

@@ -2367,6 +2361,18 @@ impl Default for Client {
23672361
}
23682362
}
23692363

2364+
#[cfg(feature = "__rustls")]
2365+
fn default_rustls_crypto_provider() -> Arc<rustls::crypto::CryptoProvider> {
2366+
#[cfg(not(any(feature = "__rustls-ring", feature = "__rustls-aws-lc-rs")))]
2367+
panic!("No provider set");
2368+
2369+
#[cfg(all(feature = "__rustls-ring", not(feature = "__rustls-aws-lc-rs")))]
2370+
return Arc::new(rustls::crypto::ring::default_provider());
2371+
2372+
#[cfg(feature = "__rustls-aws-lc-rs")]
2373+
Arc::new(rustls::crypto::aws_lc_rs::default_provider())
2374+
}
2375+
23702376
impl Client {
23712377
/// Constructs a new `Client`.
23722378
///

0 commit comments

Comments
 (0)