@@ -11,13 +11,16 @@ use self::openssl::ssl::{
1111 SslVerifyMode ,
1212} ;
1313use self :: openssl:: x509:: { store:: X509StoreBuilder , X509VerifyResult , X509 } ;
14+ use self :: openssl_probe:: ProbeResult ;
1415use std:: error;
1516use std:: fmt;
1617use std:: io;
17- use std:: sync:: Once ;
18+ use std:: sync:: LazyLock ;
1819
1920use crate :: { Protocol , TlsAcceptorBuilder , TlsConnectorBuilder } ;
2021
22+ static PROBE_RESULT : LazyLock < ProbeResult > = LazyLock :: new ( openssl_probe:: probe) ;
23+
2124#[ cfg( feature = "have_min_max_version" ) ]
2225fn supported_protocols (
2326 min : Option < Protocol > ,
@@ -85,11 +88,6 @@ fn supported_protocols(
8588 Ok ( ( ) )
8689}
8790
88- fn init_trust ( ) {
89- static ONCE : Once = Once :: new ( ) ;
90- ONCE . call_once ( openssl_probe:: init_ssl_cert_env_vars) ;
91- }
92-
9391#[ cfg( target_os = "android" ) ]
9492fn load_android_root_certs ( connector : & mut SslContextBuilder ) -> Result < ( ) , Error > {
9593 use std:: fs;
@@ -272,9 +270,20 @@ pub struct TlsConnector {
272270
273271impl TlsConnector {
274272 pub fn new ( builder : & TlsConnectorBuilder ) -> Result < TlsConnector , Error > {
275- init_trust ( ) ;
276-
277273 let mut connector = SslConnector :: builder ( SslMethod :: tls ( ) ) ?;
274+
275+ // We need to load these separately so an error on one doesn't prevent the other from loading.
276+ if let Some ( cert_file) = & PROBE_RESULT . cert_file {
277+ if let Err ( e) = connector. load_verify_locations ( Some ( cert_file) , None ) {
278+ debug ! ( "load_verify_locations cert file error: {:?}" , e) ;
279+ }
280+ }
281+ if let Some ( cert_dir) = & PROBE_RESULT . cert_dir {
282+ if let Err ( e) = connector. load_verify_locations ( None , Some ( cert_dir) ) {
283+ debug ! ( "load_verify_locations cert dir error: {:?}" , e) ;
284+ }
285+ }
286+
278287 if let Some ( ref identity) = builder. identity {
279288 connector. set_certificate ( & identity. 0 . cert ) ?;
280289 connector. set_private_key ( & identity. 0 . pkey ) ?;
0 commit comments