Skip to content

Commit da79249

Browse files
committed
Update tokio-rustls to 0.23 and release 6.0.0, this is an API break if using the secure feature
1 parent 0aabb0c commit da79249

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

3-
3+
## 6.0.0
4+
- Update tokio-rustls to 0.23
5+
- If you don't have the `secure` feature enabled, this change doesn't affect you
6+
- If you do have it enabled, the docs should explain the changes from `DnsName` to `ServerName`, and the setup of `ClientConfig`
47
## 5.1.0
58
- Add resume functionality
69
- Added function to get server welcome message.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "async_ftp"
3-
version = "5.1.0"
3+
version = "6.0.0"
44
authors = ["Daniel García <[email protected]>", "Matt McCoy <[email protected]>"]
55
documentation = "https://docs.rs/async_ftp/"
66
repository = "https://github.com/dani-garcia/rust_async_ftp"
@@ -27,7 +27,7 @@ regex = "1.3.9"
2727
chrono = "0.4.11"
2828

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

3333
[dev-dependencies]

src/ftp.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tokio::io::{
1414
use tokio::net::{TcpStream, ToSocketAddrs};
1515

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

1919
use crate::data_stream::DataStream;
2020
use crate::status;
@@ -36,7 +36,7 @@ lazy_static::lazy_static! {
3636
pub struct FtpStream {
3737
reader: BufReader<DataStream>,
3838
#[cfg(feature = "secure")]
39-
ssl_cfg: Option<(ClientConfig, DNSName)>,
39+
ssl_cfg: Option<(ClientConfig, ServerName)>,
4040
welcome_msg: Option<String>,
4141
}
4242

@@ -69,30 +69,29 @@ impl FtpStream {
6969
/// ## Example
7070
///
7171
/// ```rust,no_run
72+
/// use std::convert::TryFrom;
7273
/// use std::path::Path;
7374
/// 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};
7676
///
7777
/// let mut root_store = RootCertStore::empty();
7878
/// // 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");
8281
/// async {
8382
/// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
8483
/// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
8584
/// };
8685
/// ```
8786
#[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> {
8988
// Ask the server to start securing data.
9089
self.write_str("AUTH TLS\r\n").await?;
9190
self.read_response(status::AUTH_OK).await?;
9291

9392
let connector: TlsConnector = std::sync::Arc::new(config.clone()).into();
9493
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())
9695
.await
9796
.map_err(|e| FtpError::SecureError(format!("{}", e)))?;
9897

@@ -116,16 +115,15 @@ impl FtpStream {
116115
/// ## Example
117116
///
118117
/// ```rust,no_run
118+
/// use std::convert::TryFrom;
119119
/// use std::path::Path;
120120
/// 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};
123122
///
124123
/// let mut root_store = RootCertStore::empty();
125124
/// // 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");
129127
/// async {
130128
/// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
131129
/// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
@@ -162,7 +160,7 @@ impl FtpStream {
162160
Some((config, domain)) => {
163161
let connector: TlsConnector = std::sync::Arc::new(config.clone()).into();
164162
return connector
165-
.connect(domain.as_ref(), stream)
163+
.connect(domain.to_owned(), stream)
166164
.await
167165
.map(|stream| DataStream::Ssl(stream))
168166
.map_err(|e| FtpError::SecureError(format!("{}", e)));

src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! Here is a basic usage example:
66
//!
7-
//! ```rust
7+
//! ```rust,no_run
88
//! use async_ftp::FtpStream;
99
//! async {
1010
//! let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap_or_else(|err|
@@ -28,19 +28,18 @@
2828
//! ### FTPS Usage
2929
//!
3030
//! ```rust,no_run
31+
//! use std::convert::TryFrom;
3132
//! use std::path::Path;
3233
//! use async_ftp::FtpStream;
33-
//! use tokio_rustls::rustls::{ClientConfig, RootCertStore};
34-
//! use tokio_rustls::webpki::{DNSName, DNSNameRef};
34+
//! use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
3535
//!
3636
//! async {
3737
//! let ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
3838
//!
3939
//! let mut root_store = RootCertStore::empty();
4040
//! // root_store.add_pem_file(...);
41-
//! let mut conf = ClientConfig::new();
42-
//! conf.root_store = root_store;
43-
//! let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
41+
//! let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
42+
//! let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
4443
//!
4544
//! // Switch to the secure mode
4645
//! let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();

0 commit comments

Comments
 (0)