Skip to content

Commit c392899

Browse files
Luxedmattnenterprise
authored andcommitted
Update to version 0.9 of OpenSsl (#69)
* Issue with list found: No code is sent at the beginning and the and at the end of the list function List now works. Everthing after a list doesn't work (PASV mode removes codes ?) * Cannot move out of borrowed content.......... * rolled bad main branch * into secure now taking a SslContext * Updated help and test * Switched back to anonymous in help of secure ftp * Updated help: context is not a reference * Added openssl as an external crate in the tests * Got it back to the original, pre-update state * removed general imports for specific ones * No more issues (hopefully)
1 parent 0baeaa5 commit c392899

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ regex = "0.1"
3131
chrono = "0.2"
3232

3333
[dependencies.openssl]
34-
version = "0.7"
34+
version = "0.9"
3535
optional = true

src/ftp.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use regex::Regex;
1212
use chrono::{DateTime, UTC};
1313
use chrono::offset::TimeZone;
1414
#[cfg(feature = "secure")]
15-
use openssl::ssl::{Ssl, SslStream, IntoSsl};
15+
use openssl::ssl::{ SslContext, Ssl };
1616
use super::data_stream::DataStream;
1717
use super::status;
1818
use super::types::{FileType, FtpError, Line, Result};
@@ -34,7 +34,7 @@ lazy_static! {
3434
pub struct FtpStream {
3535
reader: BufReader<DataStream>,
3636
#[cfg(feature = "secure")]
37-
ssl_cfg: Option<Ssl>,
37+
ssl_cfg: Option<SslContext>,
3838
}
3939

4040
impl FtpStream {
@@ -77,26 +77,28 @@ impl FtpStream {
7777
/// ## Example
7878
///
7979
/// ```rust,no_run
80+
/// use std::path::Path;
8081
/// use ftp::FtpStream;
81-
/// use ftp::openssl::ssl::*;
82+
/// use ftp::openssl::ssl::{ SslContext, SslMethod };
8283
///
8384
/// // 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();
8688
/// 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();
8890
/// ```
8991
#[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> {
9193
// Ask the server to start securing data.
9294
try!(self.write_str("AUTH TLS\r\n"));
9395
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+
9799
let mut secured_ftp_tream = FtpStream {
98100
reader: BufReader::new(DataStream::Ssl(stream)),
99-
ssl_cfg: Some(ssl_copy)
101+
ssl_cfg: Some(ssl_context)
100102
};
101103
// Set protection buffer size
102104
try!(secured_ftp_tream.write_str("PBSZ 0\r\n"));
@@ -113,14 +115,17 @@ impl FtpStream {
113115
/// ## Example
114116
///
115117
/// ```rust,no_run
118+
/// use std::path::Path;
116119
/// use ftp::FtpStream;
117-
/// use ftp::openssl::ssl::*;
120+
///
121+
/// use ftp::openssl::ssl::{ SslContext, SslMethod };
118122
///
119123
/// // 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();
122127
/// 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();
124129
/// // Do all secret things
125130
/// // Switch back to the insecure mode
126131
/// let mut ftp_stream = ftp_stream.into_insecure().unwrap();
@@ -158,7 +163,7 @@ impl FtpStream {
158163
.and_then(|stream| {
159164
match self.ssl_cfg {
160165
Some(ref ssl) => {
161-
SslStream::connect(ssl.clone(), stream)
166+
Ssl::new(ssl).unwrap().connect(stream)
162167
.map(|stream| DataStream::Ssl(stream))
163168
.map_err(|e| FtpError::SecureError(e.description().to_owned()))
164169
},

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030
//!
3131
//! ```rust,no_run
3232
//! use ftp::FtpStream;
33-
//! use ftp::openssl::ssl::*;
33+
//! use ftp::openssl::ssl::{ SslContext, SslMethod };
3434
//!
3535
//! let ftp_stream = FtpStream::connect("127.0.0.1:21").unwrap();
36-
//! let ctx = SslContext::new(SslMethod::Sslv23).unwrap();
37-
//! let ssl = Ssl::new(&ctx).unwrap();
36+
//! let ctx = SslContext::builder(SslMethod::tls()).unwrap().build();
3837
//! // Switch to the secure mode
39-
//! let mut ftp_stream = ftp_stream.into_secure(ssl).unwrap();
38+
//! let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap();
4039
//! ftp_stream.login("anonymous", "anonymous").unwrap();
4140
//! // Do other secret stuff
4241
//! // Switch back to the insecure mode (if required)

src/path.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
Enum FtpPathType {
3+
directory,
4+
file,
5+
linc,
6+
}
7+
8+
Struct FtpPath {
9+
home: String,
10+
absolute_path: String,
11+
path_type: FtpPathType,
12+
}

0 commit comments

Comments
 (0)