diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 00a27e9e..1926fa2e 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -1027,20 +1027,6 @@ function lastParse(proxy) { if (!proxy['tls-fingerprint'] && caStr) { proxy['tls-fingerprint'] = rs.generateFingerprint(caStr); } - if ( - ['ss'].includes(proxy.type) && - isPresent(proxy, 'shadow-tls-password') - ) { - proxy.plugin = 'shadow-tls'; - proxy['plugin-opts'] = { - host: proxy['shadow-tls-sni'], - password: proxy['shadow-tls-password'], - version: proxy['shadow-tls-version'], - }; - delete proxy['shadow-tls-sni']; - delete proxy['shadow-tls-password']; - delete proxy['shadow-tls-version']; - } if (['tuic'].includes(proxy.type)) { proxy.alpn = Array.isArray(proxy.alpn) ? proxy.alpn diff --git a/backend/src/core/proxy-utils/parsers/peggy/loon.js b/backend/src/core/proxy-utils/parsers/peggy/loon.js index 05365196..1f9e8484 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/loon.js +++ b/backend/src/core/proxy-utils/parsers/peggy/loon.js @@ -19,6 +19,7 @@ const grammars = String.raw` const proxy = {}; const obfs = {}; const transport = {}; + const shadowTLS = {}; const $ = {}; function handleTransport() { @@ -34,6 +35,17 @@ const grammars = String.raw` } } + function handleShadowTLS() { + if (shadowTLS.password) { + proxy.plugin = "shadow-tls"; + proxy["plugin-opts"] = { + host: shadowTLS.host, + password: shadowTLS.password, + version: shadowTLS.version, + }; + } + } + function normalizeVmessSecurity(security) { const normalized = String(security || "").trim().toLowerCase(); const supported = ["none", "auto", "aes-128-gcm", "chacha20-ietf-poly1305"]; @@ -60,6 +72,7 @@ shadowsocksr = tag equals "shadowsocksr"i address method password (ssr_protocol/ proxy.type = "ssr"; // handle ssr obfs proxy.obfs = obfs.type; + handleShadowTLS(); } shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs_hostv)? (obfs_ss/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/udp_over_tcp/others)* { proxy.type = "ss"; @@ -70,6 +83,7 @@ shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs $set(proxy, "plugin-opts.host", obfs.host); $set(proxy, "plugin-opts.path", obfs.path); } + handleShadowTLS(); } vmess = tag equals "vmess"i address vmess_method uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/vmess_alterId/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* { proxy.type = "vmess"; @@ -194,9 +208,9 @@ ssr_protocol_param = comma "protocol-param" equals param:$[^=,]+ { proxy["protoc vmess_alterId = comma "alterId" equals alterId:$[0-9]+ { proxy.alterId = parseInt(alterId); } udp_port = comma "udp-port" equals match:$[0-9]+ { proxy["udp-port"] = parseInt(match.trim()); } -shadow_tls_version = comma "shadow-tls-version" equals match:$[0-9]+ { proxy["shadow-tls-version"] = parseInt(match.trim()); } -shadow_tls_sni = comma "shadow-tls-sni" equals match:[^,]+ { proxy["shadow-tls-sni"] = match.join(""); } -shadow_tls_password = comma "shadow-tls-password" equals match:[^,]+ { proxy["shadow-tls-password"] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); } +shadow_tls_version = comma "shadow-tls-version" equals match:$[0-9]+ { shadowTLS.version = parseInt(match.trim()); } +shadow_tls_sni = comma "shadow-tls-sni" equals match:[^,]+ { shadowTLS.host = match.join(""); } +shadow_tls_password = comma "shadow-tls-password" equals match:[^,]+ { shadowTLS.password = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); } over_tls = comma "over-tls" equals flag:bool { proxy.tls = flag; } tls_name = comma sni:("tls-name") equals match:[^,]+ { proxy.sni = match.join("").replace(/^"(.*)"$/, '$1'); } diff --git a/backend/src/core/proxy-utils/parsers/peggy/surge.js b/backend/src/core/proxy-utils/parsers/peggy/surge.js index 0470f85b..975f3c63 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/surge.js +++ b/backend/src/core/proxy-utils/parsers/peggy/surge.js @@ -18,6 +18,7 @@ const grammars = String.raw` { const proxy = {}; const obfs = {}; + const shadowTLS = {}; const $ = {}; function handleWebsocket() { @@ -31,8 +32,16 @@ const grammars = String.raw` } } function handleShadowTLS() { - if (proxy['shadow-tls-password'] && !proxy['shadow-tls-version']) { - proxy['shadow-tls-version'] = 2; + if (shadowTLS.password && !shadowTLS.version) { + shadowTLS.version = 2; + } + if (shadowTLS.password) { + proxy.plugin = "shadow-tls"; + proxy["plugin-opts"] = { + host: shadowTLS.host, + password: shadowTLS.password, + version: shadowTLS.version, + }; } } function stripQuotes(value) { @@ -594,9 +603,9 @@ private_key = comma "private-key" equals match:[^,]+ { proxy["keystore-private-k server_fingerprint = comma "server-fingerprint" equals match:[^,]+ { proxy["server-fingerprint"] = match.join("").replace(/^"(.*)"$/, '$1'); } block_quic = comma "block-quic" equals match:[^,]+ { proxy["block-quic"] = match.join(""); } udp_port = comma "udp-port" equals match:$[0-9]+ { proxy["udp-port"] = parseInt(match.trim()); } -shadow_tls_version = comma "shadow-tls-version" equals match:$[0-9]+ { proxy["shadow-tls-version"] = parseInt(match.trim()); } -shadow_tls_sni = comma "shadow-tls-sni" equals match:[^,]+ { proxy["shadow-tls-sni"] = match.join(""); } -shadow_tls_password = comma "shadow-tls-password" equals match:[^,]+ { proxy["shadow-tls-password"] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); } +shadow_tls_version = comma "shadow-tls-version" equals match:$[0-9]+ { shadowTLS.version = parseInt(match.trim()); } +shadow_tls_sni = comma "shadow-tls-sni" equals match:[^,]+ { shadowTLS.host = match.join(""); } +shadow_tls_password = comma "shadow-tls-password" equals match:[^,]+ { shadowTLS.password = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); } token = comma "token" equals match:[^,]+ { proxy.token = match.join(""); } alpn = comma "alpn" equals match:quoted_value { const values = parseAlpn(match); diff --git a/backend/src/core/proxy-utils/producers/clashmeta.js b/backend/src/core/proxy-utils/producers/clashmeta.js index 4fbb4641..359bf6f3 100644 --- a/backend/src/core/proxy-utils/producers/clashmeta.js +++ b/backend/src/core/proxy-utils/producers/clashmeta.js @@ -247,21 +247,6 @@ export default function ClashMeta_Producer() { ds['reality-opts'] = { 'public-key': '' }; } } - } else if (proxy.type === 'ss') { - if ( - isPresent(proxy, 'shadow-tls-password') && - !isPresent(proxy, 'plugin') - ) { - proxy.plugin = 'shadow-tls'; - proxy['plugin-opts'] = { - host: proxy['shadow-tls-sni'], - password: proxy['shadow-tls-password'], - version: proxy['shadow-tls-version'], - }; - delete proxy['shadow-tls-password']; - delete proxy['shadow-tls-sni']; - delete proxy['shadow-tls-version']; - } } if (isPresent(proxy, 'plugin-opts.mux')) { @@ -428,22 +413,11 @@ function isSupportedMihomoVersion(version, supportedVersions) { } function hasMihomoShadowTls(proxy) { - return ( - proxy?.plugin === 'shadow-tls' || - isPresent(proxy, 'shadow-tls-password') || - isPresent(proxy, 'shadow-tls-sni') || - isPresent(proxy, 'shadow-tls-version') - ); + return proxy?.plugin === 'shadow-tls'; } function getMihomoShadowTlsVersion(proxy) { - if (isPresent(proxy, 'shadow-tls-version')) { - return proxy['shadow-tls-version']; - } - - if (proxy?.plugin === 'shadow-tls') { - return proxy?.['plugin-opts']?.version; - } - - return undefined; + return proxy?.plugin === 'shadow-tls' + ? proxy?.['plugin-opts']?.version + : undefined; } diff --git a/backend/src/core/proxy-utils/producers/egern.js b/backend/src/core/proxy-utils/producers/egern.js index 02235f53..06396e07 100644 --- a/backend/src/core/proxy-utils/producers/egern.js +++ b/backend/src/core/proxy-utils/producers/egern.js @@ -554,16 +554,7 @@ export default function Egern_Producer() { 'ssh', ].includes(original.type) ) { - if (isPresent(original, 'shadow-tls-password')) { - if (original['shadow-tls-version'] != 3) - throw new Error( - `shadow-tls version ${original['shadow-tls-version']} is not supported`, - ); - proxy.shadow_tls = { - password: original['shadow-tls-password'], - sni: original['shadow-tls-sni'], - }; - } else if ( + if ( ['shadow-tls'].includes(original.plugin) && original['plugin-opts'] ) { @@ -693,12 +684,7 @@ function getUdpRelay(proxy) { } function hasShadowTls(proxy) { - return ( - proxy.plugin === 'shadow-tls' || - isPresent(proxy, 'shadow-tls-password') || - isPresent(proxy, 'shadow-tls-sni') || - isPresent(proxy, 'shadow-tls-version') - ); + return proxy.plugin === 'shadow-tls'; } function getNonEmptyValue(value) { diff --git a/backend/src/core/proxy-utils/producers/loon.js b/backend/src/core/proxy-utils/producers/loon.js index 7eea0e51..80640608 100644 --- a/backend/src/core/proxy-utils/producers/loon.js +++ b/backend/src/core/proxy-utils/producers/loon.js @@ -69,6 +69,25 @@ function appendAlpn(result, proxy) { if (alpn) result.append(`,alpn="${alpn}"`); } +function appendShadowTLS(result, proxy) { + if (proxy.plugin !== 'shadow-tls' || !proxy['plugin-opts']) return; + + const password = proxy['plugin-opts'].password; + const host = proxy['plugin-opts'].host; + const version = proxy['plugin-opts'].version; + if (!password) return; + + result.append(`,shadow-tls-password=${password}`); + if (host) result.append(`,shadow-tls-sni=${host}`); + if (version) { + if (version < 2) { + throw new Error(`shadow-tls version ${version} is not supported`); + } + result.append(`,shadow-tls-version=${version}`); + } + result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port'); +} + function appendReality(result, proxy) { result.appendIfPresent(`,sni=${proxy.sni}`, 'sni'); result.appendIfPresent( @@ -156,44 +175,7 @@ function shadowsocks(proxy) { } } - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password=${proxy['shadow-tls-password']}`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - // udp-port - result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port'); - } else if (['shadow-tls'].includes(proxy.plugin) && proxy['plugin-opts']) { - const password = proxy['plugin-opts'].password; - const host = proxy['plugin-opts'].host; - const version = proxy['plugin-opts'].version; - if (password) { - result.append(`,shadow-tls-password=${password}`); - if (host) { - result.append(`,shadow-tls-sni=${host}`); - } - if (version) { - if (version < 2) { - throw new Error( - `shadow-tls version ${version} is not supported`, - ); - } - result.append(`,shadow-tls-version=${version}`); - } - // udp-port - result.appendIfPresent( - `,udp-port=${proxy['udp-port']}`, - 'udp-port', - ); - } - } + appendShadowTLS(result, proxy); // udp over tcp if (proxy['udp-over-tcp']) { @@ -250,44 +232,7 @@ function shadowsocksr(proxy) { result.appendIfPresent(`,obfs=${proxy.obfs}`, 'obfs'); result.appendIfPresent(`,obfs-param=${proxy['obfs-param']}`, 'obfs-param'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password=${proxy['shadow-tls-password']}`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - // udp-port - result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port'); - } else if (['shadow-tls'].includes(proxy.plugin) && proxy['plugin-opts']) { - const password = proxy['plugin-opts'].password; - const host = proxy['plugin-opts'].host; - const version = proxy['plugin-opts'].version; - if (password) { - result.append(`,shadow-tls-password=${password}`); - if (host) { - result.append(`,shadow-tls-sni=${host}`); - } - if (version) { - if (version < 2) { - throw new Error( - `shadow-tls version ${version} is not supported`, - ); - } - result.append(`,shadow-tls-version=${version}`); - } - // udp-port - result.appendIfPresent( - `,udp-port=${proxy['udp-port']}`, - 'udp-port', - ); - } - } + appendShadowTLS(result, proxy); // tfo result.appendIfPresent(`,fast-open=${proxy.tfo}`, 'tfo'); diff --git a/backend/src/core/proxy-utils/producers/shadowrocket.js b/backend/src/core/proxy-utils/producers/shadowrocket.js index f1310a59..fd05f10d 100644 --- a/backend/src/core/proxy-utils/producers/shadowrocket.js +++ b/backend/src/core/proxy-utils/producers/shadowrocket.js @@ -142,20 +142,6 @@ export default function Shadowrocket_Producer() { delete proxy.sni; } } else if (proxy.type === 'ss') { - if ( - isPresent(proxy, 'shadow-tls-password') && - !isPresent(proxy, 'plugin') - ) { - proxy.plugin = 'shadow-tls'; - proxy['plugin-opts'] = { - host: proxy['shadow-tls-sni'], - password: proxy['shadow-tls-password'], - version: proxy['shadow-tls-version'], - }; - delete proxy['shadow-tls-password']; - delete proxy['shadow-tls-sni']; - delete proxy['shadow-tls-version']; - } if (isShadowsocksOverTls(proxy)) { if (isPresent(proxy, 'sni')) { proxy.servername = proxy.sni; diff --git a/backend/src/core/proxy-utils/producers/sing-box.js b/backend/src/core/proxy-utils/producers/sing-box.js index 33c708e6..f416be31 100644 --- a/backend/src/core/proxy-utils/producers/sing-box.js +++ b/backend/src/core/proxy-utils/producers/sing-box.js @@ -529,17 +529,6 @@ const getShadowTLSPluginOpts = (proxy = {}) => { if (proxy.plugin === 'shadow-tls' && proxy['plugin-opts']) { return proxy['plugin-opts']; } - if ( - proxy['shadow-tls-password'] != null || - proxy['shadow-tls-sni'] != null || - proxy['shadow-tls-version'] != null - ) { - return { - host: proxy['shadow-tls-sni'], - password: proxy['shadow-tls-password'], - version: proxy['shadow-tls-version'], - }; - } return undefined; }; diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index 12a77b9a..3cef2cce 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -65,6 +65,27 @@ function appendAlpn(result, proxy) { if (alpn) result.append(`,alpn="${alpn}"`); } +function appendShadowTLS(result, proxy, includeUdpPort = false) { + if (proxy.plugin !== 'shadow-tls' || !proxy['plugin-opts']) return; + + const password = proxy['plugin-opts'].password; + const host = proxy['plugin-opts'].host; + const version = proxy['plugin-opts'].version; + if (!password) return; + + result.append(`,shadow-tls-password="${password}"`); + if (host) result.append(`,shadow-tls-sni=${host}`); + if (version) { + if (version < 2) { + throw unsupported(`shadow-tls version ${version} is not supported`); + } + result.append(`,shadow-tls-version=${version}`); + } + if (includeUdpPort) { + result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port'); + } +} + function appendTlsProxyParams(result, proxy, enabled = true) { if (!enabled) { return; @@ -285,44 +306,7 @@ function shadowsocks(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - // udp-port - result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port'); - } else if (['shadow-tls'].includes(proxy.plugin) && proxy['plugin-opts']) { - const password = proxy['plugin-opts'].password; - const host = proxy['plugin-opts'].host; - const version = proxy['plugin-opts'].version; - if (password) { - result.append(`,shadow-tls-password="${password}"`); - if (host) { - result.append(`,shadow-tls-sni=${host}`); - } - if (version) { - if (version < 2) { - throw unsupported( - `shadow-tls version ${version} is not supported`, - ); - } - result.append(`,shadow-tls-version=${version}`); - } - // udp-port - result.appendIfPresent( - `,udp-port=${proxy['udp-port']}`, - 'udp-port', - ); - } - } + appendShadowTLS(result, proxy, true); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -383,19 +367,7 @@ function trojan(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -571,18 +543,7 @@ function h2Connect(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); result.appendIfPresent( @@ -651,19 +612,7 @@ function vmess(proxy, includeUnsupportedProxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -784,19 +733,7 @@ function http(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -904,19 +841,7 @@ function socks5(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -1015,19 +940,7 @@ function snell(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -1104,19 +1017,7 @@ function tuic(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -1182,19 +1083,7 @@ function wireguard(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -1283,19 +1172,7 @@ function wireguard_surge(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); @@ -1375,19 +1252,7 @@ function hysteria2(proxy) { ); result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); - // shadow-tls - if (isPresent(proxy, 'shadow-tls-password')) { - result.append(`,shadow-tls-password="${proxy['shadow-tls-password']}"`); - - result.appendIfPresent( - `,shadow-tls-version=${proxy['shadow-tls-version']}`, - 'shadow-tls-version', - ); - result.appendIfPresent( - `,shadow-tls-sni=${proxy['shadow-tls-sni']}`, - 'shadow-tls-sni', - ); - } + appendShadowTLS(result, proxy); // block-quic result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 2219df48..7b0e686e 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -464,7 +464,7 @@ describe('Proxy structured producers', function () { expect(output.outbounds[0]).to.not.have.property('obfs_uri'); }); - it('exports Snell shadow-tls field form to sing-box chained outbounds', function () { + it('exports Snell shadow-tls plugin form to sing-box chained outbounds', function () { const output = loadProducedJson( 'sing-box', { @@ -481,9 +481,12 @@ describe('Proxy structured producers', function () { 'dialer-proxy': 'proxy-out', 'ip-version': 'v6-only', _dns_server: 'dns-out', - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': 3, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version: 3, + }, }, { 'include-unsupported-proxy': true }, ); @@ -714,9 +717,12 @@ describe('Proxy structured producers', function () { port: 8388, cipher: 'aes-128-gcm', password: 'secret', - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': version, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version, + }, }); const proxies = [ buildShadowTlsProxy('ShadowTLS 1', 1), @@ -1731,7 +1737,7 @@ describe('Proxy structured producers', function () { }); }); - it('promotes shadow-tls fields for Shadowrocket', function () { + it('keeps shadow-tls plugin objects for Shadowrocket', function () { const proxy = { type: 'ss', name: 'ShadowTLS SS', @@ -1739,9 +1745,12 @@ describe('Proxy structured producers', function () { port: 8388, cipher: 'aes-128-gcm', password: 'secret', - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': 3, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version: 3, + }, 'skip-cert-verify': true, }; @@ -1862,7 +1871,7 @@ describe('Proxy structured producers', function () { // expect(external.proxies[0]).to.not.have.property('sni'); }); - it('maps shadowsocks shadow-tls fields into Egern nested structures', function () { + it('maps shadowsocks shadow-tls plugin objects into Egern nested structures', function () { const proxy = { type: 'ss', name: 'ShadowTLS SS', @@ -1870,9 +1879,12 @@ describe('Proxy structured producers', function () { port: 8388, cipher: 'aes-128-gcm', password: 'secret', - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': 3, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version: 3, + }, }; const internal = produceInternal('Egern', proxy)[0]; @@ -1902,7 +1914,7 @@ describe('Proxy structured producers', function () { const proxies = [ { type: 'ssh', - name: 'Egern SSH Direct Fields', + name: 'Egern SSH Plugin', server: 'ssh.example.com', port: 443, username: 'user', @@ -1911,9 +1923,12 @@ describe('Proxy structured producers', function () { 'host-key': ['ssh-ed25519 AAAATEST'], tfo: true, 'block-quic': 'off', - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': 3, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version: 3, + }, }, { type: 'ss', @@ -1931,8 +1946,8 @@ describe('Proxy structured producers', function () { const external = loadProducedYaml('Egern', proxies); for (const output of [internal, external.proxies]) { - expectSubset(getProxy(output, 'ssh', 'Egern SSH Direct Fields'), { - name: 'Egern SSH Direct Fields', + expectSubset(getProxy(output, 'ssh', 'Egern SSH Plugin'), { + name: 'Egern SSH Plugin', server: 'ssh.example.com', port: 443, username: 'user', @@ -1961,9 +1976,12 @@ describe('Proxy structured producers', function () { server: 'ssh.example.com', port: 443, username: 'user', - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': 2, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version: 2, + }, }, { type: 'ss', @@ -2147,14 +2165,17 @@ describe('Proxy structured producers', function () { const proxies = [ { type: 'snell', - name: 'Egern Snell ShadowTLS Fields', + name: 'Egern Snell ShadowTLS Plugin A', server: 'snell-shadowtls.example.com', port: 44046, psk: 'secret', version: 5, - 'shadow-tls-password': 'shadow-pass', - 'shadow-tls-sni': 'mask.example.com', - 'shadow-tls-version': 3, + plugin: 'shadow-tls', + 'plugin-opts': { + host: 'mask.example.com', + password: 'shadow-pass', + version: 3, + }, }, { type: 'snell', @@ -2188,7 +2209,7 @@ describe('Proxy structured producers', function () { ); expect(errors).to.deep.equal([ - 'Platform Egern does not support Snell shadow-tls proxy Egern Snell ShadowTLS Fields. Proxy has been filtered.', + 'Platform Egern does not support Snell shadow-tls proxy Egern Snell ShadowTLS Plugin A. Proxy has been filtered.', 'Platform Egern does not support Snell shadow-tls proxy Egern Snell ShadowTLS Plugin. Proxy has been filtered.', ]); expect(externalErrors).to.deep.equal(errors); diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 11965a7f..b433816e 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -533,14 +533,17 @@ describe('Proxy text producers', function () { const output = produceExternal('Loon', [ { type: 'ss', - name: 'Loon SS ShadowTLS Fields', + name: 'Loon SS ShadowTLS Plugin A', server: 'ss.example.com', port: 8388, cipher: 'chacha20-ietf-poly1305', password: 'ss-pass', - 'shadow-tls-password': 'dzUjK3l+mXO/xxx=', - 'shadow-tls-sni': 'p11.douyinpic.com', - 'shadow-tls-version': 3, + plugin: 'shadow-tls', + 'plugin-opts': { + password: 'dzUjK3l+mXO/xxx=', + host: 'p11.douyinpic.com', + version: 3, + }, udp: true, }, { @@ -561,7 +564,7 @@ describe('Proxy text producers', function () { expect(output).to.equal( [ - 'Loon SS ShadowTLS Fields=shadowsocks,ss.example.com,8388,chacha20-ietf-poly1305,"ss-pass",shadow-tls-password=dzUjK3l+mXO/xxx=,shadow-tls-version=3,shadow-tls-sni=p11.douyinpic.com,udp=true', + 'Loon SS ShadowTLS Plugin A=shadowsocks,ss.example.com,8388,chacha20-ietf-poly1305,"ss-pass",shadow-tls-password=dzUjK3l+mXO/xxx=,shadow-tls-sni=p11.douyinpic.com,shadow-tls-version=3,udp=true', 'Loon SS ShadowTLS Plugin=shadowsocks,ss-plugin.example.com,8388,chacha20-ietf-poly1305,"ss-pass",shadow-tls-password=plugin-shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3', ].join('\n'), ); diff --git a/scripts/demo.js b/scripts/demo.js index 1655adae..a768b2d8 100644 --- a/scripts/demo.js +++ b/scripts/demo.js @@ -53,6 +53,7 @@ function operator(proxies = [], targetPlatform, context) { // 若 `control-http-client` 非空, 输出 sing-box Tailscale endpoint 时会跳过旧版拨号字段映射, 避免和 `detour`/`dialer-proxy` 等 legacy dialer options 冲突. 需要给控制面设置前置代理时, 请写到 `control-http-client.detour`(1.14.0-alpha.26 又改回去了...) // 29. sing-box 支持使用 `ssh-server` 给 tailscale 设置 `ssh_server`, 直接设为 `true` 或 `{ "enabled": true, "disable-pty": true, "disable-sftp": true, "disable-forwarding": true }` // 30. Loon 支持使用 `_loon_tls_profile` 设置 `tls-profile` 字段('default', 'chrome', 'ios18', 'ios26'), 否则则使用 client-fingerprint 自动转换部分对应的值 + // 31. `shadow-tls-password`/`shadow-tls-sni`/`shadow-tls-version` 这套旧字段已废弃. 请使用 `plugin: 'shadow-tls'` 和 `plugin-opts: { password, host, version }` // require 为 Node.js 的 require, 在 Node.js 运行环境下 可以用来引入模块 // 例如在 Node.js 环境下, 将文件内容写入 /tmp/1.txt 文件