Add a tls_built_in_root_certs option for Client (#1150)
This commit is contained in:
		| @@ -94,6 +94,8 @@ struct Config { | ||||
|     #[cfg(feature = "__tls")] | ||||
|     root_certs: Vec<Certificate>, | ||||
|     #[cfg(feature = "__tls")] | ||||
|     tls_built_in_root_certs: bool, | ||||
|     #[cfg(feature = "__tls")] | ||||
|     tls: TlsBackend, | ||||
|     http2_only: bool, | ||||
|     http1_title_case_headers: bool, | ||||
| @@ -146,6 +148,8 @@ impl ClientBuilder { | ||||
|                 #[cfg(feature = "__tls")] | ||||
|                 root_certs: Vec::new(), | ||||
|                 #[cfg(feature = "__tls")] | ||||
|                 tls_built_in_root_certs: true, | ||||
|                 #[cfg(feature = "__tls")] | ||||
|                 identity: None, | ||||
|                 #[cfg(feature = "__tls")] | ||||
|                 tls: TlsBackend::default(), | ||||
| @@ -209,6 +213,8 @@ impl ClientBuilder { | ||||
|  | ||||
|                     tls.danger_accept_invalid_certs(!config.certs_verification); | ||||
|  | ||||
|                     tls.disable_built_in_roots(!config.tls_built_in_root_certs); | ||||
|  | ||||
|                     for cert in config.root_certs { | ||||
|                         cert.add_to_native_tls(&mut tls); | ||||
|                     } | ||||
| @@ -261,10 +267,12 @@ impl ClientBuilder { | ||||
|                         tls.set_protocols(&["h2".into(), "http/1.1".into()]); | ||||
|                     } | ||||
|                     #[cfg(feature = "rustls-tls-webpki-roots")] | ||||
|                     if config.tls_built_in_root_certs { | ||||
|                     tls.root_store | ||||
|                         .add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); | ||||
|                     } | ||||
|                     #[cfg(feature = "rustls-tls-native-roots")] | ||||
|                     { | ||||
|                     if config.tls_built_in_root_certs { | ||||
|                         let roots_slice = NATIVE_ROOTS.as_ref().unwrap().roots.as_slice(); | ||||
|                         tls.root_store.roots.extend_from_slice(roots_slice); | ||||
|                     } | ||||
| @@ -719,6 +727,23 @@ impl ClientBuilder { | ||||
|         self | ||||
|     } | ||||
|  | ||||
|     /// Controls the use of built-in/preloaded certificates during certificate validation. | ||||
|     /// | ||||
|     /// Defaults to `true` -- built-in system certs will be used. | ||||
|     /// | ||||
|     /// # Optional | ||||
|     /// | ||||
|     /// This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)` | ||||
|     /// feature to be enabled. | ||||
|     #[cfg(feature = "__tls")] | ||||
|     pub fn tls_built_in_root_certs( | ||||
|         mut self, | ||||
|         tls_built_in_root_certs: bool, | ||||
|     ) -> ClientBuilder { | ||||
|         self.config.tls_built_in_root_certs = tls_built_in_root_certs; | ||||
|         self | ||||
|     } | ||||
|  | ||||
|     /// Sets the identity to be used for client certificate authentication. | ||||
|     /// | ||||
|     /// # Optional | ||||
|   | ||||
		Reference in New Issue
	
	Block a user