mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-12-05 10:48:05 +00:00
This commit is contained in:
11 files changed
+335
-20
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.44.34",
|
||||
"version": "2.44.35",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -26,6 +26,7 @@ import PROXY_PROCESSORS, {
|
||||
import PROXY_PREPROCESSORS from './preprocessors';
|
||||
import PROXY_PRODUCERS from './producers';
|
||||
import PROXY_PARSERS from './parsers';
|
||||
import { LOON_TROJAN_GRPC_H2C } from './loon-grpc';
|
||||
import $ from '@/core/app';
|
||||
import { FILES_KEY, MODULES_KEY } from '@/constants';
|
||||
import { findByName } from '@/utils/database';
|
||||
@@ -1020,7 +1021,8 @@ function lastParse(proxy) {
|
||||
'shadowquic',
|
||||
].includes(proxy.type)
|
||||
) {
|
||||
proxy.tls = true;
|
||||
proxy.tls = !proxy[LOON_TROJAN_GRPC_H2C];
|
||||
delete proxy[LOON_TROJAN_GRPC_H2C];
|
||||
}
|
||||
if (proxy.network) {
|
||||
let transportHost = proxy[`${proxy.network}-opts`]?.headers?.Host;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { isNotBlank } from '@/utils';
|
||||
import { parseSafeIntegerValue } from './transport-path';
|
||||
|
||||
export const LOON_TROJAN_GRPC_H2C = Symbol('Loon Trojan gRPC h2c');
|
||||
|
||||
export function getLoonGrpcSettings(
|
||||
proxy,
|
||||
alpn,
|
||||
muxMaxStreams = proxy._loon_grpc_mux_max_streams,
|
||||
) {
|
||||
const mode = proxy['grpc-opts']?.['_grpc-type'];
|
||||
if (mode != null && !['gun', 'multi'].includes(mode)) {
|
||||
throw new Error('Loon grpc-mode must be gun or multi');
|
||||
}
|
||||
if (alpn && alpn !== 'h2') {
|
||||
throw new Error('Loon gRPC alpn must be h2');
|
||||
}
|
||||
|
||||
const reality = proxy['reality-opts'];
|
||||
const tls = proxy.tls ?? (Boolean(reality) || proxy.type === 'trojan');
|
||||
if (
|
||||
reality &&
|
||||
(!isNotBlank(reality['public-key']) ||
|
||||
!isNotBlank(proxy.sni) ||
|
||||
![true, 'true'].includes(tls))
|
||||
) {
|
||||
throw new Error('Loon gRPC REALITY requires a public-key, sni and TLS');
|
||||
}
|
||||
|
||||
let maxStreams;
|
||||
if (muxMaxStreams != null) {
|
||||
maxStreams = parseSafeIntegerValue(muxMaxStreams);
|
||||
if (maxStreams == null || maxStreams < 1 || maxStreams > 16) {
|
||||
throw new Error('Loon grpc-mux-max-streams must be 1–16');
|
||||
}
|
||||
}
|
||||
return { tls, maxStreams };
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Buffer } from 'buffer';
|
||||
import peggy from 'peggy';
|
||||
import { getLoonGrpcSettings, LOON_TROJAN_GRPC_H2C } from '../../loon-grpc';
|
||||
import { setLoonXhttpOption } from '../../loon-xhttp';
|
||||
|
||||
const grammars = String.raw`
|
||||
@@ -37,6 +38,24 @@ const grammars = String.raw`
|
||||
proxy.network = "http";
|
||||
$set(proxy, "http-opts.path", transport.path);
|
||||
$set(proxy, "http-opts.headers.Host", transport.host);
|
||||
} else if (transport.type === "grpc") {
|
||||
if (proxy.type === "vmess" && proxy.alterId !== 0) {
|
||||
throw new Error("VMess gRPC requires AEAD");
|
||||
}
|
||||
proxy.network = "grpc";
|
||||
proxy.udp ??= false;
|
||||
const { "service-name": serviceName, mode, host } = transport;
|
||||
if (serviceName != null) $set(proxy, "grpc-opts.grpc-service-name", serviceName);
|
||||
if (mode != null) $set(proxy, "grpc-opts._grpc-type", mode);
|
||||
if (host != null) $set(proxy, "grpc-opts._grpc-authority", host);
|
||||
const { tls, maxStreams } = options.getLoonGrpcSettings(
|
||||
proxy, proxy.alpn?.join(","), transport["mux-max-streams"]
|
||||
);
|
||||
proxy.tls = tls;
|
||||
if (proxy.type === "trojan" && tls === false) {
|
||||
proxy[options.LOON_TROJAN_GRPC_H2C] = true;
|
||||
}
|
||||
if (maxStreams != null) proxy._loon_grpc_mux_max_streams = maxStreams;
|
||||
} else if (transport.type === "xhttp") {
|
||||
if (proxy.type === "vmess" && proxy.alterId !== 0) {
|
||||
throw new Error("VMess XHTTP requires AEAD");
|
||||
@@ -113,13 +132,13 @@ shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs
|
||||
}
|
||||
handleShadowTLS();
|
||||
}
|
||||
vmess = tag equals "vmess"i address vmess_method uuid (xhttp_transport/transport/transport_host/transport_path/xhttp_option/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)* {
|
||||
vmess = tag equals "vmess"i address vmess_method uuid (grpc_transport/xhttp_transport/transport/transport_host/transport_path/grpc_option/xhttp_option/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";
|
||||
proxy.cipher = proxy.cipher || "auto";
|
||||
proxy.alterId = proxy.alterId || 0;
|
||||
handleTransport();
|
||||
}
|
||||
vless = tag equals "vless"i address uuid (xhttp_transport/transport/transport_host/transport_path/xhttp_option/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/flow/vless_encryption/public_key/short_id/block_quic/others)* {
|
||||
vless = tag equals "vless"i address uuid (grpc_transport/xhttp_transport/transport/transport_host/transport_path/grpc_option/xhttp_option/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/flow/vless_encryption/public_key/short_id/block_quic/others)* {
|
||||
proxy.type = "vless";
|
||||
const { mode, rtt, padding, "public-keys": publicKeys } = vlessEncryption;
|
||||
if (mode && mode !== "none") {
|
||||
@@ -128,7 +147,7 @@ vless = tag equals "vless"i address uuid (xhttp_transport/transport/transport_ho
|
||||
}
|
||||
handleTransport();
|
||||
}
|
||||
trojan = tag equals "trojan"i address password (xhttp_transport/transport/transport_host/transport_path/xhttp_option/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* {
|
||||
trojan = tag equals "trojan"i address password (grpc_transport/xhttp_transport/transport/transport_host/transport_path/grpc_option/xhttp_option/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* {
|
||||
proxy.type = "trojan";
|
||||
handleTransport();
|
||||
}
|
||||
@@ -271,6 +290,11 @@ transport = comma "transport" equals type:("tcp"/"ws"/"http") { transport.type =
|
||||
transport_host = comma "host" equals value:option_value { transport.host = value; }
|
||||
transport_path = comma "path" equals value:option_value { transport.path = value; }
|
||||
|
||||
grpc_transport = comma "transport" equals "grpc" { transport.type = "grpc"; }
|
||||
grpc_option = comma "grpc-" key:("service-name"/"mode"/"mux-max-streams") equals value:option_value {
|
||||
transport[key] = value;
|
||||
}
|
||||
|
||||
xhttp_transport = comma "transport" equals "xhttp" { transport.type = "xhttp"; }
|
||||
xhttp_option = comma "xhttp-" key:$[a-z0-9-]+ equals value:option_value {
|
||||
options.setLoonXhttpOption(xhttpOpts, key, value);
|
||||
@@ -379,6 +403,8 @@ export default function getParser() {
|
||||
parser = {
|
||||
parse: (input) =>
|
||||
generated.parse(input, {
|
||||
getLoonGrpcSettings,
|
||||
LOON_TROJAN_GRPC_H2C,
|
||||
setLoonXhttpOption,
|
||||
decodeGeckoPassword,
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
isPresent,
|
||||
isTrojanGrpcH2c,
|
||||
produceProxyListOutput,
|
||||
} from '@/core/proxy-utils/producers/utils';
|
||||
import { normalizeClashVmessSecurity } from '../vmess-security';
|
||||
@@ -20,6 +21,12 @@ export default function Clash_Producer() {
|
||||
const list = proxies
|
||||
.filter((proxy) => {
|
||||
if (opts['include-unsupported-proxy']) return true;
|
||||
if (isTrojanGrpcH2c(proxy)) {
|
||||
$.error(
|
||||
`Clash does not support Trojan gRPC over h2c. Proxy ${proxy.name} has been filtered.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
![
|
||||
'ss',
|
||||
@@ -178,7 +185,8 @@ export default function Clash_Producer() {
|
||||
'anytls',
|
||||
'trusttunnel',
|
||||
'naive',
|
||||
].includes(proxy.type)
|
||||
].includes(proxy.type) &&
|
||||
!isTrojanGrpcH2c(proxy)
|
||||
) {
|
||||
delete proxy.tls;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Buffer } from 'buffer';
|
||||
import {
|
||||
getWireGuardAddressWithCIDR,
|
||||
isPresent,
|
||||
isTrojanGrpcH2c,
|
||||
normalizePluginMuxBooleanValue,
|
||||
produceProxyListOutput,
|
||||
restoreShadowTLSProxyOpts,
|
||||
@@ -61,6 +62,12 @@ export default function ClashMeta_Producer() {
|
||||
}
|
||||
if (opts['include-unsupported-proxy']) return true;
|
||||
|
||||
if (isTrojanGrpcH2c(proxy)) {
|
||||
$.error(
|
||||
`mihomo does not support Trojan gRPC over h2c. Proxy ${proxy.name} has been filtered.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (proxy.type === 'h2-connect') {
|
||||
$.error(
|
||||
`mihomo does not support HTTP/2 CONNECT proxy type. Proxy ${proxy.name} has been filtered.`,
|
||||
@@ -402,7 +409,8 @@ export default function ClashMeta_Producer() {
|
||||
'naive',
|
||||
'masque',
|
||||
'shadowquic',
|
||||
].includes(proxy.type)
|
||||
].includes(proxy.type) &&
|
||||
!isTrojanGrpcH2c(proxy)
|
||||
) {
|
||||
delete proxy.tls;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import _ from 'lodash';
|
||||
import { isPresent, Result } from './utils';
|
||||
import { getIfNotBlank, isIPv4, isIPv6, isPlainObject } from '@/utils';
|
||||
import $ from '@/core/app';
|
||||
import { getLoonGrpcSettings } from '../loon-grpc';
|
||||
import { LOON_XHTTP_FIELDS, validateLoonXhttpXmux } from '../loon-xhttp';
|
||||
import { validateMieruTrafficPattern } from '../mieru-traffic-pattern';
|
||||
import { formatLoonVmessSecurity } from '../vmess-security';
|
||||
@@ -96,6 +97,23 @@ function formatLoonValue(value, quoted = false) {
|
||||
return quoted || !text || /[,\s]/.test(text) ? `"${text}"` : text;
|
||||
}
|
||||
|
||||
function appendGrpc(result, proxy) {
|
||||
const alpn = getLoonAlpn(proxy);
|
||||
const { tls, maxStreams } = getLoonGrpcSettings(proxy, alpn);
|
||||
const grpc = proxy['grpc-opts'];
|
||||
result.append(',transport=grpc');
|
||||
for (const [key, value] of [
|
||||
['grpc-service-name', grpc?.['grpc-service-name']],
|
||||
['grpc-mode', grpc?.['_grpc-type']],
|
||||
['grpc-mux-max-streams', maxStreams],
|
||||
['host', grpc?.['_grpc-authority']],
|
||||
]) {
|
||||
if (value != null) result.append(`,${key}=${formatLoonValue(value)}`);
|
||||
}
|
||||
result.append(`,over-tls=${tls}`);
|
||||
if (alpn) result.append(`,alpn="${alpn}"`);
|
||||
}
|
||||
|
||||
function appendXhttp(result, proxy) {
|
||||
const xhttp = proxy['xhttp-opts'];
|
||||
const download = xhttp?.['download-settings'];
|
||||
@@ -488,6 +506,7 @@ function snell(proxy) {
|
||||
|
||||
function trojan(proxy) {
|
||||
const isReality = !!proxy['reality-opts'];
|
||||
const isGrpc = proxy.network === 'grpc';
|
||||
const isXhttp = proxy.network === 'xhttp';
|
||||
const result = new Result(proxy);
|
||||
result.append(
|
||||
@@ -508,6 +527,8 @@ function trojan(proxy) {
|
||||
`,host=${proxy['ws-opts']?.headers?.Host}`,
|
||||
'ws-opts.headers.Host',
|
||||
);
|
||||
} else if (isGrpc) {
|
||||
appendGrpc(result, proxy);
|
||||
} else if (isXhttp) {
|
||||
appendXhttp(result, proxy);
|
||||
} else {
|
||||
@@ -521,14 +542,14 @@ function trojan(proxy) {
|
||||
'skip-cert-verify',
|
||||
);
|
||||
appendTlsProfile(result, proxy);
|
||||
appendAlpn(result, proxy, isXhttp);
|
||||
if (!isGrpc) appendAlpn(result, proxy, isXhttp);
|
||||
|
||||
if (isReality) {
|
||||
appendReality(result, proxy);
|
||||
} else {
|
||||
// sni
|
||||
result.appendIfPresent(
|
||||
`,${isXhttp ? 'sni' : 'tls-name'}=${proxy.sni}`,
|
||||
`,${isGrpc || isXhttp ? 'sni' : 'tls-name'}=${proxy.sni}`,
|
||||
'sni',
|
||||
);
|
||||
result.appendIfPresent(
|
||||
@@ -625,6 +646,7 @@ function anytls(proxy) {
|
||||
|
||||
function vmess(proxy) {
|
||||
const isReality = !!proxy['reality-opts'];
|
||||
const isGrpc = proxy.network === 'grpc';
|
||||
const isXhttp = proxy.network === 'xhttp';
|
||||
const security = formatLoonVmessSecurity(proxy.cipher);
|
||||
|
||||
@@ -659,6 +681,8 @@ function vmess(proxy) {
|
||||
`,host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`,
|
||||
'http-opts.headers.Host',
|
||||
);
|
||||
} else if (isGrpc) {
|
||||
appendGrpc(result, proxy);
|
||||
} else if (isXhttp) {
|
||||
appendXhttp(result, proxy);
|
||||
} else {
|
||||
@@ -669,7 +693,7 @@ function vmess(proxy) {
|
||||
}
|
||||
|
||||
// tls
|
||||
result.appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
if (!isGrpc) result.appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
|
||||
// tls verification
|
||||
result.appendIfPresent(
|
||||
@@ -677,14 +701,16 @@ function vmess(proxy) {
|
||||
'skip-cert-verify',
|
||||
);
|
||||
if (proxy.tls || isReality) appendTlsProfile(result, proxy);
|
||||
if (proxy.tls || isReality || isXhttp) appendAlpn(result, proxy, isXhttp);
|
||||
if (!isGrpc && (proxy.tls || isReality || isXhttp)) {
|
||||
appendAlpn(result, proxy, isXhttp);
|
||||
}
|
||||
|
||||
if (isReality) {
|
||||
appendReality(result, proxy);
|
||||
} else {
|
||||
// sni
|
||||
result.appendIfPresent(
|
||||
`,${isXhttp ? 'sni' : 'tls-name'}=${proxy.sni}`,
|
||||
`,${isGrpc || isXhttp ? 'sni' : 'tls-name'}=${proxy.sni}`,
|
||||
'sni',
|
||||
);
|
||||
result.appendIfPresent(
|
||||
@@ -700,9 +726,11 @@ function vmess(proxy) {
|
||||
// AEAD
|
||||
let alterId = proxy.alterId;
|
||||
if (isPresent(proxy, 'aead')) alterId = proxy.aead ? 0 : 1;
|
||||
if (isXhttp) {
|
||||
alterId ??= 0;
|
||||
if (Number(alterId) !== 0) throw new Error('VMess XHTTP requires AEAD');
|
||||
if (isGrpc || isXhttp) {
|
||||
if (Number(alterId ?? 0) !== 0) {
|
||||
throw new Error(`VMess ${isGrpc ? 'gRPC' : 'XHTTP'} requires AEAD`);
|
||||
}
|
||||
alterId = 0;
|
||||
}
|
||||
result.append(`,alterId=${alterId}`);
|
||||
|
||||
@@ -775,6 +803,7 @@ function vless(proxy) {
|
||||
const isXtls = !!proxy.flow;
|
||||
const reality = proxy['reality-opts'];
|
||||
const isReality = Boolean(getIfNotBlank(reality?.['public-key']));
|
||||
const isGrpc = proxy.network === 'grpc';
|
||||
const isXhttp = proxy.network === 'xhttp';
|
||||
const isTcp = (proxy.network ?? 'tcp') === 'tcp';
|
||||
const isSecure = isReality || [true, 'true'].includes(proxy.tls);
|
||||
@@ -826,6 +855,8 @@ function vless(proxy) {
|
||||
`,host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`,
|
||||
'http-opts.headers.Host',
|
||||
);
|
||||
} else if (isGrpc) {
|
||||
appendGrpc(result, proxy);
|
||||
} else if (isXhttp) {
|
||||
appendXhttp(result, proxy);
|
||||
} else {
|
||||
@@ -836,7 +867,7 @@ function vless(proxy) {
|
||||
}
|
||||
|
||||
// tls
|
||||
result.appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
if (!isGrpc) result.appendIfPresent(`,over-tls=${proxy.tls}`, 'tls');
|
||||
|
||||
// tls verification
|
||||
result.appendIfPresent(
|
||||
@@ -844,8 +875,9 @@ function vless(proxy) {
|
||||
'skip-cert-verify',
|
||||
);
|
||||
if (proxy.tls || isReality || isXtls) appendTlsProfile(result, proxy);
|
||||
if (proxy.tls || isReality || isXtls || isXhttp)
|
||||
if (!isGrpc && (proxy.tls || isReality || isXtls || isXhttp)) {
|
||||
appendAlpn(result, proxy, isXhttp);
|
||||
}
|
||||
|
||||
appendVlessEncryption(result, proxy.encryption);
|
||||
if (isXtls) result.append(`,flow=${proxy.flow}`);
|
||||
@@ -854,7 +886,7 @@ function vless(proxy) {
|
||||
} else {
|
||||
// sni
|
||||
result.appendIfPresent(
|
||||
`,${isXhttp ? 'sni' : 'tls-name'}=${proxy.sni}`,
|
||||
`,${isGrpc || isXhttp ? 'sni' : 'tls-name'}=${proxy.sni}`,
|
||||
'sni',
|
||||
);
|
||||
result.appendIfPresent(
|
||||
|
||||
@@ -2,7 +2,11 @@ import { Buffer } from 'buffer';
|
||||
import ClashMeta_Producer from './clashmeta';
|
||||
import $ from '@/core/app';
|
||||
import { isPlainObject } from '@/utils';
|
||||
import { getWireGuardAddressWithCIDR, normalizePluginMuxValue } from './utils';
|
||||
import {
|
||||
getWireGuardAddressWithCIDR,
|
||||
isTrojanGrpcH2c,
|
||||
normalizePluginMuxValue,
|
||||
} from './utils';
|
||||
import {
|
||||
extractPathQueryParam,
|
||||
getSafeIntegerPathQueryParam,
|
||||
@@ -939,7 +943,11 @@ const trojanParser = (proxy = {}) => {
|
||||
networkParser(proxy, parsedProxy);
|
||||
tfoParser(proxy, parsedProxy);
|
||||
detourParser(proxy, parsedProxy);
|
||||
tlsParser(proxy, parsedProxy);
|
||||
if (isTrojanGrpcH2c(proxy)) {
|
||||
delete parsedProxy.tls;
|
||||
} else {
|
||||
tlsParser(proxy, parsedProxy);
|
||||
}
|
||||
smuxParser(proxy.smux, parsedProxy);
|
||||
ipVersionParser(proxy, parsedProxy);
|
||||
domainResolverParser(proxy, parsedProxy);
|
||||
|
||||
@@ -50,6 +50,15 @@ export function supportsVlessTransportSecurity(proxy) {
|
||||
return encrypted || (secure && !['ws', 'xhttp'].includes(network));
|
||||
}
|
||||
|
||||
export function isTrojanGrpcH2c(proxy) {
|
||||
return (
|
||||
proxy.type === 'trojan' &&
|
||||
proxy.network === 'grpc' &&
|
||||
proxy.tls === false &&
|
||||
!proxy['reality-opts']
|
||||
);
|
||||
}
|
||||
|
||||
export function supportsTrustTunnelClientRandomAuth(proxy, targetPlatform) {
|
||||
if (
|
||||
proxy.type !== 'trusttunnel' ||
|
||||
|
||||
@@ -1364,6 +1364,73 @@ describe('Proxy structured producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Loon Trojan gRPC exports', function () {
|
||||
const input = [
|
||||
'Trojan TLS=Trojan,tls.example.com,443,"secret",transport=grpc,grpc-service-name=secure,sni=sni.example.com',
|
||||
'Trojan h2c=Trojan,h2c.example.com,8080,"secret",transport=grpc,grpc-service-name=plain,over-tls=false',
|
||||
].join('\n');
|
||||
|
||||
for (const target of ['Clash', 'Mihomo']) {
|
||||
it(`filters h2c and keeps TLS in ${target} by default`, function () {
|
||||
const proxies = ProxyUtils.parse(input);
|
||||
const { result, errors } = captureErrors(() =>
|
||||
loadProducedYaml(target, proxies),
|
||||
);
|
||||
expect(result.proxies).to.have.length(1);
|
||||
expectSubset(result.proxies[0], {
|
||||
name: 'Trojan TLS',
|
||||
type: 'trojan',
|
||||
network: 'grpc',
|
||||
sni: 'sni.example.com',
|
||||
'grpc-opts': { 'grpc-service-name': 'secure' },
|
||||
});
|
||||
expect(result.proxies[0]).not.to.have.property('tls');
|
||||
expect(errors).to.have.length(1);
|
||||
expect(errors[0]).to.include('Trojan gRPC over h2c');
|
||||
expect(errors[0]).to.include('Trojan h2c');
|
||||
});
|
||||
|
||||
it(`exports h2c with tls false when unsupported ${target} proxies are included`, function () {
|
||||
const proxies = ProxyUtils.parse(input);
|
||||
const { result, errors } = captureErrors(() =>
|
||||
loadProducedYaml(target, proxies, {
|
||||
'include-unsupported-proxy': true,
|
||||
}),
|
||||
);
|
||||
expect(result.proxies).to.have.length(2);
|
||||
expectSubset(result.proxies[1], {
|
||||
name: 'Trojan h2c',
|
||||
type: 'trojan',
|
||||
network: 'grpc',
|
||||
tls: false,
|
||||
'grpc-opts': { 'grpc-service-name': 'plain' },
|
||||
});
|
||||
expect(errors).to.be.empty;
|
||||
});
|
||||
}
|
||||
|
||||
it('preserves h2c and TLS in sing-box', function () {
|
||||
const { outbounds } = loadProducedJson(
|
||||
'sing-box',
|
||||
ProxyUtils.parse(input),
|
||||
);
|
||||
expect(outbounds).to.have.length(2);
|
||||
const [secure, cleartext] = outbounds;
|
||||
expectSubset(secure, {
|
||||
tag: 'Trojan TLS',
|
||||
type: 'trojan',
|
||||
tls: { enabled: true, server_name: 'sni.example.com' },
|
||||
transport: { type: 'grpc', service_name: 'secure' },
|
||||
});
|
||||
expectSubset(cleartext, {
|
||||
tag: 'Trojan h2c',
|
||||
type: 'trojan',
|
||||
transport: { type: 'grpc', service_name: 'plain' },
|
||||
});
|
||||
expect(cleartext).not.to.have.property('tls');
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes active stream ShadowTLS versions without enabling empty configs', function () {
|
||||
const proxies = [
|
||||
{
|
||||
|
||||
@@ -1024,6 +1024,123 @@ describe('Proxy text producers', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('round-trips Loon gRPC for VLESS, VMess AEAD, and Trojan', function () {
|
||||
const publicKey = 'A'.repeat(43);
|
||||
const input = [
|
||||
`VLESS=VLESS,example.com,443,"${UUID}",transport=grpc,grpc-service-name="/edge,a/Bridge|BridgeMulti",grpc-mode=multi,grpc-mux-max-streams=16,host=authority.example.com,sni=sni.example.com,over-tls=true,public-key="${publicKey}",short-id=0012,alpn=h2,udp=true,encryption-mode=native,encryption-public-keys=${publicKey},flow=xtls-rprx-vision`,
|
||||
`VMess=VMess,example.com,8080,aes-128-gcm,"${UUID}",alterId=0,transport=grpc,grpc-service-name="",grpc-mode=gun,grpc-mux-max-streams=1,over-tls=false`,
|
||||
'Trojan=Trojan,example.com,443,"secret",transport=grpc,grpc-service-name=trojan-grpc',
|
||||
'Trojan h2c=Trojan,example.com,8080,"secret",transport=grpc,over-tls=false',
|
||||
].join('\n');
|
||||
const proxies = ProxyUtils.parse(input);
|
||||
expect(proxies.map(({ type, network }) => [type, network])).to.deep.equal([
|
||||
['vless', 'grpc'],
|
||||
['vmess', 'grpc'],
|
||||
['trojan', 'grpc'],
|
||||
['trojan', 'grpc'],
|
||||
]);
|
||||
const [vless, vmess, trojan, trojanH2c] = proxies;
|
||||
expectSubset(vless, {
|
||||
tls: true,
|
||||
sni: 'sni.example.com',
|
||||
alpn: ['h2'],
|
||||
udp: true,
|
||||
flow: 'xtls-rprx-vision',
|
||||
encryption: `mlkem768x25519plus.native.0rtt.${publicKey}`,
|
||||
'reality-opts': { 'public-key': publicKey, 'short-id': '0012' },
|
||||
'grpc-opts': {
|
||||
'grpc-service-name': '/edge,a/Bridge|BridgeMulti',
|
||||
'_grpc-type': 'multi',
|
||||
'_grpc-authority': 'authority.example.com',
|
||||
},
|
||||
_loon_grpc_mux_max_streams: 16,
|
||||
});
|
||||
expectSubset(vmess, {
|
||||
alterId: 0,
|
||||
tls: false,
|
||||
udp: false,
|
||||
'grpc-opts': { 'grpc-service-name': '', '_grpc-type': 'gun' },
|
||||
_loon_grpc_mux_max_streams: 1,
|
||||
});
|
||||
expect(trojan.tls).to.be.true;
|
||||
expect(trojanH2c.tls).to.be.false;
|
||||
|
||||
const output = produceExternal('Loon', proxies);
|
||||
expect(output).to.include(
|
||||
',grpc-service-name="/edge,a/Bridge|BridgeMulti"',
|
||||
);
|
||||
expect(output).to.include(',grpc-mode=multi,grpc-mux-max-streams=16');
|
||||
expect(output).to.include(',host=authority.example.com');
|
||||
expect(output).to.include(',sni=sni.example.com');
|
||||
expect(output).to.include(
|
||||
'Trojan h2c=trojan,example.com,8080,"secret",transport=grpc,over-tls=false',
|
||||
);
|
||||
expect(ProxyUtils.parse(output)).to.deep.equal(proxies);
|
||||
});
|
||||
|
||||
it('keeps TLS and the default SNI for Clash Trojan gRPC input', function () {
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
'proxies:\n - {name: Trojan, type: trojan, server: example.com, port: 443, password: secret, network: grpc, tls: false}',
|
||||
);
|
||||
expect(proxy).to.include({ tls: true, sni: 'example.com' });
|
||||
expect(produceExternal('Loon', proxy)).to.include(',over-tls=true');
|
||||
});
|
||||
|
||||
it('converts VLESS gRPC share links to Loon', function () {
|
||||
const input = `vless://${UUID}@example.com:443?type=grpc&security=tls&serviceName=%2Fedge%2FBridge&authority=authority.example.com&mode=multi&sni=sni.example.com&alpn=h2#VLESS`;
|
||||
const output = produceExternal('Loon', ProxyUtils.parse(input));
|
||||
expect(output).to.include(
|
||||
',transport=grpc,grpc-service-name=/edge/Bridge,grpc-mode=multi,host=authority.example.com,over-tls=true',
|
||||
);
|
||||
expect(output).to.include(',sni=sni.example.com');
|
||||
expect(output).not.to.include(',grpc-mux-max-streams=');
|
||||
});
|
||||
|
||||
it('rejects invalid Loon gRPC configuration', function () {
|
||||
const input = `VMess=VMess,example.com,443,auto,"${UUID}",transport=grpc`;
|
||||
const proxy = {
|
||||
name: 'VMess',
|
||||
type: 'vmess',
|
||||
server: 'example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
network: 'grpc',
|
||||
};
|
||||
for (const [option, settings, error] of [
|
||||
['alterId=1', { aead: false }, 'VMess gRPC requires AEAD'],
|
||||
['alpn="h2,h3"', { alpn: ['h2', 'h3'] }, 'alpn must be h2'],
|
||||
[
|
||||
'grpc-mode=other',
|
||||
{ 'grpc-opts': { '_grpc-type': 'other' } },
|
||||
'grpc-mode must be gun or multi',
|
||||
],
|
||||
[
|
||||
'public-key=key,sni=sni.example.com,over-tls=false',
|
||||
{
|
||||
'reality-opts': { 'public-key': 'key' },
|
||||
sni: 'sni.example.com',
|
||||
tls: false,
|
||||
},
|
||||
'gRPC REALITY requires a public-key, sni and TLS',
|
||||
],
|
||||
...[0, 17, 1.5].map((maxStreams) => [
|
||||
`grpc-mux-max-streams=${maxStreams}`,
|
||||
{ _loon_grpc_mux_max_streams: maxStreams },
|
||||
'grpc-mux-max-streams must be 1–16',
|
||||
]),
|
||||
]) {
|
||||
const parsed = captureErrors(() =>
|
||||
ProxyUtils.parse(`${input},${option}`),
|
||||
);
|
||||
expect(parsed.result, option).to.be.empty;
|
||||
const { result, errors } = captureErrors(() =>
|
||||
produceInternal('Loon', { ...proxy, ...settings }),
|
||||
);
|
||||
expect(result, option).to.be.empty;
|
||||
expect(errors[0]).to.include(error);
|
||||
}
|
||||
});
|
||||
|
||||
it('round-trips Loon XHTTP for VLESS, VMess AEAD, and Trojan', function () {
|
||||
const input = [
|
||||
`VLESS=vless,example.com,80,"${UUID}",transport=xhttp,path="/xhttp?route=a,b",host=cdn.example.com,over-tls=false,alpn=http/1.1,xhttp-mode=packet-up,xhttp-max-post-bytes=0,xhttp-min-post-interval-ms=30-60,xhttp-padding-obfs-mode=false,xhttp-session-id-table=Base62,xhttp-session-id-length=16-32,xhttp-header="X-Trace: a, b",xhttp-header="X-Origin: https://example.org",udp=true`,
|
||||
|
||||
Reference in new issue
Block a user