Skip to content

Commit

Permalink
Update tokio-rustls to 0.23 and release 6.0.0, this is an API break i…
Browse files Browse the repository at this point in the history
…f using the secure feature
  • Loading branch information
dani-garcia committed Nov 4, 2021
1 parent 0aabb0c commit da79249
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog


## 6.0.0
- Update tokio-rustls to 0.23
- If you don't have the `secure` feature enabled, this change doesn't affect you
- If you do have it enabled, the docs should explain the changes from `DnsName` to `ServerName`, and the setup of `ClientConfig`
## 5.1.0
- Add resume functionality
- Added function to get server welcome message.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async_ftp"
version = "5.1.0"
version = "6.0.0"
authors = ["Daniel García <dani-garcia@users.noreply.github.com>", "Matt McCoy <mattnenterprise@yahoo.com>"]
documentation = "https://docs.rs/async_ftp/"
repository = "https://github.com/dani-garcia/rust_async_ftp"
Expand All @@ -27,7 +27,7 @@ regex = "1.3.9"
chrono = "0.4.11"

tokio = { version = "1.0.1", features = ["net", "io-util"] }
tokio-rustls = { version = "0.22.0", optional = true }
tokio-rustls = { version = "0.23.0", optional = true }
pin-project = "1.0.0"

[dev-dependencies]
Expand Down
28 changes: 13 additions & 15 deletions src/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio::io::{
use tokio::net::{TcpStream, ToSocketAddrs};

#[cfg(feature = "secure")]
use tokio_rustls::{rustls::ClientConfig, webpki::DNSName, TlsConnector};
use tokio_rustls::{rustls::ClientConfig, rustls::ServerName, TlsConnector};

use crate::data_stream::DataStream;
use crate::status;
Expand All @@ -36,7 +36,7 @@ lazy_static::lazy_static! {
pub struct FtpStream {
reader: BufReader<DataStream>,
#[cfg(feature = "secure")]
ssl_cfg: Option<(ClientConfig, DNSName)>,
ssl_cfg: Option<(ClientConfig, ServerName)>,
welcome_msg: Option<String>,
}

Expand Down Expand Up @@ -69,30 +69,29 @@ impl FtpStream {
/// ## Example
///
/// ```rust,no_run
/// use std::convert::TryFrom;
/// use std::path::Path;
/// use async_ftp::FtpStream;
/// use tokio_rustls::rustls::{ClientConfig, RootCertStore};
/// use tokio_rustls::webpki::{DNSName, DNSNameRef};
/// use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
///
/// let mut root_store = RootCertStore::empty();
/// // root_store.add_pem_file(...);
/// let mut conf = ClientConfig::new();
/// conf.root_store = root_store;
/// let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
/// let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
/// let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
/// async {
/// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
/// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
/// };
/// ```
#[cfg(feature = "secure")]
pub async fn into_secure(mut self, config: ClientConfig, domain: DNSName) -> Result<FtpStream> {
pub async fn into_secure(mut self, config: ClientConfig, domain: ServerName) -> Result<FtpStream> {
// Ask the server to start securing data.
self.write_str("AUTH TLS\r\n").await?;
self.read_response(status::AUTH_OK).await?;

let connector: TlsConnector = std::sync::Arc::new(config.clone()).into();
let stream = connector
.connect(domain.as_ref(), self.reader.into_inner().into_tcp_stream())
.connect(domain.clone(), self.reader.into_inner().into_tcp_stream())
.await
.map_err(|e| FtpError::SecureError(format!("{}", e)))?;

Expand All @@ -116,16 +115,15 @@ impl FtpStream {
/// ## Example
///
/// ```rust,no_run
/// use std::convert::TryFrom;
/// use std::path::Path;
/// use async_ftp::FtpStream;
/// use tokio_rustls::rustls::{ClientConfig, RootCertStore};
/// use tokio_rustls::webpki::{DNSName, DNSNameRef};
/// use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
///
/// let mut root_store = RootCertStore::empty();
/// // root_store.add_pem_file(...);
/// let mut conf = ClientConfig::new();
/// conf.root_store = root_store;
/// let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
/// let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
/// let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
/// async {
/// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
/// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
Expand Down Expand Up @@ -162,7 +160,7 @@ impl FtpStream {
Some((config, domain)) => {
let connector: TlsConnector = std::sync::Arc::new(config.clone()).into();
return connector
.connect(domain.as_ref(), stream)
.connect(domain.to_owned(), stream)
.await
.map(|stream| DataStream::Ssl(stream))
.map_err(|e| FtpError::SecureError(format!("{}", e)));
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! Here is a basic usage example:
//!
//! ```rust
//! ```rust,no_run
//! use async_ftp::FtpStream;
//! async {
//! let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap_or_else(|err|
Expand All @@ -28,19 +28,18 @@
//! ### FTPS Usage
//!
//! ```rust,no_run
//! use std::convert::TryFrom;
//! use std::path::Path;
//! use async_ftp::FtpStream;
//! use tokio_rustls::rustls::{ClientConfig, RootCertStore};
//! use tokio_rustls::webpki::{DNSName, DNSNameRef};
//! use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
//!
//! async {
//! let ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
//!
//! let mut root_store = RootCertStore::empty();
//! // root_store.add_pem_file(...);
//! let mut conf = ClientConfig::new();
//! conf.root_store = root_store;
//! let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
//! let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
//! let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
//!
//! // Switch to the secure mode
//! let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
Expand Down

0 comments on commit da79249

Please sign in to comment.