Skip to content

Commit 79ec500

Browse files
committed
download: statically bundle relevant trust anchors
1 parent 999abea commit 79ec500

File tree

7 files changed

+324
-8
lines changed

7 files changed

+324
-8
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, 0x78, 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, 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, 0x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, 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, 0xb9,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 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: 14 additions & 8 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(feature = "reqwest-rustls-tls")]
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,19 @@ 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()
612+
let provider = Arc::new(aws_lc_rs::default_provider());
613+
let verifier =
614+
Verifier::new_with_extra_roots(RUSTUP_TRUST_ANCHORS.iter().cloned(), provider.clone())
615615
.map_err(|err| {
616616
DownloadError::Message(format!("failed to initialize platform verifier: {err}"))
617-
})?
618-
.with_no_client_auth();
617+
})?;
618+
619+
let mut tls_config = rustls::ClientConfig::builder_with_provider(provider)
620+
.with_safe_default_protocol_versions()
621+
.unwrap()
622+
.dangerous() // We're using a rustls verifier, so it's okay
623+
.with_custom_certificate_verifier(Arc::new(verifier))
624+
.with_no_client_auth();
619625
tls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
620626

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

0 commit comments

Comments
 (0)