Skip to content

Commit 3cc4748

Browse files
authored
Merge pull request #121 from fr0der1c/anytls
feat: add AnyTLS protocol support
2 parents 2b97091 + b1c634a commit 3cc4748

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- 一键添加 TUIC
1717
- 一键添加 Trojan
1818
- 一键添加 Hysteria2
19+
- 一键添加 AnyTLS
1920
- 一键添加 Shadowsocks 2022
2021
- 一键添加 VMess-(TCP/HTTP/QUIC)
2122
- 一键添加 VMess-(WS/H2/HTTPUpgrade)-TLS

sing-box.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
args=$@
4-
is_sh_ver=v1.15
4+
is_sh_ver=v1.16
55

66
. /etc/sing-box/sh/src/init.sh

src/core.sh

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protocol_list=(
2020
Trojan-HTTPUpgrade-TLS
2121
VLESS-REALITY
2222
VLESS-HTTP2-REALITY
23+
AnyTLS
2324
# Direct
2425
Socks
2526
)
@@ -227,7 +228,7 @@ ask() {
227228
[[ $is_no_auto_tls ]] && {
228229
unset is_tmp_list
229230
for v in ${protocol_list[@]}; do
230-
[[ $(grep -i tls$ <<<$v) ]] && is_tmp_list=(${is_tmp_list[@]} $v)
231+
[[ $(grep -i "\-tls$" <<<$v) ]] && is_tmp_list=(${is_tmp_list[@]} $v)
231232
done
232233
}
233234
is_opt_msg="\n请选择协议:\n"
@@ -323,6 +324,8 @@ create() {
323324
if [[ $host ]]; then
324325
is_config_name=$2-${host}.json
325326
is_listen='listen: "127.0.0.1"'
327+
elif [[ $is_anytls_domain ]]; then
328+
is_config_name=$2-${is_anytls_domain}.json
326329
else
327330
is_config_name=$2-${port}.json
328331
fi
@@ -813,6 +816,9 @@ add() {
813816
trojan)
814817
is_new_protocol=Trojan
815818
;;
819+
anytls)
820+
is_new_protocol=AnyTLS
821+
;;
816822
socks)
817823
is_new_protocol=Socks
818824
;;
@@ -829,6 +835,14 @@ add() {
829835
# no prefer protocol
830836
[[ ! $is_new_protocol ]] && ask set_protocol
831837

838+
if [[ ${is_new_protocol,,} == 'anytls' ]]; then
839+
is_core_major=$(echo "$is_core_ver" | cut -d. -f1)
840+
is_core_minor=$(echo "$is_core_ver" | cut -d. -f2)
841+
if [[ ${is_core_major:-0} -lt 1 || ${is_core_major:-0} -eq 1 && ${is_core_minor:-0} -lt 12 ]]; then
842+
err "当前 sing-box 版本 ($is_core_ver) 不支持 AnyTLS,请先升级 sing-box core 到 1.12.0 或更高版本。"
843+
fi
844+
fi
845+
832846
case ${is_new_protocol,,} in
833847
*-tls)
834848
is_use_tls=1
@@ -866,6 +880,12 @@ add() {
866880
is_use_door_port=$4
867881
is_add_opts="[port] [remote_addr] [remote_port]"
868882
;;
883+
anytls*)
884+
is_use_port=$2
885+
is_use_pass=$3
886+
[[ $4 ]] && is_anytls_domain=$4
887+
is_add_opts="[port] [password] [domain]"
888+
;;
869889
socks)
870890
is_socks=1
871891
is_use_port=$2
@@ -963,6 +983,14 @@ add() {
963983
[[ $is_use_socks_pass ]] && is_socks_pass=$is_use_socks_pass
964984
fi
965985

986+
# anytls with domain (ACME TLS)
987+
if [[ $is_anytls_domain && ! $is_change && ! $is_gen ]]; then
988+
get_ip
989+
host=$is_anytls_domain
990+
get host-test
991+
host=
992+
fi
993+
966994
if [[ $is_use_tls ]]; then
967995
if [[ ! $is_no_auto_tls && ! $is_caddy && ! $is_gen && ! $is_dont_test_host ]]; then
968996
# test auto tls
@@ -1105,6 +1133,11 @@ get() {
11051133
is_socks_user=$username
11061134
is_socks_pass=$password
11071135
1136+
# extract anytls ACME domain
1137+
[[ $is_protocol == 'anytls' ]] && {
1138+
is_anytls_domain=$(jq -r '(.inbounds[0].tls.certificate_provider.domain[0] // .inbounds[0].tls.acme.domain[0]) // empty' <<<$is_json_str 2>/dev/null)
1139+
}
1140+
11081141
is_config_name=$is_config_file
11091142
11101143
if [[ $is_caddy && $host && -f $is_caddy_conf/$host.conf ]]; then
@@ -1169,6 +1202,24 @@ get() {
11691202
is_protocol=$net
11701203
json_str="override_port:$door_port,override_address:\"$door_addr\""
11711204
;;
1205+
anytls*)
1206+
net=anytls
1207+
is_protocol=$net
1208+
[[ ! $password ]] && password=$uuid
1209+
is_users="users:[{password:\"$password\"}]"
1210+
if [[ $is_anytls_domain ]]; then
1211+
# sing-box >= 1.14.0 uses certificate_provider; older uses acme
1212+
is_core_minor=$(echo "$is_core_ver" | cut -d. -f2)
1213+
if [[ ${is_core_minor:-0} -ge 14 ]]; then
1214+
is_anytls_tls="tls:{enabled:true,certificate_provider:{type:\"acme\",domain:[\"$is_anytls_domain\"]}}"
1215+
else
1216+
is_anytls_tls="tls:{enabled:true,acme:{domain:[\"$is_anytls_domain\"]}}"
1217+
fi
1218+
else
1219+
is_anytls_tls="${is_tls_json/alpn\:\[\"h3\"\],/}"
1220+
fi
1221+
json_str="$is_users,$is_anytls_tls"
1222+
;;
11721223
socks*)
11731224
net=socks
11741225
is_protocol=$net
@@ -1392,6 +1443,19 @@ info() {
13921443
is_info_str=($is_protocol $is_addr $port $uuid $is_flow $is_net_type reality $is_servername chrome $is_public_key)
13931444
is_url="$is_protocol://$uuid@$is_addr:$port?encryption=none&security=reality&flow=$is_flow&type=$is_net_type&sni=$is_servername&pbk=$is_public_key&fp=chrome#233boy-$net-$is_addr"
13941445
;;
1446+
anytls)
1447+
is_can_change=(0 1 4)
1448+
if [[ $is_anytls_domain ]]; then
1449+
is_info_show=(0 1 2 10 8)
1450+
is_info_str=($is_protocol $is_anytls_domain $port $password tls)
1451+
is_url="anytls://$password@$is_anytls_domain:$port#233boy-$net-$is_anytls_domain"
1452+
else
1453+
is_insecure=1
1454+
is_info_show=(0 1 2 10 8 20)
1455+
is_info_str=($is_protocol $is_addr $port $password tls true)
1456+
is_url="anytls://$password@$is_addr:$port?allowInsecure=1#233boy-$net-$is_addr"
1457+
fi
1458+
;;
13951459
direct)
13961460
is_can_change=(0 1 7 8)
13971461
is_info_show=(0 1 2 13 14)

0 commit comments

Comments
 (0)