max / makenotwork
| 1 | //! Shared TLS configuration for pom's outbound HTTP. |
| 2 | //! |
| 3 | //! Every probe (health, CORS, routes, peer, alerts) trusts the bundled Mozilla |
| 4 | //! root set via `webpki-roots`, the same anchor the TLS-expiry check reports |
| 5 | //! against, so a host with an extra local root cannot make the HTTP check and |
| 6 | //! the certificate check disagree about one target. The rustls provider is ring |
| 7 | //! (pure Rust), installed process-wide by [`install_crypto_provider`] at startup. |
| 8 | |
| 9 | /// Install ring as the process-wide rustls crypto provider. Idempotent (guarded |
| 10 | /// by a `Once`); safe to call from `main` at startup and from every config |
| 11 | /// builder, so a TLS client can never be built before a provider is installed. |
| 12 | |
| 13 | static INSTALLED: Once = new; |
| 14 | INSTALLED.call_once |
| 15 | let _ = default_provider.install_default; |
| 16 | ; |
| 17 | |
| 18 | |
| 19 | /// A rustls client config pinned to the bundled webpki (Mozilla) roots. |
| 20 | |
| 21 | // `ClientConfig::builder()` reads the process-default provider, so make sure |
| 22 | // ring is installed even if this runs before `main`'s explicit install (tests). |
| 23 | install_crypto_provider; |
| 24 | let mut roots = empty; |
| 25 | roots.extend; |
| 26 | builder |
| 27 | .with_root_certificates |
| 28 | .with_no_client_auth |
| 29 | |
| 30 | |
| 31 | /// A `reqwest` client builder that trusts the webpki root set. Callers add their |
| 32 | /// own timeout / redirect policy, then `.build()`. reqwest is compiled |
| 33 | /// `rustls-no-provider`, so without this preconfigured config it would fall back |
| 34 | /// to the OS platform verifier, a different trust model than the cert check uses. |
| 35 | |
| 36 | builder.use_preconfigured_tls |
| 37 | |
| 38 |