@@ -12,7 +12,11 @@ use std::sync::OnceLock;
1212#[ cfg( all( feature = "native-tls" , not( feature = "rustls" ) ) ) ]
1313use native_tls:: { HandshakeError , TlsConnector , TlsStream } ;
1414#[ cfg( feature = "rustls" ) ]
15- use rustls:: { self , ClientConfig , ClientConnection , RootCertStore , ServerName , StreamOwned } ;
15+ use rustls:: {
16+ self ,
17+ pki_types:: { ServerName , TrustAnchor } ,
18+ ClientConfig , ClientConnection , RootCertStore , StreamOwned ,
19+ } ;
1620#[ cfg( all( feature = "native-tls" , not( feature = "rustls" ) , feature = "tokio-native-tls" ) ) ]
1721use tokio_native_tls:: TlsConnector as AsyncTlsConnector ;
1822#[ cfg( feature = "tokio-rustls" ) ]
@@ -47,19 +51,14 @@ fn build_client_config() -> Arc<ClientConfig> {
4751 }
4852
4953 #[ cfg( feature = "rustls-webpki" ) ]
50- #[ allow( deprecated) ] // Need to use add_server_trust_anchors to compile with rustls 0.21.1
51- root_certificates. add_server_trust_anchors ( TLS_SERVER_ROOTS . iter ( ) . map ( |ta| {
52- rustls:: OwnedTrustAnchor :: from_subject_spki_name_constraints (
53- ta. subject ,
54- ta. spki ,
55- ta. name_constraints ,
56- )
54+ root_certificates. extend ( TLS_SERVER_ROOTS . iter ( ) . map ( |ta| TrustAnchor {
55+ subject : ta. subject . into ( ) ,
56+ subject_public_key_info : ta. spki . into ( ) ,
57+ name_constraints : ta. name_constraints . map ( Into :: into) ,
5758 } ) ) ;
5859
59- let config = ClientConfig :: builder ( )
60- . with_safe_defaults ( )
61- . with_root_certificates ( root_certificates)
62- . with_no_client_auth ( ) ;
60+ let config =
61+ ClientConfig :: builder ( ) . with_root_certificates ( root_certificates) . with_no_client_auth ( ) ;
6362 Arc :: new ( config)
6463}
6564
@@ -71,8 +70,9 @@ pub(super) fn wrap_stream(tcp: TcpStream, host: &str) -> Result<SecuredStream, E
7170 Ok ( result) => result,
7271 Err ( err) => return Err ( Error :: IoError ( io:: Error :: new ( io:: ErrorKind :: Other , err) ) ) ,
7372 } ;
74- let sess = ClientConnection :: new ( CONFIG . get_or_init ( build_client_config) . clone ( ) , dns_name)
75- . map_err ( Error :: RustlsCreateConnection ) ?;
73+ let sess =
74+ ClientConnection :: new ( CONFIG . get_or_init ( build_client_config) . clone ( ) , dns_name. to_owned ( ) )
75+ . map_err ( Error :: RustlsCreateConnection ) ?;
7676
7777 #[ cfg( feature = "log" ) ]
7878 log:: trace!( "Establishing TLS session to {host}." ) ;
@@ -101,7 +101,7 @@ pub(super) async fn wrap_async_stream(
101101 #[ cfg( feature = "log" ) ]
102102 log:: trace!( "Establishing TLS session to {host}." ) ;
103103
104- let tls = connector. connect ( dns_name, tcp) . await . map_err ( Error :: IoError ) ?;
104+ let tls = connector. connect ( dns_name. to_owned ( ) , tcp) . await . map_err ( Error :: IoError ) ?;
105105
106106 Ok ( AsyncHttpStream :: Secured ( Box :: new ( tls) ) )
107107}
0 commit comments