Skip to content

Commit 23dd1f8

Browse files
committed
download: statically bundle relevant trust anchors
1 parent 999abea commit 23dd1f8

File tree

7 files changed

+324
-10
lines changed

7 files changed

+324
-10
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ http-body-util = "0.1.0"
140140
hyper = { version = "1.0", default-features = false, features = ["server", "http1"] }
141141
hyper-util = { version = "0.1.1", features = ["tokio"] }
142142
proptest = "1.1.0"
143+
rustls-webpki = { version = "0.103.3" }
144+
tokio-rustls = "0.26.4"
145+
webpki-root-certs = "1"
143146

144147
[build-dependencies]
145148
platforms = "3.4"

src/anchors.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// @generated by tests/static_roots.rs
2+
use rustls::pki_types::CertificateDer;
3+
4+
pub(crate) const RUSTUP_TRUST_ANCHORS: &[CertificateDer<'static>] = &[
5+
// Root for host: fastly-static.rust-lang.org
6+
CertificateDer::from_slice(&[
7+
0x30, 0x82, 0x03, 0x5f, 0x30, 0x82, 0x02, 0x47, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0b,
8+
0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0x58, 0x53, 0x08, 0xa2, 0x30, 0x0d, 0x06, 0x09,
9+
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x4c, 0x31, 0x20,
10+
0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x17, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c,
11+
0x53, 0x69, 0x67, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x20, 0x2d, 0x20,
12+
0x52, 0x33, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x47, 0x6c,
13+
0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
14+
0x04, 0x03, 0x13, 0x0a, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x30,
15+
0x1e, 0x17, 0x0d, 0x30, 0x39, 0x30, 0x33, 0x31, 0x38, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30,
16+
0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x33, 0x31, 0x38, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30,
17+
0x5a, 0x30, 0x4c, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x17, 0x47,
18+
0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20,
19+
0x43, 0x41, 0x20, 0x2d, 0x20, 0x52, 0x33, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
20+
0x0a, 0x13, 0x0a, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x31, 0x13,
21+
0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0a, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c,
22+
0x53, 0x69, 0x67, 0x6e, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
23+
0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82,
24+
0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xcc, 0x25, 0x76, 0x90, 0x79, 0x06, 0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0xe9, 0x57, 0xcb,
37+
0xb9, 0x04, 0x92, 0x68, 0x68, 0xe5, 0x38, 0x26, 0x60, 0x75, 0xb2, 0x9f, 0x77, 0xff, 0x91,
38+
0x14, 0xef, 0xae, 0x20, 0x49, 0xfc, 0xad, 0x40, 0x15, 0x48, 0xd1, 0x02, 0x31, 0x61, 0x19,
39+
0x5e, 0xb8, 0x97, 0xef, 0xad, 0x77, 0xb7, 0x64, 0x9a, 0x7a, 0xbf, 0x5f, 0xc1, 0x13, 0xef,
40+
0x9b, 0x62, 0xfb, 0x0d, 0x6c, 0xe0, 0x54, 0x69, 0x16, 0xa9, 0x03, 0xda, 0x6e, 0xe9, 0x83,
41+
0x93, 0x71, 0x76, 0xc6, 0x69, 0x85, 0x82, 0x17, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42,
42+
0x30, 0x40, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,
43+
0x02, 0x01, 0x06, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05,
44+
0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04,
45+
0x14, 0x8f, 0xf0, 0x4b, 0x7f, 0xa8, 0x2e, 0x45, 0x24, 0xae, 0x4d, 0x50, 0xfa, 0x63, 0x9a,
46+
0x8b, 0xde, 0xe2, 0xdd, 0x1b, 0xbc, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
47+
0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x4b, 0x40, 0xdb, 0xc0,
48+
0x50, 0xaa, 0xfe, 0xc8, 0x0c, 0xef, 0xf7, 0x96, 0x54, 0x45, 0x49, 0xbb, 0x96, 0x00, 0x09,
49+
0x41, 0xac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
0x94, 0x01, 0xa8, 0x99, 0xe7, 0x2c, 0x33, 0x1f, 0x3a, 0x3b, 0x25, 0xd2, 0x86, 0x40, 0xce,
62+
0x3b, 0x2c, 0x86, 0x78, 0xc9, 0x61, 0x2f, 0x14, 0xba, 0xee, 0xdb, 0x55, 0x6f, 0xdf, 0x84,
63+
0xee, 0x05, 0x09, 0x4d, 0xbd, 0x28, 0xd8, 0x72, 0xce, 0xd3, 0x62, 0x50, 0x65, 0x1e, 0xeb,
64+
0x92, 0x97, 0x83, 0x31, 0xd9, 0xb3, 0xb5, 0xca, 0x47, 0x58, 0x3f, 0x5f,
65+
]),
66+
// Root for host: cloudfront-static.rust-lang.org
67+
CertificateDer::from_slice(&[
68+
0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x13,
69+
0x06, 0x6c, 0x9f, 0xcf, 0x99, 0xbf, 0x8c, 0x0a, 0x39, 0xe2, 0xf0, 0x78, 0x8a, 0x43, 0xe6,
70+
0x96, 0x36, 0x5b, 0xca, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
71+
0x01, 0x0b, 0x05, 0x00, 0x30, 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
72+
0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x06,
73+
0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03,
74+
0x13, 0x10, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43,
75+
0x41, 0x20, 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x35, 0x32, 0x36, 0x30, 0x30,
76+
0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x38, 0x30, 0x31, 0x31, 0x37, 0x30, 0x30,
77+
0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
78+
0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
79+
0x06, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04,
80+
0x03, 0x13, 0x10, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20,
81+
0x43, 0x41, 0x20, 0x31, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
82+
0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82,
83+
0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb2, 0x78, 0x80, 0x71, 0xca, 0x78, 0xd5, 0xe3,
84+
0x71, 0xaf, 0x47, 0x80, 0x50, 0x74, 0x7d, 0x6e, 0xd8, 0xd7, 0x88, 0x76, 0xf4, 0x99, 0x68,
85+
0xf7, 0x58, 0x21, 0x60, 0xf9, 0x74, 0x84, 0x01, 0x2f, 0xac, 0x02, 0x2d, 0x86, 0xd3, 0xa0,
86+
0x43, 0x7a, 0x4e, 0xb2, 0xa4, 0xd0, 0x36, 0xba, 0x01, 0xbe, 0x8d, 0xdb, 0x48, 0xc8, 0x07,
87+
0x17, 0x36, 0x4c, 0xf4, 0xee, 0x88, 0x23, 0xc7, 0x3e, 0xeb, 0x37, 0xf5, 0xb5, 0x19, 0xf8,
88+
0x49, 0x68, 0xb0, 0xde, 0xd7, 0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x9a, 0xc8, 0xaa, 0x0d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42,
101+
0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30,
102+
0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04,
103+
0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04,
104+
0x14, 0x84, 0x18, 0xcc, 0x85, 0x34, 0xec, 0xbc, 0x0c, 0x94, 0x94, 0x2e, 0x08, 0x59, 0x9c,
105+
0xc7, 0xb2, 0x10, 0x4e, 0x0a, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
106+
0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x98, 0xf2, 0x37, 0x5a,
107+
0x41, 0x90, 0xa1, 0x1a, 0xc5, 0x76, 0x51, 0x28, 0x20, 0x36, 0x23, 0x0e, 0xae, 0xe6, 0x28,
108+
0xbb, 0xaa, 0xf8, 0x94, 0xae, 0x48, 0xa4, 0x30, 0x7f, 0x1b, 0xfc, 0x24, 0x8d, 0x4b, 0xb4,
109+
0xc8, 0xa1, 0x97, 0xf6, 0xb6, 0xf1, 0x7a, 0x70, 0xc8, 0x53, 0x93, 0xcc, 0x08, 0x28, 0xe3,
110+
0x98, 0x25, 0xcf, 0x23, 0xa4, 0xf9, 0xde, 0x21, 0xd3, 0x7c, 0x85, 0x09, 0xad, 0x4e, 0x9a,
111+
0x75, 0x3a, 0xc2, 0x0b, 0x6a, 0x89, 0x78, 0x76, 0x44, 0x47, 0x18, 0x65, 0x6c, 0x8d, 0x41,
112+
0x8e, 0x3b, 0x7f, 0x9a, 0xcb, 0xf4, 0xb5, 0xa7, 0x50, 0xd7, 0x05, 0x2c, 0x37, 0xe8, 0x03,
113+
0x4b, 0xad, 0xe9, 0x61, 0xa0, 0x02, 0x6e, 0xf5, 0xf2, 0xf0, 0xc5, 0xb2, 0xed, 0x5b, 0xb7,
114+
0xdc, 0xfa, 0x94, 0x5c, 0x77, 0x9e, 0x13, 0xa5, 0x7f, 0x52, 0xad, 0x95, 0xf2, 0xf8, 0x93,
115+
0x3b, 0xde, 0x8b, 0x5c, 0x5b, 0xca, 0x5a, 0x52, 0x5b, 0x60, 0xaf, 0x14, 0xf7, 0x4b, 0xef,
116+
0xa3, 0xfb, 0x9f, 0x40, 0x95, 0x6d, 0x31, 0x54, 0xfc, 0x42, 0xd3, 0xc7, 0x46, 0x1f, 0x23,
117+
0xad, 0xd9, 0x0f, 0x48, 0x70, 0x9a, 0xd9, 0x75, 0x78, 0x71, 0xd1, 0x72, 0x43, 0x34, 0x75,
118+
0x6e, 0x57, 0x59, 0xc2, 0x02, 0x5c, 0x26, 0x60, 0x29, 0xcf, 0x23, 0x19, 0x16, 0x8e, 0x88,
119+
0x43, 0xa5, 0xd4, 0xe4, 0xcb, 0x08, 0xfb, 0x23, 0x11, 0x43, 0xe8, 0x43, 0x29, 0x72, 0x62,
120+
0xa1, 0xa9, 0x5d, 0x5e, 0x08, 0xd4, 0x90, 0xae, 0xb8, 0xd8, 0xce, 0x14, 0xc2, 0xd0, 0x55,
121+
0xf2, 0x86, 0xf6, 0xc4, 0x93, 0x43, 0x77, 0x66, 0x61, 0xc0, 0xb9, 0xe8, 0x41, 0xd7, 0x97,
122+
0x78, 0x60, 0x03, 0x6e, 0x4a, 0x72, 0xae, 0xa5, 0xd1, 0x7d, 0xba, 0x10, 0x9e, 0x86, 0x6c,
123+
0x1b, 0x8a, 0xb9, 0x59, 0x33, 0xf8, 0xeb, 0xc4, 0x90, 0xbe, 0xf1, 0xb9,
124+
]),
125+
];

src/download/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,14 @@ mod reqwest_be {
546546
use std::sync::{Arc, OnceLock};
547547
use std::time::Duration;
548548

549+
#[cfg(all(feature = "reqwest-rustls-tls", not(target_os = "android")))]
550+
use crate::anchors::RUSTUP_TRUST_ANCHORS;
549551
use anyhow::{Context, anyhow};
550552
use reqwest::{Client, ClientBuilder, Proxy, Response, header};
551553
#[cfg(feature = "reqwest-rustls-tls")]
552554
use rustls::crypto::aws_lc_rs;
553555
#[cfg(feature = "reqwest-rustls-tls")]
554-
use rustls_platform_verifier::BuilderVerifierExt;
556+
use rustls_platform_verifier::Verifier;
555557
use tokio_stream::StreamExt;
556558
use url::Url;
557559

@@ -607,15 +609,22 @@ mod reqwest_be {
607609
return Ok(client);
608610
}
609611

610-
let mut tls_config =
611-
rustls::ClientConfig::builder_with_provider(Arc::new(aws_lc_rs::default_provider()))
612-
.with_safe_default_protocol_versions()
613-
.unwrap()
614-
.with_platform_verifier()
615-
.map_err(|err| {
616-
DownloadError::Message(format!("failed to initialize platform verifier: {err}"))
617-
})?
618-
.with_no_client_auth();
612+
let provider = Arc::new(aws_lc_rs::default_provider());
613+
#[cfg(not(target_os = "android"))]
614+
let result =
615+
Verifier::new_with_extra_roots(RUSTUP_TRUST_ANCHORS.iter().cloned(), provider.clone());
616+
#[cfg(target_os = "android")]
617+
let result = Verifier::new(provider.clone());
618+
let verifier = result.map_err(|err| {
619+
DownloadError::Message(format!("failed to initialize platform verifier: {err}"))
620+
})?;
621+
622+
let mut tls_config = rustls::ClientConfig::builder_with_provider(provider)
623+
.with_safe_default_protocol_versions()
624+
.unwrap()
625+
.dangerous() // We're using a rustls verifier, so it's okay
626+
.with_custom_certificate_verifier(Arc::new(verifier))
627+
.with_no_client_auth();
619628
tls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
620629

621630
let client = client_generic()

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ fn component_for_bin(binary: &str) -> Option<&'static str> {
7070

7171
#[macro_use]
7272
pub mod cli;
73+
#[cfg(all(feature = "reqwest-rustls-tls", not(target_os = "android")))]
74+
mod anchors;
7375
mod command;
7476
mod config;
7577
mod diskio;

tests/suite/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ mod cli_v1;
1010
mod cli_v2;
1111
mod dist_install;
1212
mod known_triples;
13+
mod static_roots;

tests/suite/static_roots.rs

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
//! Connects to a known set of `HOSTS`, captures the root certificates for the
2+
//! certificate chain presented, and writes them to `src/anchors.rs` in a way
3+
//! that is easy to consume for use as `extra_roots` in rustls-platform-verifier.
4+
5+
use std::{
6+
fs,
7+
sync::{Arc, Mutex},
8+
};
9+
10+
use rustls::{
11+
DigitallySignedStruct, Error, RootCertStore, SignatureScheme,
12+
client::{
13+
WebPkiServerVerifier,
14+
danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier},
15+
},
16+
crypto::{CryptoProvider, aws_lc_rs},
17+
pki_types::{CertificateDer, ServerName, TrustAnchor, UnixTime},
18+
};
19+
use tokio::net::TcpStream;
20+
use tokio_rustls::TlsConnector;
21+
use webpki::{EndEntityCert, anchor_from_trusted_cert};
22+
use webpki_root_certs::TLS_SERVER_ROOT_CERTS;
23+
24+
#[tokio::test]
25+
async fn store_static_roots() {
26+
let provider = Arc::new(aws_lc_rs::default_provider());
27+
let mut root_store = RootCertStore::empty();
28+
let mut roots = Vec::with_capacity(TLS_SERVER_ROOT_CERTS.len());
29+
for cert_der in TLS_SERVER_ROOT_CERTS {
30+
let ta = anchor_from_trusted_cert(cert_der).unwrap();
31+
roots.push((cert_der, ta.clone()));
32+
root_store.roots.push(ta);
33+
}
34+
35+
let root_store = Arc::new(root_store);
36+
let inner = WebPkiServerVerifier::builder_with_provider(root_store.clone(), provider.clone())
37+
.build()
38+
.unwrap();
39+
40+
let verifier = Arc::new(TrackRootVerifier {
41+
root: Mutex::default(),
42+
roots: root_store,
43+
inner,
44+
provider: provider.clone(),
45+
});
46+
47+
let config = Arc::new(
48+
rustls::ClientConfig::builder_with_provider(provider)
49+
.with_safe_default_protocol_versions()
50+
.unwrap()
51+
.dangerous()
52+
.with_custom_certificate_verifier(verifier.clone())
53+
.with_no_client_auth(),
54+
);
55+
56+
let mut code = "// @generated by tests/static_roots.rs\n".to_string();
57+
code.push_str("use rustls::pki_types::CertificateDer;\n\n");
58+
code.push_str("pub(crate) const RUSTUP_TRUST_ANCHORS: &[CertificateDer<'static>] = &[\n");
59+
let connector = TlsConnector::from(config);
60+
for &host in HOSTS {
61+
connector
62+
.connect(
63+
ServerName::try_from(host).unwrap(),
64+
TcpStream::connect((host, 443)).await.unwrap(),
65+
)
66+
.await
67+
.unwrap();
68+
69+
let root = verifier.root.lock().unwrap().take().unwrap();
70+
let root_cert = roots
71+
.iter()
72+
.find_map(|(cert_der, ta)| (ta == &root).then_some(*cert_der))
73+
.unwrap();
74+
75+
code.push_str(&format!(" // Root for host: {host}\n"));
76+
code.push_str(" CertificateDer::from_slice(&[\n");
77+
for chunk in root_cert.chunks(15) {
78+
code.push_str(" ");
79+
for (i, byte) in chunk.iter().enumerate() {
80+
if i > 0 {
81+
code.push(' ');
82+
}
83+
code.push_str(&format!("0x{:02x},", byte));
84+
}
85+
code.push('\n');
86+
}
87+
code.push_str(" ]),\n");
88+
}
89+
code.push_str("];\n");
90+
91+
let old = fs::read_to_string(PATH).unwrap();
92+
if old != code {
93+
fs::write(PATH, &code).unwrap();
94+
panic!("anchors.rs is outdated; updated it");
95+
}
96+
}
97+
98+
const PATH: &str = "src/anchors.rs";
99+
100+
#[derive(Debug)]
101+
struct TrackRootVerifier {
102+
root: Mutex<Option<TrustAnchor<'static>>>,
103+
inner: Arc<WebPkiServerVerifier>,
104+
roots: Arc<RootCertStore>,
105+
provider: Arc<CryptoProvider>,
106+
}
107+
108+
impl ServerCertVerifier for TrackRootVerifier {
109+
fn verify_server_cert(
110+
&self,
111+
end_entity: &CertificateDer<'_>,
112+
intermediates: &[CertificateDer<'_>],
113+
server_name: &ServerName<'_>,
114+
ocsp_response: &[u8],
115+
now: UnixTime,
116+
) -> Result<ServerCertVerified, Error> {
117+
let verified = self.inner.verify_server_cert(
118+
end_entity,
119+
intermediates,
120+
server_name,
121+
ocsp_response,
122+
now,
123+
)?;
124+
125+
let cert = EndEntityCert::try_from(end_entity)
126+
.map_err(|e| Error::General(format!("invalid end entity certificate: {e}")))?;
127+
128+
let path = cert
129+
.verify_for_usage(
130+
self.provider.signature_verification_algorithms.all,
131+
&self.roots.roots,
132+
intermediates,
133+
now,
134+
webpki::KeyUsage::server_auth(),
135+
None,
136+
None,
137+
)
138+
.unwrap();
139+
140+
let mut root = self.root.lock().unwrap();
141+
*root = Some(path.anchor().to_owned());
142+
Ok(verified)
143+
}
144+
145+
fn verify_tls12_signature(
146+
&self,
147+
message: &[u8],
148+
cert: &CertificateDer<'_>,
149+
dss: &DigitallySignedStruct,
150+
) -> Result<HandshakeSignatureValid, Error> {
151+
self.inner.verify_tls12_signature(message, cert, dss)
152+
}
153+
154+
fn verify_tls13_signature(
155+
&self,
156+
message: &[u8],
157+
cert: &CertificateDer<'_>,
158+
dss: &DigitallySignedStruct,
159+
) -> Result<HandshakeSignatureValid, Error> {
160+
self.inner.verify_tls13_signature(message, cert, dss)
161+
}
162+
163+
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
164+
self.inner.supported_verify_schemes()
165+
}
166+
}
167+
168+
const HOSTS: &[&str] = &[
169+
"fastly-static.rust-lang.org",
170+
"cloudfront-static.rust-lang.org",
171+
];

0 commit comments

Comments
 (0)