cty123 / TrojanRust

Trojan-rust is a rust implementation for Trojan protocol that is targeted to circumvent GFW. This implementation focus on performance and stability above everything else.
MIT License
112 stars 24 forks source link

alpn support #15

Closed spongebob888 closed 1 year ago

spongebob888 commented 1 year ago

能否添加quic 服务端alpn的支持以兼容*ray,sing-box。现在使用xray的trojan + quic作为客户端,会报alpn错误:

[2023-02-12T17:01:39Z WARN rustls::conn] Sending fatal alert NoApplicationProtocol

抓包发现 *ray,sing-box的trojan + quic client 实现总是会有alpn拓展

cty123 commented 1 year ago

感谢测试,我之前也试过用xray当client,显示的错误跟你发的一样,当时好像是因为rust的实现不完全所以这个feature我没做下去,我现在再看看rust的实现能否支持alpn

spongebob888 commented 1 year ago

非常感谢,我通过抓包发现,xray默认的alpn是[“h2","http/1.1"]。然后leaf的quic实现表现和TrojanRust一样,不支持alpn 拓展。

cty123 commented 1 year ago

alpn可以通过在rustls config里面加上h2解决,但是解决之后跟xray还是有问题,leaf能支持xray的quic+trojan吗?

spongebob888 commented 1 year ago

leaf 在提交 eycorsican/leaf@5fa702d4eb5cad1da7610cd67c346951a70bb327 之后可以支持 xray/singbox 的quic + trojan了。按道理,在rustls config中加入alpn应该可以解决,我帮你测试下

cty123 commented 1 year ago

我知道了,我之前对quic实现的理解有问题,quic连接一旦建立,只要不断accept_bi stream就可以,不用每个请求都重新握手一遍,其实就跟mux的实现差不多。

spongebob888 commented 1 year ago

请问quic 现在可用了吗,我尝试了下,运行服务端,启动后报配置文件错误,

cty123 commented 1 year ago

可以了,我已经用了好几天了,你把错误发上来看看

spongebob888 commented 1 year ago

我是用的平台是 Ubuntu,启动后报下述错误

thread 'main' panicked at 'Mismatch between definition and access of config. Could not downcast to TypeId { t: 9919015677752515272 }, need to downcast to TypeId { t: 14429720537726057407 } ', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-4.1.4/src/parser/error.rs:30:9 stack backtrace: 0: rust_begin_unwind at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5 1: core::panicking::panic_fmt at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14 2: clap::parser::matches::arg_matches::ArgMatches::get_one 3: std::sys_common::once::futex::Once::call 4: std::sys_common::once::futex::Once::call 5: trojan_rust::main::{{closure}} 6: tokio::runtime::park::CachedParkThread::block_on 7: tokio::runtime::runtime::Runtime::block_on 8: trojan_rust::main note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

使用的配置文件如下

{ "inbound": { "protocol": "TROJAN", "address": "0.0.0.0", "secret": "password", "port": 3005, "mode": "QUIC", "tls": { "cert_path": "mycert.crt", "key_path": "mykey.key" }

},
"outbound": {
    "protocol": "DIRECT",
    "mode": "DIRECT"
}

}

spongebob888 commented 1 year ago

我重新写了一个配置,现在可以用了。