mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-14 01:55:54 +08:00
fix: trojan uri and tls
This commit is contained in:
parent
497bc264e3
commit
1f505752ae
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.21",
|
"version": "2.14.22",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -36,11 +36,7 @@ function parse(raw) {
|
|||||||
if (lastParser) {
|
if (lastParser) {
|
||||||
const [proxy, error] = tryParse(lastParser, line);
|
const [proxy, error] = tryParse(lastParser, line);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// 前面已经处理过普通情况下的 SNI, 这里显式设置 SNI, 防止之后解析成 IP 后丢失域名 SNI
|
proxies.push(lastParse(proxy));
|
||||||
if (proxy.tls && !proxy.sni && !isIP(proxy.server)) {
|
|
||||||
proxy.sni = proxy.server;
|
|
||||||
}
|
|
||||||
proxies.push(proxy);
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +46,7 @@ function parse(raw) {
|
|||||||
for (const parser of PROXY_PARSERS) {
|
for (const parser of PROXY_PARSERS) {
|
||||||
const [proxy, error] = tryParse(parser, line);
|
const [proxy, error] = tryParse(parser, line);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
proxies.push(proxy);
|
proxies.push(lastParse(proxy));
|
||||||
lastParser = parser;
|
lastParser = parser;
|
||||||
success = true;
|
success = true;
|
||||||
$.info(`${parser.name} is activated`);
|
$.info(`${parser.name} is activated`);
|
||||||
@ -187,6 +183,27 @@ function safeMatch(parser, line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lastParse(proxy) {
|
||||||
|
if (proxy.type === 'trojan') {
|
||||||
|
proxy.tls = true;
|
||||||
|
}
|
||||||
|
if (proxy.tls && !proxy.sni) {
|
||||||
|
if (proxy.network) {
|
||||||
|
let transportHost = proxy[`${proxy.network}-opts`]?.headers?.Host;
|
||||||
|
transportHost = Array.isArray(transportHost)
|
||||||
|
? transportHost[0]
|
||||||
|
: transportHost;
|
||||||
|
if (transportHost) {
|
||||||
|
proxy.sni = transportHost;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!proxy.sni && !isIP(proxy.server)) {
|
||||||
|
proxy.sni = proxy.server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
function isIP(ip) {
|
function isIP(ip) {
|
||||||
return isIPv4(ip) || isIPv6(ip);
|
return isIPv4(ip) || isIPv6(ip);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ port = digits:[0-9]+ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
params = "?" head:param tail:("&"@param)* {
|
params = "/"? "?" head:param tail:("&"@param)* {
|
||||||
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
||||||
proxy.sni = params["sni"] || params["peer"];
|
proxy.sni = params["sni"] || params["peer"];
|
||||||
|
|
||||||
@ -87,6 +87,15 @@ params = "?" head:param tail:("&"@param)* {
|
|||||||
proxy.network = "ws";
|
proxy.network = "ws";
|
||||||
$set(proxy, "ws-opts.path", params["wspath"]);
|
$set(proxy, "ws-opts.path", params["wspath"]);
|
||||||
}
|
}
|
||||||
|
if (params["type"]) {
|
||||||
|
proxy.network = params["type"]
|
||||||
|
if (params["path"]) {
|
||||||
|
$set(proxy, proxy.network+"-opts.path", decodeURIComponent(params["path"]));
|
||||||
|
}
|
||||||
|
if (params["host"]) {
|
||||||
|
$set(proxy, proxy.network+"-opts.headers.Host", decodeURIComponent(params["host"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proxy.udp = toBool(params["udp"]);
|
proxy.udp = toBool(params["udp"]);
|
||||||
proxy.tfo = toBool(params["tfo"]);
|
proxy.tfo = toBool(params["tfo"]);
|
||||||
|
@ -77,7 +77,7 @@ port = digits:[0-9]+ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
params = "?" head:param tail:("&"@param)* {
|
params = "/"? "?" head:param tail:("&"@param)* {
|
||||||
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
|
||||||
proxy.sni = params["sni"] || params["peer"];
|
proxy.sni = params["sni"] || params["peer"];
|
||||||
|
|
||||||
@ -85,6 +85,16 @@ params = "?" head:param tail:("&"@param)* {
|
|||||||
proxy.network = "ws";
|
proxy.network = "ws";
|
||||||
$set(proxy, "ws-opts.path", params["wspath"]);
|
$set(proxy, "ws-opts.path", params["wspath"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params["type"]) {
|
||||||
|
proxy.network = params["type"]
|
||||||
|
if (params["path"]) {
|
||||||
|
$set(proxy, proxy.network+"-opts.path", decodeURIComponent(params["path"]));
|
||||||
|
}
|
||||||
|
if (params["host"]) {
|
||||||
|
$set(proxy, proxy.network+"-opts.headers.Host", decodeURIComponent(params["host"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proxy.udp = toBool(params["udp"]);
|
proxy.udp = toBool(params["udp"]);
|
||||||
proxy.tfo = toBool(params["tfo"]);
|
proxy.tfo = toBool(params["tfo"]);
|
||||||
|
@ -210,14 +210,18 @@ function vmess(proxy) {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(`network ${proxy.network} is unsupported`);
|
throw new Error(`network ${proxy.network} is unsupported`);
|
||||||
}
|
}
|
||||||
let httpPath = proxy[`${proxy.network}-opts`]?.path;
|
let transportPath = proxy[`${proxy.network}-opts`]?.path;
|
||||||
let httpHost = proxy[`${proxy.network}-opts`]?.headers?.Host;
|
let transportHost = proxy[`${proxy.network}-opts`]?.headers?.Host;
|
||||||
appendIfPresent(
|
appendIfPresent(
|
||||||
`,obfs-uri=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`,
|
`,obfs-uri=${
|
||||||
|
Array.isArray(transportPath) ? transportPath[0] : transportPath
|
||||||
|
}`,
|
||||||
`${proxy.network}-opts.path`,
|
`${proxy.network}-opts.path`,
|
||||||
);
|
);
|
||||||
appendIfPresent(
|
appendIfPresent(
|
||||||
`,obfs-host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`,
|
`,obfs-host=${
|
||||||
|
Array.isArray(transportHost) ? transportHost[0] : transportHost
|
||||||
|
}`,
|
||||||
`${proxy.network}-opts.headers.Host`,
|
`${proxy.network}-opts.headers.Host`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,11 +78,32 @@ export default function URI_Producer() {
|
|||||||
result = 'vmess://' + Base64.encode(JSON.stringify(result));
|
result = 'vmess://' + Base64.encode(JSON.stringify(result));
|
||||||
break;
|
break;
|
||||||
case 'trojan':
|
case 'trojan':
|
||||||
|
let transport = '';
|
||||||
|
if (proxy.network) {
|
||||||
|
transport = `&type=${proxy.network}`;
|
||||||
|
let transportPath = proxy[`${proxy.network}-opts`]?.path;
|
||||||
|
let transportHost =
|
||||||
|
proxy[`${proxy.network}-opts`]?.headers?.Host;
|
||||||
|
if (transportPath) {
|
||||||
|
transport += `&path=${encodeURIComponent(
|
||||||
|
Array.isArray(transportPath)
|
||||||
|
? transportPath[0]
|
||||||
|
: transportPath,
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
if (transportHost) {
|
||||||
|
transport += `&host=${encodeURIComponent(
|
||||||
|
Array.isArray(transportHost)
|
||||||
|
? transportHost[0]
|
||||||
|
: transportHost,
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
result = `trojan://${proxy.password}@${proxy.server}:${
|
result = `trojan://${proxy.password}@${proxy.server}:${
|
||||||
proxy.port
|
proxy.port
|
||||||
}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${
|
}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${
|
||||||
proxy['skip-cert-verify'] ? '&allowInsecure=1' : ''
|
proxy['skip-cert-verify'] ? '&allowInsecure=1' : ''
|
||||||
}#${encodeURIComponent(proxy.name)}`;
|
}${transport}#${encodeURIComponent(proxy.name)}`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user