diff --git a/Cargo.lock b/Cargo.lock index 0f6f35a75f..c11e823467 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2080,6 +2080,7 @@ dependencies = [ "rs_tracing", "rustls", "rustls-platform-verifier", + "rustls-webpki", "same-file", "scopeguard", "semver", @@ -2094,6 +2095,7 @@ dependencies = [ "threadpool", "tokio", "tokio-retry", + "tokio-rustls", "tokio-stream", "toml", "tracing", @@ -2103,6 +2105,7 @@ dependencies = [ "url", "wait-timeout", "walkdir", + "webpki-root-certs", "windows-registry", "windows-result", "windows-sys 0.61.2", diff --git a/Cargo.toml b/Cargo.toml index 8d3e0e0d1c..cc2fd7cd60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -140,6 +140,9 @@ http-body-util = "0.1.0" hyper = { version = "1.0", default-features = false, features = ["server", "http1"] } hyper-util = { version = "0.1.1", features = ["tokio"] } proptest = "1.1.0" +rustls-webpki = { version = "0.103.3" } +tokio-rustls = "0.26.4" +webpki-root-certs = "1" [build-dependencies] platforms = "3.4" diff --git a/src/anchors.rs b/src/anchors.rs new file mode 100644 index 0000000000..849a7bac51 --- /dev/null +++ b/src/anchors.rs @@ -0,0 +1,125 @@ +// @generated by tests/static_roots.rs +use rustls::pki_types::CertificateDer; + +pub(crate) const RUSTUP_TRUST_ANCHORS: &[CertificateDer<'static>] = &[ + // Root for host: fastly-static.rust-lang.org + CertificateDer::from_slice(&[ + 0x30, 0x82, 0x03, 0x5f, 0x30, 0x82, 0x02, 0x47, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0b, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0x58, 0x53, 0x08, 0xa2, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x4c, 0x31, 0x20, + 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x17, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x53, 0x69, 0x67, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x20, 0x2d, 0x20, + 0x52, 0x33, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x47, 0x6c, + 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x13, 0x0a, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x30, + 0x1e, 0x17, 0x0d, 0x30, 0x39, 0x30, 0x33, 0x31, 0x38, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x33, 0x31, 0x38, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x5a, 0x30, 0x4c, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x17, 0x47, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, + 0x43, 0x41, 0x20, 0x2d, 0x20, 0x52, 0x33, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, + 0x0a, 0x13, 0x0a, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x31, 0x13, + 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0a, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x53, 0x69, 0x67, 0x6e, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, + 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xcc, 0x25, 0x76, 0x90, 0x79, 0x06, 0x78, 0x22, + 0x16, 0xf5, 0xc0, 0x83, 0xb6, 0x84, 0xca, 0x28, 0x9e, 0xfd, 0x05, 0x76, 0x11, 0xc5, 0xad, + 0x88, 0x72, 0xfc, 0x46, 0x02, 0x43, 0xc7, 0xb2, 0x8a, 0x9d, 0x04, 0x5f, 0x24, 0xcb, 0x2e, + 0x4b, 0xe1, 0x60, 0x82, 0x46, 0xe1, 0x52, 0xab, 0x0c, 0x81, 0x47, 0x70, 0x6c, 0xdd, 0x64, + 0xd1, 0xeb, 0xf5, 0x2c, 0xa3, 0x0f, 0x82, 0x3d, 0x0c, 0x2b, 0xae, 0x97, 0xd7, 0xb6, 0x14, + 0x86, 0x10, 0x79, 0xbb, 0x3b, 0x13, 0x80, 0x77, 0x8c, 0x08, 0xe1, 0x49, 0xd2, 0x6a, 0x62, + 0x2f, 0x1f, 0x5e, 0xfa, 0x96, 0x68, 0xdf, 0x89, 0x27, 0x95, 0x38, 0x9f, 0x06, 0xd7, 0x3e, + 0xc9, 0xcb, 0x26, 0x59, 0x0d, 0x73, 0xde, 0xb0, 0xc8, 0xe9, 0x26, 0x0e, 0x83, 0x15, 0xc6, + 0xef, 0x5b, 0x8b, 0xd2, 0x04, 0x60, 0xca, 0x49, 0xa6, 0x28, 0xf6, 0x69, 0x3b, 0xf6, 0xcb, + 0xc8, 0x28, 0x91, 0xe5, 0x9d, 0x8a, 0x61, 0x57, 0x37, 0xac, 0x74, 0x14, 0xdc, 0x74, 0xe0, + 0x3a, 0xee, 0x72, 0x2f, 0x2e, 0x9c, 0xfb, 0xd0, 0xbb, 0xbf, 0xf5, 0x3d, 0x00, 0xe1, 0x06, + 0x33, 0xe8, 0x82, 0x2b, 0xae, 0x53, 0xa6, 0x3a, 0x16, 0x73, 0x8c, 0xdd, 0x41, 0x0e, 0x20, + 0x3a, 0xc0, 0xb4, 0xa7, 0xa1, 0xe9, 0xb2, 0x4f, 0x90, 0x2e, 0x32, 0x60, 0xe9, 0x57, 0xcb, + 0xb9, 0x04, 0x92, 0x68, 0x68, 0xe5, 0x38, 0x26, 0x60, 0x75, 0xb2, 0x9f, 0x77, 0xff, 0x91, + 0x14, 0xef, 0xae, 0x20, 0x49, 0xfc, 0xad, 0x40, 0x15, 0x48, 0xd1, 0x02, 0x31, 0x61, 0x19, + 0x5e, 0xb8, 0x97, 0xef, 0xad, 0x77, 0xb7, 0x64, 0x9a, 0x7a, 0xbf, 0x5f, 0xc1, 0x13, 0xef, + 0x9b, 0x62, 0xfb, 0x0d, 0x6c, 0xe0, 0x54, 0x69, 0x16, 0xa9, 0x03, 0xda, 0x6e, 0xe9, 0x83, + 0x93, 0x71, 0x76, 0xc6, 0x69, 0x85, 0x82, 0x17, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, + 0x30, 0x40, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, + 0x02, 0x01, 0x06, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, + 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, + 0x14, 0x8f, 0xf0, 0x4b, 0x7f, 0xa8, 0x2e, 0x45, 0x24, 0xae, 0x4d, 0x50, 0xfa, 0x63, 0x9a, + 0x8b, 0xde, 0xe2, 0xdd, 0x1b, 0xbc, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, + 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x4b, 0x40, 0xdb, 0xc0, + 0x50, 0xaa, 0xfe, 0xc8, 0x0c, 0xef, 0xf7, 0x96,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0xce, 0xf7, 0x32, 0x6b, + 0x94, 0x01, 0xa8, 0x99, 0xe7, 0x2c, 0x33, 0x1f, 0x3a, 0x3b, 0x25, 0xd2, 0x86, 0x40, 0xce, + 0x3b, 0x2c, 0x86, 0x78, 0xc9, 0x61, 0x2f, 0x14, 0xba, 0xee, 0xdb, 0x55, 0x6f, 0xdf, 0x84, + 0xee, 0x05, 0x09, 0x4d, 0xbd, 0x28, 0xd8, 0x72, 0xce, 0xd3, 0x62, 0x50, 0x65, 0x1e, 0xeb, + 0x92, 0x97, 0x83, 0x31, 0xd9, 0xb3, 0xb5, 0xca, 0x47, 0x58, 0x3f, 0x5f, + ]), + // Root for host: cloudfront-static.rust-lang.org + CertificateDer::from_slice(&[ + 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x13, + 0x06, 0x6c, 0x9f, 0xcf, 0x99, 0xbf, 0x8c, 0x0a, 0x39, 0xe2, 0xf0, 0x78, 0x8a, 0x43, 0xe6, + 0x96, 0x36, 0x5b, 0xca, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, + 0x01, 0x0b, 0x05, 0x00, 0x30, 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, + 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x06, + 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x13, 0x10, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, + 0x41, 0x20, 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x35, 0x32, 0x36, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x38, 0x30, 0x31, 0x31, 0x37, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, + 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, + 0x06, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, + 0x03, 0x13, 0x10, 0x41, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, + 0x43, 0x41, 0x20, 0x31, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, + 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb2, 0x78, 0x80, 0x71, 0xca, 0x78, 0xd5, 0xe3, + 0x71, 0xaf, 0x47, 0x80, 0x50, 0x74, 0x7d, 0x6e, 0xd8, 0xd7, 0x88, 0x76, 0xf4, 0x99, 0x68, + 0xf7, 0x58, 0x21, 0x60, 0xf9, 0x74, 0x84, 0x01, 0x2f, 0xac, 0x02, 0x2d, 0x86, 0xd3, 0xa0, + 0x43, 0x7a, 0x4e, 0xb2, 0xa4, 0xd0, 0x36, 0xba, 0x01, 0xbe, 0x8d, 0xdb, 0x48, 0xc8, 0x07, + 0x17, 0x36, 0x4c, 0xf4, 0xee, 0x88, 0x23, 0xc7, 0x3e, 0xeb, 0x37, 0xf5, 0xb5, 0x19, 0xf8, + 0x49, 0x68, 0xb0, 0xde, 0xd7, 0xb9, 0x76, 0x38, 0x1d, 0x61, 0x9e, 0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, + 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, + 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, + 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, + 0x14, 0x84, 0x18, 0xcc, 0x85, 0x34, 0xec, 0xbc, 0x0c, 0x94, 0x94, 0x2e, 0x08, 0x59, 0x9c, + 0xc7, 0xb2, 0x10, 0x4e, 0x0a, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, + 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x98, 0xf2, 0x37, 0x5a, + 0x41, 0x90, 0xa1, 0x1a, 0xc5, 0x76, 0x51, 0x28, 0x20, 0x36, 0x23, 0x0e, 0xae, 0xe6, 0x28, + 0xbb, 0xaa, 0xf8, 0x94, 0xae, 0x48, 0xa4, 0x30, 0x7f, 0x1b, 0xfc, 0x24, 0x8d, 0x4b, 0xb4, + 0xc8, 0xa1, 0x97, 0xf6, 0xb6, 0xf1, 0x7a, 0x70, 0xc8, 0x53, 0x93, 0xcc, 0x08, 0x28, 0xe3, + 0x98, 0x25, 0xcf, 0x23, 0xa4, 0xf9, 0xde, 0x21, 0xd3, 0x7c, 0x85, 0x09, 0xad, 0x4e, 0x9a, + 0x75, 0x3a, 0xc2, 0x0b, 0x6a, 0x89, 0x78, 0x76, 0x44, 0x47, 0x18, 0x65, 0x6c, 0x8d, 0x41, + 0x8e, 0x3b, 0x7f, 0x9a, 0xcb, 0xf4, 0xb5, 0xa7, 0x50, 0xd7, 0x05, 0x2c, 0x37, 0xe8, 0x03, + 0x4b, 0xad, 0xe9, 0x61, 0xa0, 0x02, 0x6e, 0xf5, 0xf2, 0xf0, 0xc5, 0xb2, 0xed, 0x5b, 0xb7, + 0xdc, 0xfa, 0x94, 0x5c, 0x77, 0x9e, 0x13, 0xa5, 0x7f, 0x52, 0xad, 0x95, 0xf2, 0xf8, 0x93, + 0x3b, 0xde, 0x8b, 0x5c, 0x5b, 0xca, 0x5a, 0x52, 0x5b, 0x60, 0xaf, 0x14, 0xf7, 0x4b, 0xef, + 0xa3, 0xfb, 0x9f, 0x40, 0x95, 0x6d, 0x31, 0x54, 0xfc, 0x42, 0xd3, 0xc7, 0x46, 0x1f, 0x23, + 0xad, 0xd9, 0x0f, 0x48, 0x70, 0x9a, 0xd9, 0x75, 0x78, 0x71, 0xd1, 0x72, 0x43, 0x34, 0x75, + 0x6e, 0x57, 0x59, 0xc2, 0x02, 0x5c, 0x26, 0x60, 0x29, 0xcf, 0x23, 0x19, 0x16, 0x8e, 0x88, + 0x43, 0xa5, 0xd4, 0xe4, 0xcb, 0x08, 0xfb, 0x23, 0x11, 0x43, 0xe8, 0x43, 0x29, 0x72, 0x62, + 0xa1, 0xa9, 0x5d, 0x5e, 0x08, 0xd4, 0x90, 0xae, 0xb8, 0xd8, 0xce, 0x14, 0xc2, 0xd0, 0x55, + 0xf2, 0x86, 0xf6, 0xc4, 0x93, 0x43, 0x77, 0x66, 0x61, 0xc0, 0xb9, 0xe8, 0x41, 0xd7, 0x97, + 0x78, 0x60, 0x03, 0x6e, 0x4a, 0x72, 0xae, 0xa5, 0xd1, 0x7d, 0xba, 0x10, 0x9e, 0x86, 0x6c, + 0x1b, 0x8a, 0xb9, 0x59, 0x33, 0xf8, 0xeb, 0xc4, 0x90, 0xbe, 0xf1, 0xb9, + ]), +]; diff --git a/src/download/mod.rs b/src/download/mod.rs index b32524a596..37ae9b32d4 100644 --- a/src/download/mod.rs +++ b/src/download/mod.rs @@ -546,12 +546,14 @@ mod reqwest_be { use std::sync::{Arc, OnceLock}; use std::time::Duration; + #[cfg(all(feature = "reqwest-rustls-tls", not(target_os = "android")))] + use crate::anchors::RUSTUP_TRUST_ANCHORS; use anyhow::{Context, anyhow}; use reqwest::{Client, ClientBuilder, Proxy, Response, header}; #[cfg(feature = "reqwest-rustls-tls")] use rustls::crypto::aws_lc_rs; #[cfg(feature = "reqwest-rustls-tls")] - use rustls_platform_verifier::BuilderVerifierExt; + use rustls_platform_verifier::Verifier; use tokio_stream::StreamExt; use url::Url; @@ -607,15 +609,22 @@ mod reqwest_be { return Ok(client); } - let mut tls_config = - rustls::ClientConfig::builder_with_provider(Arc::new(aws_lc_rs::default_provider())) - .with_safe_default_protocol_versions() - .unwrap() - .with_platform_verifier() - .map_err(|err| { - DownloadError::Message(format!("failed to initialize platform verifier: {err}")) - })? - .with_no_client_auth(); + let provider = Arc::new(aws_lc_rs::default_provider()); + #[cfg(not(target_os = "android"))] + let result = + Verifier::new_with_extra_roots(RUSTUP_TRUST_ANCHORS.iter().cloned(), provider.clone()); + #[cfg(target_os = "android")] + let result = Verifier::new(provider.clone()); + let verifier = result.map_err(|err| { + DownloadError::Message(format!("failed to initialize platform verifier: {err}")) + })?; + + let mut tls_config = rustls::ClientConfig::builder_with_provider(provider) + .with_safe_default_protocol_versions() + .unwrap() + .dangerous() // We're using a rustls verifier, so it's okay + .with_custom_certificate_verifier(Arc::new(verifier)) + .with_no_client_auth(); tls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; let client = client_generic() diff --git a/src/lib.rs b/src/lib.rs index 14f2583a43..7192d9eafc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,6 +70,8 @@ fn component_for_bin(binary: &str) -> Option<&'static str> { #[macro_use] pub mod cli; +#[cfg(all(feature = "reqwest-rustls-tls", not(target_os = "android")))] +mod anchors; mod command; mod config; mod diskio; diff --git a/tests/suite/mod.rs b/tests/suite/mod.rs index ce3956ca3d..d36dba144b 100644 --- a/tests/suite/mod.rs +++ b/tests/suite/mod.rs @@ -10,3 +10,4 @@ mod cli_v1; mod cli_v2; mod dist_install; mod known_triples; +mod static_roots; diff --git a/tests/suite/static_roots.rs b/tests/suite/static_roots.rs new file mode 100644 index 0000000000..eaa55f543d --- /dev/null +++ b/tests/suite/static_roots.rs @@ -0,0 +1,171 @@ +//! Connects to a known set of `HOSTS`, captures the root certificates for the +//! certificate chain presented, and writes them to `src/anchors.rs` in a way +//! that is easy to consume for use as `extra_roots` in rustls-platform-verifier. + +use std::{ + fs, + sync::{Arc, Mutex}, +}; + +use rustls::{ + DigitallySignedStruct, Error, RootCertStore, SignatureScheme, + client::{ + WebPkiServerVerifier, + danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}, + }, + crypto::{CryptoProvider, aws_lc_rs}, + pki_types::{CertificateDer, ServerName, TrustAnchor, UnixTime}, +}; +use tokio::net::TcpStream; +use tokio_rustls::TlsConnector; +use webpki::{EndEntityCert, anchor_from_trusted_cert}; +use webpki_root_certs::TLS_SERVER_ROOT_CERTS; + +#[tokio::test] +async fn store_static_roots() { + let provider = Arc::new(aws_lc_rs::default_provider()); + let mut root_store = RootCertStore::empty(); + let mut roots = Vec::with_capacity(TLS_SERVER_ROOT_CERTS.len()); + for cert_der in TLS_SERVER_ROOT_CERTS { + let ta = anchor_from_trusted_cert(cert_der).unwrap(); + roots.push((cert_der, ta.clone())); + root_store.roots.push(ta); + } + + let root_store = Arc::new(root_store); + let inner = WebPkiServerVerifier::builder_with_provider(root_store.clone(), provider.clone()) + .build() + .unwrap(); + + let verifier = Arc::new(TrackRootVerifier { + root: Mutex::default(), + roots: root_store, + inner, + provider: provider.clone(), + }); + + let config = Arc::new( + rustls::ClientConfig::builder_with_provider(provider) + .with_safe_default_protocol_versions() + .unwrap() + .dangerous() + .with_custom_certificate_verifier(verifier.clone()) + .with_no_client_auth(), + ); + + let mut code = "// @generated by tests/static_roots.rs\n".to_string(); + code.push_str("use rustls::pki_types::CertificateDer;\n\n"); + code.push_str("pub(crate) const RUSTUP_TRUST_ANCHORS: &[CertificateDer<'static>] = &[\n"); + let connector = TlsConnector::from(config); + for &host in HOSTS { + connector + .connect( + ServerName::try_from(host).unwrap(), + TcpStream::connect((host, 443)).await.unwrap(), + ) + .await + .unwrap(); + + let root = verifier.root.lock().unwrap().take().unwrap(); + let root_cert = roots + .iter() + .find_map(|(cert_der, ta)| (ta == &root).then_some(*cert_der)) + .unwrap(); + + code.push_str(&format!(" // Root for host: {host}\n")); + code.push_str(" CertificateDer::from_slice(&[\n"); + for chunk in root_cert.chunks(15) { + code.push_str(" "); + for (i, byte) in chunk.iter().enumerate() { + if i > 0 { + code.push(' '); + } + code.push_str(&format!("0x{:02x},", byte)); + } + code.push('\n'); + } + code.push_str(" ]),\n"); + } + code.push_str("];\n"); + + let old = fs::read_to_string(PATH).unwrap(); + if old != code { + fs::write(PATH, &code).unwrap(); + panic!("anchors.rs is outdated; updated it"); + } +} + +const PATH: &str = "src/anchors.rs"; + +#[derive(Debug)] +struct TrackRootVerifier { + root: Mutex>>, + inner: Arc, + roots: Arc, + provider: Arc, +} + +impl ServerCertVerifier for TrackRootVerifier { + fn verify_server_cert( + &self, + end_entity: &CertificateDer<'_>, + intermediates: &[CertificateDer<'_>], + server_name: &ServerName<'_>, + ocsp_response: &[u8], + now: UnixTime, + ) -> Result { + let verified = self.inner.verify_server_cert( + end_entity, + intermediates, + server_name, + ocsp_response, + now, + )?; + + let cert = EndEntityCert::try_from(end_entity) + .map_err(|e| Error::General(format!("invalid end entity certificate: {e}")))?; + + let path = cert + .verify_for_usage( + self.provider.signature_verification_algorithms.all, + &self.roots.roots, + intermediates, + now, + webpki::KeyUsage::server_auth(), + None, + None, + ) + .unwrap(); + + let mut root = self.root.lock().unwrap(); + *root = Some(path.anchor().to_owned()); + Ok(verified) + } + + fn verify_tls12_signature( + &self, + message: &[u8], + cert: &CertificateDer<'_>, + dss: &DigitallySignedStruct, + ) -> Result { + self.inner.verify_tls12_signature(message, cert, dss) + } + + fn verify_tls13_signature( + &self, + message: &[u8], + cert: &CertificateDer<'_>, + dss: &DigitallySignedStruct, + ) -> Result { + self.inner.verify_tls13_signature(message, cert, dss) + } + + fn supported_verify_schemes(&self) -> Vec { + self.inner.supported_verify_schemes() + } +} + +const HOSTS: &[&str] = &[ + "fastly-static.rust-lang.org", + "cloudfront-static.rust-lang.org", +];