mirror of https://github.com/fafhrd91/actix-net
use prefix tls acceptors
This commit is contained in:
parent
25ed4ba4eb
commit
236c0a6b12
|
@ -1,23 +1,30 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## Unreleased - 2021-xx-xx
|
||||||
* There are now no default features. [#422]
|
### Added
|
||||||
* Implement `Default` for `connect::Resolver`. [#422]
|
|
||||||
* Derive `Debug` for `connect::Connection`. [#422]
|
* Derive `Debug` for `connect::Connection`. [#422]
|
||||||
* Remove redundant `connect::Connection::from_parts` method. [#422]
|
* Implement `Default` for `connect::Resolver`. [#422]
|
||||||
* Rename TLS acceptor service future types and hide from docs. [#422]
|
* Implement `Display` for `TlsError`. [#422]
|
||||||
* Implement `Error` for `ConnectError`. [#422]
|
* Implement `Error` for `ConnectError`. [#422]
|
||||||
* Implement `Error` for `TlsError` where both types also implement `Error`. [#422]
|
* Implement `Error` for `TlsError` where both types also implement `Error`. [#422]
|
||||||
* Rename `accept::native_tls::{NativeTlsAcceptorService => AcceptorService}`. [#422]
|
|
||||||
|
### Changed
|
||||||
|
* There are now no default features. [#422]
|
||||||
|
* Useful re-exports from underlying TLS crates are exposed in a `reexports` modules in all acceptors and connectors.
|
||||||
|
* Convert `connect::ResolverService` from enum to struct. [#422]
|
||||||
* Make `ConnectAddrsIter` private. [#422]
|
* Make `ConnectAddrsIter` private. [#422]
|
||||||
|
* Rename `accept::native_tls::{NativeTlsAcceptorService => AcceptorService}`. [#422]
|
||||||
|
* Rename `connect::{Address => Host}` trait. [#422]
|
||||||
* Rename method `connect::Connection::{host => hostname}`. [#422]
|
* Rename method `connect::Connection::{host => hostname}`. [#422]
|
||||||
* Rename struct `connect::{Connect => ConnectionInfo}`. [#422]
|
* Rename struct `connect::{Connect => ConnectionInfo}`. [#422]
|
||||||
* Rename struct `connect::{ConnectServiceFactory => Connector}`. [#422]
|
|
||||||
* Rename struct `connect::{ConnectService => ConnectorService}`. [#422]
|
* Rename struct `connect::{ConnectService => ConnectorService}`. [#422]
|
||||||
|
* Rename struct `connect::{ConnectServiceFactory => Connector}`. [#422]
|
||||||
|
* Rename TLS acceptor service future types and hide from docs. [#422]
|
||||||
|
|
||||||
|
### Removed
|
||||||
* Remove `connect::{new_connector, new_connector_factory, default_connector, default_connector_factory}` methods. [#422]
|
* Remove `connect::{new_connector, new_connector_factory, default_connector, default_connector_factory}` methods. [#422]
|
||||||
* Convert `connect::ResolverService` from enum to struct. [#422]
|
|
||||||
* Remove `connect::native_tls::Connector::service` method. [#422]
|
* Remove `connect::native_tls::Connector::service` method. [#422]
|
||||||
* Rename `connect::{Address => Host}` trait. [#422]
|
* Remove redundant `connect::Connection::from_parts` method. [#422]
|
||||||
|
|
||||||
[#422]: https://github.com/actix/actix-net/pull/422
|
[#422]: https://github.com/actix/actix-net/pull/422
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ name = "actix_tls"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["accept", "connect", "uri", "rustls", "openssl", "native-tls"]
|
||||||
|
|
||||||
# enable acceptor services
|
# enable acceptor services
|
||||||
accept = []
|
accept = []
|
||||||
|
|
|
@ -22,10 +22,16 @@ use actix_utils::{
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut, From};
|
use derive_more::{Deref, DerefMut, From};
|
||||||
use futures_core::future::LocalBoxFuture;
|
use futures_core::future::LocalBoxFuture;
|
||||||
pub use tokio_native_tls::{native_tls::Error, TlsAcceptor};
|
use tokio_native_tls::{native_tls::Error, TlsAcceptor};
|
||||||
|
|
||||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||||
|
|
||||||
|
pub mod reexports {
|
||||||
|
//! Re-exports from `native-tls` that are useful for acceptors.
|
||||||
|
|
||||||
|
pub use tokio_native_tls::{native_tls::Error, TlsAcceptor};
|
||||||
|
}
|
||||||
|
|
||||||
/// Wraps a `native-tls` based async TLS stream in order to implement [`ActixStream`].
|
/// Wraps a `native-tls` based async TLS stream in order to implement [`ActixStream`].
|
||||||
#[derive(Deref, DerefMut, From)]
|
#[derive(Deref, DerefMut, From)]
|
||||||
pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>);
|
pub struct TlsStream<IO>(tokio_native_tls::TlsStream<IO>);
|
||||||
|
|
|
@ -22,13 +22,19 @@ use actix_utils::{
|
||||||
future::{ready, Ready as FutReady},
|
future::{ready, Ready as FutReady},
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut, From};
|
use derive_more::{Deref, DerefMut, From};
|
||||||
pub use openssl::ssl::{
|
use openssl::ssl::{Error, Ssl, SslAcceptor};
|
||||||
AlpnError, Error, HandshakeError, Ssl, SslAcceptor, SslAcceptorBuilder,
|
|
||||||
};
|
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||||
|
|
||||||
|
pub mod reexports {
|
||||||
|
//! Re-exports from `openssl` that are useful for acceptors.
|
||||||
|
|
||||||
|
pub use openssl::ssl::{
|
||||||
|
AlpnError, Error, HandshakeError, Ssl, SslAcceptor, SslAcceptorBuilder,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
|
/// Wraps an `openssl` based async TLS stream in order to implement [`ActixStream`].
|
||||||
#[derive(Deref, DerefMut, From)]
|
#[derive(Deref, DerefMut, From)]
|
||||||
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
|
pub struct TlsStream<IO>(tokio_openssl::SslStream<IO>);
|
||||||
|
|
|
@ -24,11 +24,17 @@ use actix_utils::{
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut, From};
|
use derive_more::{Deref, DerefMut, From};
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
pub use tokio_rustls::rustls::ServerConfig;
|
use tokio_rustls::rustls::ServerConfig;
|
||||||
use tokio_rustls::{Accept, TlsAcceptor};
|
use tokio_rustls::{Accept, TlsAcceptor};
|
||||||
|
|
||||||
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
use super::{TlsError, DEFAULT_TLS_HANDSHAKE_TIMEOUT, MAX_CONN_COUNTER};
|
||||||
|
|
||||||
|
pub mod reexports {
|
||||||
|
//! Re-exports from `rustls` that are useful for acceptors.
|
||||||
|
|
||||||
|
pub use tokio_rustls::rustls::ServerConfig;
|
||||||
|
}
|
||||||
|
|
||||||
/// Wraps a `rustls` based async TLS stream in order to implement [`ActixStream`].
|
/// Wraps a `rustls` based async TLS stream in order to implement [`ActixStream`].
|
||||||
#[derive(Deref, DerefMut, From)]
|
#[derive(Deref, DerefMut, From)]
|
||||||
pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>);
|
pub struct TlsStream<IO>(tokio_rustls::server::TlsStream<IO>);
|
||||||
|
|
|
@ -18,7 +18,7 @@ use super::{
|
||||||
|
|
||||||
/// Combined resolver and TCP connector service factory.
|
/// Combined resolver and TCP connector service factory.
|
||||||
///
|
///
|
||||||
/// Used to create [`ConnectService`]s which receive connection information, resolve DNS if
|
/// Used to create [`ConnectorService`]s which receive connection information, resolve DNS if
|
||||||
/// required, and return a TCP stream.
|
/// required, and return a TCP stream.
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct Connector {
|
pub struct Connector {
|
||||||
|
|
|
@ -7,11 +7,9 @@
|
||||||
//! # Stages of TLS connector services:
|
//! # Stages of TLS connector services:
|
||||||
//! 1. Resolve DNS and establish a [`TcpStream`] with the TCP connector service.
|
//! 1. Resolve DNS and establish a [`TcpStream`] with the TCP connector service.
|
||||||
//! 1. Wrap the stream and perform connect handshake with remote peer.
|
//! 1. Wrap the stream and perform connect handshake with remote peer.
|
||||||
//! 1. Return wrapped stream type that implements [`AsyncRead`] and [`AsyncWrite`].
|
//! 1. Return wrapped stream type that implements `AsyncRead` and `AsyncWrite`.
|
||||||
//!
|
//!
|
||||||
//! [`TcpStream`]: actix_rt::net::TcpStream
|
//! [`TcpStream`]: actix_rt::net::TcpStream
|
||||||
//! [`AsyncRead`]: actix_rt::net::AsyncRead
|
|
||||||
//! [`AsyncWrite`]: actix_rt::net::AsyncWrite
|
|
||||||
|
|
||||||
mod connect_addrs;
|
mod connect_addrs;
|
||||||
mod connection;
|
mod connection;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Native-TLS based connector service.
|
//! Native-TLS based connector service.
|
||||||
//!
|
//!
|
||||||
//! See [`Connector`] for main connector service factory docs.
|
//! See [`TlsConnector`] for main connector service factory docs.
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! OpenSSL based connector service.
|
//! OpenSSL based connector service.
|
||||||
//!
|
//!
|
||||||
//! See [`Connector`] for main connector service factory docs.
|
//! See [`TlsConnector`] for main connector service factory docs.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
|
@ -26,23 +26,23 @@ pub mod reexports {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connector service factory using `openssl`.
|
/// Connector service factory using `openssl`.
|
||||||
pub struct Connector {
|
pub struct TlsConnector {
|
||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connector {
|
impl TlsConnector {
|
||||||
/// Constructs new connector service factory from an `openssl` connector.
|
/// Constructs new connector service factory from an `openssl` connector.
|
||||||
pub fn new(connector: SslConnector) -> Self {
|
pub fn new(connector: SslConnector) -> Self {
|
||||||
Connector { connector }
|
TlsConnector { connector }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs new connector service from an `openssl` connector.
|
/// Constructs new connector service from an `openssl` connector.
|
||||||
pub fn service(connector: SslConnector) -> ConnectorService {
|
pub fn service(connector: SslConnector) -> TlsConnectorService {
|
||||||
ConnectorService { connector }
|
TlsConnectorService { connector }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Connector {
|
impl Clone for TlsConnector {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connector: self.connector.clone(),
|
connector: self.connector.clone(),
|
||||||
|
@ -50,7 +50,7 @@ impl Clone for Connector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, IO> ServiceFactory<Connection<R, IO>> for Connector
|
impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
|
||||||
where
|
where
|
||||||
R: Host,
|
R: Host,
|
||||||
IO: ActixStream + 'static,
|
IO: ActixStream + 'static,
|
||||||
|
@ -58,23 +58,23 @@ where
|
||||||
type Response = Connection<R, SslStream<IO>>;
|
type Response = Connection<R, SslStream<IO>>;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
type Service = ConnectorService;
|
type Service = TlsConnectorService;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = Ready<Result<Self::Service, Self::InitError>>;
|
type Future = Ready<Result<Self::Service, Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, _: ()) -> Self::Future {
|
fn new_service(&self, _: ()) -> Self::Future {
|
||||||
ok(ConnectorService {
|
ok(TlsConnectorService {
|
||||||
connector: self.connector.clone(),
|
connector: self.connector.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connector service using `openssl`.
|
/// Connector service using `openssl`.
|
||||||
pub struct ConnectorService {
|
pub struct TlsConnectorService {
|
||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for ConnectorService {
|
impl Clone for TlsConnectorService {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connector: self.connector.clone(),
|
connector: self.connector.clone(),
|
||||||
|
@ -82,7 +82,7 @@ impl Clone for ConnectorService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, IO> Service<Connection<R, IO>> for ConnectorService
|
impl<R, IO> Service<Connection<R, IO>> for TlsConnectorService
|
||||||
where
|
where
|
||||||
R: Host,
|
R: Host,
|
||||||
IO: ActixStream,
|
IO: ActixStream,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Rustls based connector service.
|
//! Rustls based connector service.
|
||||||
//!
|
//!
|
||||||
//! See [`Connector`] for main connector service factory docs.
|
//! See [`TlsConnector`] for main connector service factory docs.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
|
@ -48,23 +48,23 @@ pub fn webpki_roots_cert_store() -> RootCertStore {
|
||||||
|
|
||||||
/// Connector service factory using `rustls`.
|
/// Connector service factory using `rustls`.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Connector {
|
pub struct TlsConnector {
|
||||||
connector: Arc<ClientConfig>,
|
connector: Arc<ClientConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connector {
|
impl TlsConnector {
|
||||||
/// Constructs new connector service factory from a `rustls` client configuration.
|
/// Constructs new connector service factory from a `rustls` client configuration.
|
||||||
pub fn new(connector: Arc<ClientConfig>) -> Self {
|
pub fn new(connector: Arc<ClientConfig>) -> Self {
|
||||||
Connector { connector }
|
TlsConnector { connector }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs new connector service from a `rustls` client configuration.
|
/// Constructs new connector service from a `rustls` client configuration.
|
||||||
pub fn service(connector: Arc<ClientConfig>) -> ConnectorService {
|
pub fn service(connector: Arc<ClientConfig>) -> TlsConnectorService {
|
||||||
ConnectorService { connector }
|
TlsConnectorService { connector }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, IO> ServiceFactory<Connection<R, IO>> for Connector
|
impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
|
||||||
where
|
where
|
||||||
R: Host,
|
R: Host,
|
||||||
IO: ActixStream + 'static,
|
IO: ActixStream + 'static,
|
||||||
|
@ -72,12 +72,12 @@ where
|
||||||
type Response = Connection<R, TlsStream<IO>>;
|
type Response = Connection<R, TlsStream<IO>>;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
type Service = ConnectorService;
|
type Service = TlsConnectorService;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = Ready<Result<Self::Service, Self::InitError>>;
|
type Future = Ready<Result<Self::Service, Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, _: ()) -> Self::Future {
|
fn new_service(&self, _: ()) -> Self::Future {
|
||||||
ok(ConnectorService {
|
ok(TlsConnectorService {
|
||||||
connector: self.connector.clone(),
|
connector: self.connector.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -85,11 +85,11 @@ where
|
||||||
|
|
||||||
/// Connector service using `rustls`.
|
/// Connector service using `rustls`.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ConnectorService {
|
pub struct TlsConnectorService {
|
||||||
connector: Arc<ClientConfig>,
|
connector: Arc<ClientConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, IO> Service<Connection<R, IO>> for ConnectorService
|
impl<R, IO> Service<Connection<R, IO>> for TlsConnectorService
|
||||||
where
|
where
|
||||||
R: Host,
|
R: Host,
|
||||||
IO: ActixStream,
|
IO: ActixStream,
|
||||||
|
|
Loading…
Reference in New Issue