Skip to content

Commit 8a939c7

Browse files
authored
polyfill with_native_roots in hyper_legacy to avoid RUSTSEC-2025-0134 (#4441)
2 parents 5e55a7c + e3a560a commit 8a939c7

8 files changed

Lines changed: 93 additions & 53 deletions

File tree

.changelog/1765121185.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
applies_to:
3+
- client
4+
- aws-sdk-rust
5+
authors:
6+
- arielb1
7+
references:
8+
- aws-sdk-rust#1390
9+
breaking: false
10+
new_feature: false
11+
bug_fix: true
12+
---
13+
In `legacy-rustls-ring`, polyfill `with_native_roots` to use `rustls_native_certs 0.8` to avoid
14+
RUSTSEC-2025-0134.

.github/workflows/ci.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
# These correspond to scripts in tools/ci-scripts that will be run in the Docker build image
8989
test:
9090
- action: check-aws-sdk-adhoc-tests
91-
runner: ubuntu-latest
91+
runner: smithy_ubuntu-latest_8-core
9292
- action: check-client-codegen-integration-tests
9393
runner: smithy_ubuntu-latest_8-core
9494
- action: check-client-codegen-unit-tests
@@ -101,31 +101,31 @@ jobs:
101101
- action: check-sdk-codegen-unit-tests
102102
runner: smithy_ubuntu-latest_8-core
103103
- action: check-fuzzgen
104-
runner: ubuntu-latest
104+
runner: smithy_ubuntu-latest_8-core
105105
- action: check-server-codegen-integration-tests
106106
runner: smithy_ubuntu-latest_8-core
107107
- action: check-server-codegen-integration-tests-python
108-
runner: ubuntu-latest
108+
runner: smithy_ubuntu-latest_8-core
109109
- action: check-server-codegen-unit-tests
110-
runner: ubuntu-latest
110+
runner: smithy_ubuntu-latest_8-core
111111
- action: check-server-codegen-unit-tests-python
112-
runner: ubuntu-latest
112+
runner: smithy_ubuntu-latest_8-core
113113
- action: check-serde-codegen-unit-tests
114-
runner: ubuntu-latest
114+
runner: smithy_ubuntu-latest_8-core
115115
- action: check-server-e2e-test
116-
runner: ubuntu-latest
116+
runner: smithy_ubuntu-latest_8-core
117117
- action: check-server-python-e2e-test
118-
runner: ubuntu-latest
118+
runner: smithy_ubuntu-latest_8-core
119119
- action: check-style-and-lints
120-
runner: ubuntu-latest
120+
runner: smithy_ubuntu-latest_8-core
121121
- action: check-book
122-
runner: ubuntu-latest
122+
runner: smithy_ubuntu-latest_8-core
123123
- action: check-tools
124124
runner: smithy_ubuntu-latest_8-core
125125
- action: check-deterministic-codegen
126126
runner: smithy_ubuntu-latest_8-core
127127
- action: check-codegen-version
128-
runner: ubuntu-latest
128+
runner: smithy_ubuntu-latest_8-core
129129
steps:
130130
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
131131
- uses: actions/checkout@v4
@@ -177,19 +177,19 @@ jobs:
177177
- action: check-aws-config
178178
runner: smithy_ubuntu-latest_8-core
179179
- action: check-aws-sdk-canary
180-
runner: ubuntu-latest
180+
runner: smithy_ubuntu-latest_8-core
181181
- action: check-aws-sdk-cargo-deny
182-
runner: ubuntu-latest
182+
runner: smithy_ubuntu-latest_8-core
183183
- action: check-only-aws-sdk-services
184184
runner: smithy_ubuntu-latest_8-core
185185
- action: check-aws-sdk-smoketest-docs-clippy-udeps
186186
runner: smithy_ubuntu-latest_8-core
187187
- action: check-aws-sdk-smoketest-unit-tests
188188
runner: smithy_ubuntu-latest_8-core
189189
- action: check-aws-sdk-standalone-integration-tests
190-
runner: ubuntu-latest
190+
runner: smithy_ubuntu-latest_8-core
191191
- action: check-aws-sdk-benchmarks
192-
runner: ubuntu-latest
192+
runner: smithy_ubuntu-latest_8-core
193193
steps:
194194
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
195195
- uses: actions/checkout@v4

aws/rust-runtime/Cargo.lock

Lines changed: 12 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tracing = "0.1.40"
2222
# cargo does not support optional test dependencies, so to completely disable rustls
2323
# we need to add the webpki-roots feature here.
2424
# https://github.com/rust-lang/cargo/issues/1596
25-
hyper-rustls = { version = "0.24", optional = true, features = ["rustls-native-certs", "http2", "webpki-roots"] }
25+
hyper-rustls = { version = "0.24.2", optional = true, default-features = false, features = ["http2", "webpki-roots"] }
2626

2727
[dev-dependencies]
2828
http = "0.2.4"

codegen-server-test/integration-tests/Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-runtime/aws-smithy-http-client/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ legacy-test-util = [
6565
"aws-smithy-types/http-body-0-4-x",
6666
]
6767

68-
legacy-rustls-ring = ["dep:legacy-hyper-rustls", "dep:legacy-rustls", "hyper-014"]
68+
legacy-rustls-ring = ["dep:legacy-hyper-rustls", "dep:legacy-rustls", "dep:rustls-native-certs", "hyper-014"]
6969

7070
rustls-ring = ["dep:rustls", "rustls?/ring", "dep:hyper-rustls", "dep:tokio-rustls", "default-client"]
7171
rustls-aws-lc = ["dep:rustls", "rustls?/aws_lc_rs", "rustls?/prefer-post-quantum", "dep:hyper-rustls", "dep:tokio-rustls", "default-client"]
@@ -103,7 +103,7 @@ rustls-native-certs = { version = "0.8.1", optional = true }
103103
http-02x = { package = "http", version = "0.2.9", optional = true}
104104
http-body-04x = { package = "http-body", version = "0.4.5" , optional = true}
105105
hyper-0-14 = { package = "hyper", version = "0.14.26", default-features = false, features = ["client", "http1", "http2", "tcp", "stream"], optional = true }
106-
legacy-hyper-rustls = { package = "hyper-rustls", version = "0.24", features = ["rustls-native-certs", "http2"], optional = true }
106+
legacy-hyper-rustls = { package = "hyper-rustls", version = "0.24.2", default-features = false, features = ["http1", "tls12", "logging", "acceptor", "tokio-runtime", "http2"], optional = true }
107107
legacy-rustls = { package = "rustls", version = "0.21.8", optional = true }
108108
h2-0-3 = { package = "h2", version = "0.3.24", optional = true }
109109
# end legacy stack deps

rust-runtime/aws-smithy-http-client/src/hyper_legacy.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,43 @@ mod default_connector {
4949
> = LazyLock::new(default_tls);
5050

5151
fn default_tls() -> hyper_rustls::HttpsConnector<hyper_0_14::client::HttpConnector> {
52-
use hyper_rustls::ConfigBuilderExt;
52+
use legacy_rustls::client::WantsTransparencyPolicyOrClientCert;
53+
use legacy_rustls::{ClientConfig, ConfigBuilder, WantsVerifier};
54+
use rustls_native_certs;
55+
// polyfill with_native_roots from https://docs.rs/hyper-rustls/0.24.2/src/hyper_rustls/config.rs.html#22-70
56+
// to use the new rustls_native_certs, since rustls_native_certs 0.6 depends on rustls-pemfile which is deprecated
57+
fn with_native_roots(
58+
this: ConfigBuilder<ClientConfig, WantsVerifier>,
59+
) -> ConfigBuilder<ClientConfig, WantsTransparencyPolicyOrClientCert> {
60+
let mut roots = rustls::RootCertStore::empty();
61+
let mut valid_count = 0;
62+
let mut invalid_count = 0;
63+
64+
for cert in
65+
rustls_native_certs::load_native_certs().expect("could not load platform certs")
66+
{
67+
let cert = rustls::Certificate(cert.to_vec());
68+
match roots.add(&cert) {
69+
Ok(_) => valid_count += 1,
70+
Err(err) => {
71+
tracing::trace!("invalid cert der {:?}", cert.0);
72+
tracing::debug!("certificate parsing failed: {:?}", err);
73+
invalid_count += 1
74+
}
75+
}
76+
}
77+
tracing::debug!(
78+
"with_native_roots processed {} valid and {} invalid certs",
79+
valid_count,
80+
invalid_count
81+
);
82+
assert!(!roots.is_empty(), "no CA certificates found");
83+
84+
this.with_root_certificates(roots)
85+
}
5386
hyper_rustls::HttpsConnectorBuilder::new()
5487
.with_tls_config(
55-
rustls::ClientConfig::builder()
88+
with_native_roots(rustls::ClientConfig::builder()
5689
.with_cipher_suites(&[
5790
// TLS1.3 suites
5891
rustls::cipher_suite::TLS13_AES_256_GCM_SHA384,
@@ -66,8 +99,7 @@ mod default_connector {
6699
])
67100
.with_safe_default_kx_groups()
68101
.with_safe_default_protocol_versions()
69-
.expect("Error with the TLS configuration. Please file a bug report under https://github.com/smithy-lang/smithy-rs/issues.")
70-
.with_native_roots()
102+
.expect("Error with the TLS configuration. Please file a bug report under https://github.com/smithy-lang/smithy-rs/issues."))
71103
.with_no_client_auth()
72104
)
73105
.https_or_http()

rust-runtime/aws-smithy-http-server-python/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tower-test = "0.4"
4949
tokio-test = "0.4"
5050
pyo3-asyncio = { version = "0.20.0", features = ["testing", "attributes", "tokio-runtime", "unstable-streams"] }
5151
rcgen = "0.10.0"
52-
hyper-rustls = { version = "0.24", features = ["http2"] }
52+
hyper-rustls = { version = "0.24.2", features = ["http2"] }
5353

5454
# PyO3 Asyncio tests cannot use Cargo's default testing harness because `asyncio`
5555
# wants to control the main thread. So we need to use testing harness provided by `pyo3_asyncio`

0 commit comments

Comments
 (0)