Skip to content

Commit

Permalink
feat: support shadow-tls(v3 only) (#346)
Browse files Browse the repository at this point in the history
* update rustls & tokio-rustls deps, add utls feature; add shadows-tls impl

* fix: remove unnecessary logs; check fake_request's result before return error

* cargo fmt

* add MultiDockerTestRunner to support shadowtls plugin test; modify some names

* simplify docker test workflow

* fix clippy warnings

* cargo fmt

* f

---------

Co-authored-by: Yuwei Ba <[email protected]>
Co-authored-by: Yuwei B <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent 2928780 commit a0b2604
Show file tree
Hide file tree
Showing 16 changed files with 1,018 additions and 72 deletions.
82 changes: 40 additions & 42 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ edition = "2021"
opt-level = "s"
codegen-units = 1
lto = true
strip = true
strip = true

[patch.crates-io]
tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "fcda89f6348c1e696b239bc7e0b168015cfb8c08"}
rustls = { git = "https://github.com/Watfaq/rustls.git", rev = "43ecd5c610741668488e6d57857f9900a2087a5b"}
2 changes: 1 addition & 1 deletion clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ opentelemetry-otlp = { version = "0.15.0", features = ["http-proto"] }
crc32fast = "1.4.0"
brotli = "4.0.0"
hmac = "0.12.1"
sha1 = "0.10"
sha2 = "0.10.8"
md-5 = "0.10.5"
chacha20poly1305 = "0.10"
Expand Down Expand Up @@ -126,7 +127,6 @@ tokio-test = "0.4.4"
axum-macros = "0.4.0"
bollard = "0.16"
serial_test = "3.0.0"
tracing-test = "0.2.4"

[target.'cfg(macos)'.dependencies]
security-framework = "2.10.0"
5 changes: 3 additions & 2 deletions clash_lib/src/app/inbound/network_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::{info, warn};
use std::net::{IpAddr, Ipv4Addr};
use std::sync::Arc;

#[derive(Eq, PartialEq, Hash)]
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
pub enum ListenerType {
Http,
Socks5,
Expand Down Expand Up @@ -114,13 +114,14 @@ impl NetworkInboundListener {
};

if listener.handle_tcp() {
let listener_type = self.listener_type.clone();
info!("{} TCP listening at: {}:{}", self.name, ip, self.port);

let tcp_listener = listener.clone();
runners.push(
async move {
tcp_listener.listen_tcp().await.map_err(|e| {
warn!("handler tcp listen failed: {}", e);
warn!("handler of {:?} tcp listen failed: {}", listener_type, e);
e.into()
})
}
Expand Down
9 changes: 9 additions & 0 deletions clash_lib/src/proxy/converters/shadowsocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ impl TryFrom<&OutboundShadowsocks> for AnyOutboundHandler {
.try_into()
.map(OBFSOption::V2Ray)
.ok(),
"shadow-tls" => s
.plugin_opts
.clone()
.ok_or(Error::InvalidConfig(
"plugin_opts is required for plugin obfs".to_owned(),
))?
.try_into()
.map(OBFSOption::ShadowTls)
.ok(),
_ => {
return Err(Error::InvalidConfig(format!(
"unsupported plugin: {}",
Expand Down
Loading

0 comments on commit a0b2604

Please sign in to comment.