Skip to content

Commit

Permalink
Merge pull request #347 from gngpp/feat
Browse files Browse the repository at this point in the history
feat(proxy): Add socks5h support
  • Loading branch information
0x676e67 authored Nov 30, 2023
2 parents 432e333 + b352626 commit b1dadfb
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Recently, `OpenAI` has canceled the `Arkose` verification for `GPT-3.5`. It can

##### Advanced proxy usage

The built-in protocols and proxy types of agents are divided into built-in protocols: `all/api/auth/arkose`, where `all` is for all clients, `api` is for all `OpenAI API`, `auth` is for authorization/login, `arkose` For ArkoseLabs; proxy type: `interface/proxy/ipv6_subnet`, where `interface` represents the bound export `IP` address, `proxy` represents the upstream proxy protocol: `http/https/socks5`, `ipv6_subnet` represents the A random IP address within the IPv6 subnet acts as a proxy. The format is `proto|proxy`, example: **`all|socks5://192.168.1.1:1080, api|10.0.0.1, auth|2001:db8::/32, http://192.168.1.1:1081`**, without built-in protocol, the protocol defaults to `all`.
The built-in protocols and proxy types of agents are divided into built-in protocols: `all/api/auth/arkose`, where `all` is for all clients, `api` is for all `OpenAI API`, `auth` is for authorization/login, `arkose` For ArkoseLabs; proxy type: `interface/proxy/ipv6_subnet`, where `interface` represents the bound export `IP` address, `proxy` represents the upstream proxy protocol: `http/https/socks5/socks5h`, `ipv6_subnet` represents the A random IP address within the IPv6 subnet acts as a proxy. The format is `proto|proxy`, example: **`all|socks5://192.168.1.1:1080, api|10.0.0.1, auth|2001:db8::/32, http://192.168.1.1:1081`**, without built-in protocol, the protocol defaults to `all`.

##### Agent usage rules

Expand Down Expand Up @@ -313,7 +313,7 @@ Options:
-B, --pbind <PBIND>
Preauth MITM server bind address [env: PREAUTH_BIND=]
-X, --pupstream <PUPSTREAM>
Preauth MITM server upstream proxy, Only support http/https/socks5 protocol [env: PREAUTH_UPSTREAM=]
Preauth MITM server upstream proxy, Only support http/https/socks5/socks5h protocol [env: PREAUTH_UPSTREAM=]
--pcert <PCERT>
Preauth MITM server CA certificate file path [default: ca/cert.crt]
--pkey <PKEY>
Expand Down
4 changes: 2 additions & 2 deletions doc/readme_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ services:

##### 代理高阶用法

分代理内置协议和代理类型,内置协议: `all/api/auth/arkose`,其中`all`针对所有客户端,`api`针对所有`OpenAI API``auth`针对授权/登录,`arkose`针对ArkoseLabs;代理类型: `interface/proxy/ipv6_subnet`,其中`interface`表示绑定的出口`IP`地址,`proxy`表示上游代理协议: `http/https/socks5``ipv6_subnet`表示用Ipv6子网段内随机IP地址作为代理。格式为`proto|proxy`,例子: **`all|socks5://192.168.1.1:1080, api|10.0.0.1, auth|2001:db8::/32, http://192.168.1.1:1081`**,不带内置协议,协议默认为`all`
分代理内置协议和代理类型,内置协议: `all/api/auth/arkose`,其中`all`针对所有客户端,`api`针对所有`OpenAI API``auth`针对授权/登录,`arkose`针对ArkoseLabs;代理类型: `interface/proxy/ipv6_subnet`,其中`interface`表示绑定的出口`IP`地址,`proxy`表示上游代理协议: `http/https/socks5/socks5h``ipv6_subnet`表示用Ipv6子网段内随机IP地址作为代理。格式为`proto|proxy`,例子: **`all|socks5://192.168.1.1:1080, api|10.0.0.1, auth|2001:db8::/32, http://192.168.1.1:1081`**,不带内置协议,协议默认为`all`

##### 代理使用规则

Expand Down Expand Up @@ -313,7 +313,7 @@ Options:
-B, --pbind <PBIND>
Preauth MITM server bind address [env: PREAUTH_BIND=]
-X, --pupstream <PUPSTREAM>
Preauth MITM server upstream proxy, Only support http/https/socks5 protocol [env: PREAUTH_UPSTREAM=]
Preauth MITM server upstream proxy, Only support http/https/socks5/socks5h protocol [env: PREAUTH_UPSTREAM=]
--pcert <PCERT>
Preauth MITM server CA certificate file path [default: ca/cert.crt]
--pkey <PKEY>
Expand Down
2 changes: 1 addition & 1 deletion examples/har.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use openai::arkose::ArkoseToken;
async fn main() {
for _ in 0..100 {
let token =
ArkoseToken::new_from_har("/Users/gngpp/VSCode/ninja/auth0.openai.com_Archive.har")
ArkoseToken::new_from_har("/Users/gngpp/VSCode/ninja/har/6.login.chat.openai.com.har")
.await
.unwrap();
println!("{}", token.value());
Expand Down
2 changes: 1 addition & 1 deletion openai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ log = "0.4.20"
anyhow = "1.0.75"
thiserror = "1.0.48"
reqwest = { package = "reqwest-impersonate", version ="0.11.30", default-features = false, features = [
"boring-tls", "impersonate","json", "cookies", "stream", "multipart", "socks"
"boring-tls", "impersonate","json", "cookies", "stream", "multipart", "socks", "trust-dns"
] }
tokio = { version = "1.32.0", features = ["fs", "sync", "signal", "rt-multi-thread"] }
serde_json = "1.0.107"
Expand Down
2 changes: 1 addition & 1 deletion openai/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl TryFrom<(&str, Url)> for Proxy {

fn try_from((proto, url): (&str, Url)) -> Result<Self, Error> {
match url.scheme() {
"http" | "https" | "socks5" => {
"http" | "https" | "socks5" | "socks5h" => {
let inner_proxy = InnerProxy::Proxy(url);
make_proxy(inner_proxy, proto)
}
Expand Down
7 changes: 2 additions & 5 deletions openai/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,12 @@ impl Serve {
let router = route::config(router, &self.0).layer(global_layer);

let http_config = HttpConfig::new()
.http1_keep_alive(true)
.http1_header_read_timeout(Duration::from_secs(self.0.tcp_keepalive as u64))
.http2_keep_alive_timeout(Duration::from_secs(self.0.tcp_keepalive as u64))
.http2_keep_alive_interval(Some(Duration::from_secs(self.0.tcp_keepalive as u64)))
.http1_title_case_headers(true)
.http1_preserve_header_case(true)
.build();

let incoming_config = AddrIncomingConfig::new()
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive_interval(Some(Duration::from_secs(self.0.tcp_keepalive as u64)))
.tcp_keepalive(Some(Duration::from_secs(self.0.tcp_keepalive as u64)))
.build();

Expand Down
4 changes: 2 additions & 2 deletions openwrt/luci-app-ninja/luasrc/model/cbi/ninja/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ s.anonymous = true
o = s:option(Flag, "enabled", translate("Enabled"))
o.rmempty = false

o = s:option(Value, "proxies", translate("Proxies"), translate("Supports http/https/socks5, format: protocol://user:pass@ip:port"))
o = s:option(Value, "proxies", translate("Proxies"), translate("Supports http/https/socks5/socks5h, format: protocol://user:pass@ip:port"))


o = s:option(Flag, "enable_direct", translate("Turn on direct connection"), translate("Turn on direct connection using proxy"))
Expand Down Expand Up @@ -101,7 +101,7 @@ o.default = "86400"

o = s:option(Value, "pbind", translate("Preauth MITM server bind address"))

o = s:option(Value, "pupstream", translate("MITM Upstream proxy"), translate("Supports http/https/socks5, format: protocol://user:pass@ip:port"))
o = s:option(Value, "pupstream", translate("MITM Upstream proxy"), translate("Supports http/https/socks5/socks5h, format: protocol://user:pass@ip:port"))

o = s:option(Value, "pcert", translate("Preauth MITM server CA certificate file path"))

Expand Down
8 changes: 4 additions & 4 deletions openwrt/luci-app-ninja/po/zh-cn/ninja.po
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ msgstr "默认监听端口: 7999"
msgid "Default 1 worker thread"
msgstr "默认 1 个工作线程"

msgid "Supports http/https/socks5, format: protocol://user:pass@ip:port"
msgstr "支持http/https/socks5,格式: protocol://user:pass@ip:port"
msgid "Supports http/https/socks5/socks5h, format: protocol://user:pass@ip:port"
msgstr "支持http/https/socks5/socks5h,格式: protocol://user:pass@ip:port"

msgid "Default 60 seconds"
msgstr "默认 60 秒"
Expand Down Expand Up @@ -223,8 +223,8 @@ msgstr "Preauth MITM 服务绑定地址"
msgid "MITM Upstream proxy"
msgstr "MITM 上游代理"

msgid "Supports http/https/socks5, format: protocol://user:pass@ip:port"
msgstr "支持http/https/socks5,格式: protocol://user:pass@ip:port"
msgid "Supports http/https/socks5/socks5h, format: protocol://user:pass@ip:port"
msgstr "支持http/https/socks5/socks5h,格式: protocol://user:pass@ip:port"

msgid "Preauth MITM server CA certificate file path"
msgstr "Preauth MITM 服务 CA 证书文件路径"
Expand Down
4 changes: 2 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct ServeArgs {
pub(super) timeout: usize,

/// Client connect timeout (seconds)
#[clap(long, default_value = "20")]
#[clap(long, default_value = "5")]
pub(super) connect_timeout: usize,

/// TCP keepalive (seconds)
Expand Down Expand Up @@ -232,7 +232,7 @@ pub struct ServeArgs {
)]
pub(super) pbind: Option<std::net::SocketAddr>,

/// Preauth MITM server upstream proxy, Only support http/https/socks5 protocol
/// Preauth MITM server upstream proxy, Only support http/https/socks5/socks5h protocol
#[clap(
short = 'X',
long,
Expand Down

0 comments on commit b1dadfb

Please sign in to comment.