@@ -14,7 +14,7 @@ use tokio::io::{
14
14
use tokio:: net:: { TcpStream , ToSocketAddrs } ;
15
15
16
16
#[ cfg( feature = "secure" ) ]
17
- use tokio_rustls:: { rustls:: ClientConfig , webpki :: DNSName , TlsConnector } ;
17
+ use tokio_rustls:: { rustls:: ClientConfig , rustls :: ServerName , TlsConnector } ;
18
18
19
19
use crate :: data_stream:: DataStream ;
20
20
use crate :: status;
@@ -36,7 +36,7 @@ lazy_static::lazy_static! {
36
36
pub struct FtpStream {
37
37
reader : BufReader < DataStream > ,
38
38
#[ cfg( feature = "secure" ) ]
39
- ssl_cfg : Option < ( ClientConfig , DNSName ) > ,
39
+ ssl_cfg : Option < ( ClientConfig , ServerName ) > ,
40
40
welcome_msg : Option < String > ,
41
41
}
42
42
@@ -69,30 +69,29 @@ impl FtpStream {
69
69
/// ## Example
70
70
///
71
71
/// ```rust,no_run
72
+ /// use std::convert::TryFrom;
72
73
/// use std::path::Path;
73
74
/// use async_ftp::FtpStream;
74
- /// use tokio_rustls::rustls::{ClientConfig, RootCertStore};
75
- /// use tokio_rustls::webpki::{DNSName, DNSNameRef};
75
+ /// use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
76
76
///
77
77
/// let mut root_store = RootCertStore::empty();
78
78
/// // root_store.add_pem_file(...);
79
- /// let mut conf = ClientConfig::new();
80
- /// conf.root_store = root_store;
81
- /// let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
79
+ /// let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
80
+ /// let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
82
81
/// async {
83
82
/// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
84
83
/// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
85
84
/// };
86
85
/// ```
87
86
#[ cfg( feature = "secure" ) ]
88
- pub async fn into_secure ( mut self , config : ClientConfig , domain : DNSName ) -> Result < FtpStream > {
87
+ pub async fn into_secure ( mut self , config : ClientConfig , domain : ServerName ) -> Result < FtpStream > {
89
88
// Ask the server to start securing data.
90
89
self . write_str ( "AUTH TLS\r \n " ) . await ?;
91
90
self . read_response ( status:: AUTH_OK ) . await ?;
92
91
93
92
let connector: TlsConnector = std:: sync:: Arc :: new ( config. clone ( ) ) . into ( ) ;
94
93
let stream = connector
95
- . connect ( domain. as_ref ( ) , self . reader . into_inner ( ) . into_tcp_stream ( ) )
94
+ . connect ( domain. clone ( ) , self . reader . into_inner ( ) . into_tcp_stream ( ) )
96
95
. await
97
96
. map_err ( |e| FtpError :: SecureError ( format ! ( "{}" , e) ) ) ?;
98
97
@@ -116,16 +115,15 @@ impl FtpStream {
116
115
/// ## Example
117
116
///
118
117
/// ```rust,no_run
118
+ /// use std::convert::TryFrom;
119
119
/// use std::path::Path;
120
120
/// use async_ftp::FtpStream;
121
- /// use tokio_rustls::rustls::{ClientConfig, RootCertStore};
122
- /// use tokio_rustls::webpki::{DNSName, DNSNameRef};
121
+ /// use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
123
122
///
124
123
/// let mut root_store = RootCertStore::empty();
125
124
/// // root_store.add_pem_file(...);
126
- /// let mut conf = ClientConfig::new();
127
- /// conf.root_store = root_store;
128
- /// let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
125
+ /// let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
126
+ /// let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
129
127
/// async {
130
128
/// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
131
129
/// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
@@ -162,7 +160,7 @@ impl FtpStream {
162
160
Some ( ( config, domain) ) => {
163
161
let connector: TlsConnector = std:: sync:: Arc :: new ( config. clone ( ) ) . into ( ) ;
164
162
return connector
165
- . connect ( domain. as_ref ( ) , stream)
163
+ . connect ( domain. to_owned ( ) , stream)
166
164
. await
167
165
. map ( |stream| DataStream :: Ssl ( stream) )
168
166
. map_err ( |e| FtpError :: SecureError ( format ! ( "{}" , e) ) ) ;
0 commit comments