@@ -12,7 +12,7 @@ use regex::Regex;
12
12
use chrono:: { DateTime , UTC } ;
13
13
use chrono:: offset:: TimeZone ;
14
14
#[ cfg( feature = "secure" ) ]
15
- use openssl:: ssl:: { Ssl , SslStream , IntoSsl } ;
15
+ use openssl:: ssl:: { SslContext , Ssl } ;
16
16
use super :: data_stream:: DataStream ;
17
17
use super :: status;
18
18
use super :: types:: { FileType , FtpError , Line , Result } ;
@@ -34,7 +34,7 @@ lazy_static! {
34
34
pub struct FtpStream {
35
35
reader : BufReader < DataStream > ,
36
36
#[ cfg( feature = "secure" ) ]
37
- ssl_cfg : Option < Ssl > ,
37
+ ssl_cfg : Option < SslContext > ,
38
38
}
39
39
40
40
impl FtpStream {
@@ -77,26 +77,28 @@ impl FtpStream {
77
77
/// ## Example
78
78
///
79
79
/// ```rust,no_run
80
+ /// use std::path::Path;
80
81
/// use ftp::FtpStream;
81
- /// use ftp::openssl::ssl::* ;
82
+ /// use ftp::openssl::ssl::{ SslContext, SslMethod } ;
82
83
///
83
84
/// // Create an SslContext with a custom cert.
84
- /// let mut ctx = SslContext::new(SslMethod::Sslv23).unwrap();
85
- /// let _ = ctx.set_CA_file("/path/to/a/cert.pem").unwrap();
85
+ /// let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
86
+ /// let _ = ctx.set_ca_file(Path::new("/path/to/a/cert.pem")).unwrap();
87
+ /// let ctx = ctx.build();
86
88
/// let mut ftp_stream = FtpStream::connect("127.0.0.1:21").unwrap();
87
- /// let mut ftp_stream = ftp_stream.into_secure(& ctx).unwrap();
89
+ /// let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap();
88
90
/// ```
89
91
#[ cfg( feature = "secure" ) ]
90
- pub fn into_secure < T : IntoSsl + Clone > ( mut self , ssl : T ) -> Result < FtpStream > {
92
+ pub fn into_secure ( mut self , ssl_context : SslContext ) -> Result < FtpStream > {
91
93
// Ask the server to start securing data.
92
94
try!( self . write_str ( "AUTH TLS\r \n " ) ) ;
93
95
try!( self . read_response ( status:: AUTH_OK ) ) ;
94
- let ssl_copy = try!( ssl . clone ( ) . into_ssl ( ) . map_err ( |e| FtpError :: SecureError ( e. description ( ) . to_owned ( ) ) ) ) ;
95
- let stream = try!( SslStream :: connect ( ssl , self . reader . into_inner ( ) . into_tcp_stream ( ) )
96
- . map_err ( |e| FtpError :: SecureError ( e . description ( ) . to_owned ( ) ) ) ) ;
96
+ let ssl_cfg = try!( Ssl :: new ( & ssl_context ) . map_err ( |e| FtpError :: SecureError ( e. description ( ) . to_owned ( ) ) ) ) ;
97
+ let stream = try!( ssl_cfg . connect ( self . reader . into_inner ( ) . into_tcp_stream ( ) ) . map_err ( |e| FtpError :: SecureError ( e . description ( ) . to_owned ( ) ) ) ) ;
98
+
97
99
let mut secured_ftp_tream = FtpStream {
98
100
reader : BufReader :: new ( DataStream :: Ssl ( stream) ) ,
99
- ssl_cfg : Some ( ssl_copy )
101
+ ssl_cfg : Some ( ssl_context )
100
102
} ;
101
103
// Set protection buffer size
102
104
try!( secured_ftp_tream. write_str ( "PBSZ 0\r \n " ) ) ;
@@ -113,14 +115,17 @@ impl FtpStream {
113
115
/// ## Example
114
116
///
115
117
/// ```rust,no_run
118
+ /// use std::path::Path;
116
119
/// use ftp::FtpStream;
117
- /// use ftp::openssl::ssl::*;
120
+ ///
121
+ /// use ftp::openssl::ssl::{ SslContext, SslMethod };
118
122
///
119
123
/// // Create an SslContext with a custom cert.
120
- /// let mut ctx = SslContext::new(SslMethod::Sslv23).unwrap();
121
- /// let _ = ctx.set_CA_file("/path/to/a/cert.pem").unwrap();
124
+ /// let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
125
+ /// let _ = ctx.set_ca_file(Path::new("/path/to/a/cert.pem")).unwrap();
126
+ /// let ctx = ctx.build();
122
127
/// let mut ftp_stream = FtpStream::connect("127.0.0.1:21").unwrap();
123
- /// let mut ftp_stream = ftp_stream.into_secure(& ctx).unwrap();
128
+ /// let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap();
124
129
/// // Do all secret things
125
130
/// // Switch back to the insecure mode
126
131
/// let mut ftp_stream = ftp_stream.into_insecure().unwrap();
@@ -158,7 +163,7 @@ impl FtpStream {
158
163
. and_then ( |stream| {
159
164
match self . ssl_cfg {
160
165
Some ( ref ssl) => {
161
- SslStream :: connect ( ssl. clone ( ) , stream)
166
+ Ssl :: new ( ssl) . unwrap ( ) . connect ( stream)
162
167
. map ( |stream| DataStream :: Ssl ( stream) )
163
168
. map_err ( |e| FtpError :: SecureError ( e. description ( ) . to_owned ( ) ) )
164
169
} ,
0 commit comments