Skip to content

Commit

Permalink
feat: 处理 sni off 的情况. 若出现问题, 麻烦大家及时反馈
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Mar 29, 2024
1 parent 56870bb commit 89dbe9a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.266",
"version": "2.14.269",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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 (tls-fingerprint and skip-cert-verify) will be modified.`,
);
delete proxy.sni;
proxy['skip-cert-verify'] = true;
delete proxy['tls-fingerprint'];
}
}
return proxy;
});

Expand Down
8 changes: 7 additions & 1 deletion backend/src/core/proxy-utils/parsers/peggy/surge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
8 changes: 7 additions & 1 deletion backend/src/core/proxy-utils/parsers/peggy/surge.peg
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down

0 comments on commit 89dbe9a

Please sign in to comment.