Commit 0ad45d43 authored by Ian Jackson's avatar Ian Jackson 💬
Browse files

Merge branch 'tls-trait' into 'main'

tor-rtcompat: Provide TLS wrapping for all streams

See merge request !349
parents 3e37d7e1 5f83b2b7
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ pem: (see arti#146 for discussion)


tls-api:
* Async support
* Support for disabling certificate & hostname verification
* Support for disabling certificate verification
* Support for getting certificate (or does it have it?)
* Support for RFC5705 exporters
+2 −3
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ use std::io::Result as IoResult;
use crate::impls::native_tls::NativeTlsProvider;
#[cfg(feature = "rustls")]
use crate::impls::rustls::RustlsProvider;
use async_std_crate::net::TcpStream;

use async_executors::AsyncStd;

@@ -36,7 +35,7 @@ pub struct AsyncStdNativeTlsRuntime {

/// Implementation type for AsyncStdRuntime.
#[cfg(all(feature = "native-tls"))]
type NativeTlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider<TcpStream>>;
type NativeTlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider>;

#[cfg(all(feature = "native-tls"))]
crate::opaque::implement_opaque_runtime! {
@@ -53,7 +52,7 @@ pub struct AsyncStdRustlsRuntime {

/// Implementation type for AsyncStdRustlsRuntime.
#[cfg(feature = "rustls")]
type RustlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, RustlsProvider<TcpStream>>;
type RustlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, RustlsProvider>;

#[cfg(feature = "rustls")]
crate::opaque::implement_opaque_runtime! {
+2 −3
Original line number Diff line number Diff line
@@ -118,11 +118,10 @@ where
    }
}

impl<SpawnR, SleepR, TcpR, TlsR> TlsProvider<TcpR::TcpStream>
    for CompoundRuntime<SpawnR, SleepR, TcpR, TlsR>
impl<SpawnR, SleepR, TcpR, TlsR, S> TlsProvider<S> for CompoundRuntime<SpawnR, SleepR, TcpR, TlsR>
where
    TcpR: TcpProvider,
    TlsR: TlsProvider<TcpR::TcpStream>,
    TlsR: TlsProvider<S>,
{
    type Connector = TlsR::Connector;
    type TlsStream = TlsR::TlsStream;
+5 −10
Original line number Diff line number Diff line
@@ -14,10 +14,7 @@ use std::{
///
/// It supports wrapping any reasonable stream type that implements `AsyncRead` + `AsyncWrite`.
#[non_exhaustive]
pub struct NativeTlsProvider<S> {
    /// Phantom data to ensure proper variance.
    _phantom: std::marker::PhantomData<fn(S) -> S>,
}
pub struct NativeTlsProvider {}

impl<S> CertifiedConn for async_native_tls::TlsStream<S>
where
@@ -63,7 +60,7 @@ where
    }
}

impl<S> TlsProvider<S> for NativeTlsProvider<S>
impl<S> TlsProvider<S> for NativeTlsProvider
where
    S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
@@ -90,16 +87,14 @@ where
    }
}

impl<S> NativeTlsProvider<S> {
impl NativeTlsProvider {
    /// Construct a new [`NativeTlsProvider`.]
    pub(crate) fn new() -> Self {
        NativeTlsProvider {
            _phantom: std::marker::PhantomData,
        }
        NativeTlsProvider {}
    }
}

impl<S> Default for NativeTlsProvider<S> {
impl Default for NativeTlsProvider {
    fn default() -> Self {
        Self::new()
    }
+4 −7
Original line number Diff line number Diff line
@@ -16,11 +16,9 @@ use std::{
///
/// It supports wrapping any reasonable stream type that implements `AsyncRead` + `AsyncWrite`.
#[non_exhaustive]
pub struct RustlsProvider<S> {
pub struct RustlsProvider {
    /// Inner `ClientConfig` logic used to create connectors.
    config: Arc<async_rustls::rustls::ClientConfig>,
    /// Phantom data to ensure proper variance.
    _phantom: std::marker::PhantomData<fn(S) -> S>,
}

impl<S> CertifiedConn for async_rustls::client::TlsStream<S> {
@@ -53,7 +51,7 @@ where
    }
}

impl<S> TlsProvider<S> for RustlsProvider<S>
impl<S> TlsProvider<S> for RustlsProvider
where
    S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
@@ -70,7 +68,7 @@ where
    }
}

impl<S> RustlsProvider<S> {
impl RustlsProvider {
    /// Construct a new [`RustlsProvider`.]
    pub(crate) fn new() -> Self {
        let mut config = async_rustls::rustls::ClientConfig::new();
@@ -89,12 +87,11 @@ impl<S> RustlsProvider<S> {

        RustlsProvider {
            config: Arc::new(config),
            _phantom: std::marker::PhantomData,
        }
    }
}

impl<S> Default for RustlsProvider<S> {
impl Default for RustlsProvider {
    fn default() -> Self {
        Self::new()
    }
Loading