@@ -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,15 @@ 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+ #[ allow( deprecated) ]
55+ root_certificates. extend ( TLS_SERVER_ROOTS . iter ( ) . map ( |ta| TrustAnchor {
56+ subject : ta. subject . into ( ) ,
57+ subject_public_key_info : ta. spki . into ( ) ,
58+ name_constraints : ta. name_constraints . map ( Into :: into) ,
5759 } ) ) ;
5860
59- let config = ClientConfig :: builder ( )
60- . with_safe_defaults ( )
61- . with_root_certificates ( root_certificates)
62- . with_no_client_auth ( ) ;
61+ let config =
62+ ClientConfig :: builder ( ) . with_root_certificates ( root_certificates) . with_no_client_auth ( ) ;
6363 Arc :: new ( config)
6464}
6565
@@ -71,8 +71,9 @@ pub(super) fn wrap_stream(tcp: TcpStream, host: &str) -> Result<SecuredStream, E
7171 Ok ( result) => result,
7272 Err ( err) => return Err ( Error :: IoError ( io:: Error :: new ( io:: ErrorKind :: Other , err) ) ) ,
7373 } ;
74- let sess = ClientConnection :: new ( CONFIG . get_or_init ( build_client_config) . clone ( ) , dns_name)
75- . map_err ( Error :: RustlsCreateConnection ) ?;
74+ let sess =
75+ ClientConnection :: new ( CONFIG . get_or_init ( build_client_config) . clone ( ) , dns_name. to_owned ( ) )
76+ . map_err ( Error :: RustlsCreateConnection ) ?;
7677
7778 #[ cfg( feature = "log" ) ]
7879 log:: trace!( "Establishing TLS session to {host}." ) ;
@@ -101,7 +102,7 @@ pub(super) async fn wrap_async_stream(
101102 #[ cfg( feature = "log" ) ]
102103 log:: trace!( "Establishing TLS session to {host}." ) ;
103104
104- let tls = connector. connect ( dns_name, tcp) . await . map_err ( Error :: IoError ) ?;
105+ let tls = connector. connect ( dns_name. to_owned ( ) , tcp) . await . map_err ( Error :: IoError ) ?;
105106
106107 Ok ( AsyncHttpStream :: Secured ( Box :: new ( tls) ) )
107108}
0 commit comments