@@ -402,13 +402,15 @@ impl ConnectionInfo {
402402 // do not apply validation if using a self-signed certificate,as the documentation suggests
403403 let config = if !validation {
404404 match tls_config {
405- ConnectionTLSConfig :: MutualTLS ( _) => tls_config,
406- _ => & ConnectionTLSConfig :: NoSSLValidation ,
405+ ConnectionTLSConfig :: MutualTLS ( mtls) => {
406+ ConnectionTLSConfig :: MutualTLS ( mtls. with_no_validation ( ) )
407+ }
408+ _ => ConnectionTLSConfig :: NoSSLValidation ,
407409 }
408410 } else {
409- tls_config
411+ tls_config. clone ( )
410412 } ;
411- Self :: tls_connector ( url. host ( ) , config)
413+ Self :: tls_connector ( url. host ( ) , & config)
412414 } )
413415 . transpose ( ) ?;
414416
@@ -498,9 +500,23 @@ impl ConnectionInfo {
498500 . with_root_certificates ( root_cert_store)
499501 . with_client_auth_cert ( cert_certs. collect ( ) , keys)
500502 . map_err ( |_e| Error :: ConnectionError ) ?
503+ } else if mutual. validation {
504+ match rustls_native_certs:: load_native_certs ( ) {
505+ Ok ( certs) => {
506+ root_cert_store. add_parsable_certificates ( certs) ;
507+ }
508+ Err ( e) => {
509+ warn ! ( "Failed to load native certificates: {e}" ) ;
510+ }
511+ }
512+ builder
513+ . with_root_certificates ( root_cert_store)
514+ . with_client_auth_cert ( cert_certs. collect ( ) , keys)
515+ . map_err ( |_e| Error :: ConnectionError ) ?
501516 } else {
502517 builder
503- . with_root_certificates ( RootCertStore :: empty ( ) )
518+ . dangerous ( )
519+ . with_custom_certificate_verifier ( Arc :: new ( NoCertificateVerification ) )
504520 . with_client_auth_cert ( cert_certs. collect ( ) , keys)
505521 . map_err ( |_e| Error :: ConnectionError ) ?
506522 }
0 commit comments