Skip to content

Commit 7ae63b1

Browse files
committed
Revert "mobile wss use rustls_platform_verifier"
This reverts commit bf9a79f.
1 parent b166534 commit 7ae63b1

File tree

5 files changed

+7
-77
lines changed

5 files changed

+7
-77
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ tokio-rustls = { version = "0.26", features = [
5959
"tls12",
6060
"ring",
6161
], default-features = false }
62-
rustls-platform-verifier = "0.6"
62+
rustls-platform-verifier = "0.5"
6363
rustls-pki-types = "1.11"
6464
tokio-tungstenite = { version = "0.26", features = ["rustls-tls-native-roots", "rustls-tls-webpki-roots"] }
6565
tungstenite = { version = "0.26", features = ["rustls-tls-native-roots", "rustls-tls-webpki-roots"] }

src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
66
ops::{Deref, DerefMut},
77
path::{Path, PathBuf},
8-
sync::{atomic::AtomicBool, Mutex, RwLock},
8+
sync::{Mutex, RwLock},
99
time::{Duration, Instant, SystemTime},
1010
};
1111

@@ -70,7 +70,6 @@ lazy_static::lazy_static! {
7070
pub static ref OVERWRITE_LOCAL_SETTINGS: RwLock<HashMap<String, String>> = Default::default();
7171
pub static ref HARD_SETTINGS: RwLock<HashMap<String, String>> = Default::default();
7272
pub static ref BUILTIN_SETTINGS: RwLock<HashMap<String, String>> = Default::default();
73-
pub static ref RUSTLS_PLATFORM_VERIFIER_INITIALIZED: AtomicBool = AtomicBool::new(false);
7473
}
7574

7675
lazy_static::lazy_static! {

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ pub use toml;
5757
pub use uuid;
5858
pub mod fingerprint;
5959
pub use flexi_logger;
60-
pub mod stream;
6160
pub mod websocket;
62-
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
63-
pub use rustls_platform_verifier;
61+
pub mod stream;
6462
pub use stream::Stream;
6563
pub use whoami;
6664

src/proxy.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const MAXIMUM_RESPONSE_HEADERS: usize = 16;
5656
const DEFINE_TIME_OUT: u64 = 600;
5757

5858
pub trait IntoUrl {
59+
5960
// Besides parsing as a valid `Url`, the `Url` must be a valid
6061
// `http::Uri`, in that it makes sense to use in a network request.
6162
fn into_url(self) -> Result<Url, ProxyError>;
@@ -454,10 +455,8 @@ impl Proxy {
454455
Input: AsyncRead + AsyncWrite + Unpin,
455456
T: IntoTargetAddr<'a>,
456457
{
457-
use rustls_platform_verifier::ConfigVerifierExt;
458458
use std::convert::TryFrom;
459-
let verifier = tokio_rustls::rustls::ClientConfig::with_platform_verifier()
460-
.map_err(|e| ProxyError::IoError(std::io::Error::other(e)))?;
459+
let verifier = rustls_platform_verifier::tls_config();
461460
let url_domain = self.intercept.get_domain()?;
462461

463462
let domain = rustls_pki_types::ServerName::try_from(url_domain.as_str())

src/websocket.rs

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ use crate::{
88
ResultType,
99
};
1010
use bytes::{Bytes, BytesMut};
11-
#[cfg(any(target_os = "android", target_os = "ios"))]
12-
use futures::future::{select_ok, FutureExt};
1311
use futures::{SinkExt, StreamExt};
14-
#[cfg(any(target_os = "android", target_os = "ios"))]
15-
use std::future::Future;
1612
use std::{
1713
io::{Error, ErrorKind},
1814
net::SocketAddr,
@@ -32,19 +28,6 @@ pub struct WsFramedStream {
3228
send_timeout: u64,
3329
}
3430

35-
#[cfg(any(target_os = "android", target_os = "ios"))]
36-
async fn await_timeout_result<F, T, E>(future: F) -> ResultType<T>
37-
where
38-
F: Future<Output = Result<Result<T, E>, tokio::time::error::Elapsed>>,
39-
E: std::error::Error + Send + Sync + 'static,
40-
{
41-
match future.await {
42-
Ok(Ok(result)) => Ok(result),
43-
Ok(Err(e)) => Err(e.into()),
44-
Err(elapsed) => Err(Error::new(ErrorKind::TimedOut, elapsed).into()),
45-
}
46-
}
47-
4831
impl WsFramedStream {
4932
pub async fn new<T: AsRef<str>>(
5033
url: T,
@@ -60,57 +43,8 @@ impl WsFramedStream {
6043
.into_client_request()
6144
.map_err(|e| Error::new(ErrorKind::Other, e))?;
6245

63-
let stream;
64-
#[cfg(any(target_os = "android", target_os = "ios"))]
65-
{
66-
let mut futures = vec![];
67-
68-
let is_wss = url_str.starts_with("wss://");
69-
let rustls_platform_verifier_initialized = !cfg!(target_os = "android")
70-
|| crate::config::RUSTLS_PLATFORM_VERIFIER_INITIALIZED
71-
.load(std::sync::atomic::Ordering::Relaxed);
72-
if is_wss && rustls_platform_verifier_initialized {
73-
use rustls_platform_verifier::ConfigVerifierExt;
74-
use std::sync::Arc;
75-
use tokio_rustls::rustls::ClientConfig;
76-
use tokio_tungstenite::{connect_async_tls_with_config, Connector};
77-
match ClientConfig::with_platform_verifier() {
78-
Ok(config) => {
79-
let connector = Connector::Rustls(Arc::new(config));
80-
futures.push(
81-
await_timeout_result(timeout(
82-
Duration::from_millis(ms_timeout),
83-
connect_async_tls_with_config(
84-
request.clone(),
85-
None,
86-
false,
87-
Some(connector),
88-
),
89-
))
90-
.boxed(),
91-
);
92-
}
93-
Err(e) => {
94-
log::error!("with_platform_verifier failed: {:?}", e);
95-
}
96-
}
97-
}
98-
futures.push(
99-
await_timeout_result(timeout(
100-
Duration::from_millis(ms_timeout),
101-
connect_async(request),
102-
))
103-
.boxed(),
104-
);
105-
let ((s, _), _) = select_ok(futures).await?;
106-
stream = s;
107-
}
108-
#[cfg(not(any(target_os = "android", target_os = "ios")))]
109-
{
110-
let (s, _) =
111-
timeout(Duration::from_millis(ms_timeout), connect_async(request)).await??;
112-
stream = s;
113-
}
46+
let (stream, _) =
47+
timeout(Duration::from_millis(ms_timeout), connect_async(request)).await??;
11448

11549
let addr = match stream.get_ref() {
11650
MaybeTlsStream::Plain(tcp) => tcp.peer_addr()?,

0 commit comments

Comments
 (0)