|
|
@@ -122,6 +122,8 @@ pub struct Dialer {
|
|
|
endpoint: Url,
|
|
|
/// The dialer variant (transport protocol)
|
|
|
variant: DialerVariant,
|
|
|
+ /// Marker if TLS client certificate should be provided for this instance
|
|
|
+ provide_tls_client_cert: bool,
|
|
|
}
|
|
|
|
|
|
macro_rules! enforce_hostport {
|
|
|
@@ -151,6 +153,7 @@ impl Dialer {
|
|
|
endpoint: Url,
|
|
|
datastore: Option<String>,
|
|
|
i2p_socks5_proxy: Option<Url>,
|
|
|
+ provide_tls_client_cert: bool,
|
|
|
) -> io::Result<Self> {
|
|
|
match endpoint.scheme().to_lowercase().as_str() {
|
|
|
"tcp" => {
|
|
|
@@ -158,7 +161,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tcp::TcpDialer::new(None).await?;
|
|
|
let variant = DialerVariant::Tcp(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
"tcp+tls" => {
|
|
|
@@ -166,7 +169,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tcp::TcpDialer::new(None).await?;
|
|
|
let variant = DialerVariant::TcpTls(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-tor")]
|
|
|
@@ -175,7 +178,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tor::TorDialer::new(datastore).await?;
|
|
|
let variant = DialerVariant::Tor(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-tor")]
|
|
|
@@ -184,7 +187,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tor::TorDialer::new(datastore).await?;
|
|
|
let variant = DialerVariant::TorTls(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-nym")]
|
|
|
@@ -193,7 +196,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = nym::NymDialer::new().await?;
|
|
|
let variant = DialerVariant::Nym(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-nym")]
|
|
|
@@ -202,7 +205,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = nym::NymDialer::new().await?;
|
|
|
let variant = DialerVariant::NymTls(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-unix")]
|
|
|
@@ -211,7 +214,7 @@ impl Dialer {
|
|
|
enforce_abspath!(endpoint);
|
|
|
let variant = unix::UnixDialer::new().await?;
|
|
|
let variant = DialerVariant::Unix(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-socks5")]
|
|
|
@@ -220,7 +223,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = socks5::Socks5Dialer::new(&endpoint).await?;
|
|
|
let variant = DialerVariant::Socks5(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-socks5")]
|
|
|
@@ -229,7 +232,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = socks5::Socks5Dialer::new(&endpoint).await?;
|
|
|
let variant = DialerVariant::Socks5Tls(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-i2p")]
|
|
|
@@ -240,7 +243,7 @@ impl Dialer {
|
|
|
url.set_path(&format!("{}:{}", endpoint.host().unwrap(), endpoint.port().unwrap()));
|
|
|
let variant = socks5::Socks5Dialer::new(&url).await?;
|
|
|
let variant = DialerVariant::Socks5(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-i2p")]
|
|
|
@@ -252,7 +255,7 @@ impl Dialer {
|
|
|
url.set_scheme("socks5+tls").unwrap();
|
|
|
let variant = socks5::Socks5Dialer::new(&url).await?;
|
|
|
let variant = DialerVariant::Socks5Tls(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-quic")]
|
|
|
@@ -261,7 +264,7 @@ impl Dialer {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = quic::QuicDialer::new().await?;
|
|
|
let variant = DialerVariant::Quic(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, provide_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
x => {
|
|
|
@@ -288,7 +291,7 @@ impl Dialer {
|
|
|
DialerVariant::TcpTls(dialer) => {
|
|
|
let sockaddr = self.endpoint.socket_addrs(|| None)?;
|
|
|
let stream = dialer.do_dial(sockaddr[0], timeout).await?;
|
|
|
- let tlsupgrade = tls::TlsUpgrade::new().await?;
|
|
|
+ let tlsupgrade = tls::TlsUpgrade::new(self.provide_tls_client_cert).await?;
|
|
|
let stream = tlsupgrade.upgrade_dialer_tls(stream).await?;
|
|
|
Ok(Box::new(stream))
|
|
|
}
|
|
|
@@ -306,7 +309,7 @@ impl Dialer {
|
|
|
let host = self.endpoint.host_str().unwrap();
|
|
|
let port = self.endpoint.port().unwrap();
|
|
|
let stream = dialer.do_dial(host, port, timeout).await?;
|
|
|
- let tlsupgrade = tls::TlsUpgrade::new().await?;
|
|
|
+ let tlsupgrade = tls::TlsUpgrade::new(self.provide_tls_client_cert).await?;
|
|
|
let stream = tlsupgrade.upgrade_dialer_tls(stream).await?;
|
|
|
Ok(Box::new(stream))
|
|
|
}
|
|
|
@@ -340,7 +343,7 @@ impl Dialer {
|
|
|
#[cfg(feature = "p2p-socks5")]
|
|
|
DialerVariant::Socks5Tls(dialer) => {
|
|
|
let stream = dialer.do_dial().await?;
|
|
|
- let tlsupgrade = tls::TlsUpgrade::new().await?;
|
|
|
+ let tlsupgrade = tls::TlsUpgrade::new(self.provide_tls_client_cert).await?;
|
|
|
let stream = tlsupgrade.upgrade_dialer_tls(stream).await?;
|
|
|
Ok(Box::new(stream))
|
|
|
}
|
|
|
@@ -366,19 +369,25 @@ pub struct Listener {
|
|
|
endpoint: Url,
|
|
|
/// The listener variant (transport protocol)
|
|
|
variant: ListenerVariant,
|
|
|
+ /// Marker if TLS client cert should be required for this instance
|
|
|
+ require_tls_client_cert: bool,
|
|
|
}
|
|
|
|
|
|
impl Listener {
|
|
|
/// Instantiate a new [`Listener`] with the given [`Url`] and datastore path.
|
|
|
/// Must contain a scheme, host string, and a port.
|
|
|
- pub async fn new(endpoint: Url, datastore: Option<String>) -> io::Result<Self> {
|
|
|
+ pub async fn new(
|
|
|
+ endpoint: Url,
|
|
|
+ datastore: Option<String>,
|
|
|
+ require_tls_client_cert: bool,
|
|
|
+ ) -> io::Result<Self> {
|
|
|
match endpoint.scheme().to_lowercase().as_str() {
|
|
|
"tcp" => {
|
|
|
// Build a TCP listener
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tcp::TcpListener::new(1024).await?;
|
|
|
let variant = ListenerVariant::Tcp(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, require_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
"tcp+tls" => {
|
|
|
@@ -386,7 +395,7 @@ impl Listener {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tcp::TcpListener::new(1024).await?;
|
|
|
let variant = ListenerVariant::TcpTls(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, require_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-tor")]
|
|
|
@@ -395,7 +404,7 @@ impl Listener {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = tor::TorListener::new(datastore).await?;
|
|
|
let variant = ListenerVariant::Tor(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, require_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-unix")]
|
|
|
@@ -403,7 +412,7 @@ impl Listener {
|
|
|
enforce_abspath!(endpoint);
|
|
|
let variant = unix::UnixListener::new().await?;
|
|
|
let variant = ListenerVariant::Unix(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, require_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
#[cfg(feature = "p2p-quic")]
|
|
|
@@ -411,7 +420,7 @@ impl Listener {
|
|
|
enforce_hostport!(endpoint);
|
|
|
let variant = quic::QuicListener::new().await?;
|
|
|
let variant = ListenerVariant::Quic(variant);
|
|
|
- Ok(Self { endpoint, variant })
|
|
|
+ Ok(Self { endpoint, variant, require_tls_client_cert })
|
|
|
}
|
|
|
|
|
|
x => {
|
|
|
@@ -434,7 +443,7 @@ impl Listener {
|
|
|
ListenerVariant::TcpTls(listener) => {
|
|
|
let sockaddr = self.endpoint.socket_addrs(|| None)?;
|
|
|
let l = listener.do_listen(sockaddr[0]).await?;
|
|
|
- let tlsupgrade = tls::TlsUpgrade::new().await?;
|
|
|
+ let tlsupgrade = tls::TlsUpgrade::new(self.require_tls_client_cert).await?;
|
|
|
let l = tlsupgrade.upgrade_listener_tcp_tls(l).await?;
|
|
|
Ok(Box::new(l))
|
|
|
}
|