@@ -85,7 +85,7 @@ use openssl::ssl::{SslConnector as OpenSslConnector, SslMethod};
85
85
#[ cfg( feature = "openssl-tls" ) ]
86
86
use tokio_openssl:: SslStream ;
87
87
#[ cfg( feature = "rustls-base" ) ]
88
- use webpki :: DNSNameRef ;
88
+ use tokio_rustls :: rustls :: ServerName ;
89
89
90
90
type BoxError = Box < dyn std:: error:: Error + Send + Sync > ;
91
91
@@ -288,19 +288,31 @@ impl<C> ProxyConnector<C> {
288
288
/// Create a new secured Proxies
289
289
#[ cfg( feature = "rustls-base" ) ]
290
290
pub fn new ( connector : C ) -> Result < Self , io:: Error > {
291
- let mut config = tokio_rustls:: rustls:: ClientConfig :: new ( ) ;
291
+ let mut config = tokio_rustls:: rustls:: ClientConfig :: builder ( ) ;
292
292
293
293
#[ cfg( feature = "rustls" ) ]
294
294
{
295
- config. root_store =
296
- rustls_native_certs:: load_native_certs ( ) . map_err ( |( _store, io) | io) ?;
295
+ let mut roots = tokio_rustls:: rustls:: RootCertStore :: empty ( ) ;
296
+ for cert in rustls_native_certs:: load_native_certs ( ) ? {
297
+ let cert = rustls:: Certificate ( cert. 0 ) ;
298
+ roots. add ( & cert) . map_err ( io_err) ?;
299
+ }
300
+ config. with_root_certificates ( roots) . with_no_client_auth ( )
297
301
}
298
302
299
303
#[ cfg( feature = "rustls-webpki" ) ]
300
304
{
301
- config
302
- . root_store
303
- . add_server_trust_anchors ( & webpki_roots:: TLS_SERVER_ROOTS ) ;
305
+ let mut roots = tokio_rustls:: rustls:: RootCertStore :: empty ( ) ;
306
+ roots. add_server_trust_anchors ( webpki_roots:: TLS_SERVER_ROOTS . 0 . into_iter ( ) . map (
307
+ |trust_achor| {
308
+ rustls:: OwnedTrustAnchor :: from_subject_spki_name_constraints (
309
+ trust_anchor. subject ,
310
+ trust_anchor. spki ,
311
+ trust_anchor. name_constraints ,
312
+ )
313
+ }
314
+ ) ) ;
315
+ config. with_root_certificates ( roots) . with_no_client_auth ( )
304
316
}
305
317
306
318
let cfg = Arc :: new ( config) ;
@@ -442,7 +454,13 @@ where
442
454
if let ( Some ( p) , Some ( host) ) = ( self . match_proxy ( & uri) , uri. host ( ) ) {
443
455
if uri. scheme ( ) == Some ( & http:: uri:: Scheme :: HTTPS ) || p. force_connect {
444
456
let host = host. to_owned ( ) ;
445
- let port = uri. port_u16 ( ) . unwrap_or ( if uri. scheme ( ) == Some ( & http:: uri:: Scheme :: HTTP ) { 80 } else { 443 } ) ;
457
+ let port =
458
+ uri. port_u16 ( )
459
+ . unwrap_or ( if uri. scheme ( ) == Some ( & http:: uri:: Scheme :: HTTP ) {
460
+ 80
461
+ } else {
462
+ 443
463
+ } ) ;
446
464
let tunnel = tunnel:: new ( & host, port, & p. headers ) ;
447
465
let connection =
448
466
proxy_dst ( & uri, & p. uri ) . map ( |proxy_url| self . connector . call ( proxy_url) ) ;
@@ -471,7 +489,7 @@ where
471
489
#[ cfg( feature = "rustls-base" ) ]
472
490
Some ( tls) => {
473
491
let dnsref =
474
- mtry ! ( DNSNameRef :: try_from_ascii_str ( & host) . map_err( io_err) ) ;
492
+ mtry ! ( ServerName :: try_from ( host. as_str ( ) ) . map_err( io_err) ) ;
475
493
let tls = TlsConnector :: from ( tls) ;
476
494
let secure_stream =
477
495
mtry ! ( tls. connect( dnsref, tunnel_stream) . await . map_err( io_err) ) ;
0 commit comments