diff --git a/backend/package.json b/backend/package.json index 91950984a..3b56a4442 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.266", + "version": "2.14.270", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 62ee4524d..807eec7ce 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -186,6 +186,10 @@ function produce(proxies, targetPlatform, type, opts = {}) { throw new Error(`Target platform: ${targetPlatform} is not supported!`); } + const sni_off_supported = /Surge|SurgeMac|Shadowrocket/i.test( + targetPlatform, + ); + // filter unsupported proxies proxies = proxies.filter( (proxy) => @@ -196,6 +200,18 @@ function produce(proxies, targetPlatform, type, opts = {}) { if (!isNotBlank(proxy.name)) { proxy.name = `${proxy.type} ${proxy.server}:${proxy.port}`; } + if (proxy['disable-sni']) { + if (sni_off_supported) { + proxy.sni = 'off'; + } else if (!['tuic'].includes(proxy.type)) { + $.error( + `Target platform ${targetPlatform} does not support sni off. Proxy's fields (sni, tls-fingerprint and skip-cert-verify) will be modified.`, + ); + proxy.sni = ''; + proxy['skip-cert-verify'] = true; + delete proxy['tls-fingerprint']; + } + } return proxy; }); @@ -396,6 +412,9 @@ function lastParse(proxy) { proxy.name = `${proxy.type} ${proxy.server}:${proxy.port}`; } } + if (['', 'off'].includes(proxy.sni)) { + proxy['disable-sni'] = true; + } return proxy; } diff --git a/backend/src/core/proxy-utils/parsers/peggy/surge.js b/backend/src/core/proxy-utils/parsers/peggy/surge.js index 61ca022f9..0cf03af80 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/surge.js +++ b/backend/src/core/proxy-utils/parsers/peggy/surge.js @@ -177,7 +177,13 @@ username = & { password = comma match:[^,]+ { proxy.password = match.join(""); } tls = comma "tls" equals flag:bool { proxy.tls = flag; } -sni = comma "sni" equals sni:domain { proxy.sni = sni; } +sni = comma "sni" equals sni:("off"/domain) { + if (sni === "off") { + proxy["disable-sni"] = true; + } else { + proxy.sni = sni; + } +} tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; } tls_fingerprint = comma "server-cert-fingerprint-sha256" equals tls_fingerprint:$[^,]+ { proxy["tls-fingerprint"] = tls_fingerprint.trim(); } diff --git a/backend/src/core/proxy-utils/parsers/peggy/surge.peg b/backend/src/core/proxy-utils/parsers/peggy/surge.peg index 916477735..2ebf7439a 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/surge.peg +++ b/backend/src/core/proxy-utils/parsers/peggy/surge.peg @@ -175,7 +175,13 @@ username = & { password = comma match:[^,]+ { proxy.password = match.join(""); } tls = comma "tls" equals flag:bool { proxy.tls = flag; } -sni = comma "sni" equals sni:domain { proxy.sni = sni; } +sni = comma "sni" equals sni:("off"/domain) { + if (sni === "off") { + proxy["disable-sni"] = true; + } else { + proxy.sni = sni; + } +} tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; } tls_fingerprint = comma "server-cert-fingerprint-sha256" equals tls_fingerprint:$[^,]+ { proxy["tls-fingerprint"] = tls_fingerprint.trim(); }