Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Dec 9, 2019
1 parent 5ca414e commit e66e7c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ builder = ["email", "mime", "time", "base64", "uuid"]
connection-pool = ["r2d2"]
default = ["file-transport", "smtp-transport", "sendmail-transport", "rustls-tls", "builder"]
file-transport = ["serde", "serde_json"]
rustls-tls = ["webpki", "rustls"]
sendmail-transport = []
smtp-transport = ["bufstream", "base64", "nom", "hostname"]
rustls-tls = ["webpki", "rustls"]
unstable = []

[[example]]
Expand Down
13 changes: 4 additions & 9 deletions src/smtp/client/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
use crate::smtp::client::mock::MockStream;
use crate::smtp::error::Error;
#[cfg(feature = "native-tls")]
use native_tls::{Protocol, TlsConnector, TlsStream};
use native_tls::{TlsConnector, TlsStream};
#[cfg(feature = "rustls")]
use rustls::{ClientConfig, ClientSession};
#[cfg(feature = "native-tls")]
use std::io::ErrorKind;
use std::io::{self, Read, Write};
use std::net::{Ipv4Addr, Shutdown, SocketAddr, SocketAddrV4, TcpStream};
#[cfg(feature = "rustls")]
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -45,12 +46,6 @@ impl ClientTlsParameters {
}
}

/// Accepted protocols by default.
/// This removes TLS 1.0 and 1.1 compared to tls-native defaults.
/// This is also rustls' default behavior
#[cfg(feature = "native-tls")]
const DEFAULT_TLS_MIN_PROTOCOL: Protocol = Protocol::Tlsv12;

/// Represents the different types of underlying network streams
pub enum NetworkStream {
/// Plain TCP stream
Expand Down Expand Up @@ -161,7 +156,7 @@ impl Connector for NetworkStream {
.connector
.connect(context.domain.as_ref(), tcp_stream)
.map(|tls| NetworkStream::Tls(Box::new(tls)))
.map_err(|e| io::Error::new(ErrorKind::Other, e)),
.map_err(|e| Error::Io(io::Error::new(ErrorKind::Other, e))),
#[cfg(feature = "rustls")]
Some(context) => {
let domain = webpki::DNSNameRef::try_from_ascii_str(&context.domain)?;
Expand All @@ -183,7 +178,7 @@ impl Connector for NetworkStream {
.connect(tls_parameters.domain.as_ref(), stream.try_clone().unwrap())
{
Ok(tls_stream) => NetworkStream::Tls(Box::new(tls_stream)),
Err(err) => return Err(io::Error::new(ErrorKind::Other, err)),
Err(err) => return Err(Error::Io(io::Error::new(ErrorKind::Other, err))),
},
#[cfg(feature = "rustls")]
NetworkStream::Tcp(ref mut stream) => {
Expand Down
2 changes: 2 additions & 0 deletions src/smtp/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl StdError for Error {
#[cfg(feature = "native-tls")]
Tls(ref err) => err.description(),
Parsing(ref err) => err.description(),
#[cfg(feature = "rustls-tls")]
InvalidDNSName(ref err) => err.description(),
}
}
Expand Down Expand Up @@ -125,6 +126,7 @@ impl From<FromUtf8Error> for Error {
}
}

#[cfg(feature = "rustls-tls")]
impl From<webpki::InvalidDNSNameError> for Error {
fn from(err: webpki::InvalidDNSNameError) -> Error {
InvalidDNSName(err)
Expand Down
10 changes: 7 additions & 3 deletions src/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ use crate::smtp::authentication::{
Credentials, Mechanism, DEFAULT_ENCRYPTED_MECHANISMS, DEFAULT_UNENCRYPTED_MECHANISMS,
};
use crate::smtp::client::net::ClientTlsParameters;
#[cfg(feature = "native-tls")]
use crate::smtp::client::net::DEFAULT_TLS_MIN_PROTOCOL;
use crate::smtp::client::InnerClient;
use crate::smtp::commands::*;
use crate::smtp::error::{Error, SmtpResult};
use crate::smtp::extension::{ClientId, Extension, MailBodyParameter, MailParameter, ServerInfo};
use crate::{SendableEmail, Transport};
use log::{debug, info};
#[cfg(feature = "native-tls")]
use native_tls::TlsConnector;
use native_tls::{Protocol, TlsConnector};
#[cfg(feature = "rustls")]
use rustls::ClientConfig;
use std::net::{SocketAddr, ToSocketAddrs};
Expand All @@ -53,6 +51,12 @@ pub const SUBMISSION_PORT: u16 = 587;
/// Default submission over TLS port
pub const SUBMISSIONS_PORT: u16 = 465;

/// Accepted protocols by default.
/// This removes TLS 1.0 and 1.1 compared to tls-native defaults.
/// This is also rustls' default behavior
#[cfg(feature = "native-tls")]
const DEFAULT_TLS_MIN_PROTOCOL: Protocol = Protocol::Tlsv12;

/// How to apply TLS to a client connection
#[derive(Clone)]
#[allow(missing_debug_implementations)]
Expand Down

0 comments on commit e66e7c5

Please sign in to comment.