mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-16 01:31:01 +03:00
For linux platform, add rustls support
This commit is contained in:
@@ -40,14 +40,19 @@ toml = "0.7"
|
||||
uuid = { version = "1.3", features = ["v4"] }
|
||||
# crash, versions >= 0.29.1 are affected by #GuillaumeGomez/sysinfo/1052
|
||||
sysinfo = { git = "https://github.com/rustdesk-org/sysinfo" }
|
||||
thiserror = "1.0.30"
|
||||
httparse = "1.5.1"
|
||||
base64 = "0.21.5"
|
||||
url = "2.2.2"
|
||||
tokio-native-tls ="0.3.1"
|
||||
thiserror = "1.0"
|
||||
httparse = "1.5"
|
||||
base64 = "0.22"
|
||||
url = "2.2"
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
mac_address = "1.1"
|
||||
machine-uid = { git = "https://github.com/21pages/machine-uid" }
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows")))'.dependencies]
|
||||
tokio-rustls = "0.26"
|
||||
webpki-roots = "0.26"
|
||||
rustls-pki-types = "1.4"
|
||||
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
|
||||
tokio-native-tls ="0.3"
|
||||
|
||||
[features]
|
||||
quic = []
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::io::{Error as IoError};
|
||||
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
|
||||
use std::sync::Arc;
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose;
|
||||
|
||||
use httparse::{EMPTY_HEADER, Error as HttpParseError, Response};
|
||||
use log::{info};
|
||||
use thiserror::Error as ThisError;
|
||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufStream};
|
||||
use tokio_native_tls::{native_tls, TlsConnector, TlsStream};
|
||||
use tokio_socks::{IntoTargetAddr};
|
||||
use tokio_socks::tcp::Socks5Stream;
|
||||
use tokio_util::codec::Framed;
|
||||
@@ -18,6 +16,11 @@ use crate::config::Socks5Server;
|
||||
use crate::{ResultType};
|
||||
use crate::bytes_codec::BytesCodec;
|
||||
use crate::tcp::{DynTcpStream, FramedStream};
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
use tokio_native_tls::{native_tls, TlsConnector, TlsStream};
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
||||
use tokio_rustls::{rustls, TlsConnector, client::TlsStream };
|
||||
use rustls_pki_types;
|
||||
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum ProxyError {
|
||||
@@ -389,15 +392,36 @@ impl Proxy {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
pub async fn https_connect<'a, Input, T>(self, io: Input, target: T) -> Result<BufStream<TlsStream<Input>>, ProxyError>
|
||||
where
|
||||
Input: AsyncRead + AsyncWrite + Unpin,
|
||||
T: IntoTargetAddr<'a> {
|
||||
let tls_connector = TlsConnector::from(native_tls::TlsConnector::new()?);
|
||||
let stream = tls_connector.connect(&self.intercept.get_domain()?, io).await?;
|
||||
self.http_connect(stream, target).await
|
||||
}
|
||||
|
||||
// tls 进行握手
|
||||
let tls_connector = TlsConnector::from(native_tls::TlsConnector::new().unwrap());
|
||||
let stream = tls_connector.connect(&self.intercept.get_domain()?, io).await.unwrap();
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
||||
pub async fn https_connect<'a, Input, T>(self, io: Input, target: T) -> Result<BufStream<TlsStream<Input>>, ProxyError>
|
||||
where
|
||||
Input: AsyncRead + AsyncWrite + Unpin,
|
||||
T: IntoTargetAddr<'a> {
|
||||
let root_store = rustls::RootCertStore {
|
||||
roots: webpki_roots::TLS_SERVER_ROOTS.into(),
|
||||
};
|
||||
|
||||
let config = rustls::ClientConfig::builder()
|
||||
.with_root_certificates(root_store)
|
||||
.with_no_client_auth();
|
||||
let url_domain = self.intercept.get_domain()?;
|
||||
|
||||
let domain = rustls_pki_types::ServerName::try_from(url_domain.as_str())
|
||||
.map_err(|e| ProxyError::AddressResolutionFailed(e.to_string()))?
|
||||
.to_owned();
|
||||
|
||||
let tls_connector = TlsConnector::from(Arc::new(config));
|
||||
let stream = tls_connector.connect(domain, io).await?;
|
||||
self.http_connect(stream, target).await
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@ use std::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use log::info;
|
||||
use tokio::{
|
||||
io::{AsyncRead, AsyncWrite, ReadBuf},
|
||||
net::{lookup_host, TcpListener, TcpSocket, ToSocketAddrs},
|
||||
};
|
||||
use tokio_socks::{tcp::Socks5Stream, IntoTargetAddr, ToProxyAddrs};
|
||||
use tokio_socks::IntoTargetAddr;
|
||||
use tokio_util::codec::Framed;
|
||||
use crate::config::Socks5Server;
|
||||
use crate::proxy::Proxy;
|
||||
|
||||
Reference in New Issue
Block a user