mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 22:46:29 +03:00
HTTPS requests are used to fetch remote images in HTML emails, to fetch autoconfig XML, to POST requests for `DCACCOUNT:` QR codes to make OAuth 2 API requests and to connect to HTTPS proxies. Rustls is more aggressive than OpenSSL in deprecating cryptographic algorithms so we cannot use it for IMAP and SMTP to avoid breaking compatibility, but for HTTPS requests listed above this should not result in problems. As HTTPS requests use only strict TLS checks, there is no `strict_tls` argument in `wrap_rustls` function. Rustls is already used by iroh, so this change does not introduce new dependencies.
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
use fast_socks5::client::Socks5Stream;
|
|
use std::pin::Pin;
|
|
use std::time::Duration;
|
|
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, BufStream, BufWriter};
|
|
use tokio_io_timeout::TimeoutStream;
|
|
|
|
pub(crate) trait SessionStream:
|
|
AsyncRead + AsyncWrite + Unpin + Send + Sync + std::fmt::Debug
|
|
{
|
|
/// Change the read timeout on the session stream.
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>);
|
|
}
|
|
|
|
impl SessionStream for Box<dyn SessionStream> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.as_mut().set_read_timeout(timeout);
|
|
}
|
|
}
|
|
impl<T: SessionStream> SessionStream for async_native_tls::TlsStream<T> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.get_mut().set_read_timeout(timeout);
|
|
}
|
|
}
|
|
impl<T: SessionStream> SessionStream for tokio_rustls::client::TlsStream<T> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.get_mut().0.set_read_timeout(timeout);
|
|
}
|
|
}
|
|
impl<T: SessionStream> SessionStream for BufStream<T> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.get_mut().set_read_timeout(timeout);
|
|
}
|
|
}
|
|
impl<T: SessionStream> SessionStream for BufWriter<T> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.get_mut().set_read_timeout(timeout);
|
|
}
|
|
}
|
|
impl<T: AsyncRead + AsyncWrite + Send + Sync + std::fmt::Debug> SessionStream
|
|
for Pin<Box<TimeoutStream<T>>>
|
|
{
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.as_mut().set_read_timeout_pinned(timeout);
|
|
}
|
|
}
|
|
impl<T: SessionStream> SessionStream for Socks5Stream<T> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.get_socket_mut().set_read_timeout(timeout)
|
|
}
|
|
}
|
|
impl<T: SessionStream> SessionStream for shadowsocks::ProxyClientStream<T> {
|
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
|
self.get_mut().set_read_timeout(timeout)
|
|
}
|
|
}
|
|
|
|
/// Session stream with a read buffer.
|
|
pub(crate) trait SessionBufStream: SessionStream + AsyncBufRead {}
|
|
|
|
impl<T: SessionStream + AsyncBufRead> SessionBufStream for T {}
|