Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 28 additions & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docker_test)', 'cfg(throug
[workspace.lints.clippy]
redundant_clone = "deny"
needless_collect = "deny"

[patch.crates-io]
rustls = { git = "https://github.com/Watfaq/rustls.git", branch = "watfaq/0.23.40" }
tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", branch = "watfaq/0.26.4" }
Comment on lines +48 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "--- Watfaq/rustls @ watfaq/0.23.40 ---"
git ls-remote https://github.com/Watfaq/rustls.git refs/heads/watfaq/0.23.40
echo "--- Watfaq/tokio-rustls @ watfaq/0.26.4 ---"
git ls-remote https://github.com/Watfaq/tokio-rustls.git refs/heads/watfaq/0.26.4

Repository: Watfaq/clash-rs

Length of output: 275


🏁 Script executed:

# First, verify the root Cargo.toml has the patch section mentioned
cat -n Cargo.toml | sed -n '45,55p'

Repository: Watfaq/clash-rs

Length of output: 352


🏁 Script executed:

# Find and examine clash-lib/Cargo.toml for git dependencies
fd -name "Cargo.toml" -path "*/clash-lib/*"

Repository: Watfaq/clash-rs

Length of output: 290


🏁 Script executed:

# Search for all git dependencies in Cargo.toml files to verify the pattern
rg "git = " --type toml -B1 -A1

Repository: Watfaq/clash-rs

Length of output: 3035


Pin patched rustls/tokio-rustls to specific commits, not branches.

Using branch = makes cargo update (or a fresh Cargo.lock) silently follow whatever the branch tip becomes, and the branch can be force-pushed or rewritten in the fork. The workspace predominantly pins git dependencies to rev = (e.g. shadowsocks-rust, boring-noise, smoltcp, shadowquic, unix-udp-sock, sock2proc) — patches replacing core TLS crates should follow this pattern.

🔒 Suggested change: pin to commit SHAs
 [patch.crates-io]
-rustls = { git = "https://github.com/Watfaq/rustls.git", branch = "watfaq/0.23.40" }
-tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", branch = "watfaq/0.26.4" }
+rustls = { git = "https://github.com/Watfaq/rustls.git", rev = "8211697ce28686d72c92c2fc4b440b7ffc9a3ee3" }
+tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "b26e3e2b7a0161d505fd12d6e545b16463f1a45f" }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[patch.crates-io]
rustls = { git = "https://github.com/Watfaq/rustls.git", branch = "watfaq/0.23.40" }
tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", branch = "watfaq/0.26.4" }
[patch.crates-io]
rustls = { git = "https://github.com/Watfaq/rustls.git", rev = "8211697ce28686d72c92c2fc4b440b7ffc9a3ee3" }
tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "b26e3e2b7a0161d505fd12d6e545b16463f1a45f" }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Cargo.toml` around lines 48 - 50, The Cargo.toml patch entries for rustls and
tokio-rustls currently use branch= which tracks moving tips; change them to pin
specific commit SHAs by replacing branch = "watfaq/0.23.40" and branch =
"watfaq/0.26.4" with rev = "<commit-sha>" for the corresponding commits in the
Watfaq forks (update both rustls and tokio-rustls entries), ensuring you pick
the exact commit SHAs you want to lock to and run cargo update to refresh
Cargo.lock.

10 changes: 2 additions & 8 deletions clash-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ default = ["zero_copy", "aws-lc-rs", "dashboard"]
aws-lc-rs = [
"dep:aws-lc-rs",
"rustls/aws-lc-rs",
"watfaq-rustls/aws-lc-rs",
"quinn-proto/rustls-aws-lc-rs",
"watfaq-dns/aws-lc-rs",
"russh/aws-lc-rs",
"boringtun/aws-lc-rs",
"hickory-client/https-aws-lc-rs",
"tuic-quinn?/rustls-aws-lc-rs",
"watfaq-dns/aws-lc-rs",
]
ring = [
"rustls/ring",
"watfaq-rustls/ring",
"quinn-proto/ring",
"watfaq-dns/ring",
"russh/ring",
"boringtun/ring",
"hickory-client/https-ring",
"tuic-quinn?/rustls-ring",
"watfaq-dns/ring",
]

# Protos
Expand Down Expand Up @@ -75,10 +73,6 @@ rustls-pemfile = "2"
rcgen = { version = "0.14", features = ["pem"] }
webpki-roots = "1.0"

# shadow-tls
tokio-watfaq-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "cf8961ac1a36e580d0e38bedc8a41ca4a9b301e8", default-features = false, features = ["logging", "tls12"] }
watfaq-rustls = { git = "https://github.com/Watfaq/rustls.git", rev = "c3ab043d673029d245fd618b9bc86fd6a6109bae", default-features = false }

# Error handing & logging
thiserror = "2"
anyhow = "1"
Expand Down
9 changes: 0 additions & 9 deletions clash-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,10 @@ pub fn setup_default_crypto_provider() {
#[cfg(feature = "aws-lc-rs")]
{
_ = rustls::crypto::aws_lc_rs::default_provider().install_default();
// watfaq-rustls is a separate fork with its own global provider
// state. When both `ring` and `aws-lc-rs` features are active
// (e.g. `--all-features`), its
// `get_default_or_install_from_crate_features` treats the
// combination as ambiguous and returns None, causing a
// panic. Explicit installation is therefore required.
_ = watfaq_rustls::crypto::aws_lc_rs::default_provider()
.install_default();
}
#[cfg(all(feature = "ring", not(feature = "aws-lc-rs")))]
{
_ = rustls::crypto::ring::default_provider().install_default();
_ = watfaq_rustls::crypto::ring::default_provider().install_default();
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions clash-lib/src/proxy/transport/reality.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use async_trait::async_trait;
use tokio_watfaq_rustls::{TlsConnector, client::TlsStream};
use watfaq_rustls::{
use rustls::{
ClientConfig, RootCertStore, client::RealityConfig, pki_types::ServerName,
};
use tokio_rustls::{TlsConnector, client::TlsStream};

use std::{
io,
Expand Down
37 changes: 16 additions & 21 deletions clash-lib/src/proxy/transport/shadow_tls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
use async_trait::async_trait;
use rand::{RngExt, distr::Distribution};
use std::{
io,
ptr::copy_nonoverlapping,
sync::{Arc, LazyLock},
};
use std::{io, ptr::copy_nonoverlapping, sync::Arc};
use stream::{ProxyTlsStream, VerifiedStream};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio_watfaq_rustls::{TlsConnector, client::TlsStream};
use tokio_rustls::{TlsConnector, client::TlsStream};
use utils::Hmac;

mod prelude;
mod stream;
mod utils;

use super::Transport;
use crate::{common::errors::map_io_error, proxy::AnyStream};
use crate::{
common::{errors::map_io_error, tls::GLOBAL_ROOT_STORE},
proxy::AnyStream,
};
use prelude::*;

static ROOT_STORE: LazyLock<Arc<watfaq_rustls::RootCertStore>> =
LazyLock::new(root_store);

fn root_store() -> Arc<watfaq_rustls::RootCertStore> {
let root_store = webpki_roots::TLS_SERVER_ROOTS.iter().cloned().collect();
Arc::new(root_store)
}

pub struct Client {
host: String,
password: String,
Expand All @@ -49,14 +40,18 @@ impl Client {

// handshake
let hamc_handshake = Hmac::new(&self.password, (&[], &[]));
let sni_name =
watfaq_rustls::pki_types::ServerName::try_from(self.host.clone())
.map_err(map_io_error)?;
let sni_name = rustls::pki_types::ServerName::try_from(self.host.clone())
.map_err(map_io_error)?;
let session_id_generator =
move |data: &_| generate_session_id(&hamc_handshake, data);
let connector = new_connector();
let mut tls = connector
.connect_with(sni_name, proxy_stream, Some(session_id_generator), |_| {})
.connect_with_session_id_generator(
sni_name,
proxy_stream,
Some(session_id_generator),
|_| {},
)
.await?;

// check if is authorized
Expand Down Expand Up @@ -120,8 +115,8 @@ impl Transport for Client {
}

fn new_connector() -> TlsConnector {
let tls_config = watfaq_rustls::ClientConfig::builder()
.with_root_certificates(ROOT_STORE.clone())
let tls_config = rustls::ClientConfig::builder()
.with_root_certificates(GLOBAL_ROOT_STORE.clone())
.with_no_client_auth();

TlsConnector::from(Arc::new(tls_config))
Expand Down
2 changes: 1 addition & 1 deletion clash-lib/src/proxy/transport/splice_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tracing::debug;

use crate::proxy::AnyStream;

pub type RealityTlsStream = tokio_watfaq_rustls::client::TlsStream<AnyStream>;
pub type RealityTlsStream = tokio_rustls::client::TlsStream<AnyStream>;

/// Options passed to `VisionStream` when XTLS-splice mode is active.
///
Expand Down
Loading