feat: Loon 支持 tls-profile; sing-box 支持 packet-encoding, global-padding, authenticated-length; 优化 packet-encoding 转换逻辑

This commit is contained in:
xream committed 2026-06-02 16:49:40 +08:00
1 parent 4cc11dd35a
commit 3078e159c8
10 files changed
+577 -31

No files matched your search

+10
View File
@@ -801,6 +801,16 @@ function lastParse(proxy) {
if (['vless'].includes(proxy.type)) {
proxy.network = proxy.network || 'tcp';
}
if (
['vmess', 'vless'].includes(proxy.type) &&
proxy['packet-encoding'] == null
) {
if (proxy.xudp) {
proxy['packet-encoding'] = 'xudp';
} else if (proxy['packet-addr']) {
proxy['packet-encoding'] = 'packetaddr';
}
}
if (
[
'trojan',
@@ -855,8 +855,9 @@ function URI_VMess() {
const normalizedTransportHost =
getIfNotBlank(transportHost);
if (proxy.network === 'h2') {
const h2Hosts =
splitURIHostList(normalizedTransportHost);
const h2Hosts = splitURIHostList(
normalizedTransportHost,
);
if (h2Hosts) {
opts.host = h2Hosts;
}
@@ -1820,14 +1821,15 @@ function URI_VLESS() {
proxy['tls-fingerprint'] = getIfPresent(params.pcs);
proxy._h2 = /(TRUE)|1/i.test(params.h2);
switch (`${params.packetEncoding || ''}`.toLowerCase()) {
switch (`${params.packetEncoding || ''}`.trim().toLowerCase()) {
case 'none':
proxy['packet-encoding'] = '';
break;
case 'packet':
proxy['packet-addr'] = true;
proxy['packet-encoding'] = 'packetaddr';
break;
default:
proxy.xudp = true;
proxy['packet-encoding'] = 'xudp';
break;
}
@@ -54,35 +54,35 @@ shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs
$set(proxy, "plugin-opts.path", obfs.path);
}
}
vmess = tag equals "vmess"i address method uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/vmess_alterId/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* {
vmess = tag equals "vmess"i address method uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/vmess_alterId/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* {
proxy.type = "vmess";
proxy.cipher = proxy.cipher || "none";
proxy.alterId = proxy.alterId || 0;
handleTransport();
}
vless = tag equals "vless"i address uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/flow/public_key/short_id/block_quic/others)* {
vless = tag equals "vless"i address uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/fast_open/udp_relay/ip_mode/flow/public_key/short_id/block_quic/others)* {
proxy.type = "vless";
handleTransport();
}
trojan = tag equals "trojan"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
trojan = tag equals "trojan"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/fast_open/udp_relay/ip_mode/block_quic/others)* {
proxy.type = "trojan";
handleTransport();
}
anytls = tag equals "anytls"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/idle_session_check_interval/idle_session_timeout/min_idle_session/max_stream_count/others)* {
anytls = tag equals "anytls"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/fast_open/udp_relay/ip_mode/block_quic/idle_session_check_interval/idle_session_timeout/min_idle_session/max_stream_count/others)* {
proxy.type = "anytls";
handleTransport();
}
hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/udp_relay/fast_open/download_bandwidth/server_ports/hop_interval/salamander_password/ecn/ip_mode/block_quic/others)* {
hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/udp_relay/fast_open/download_bandwidth/server_ports/hop_interval/salamander_password/ecn/ip_mode/block_quic/others)* {
proxy.type = "hysteria2";
}
https = tag equals "https"i address (username password)? (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
https = tag equals "https"i address (username password)? (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/fast_open/udp_relay/ip_mode/block_quic/others)* {
proxy.type = "http";
proxy.tls = true;
}
http = tag equals "http"i address (username password)? (fast_open/udp_relay/ip_mode/block_quic/others)* {
proxy.type = "http";
}
socks5 = tag equals "socks5"i address (username password)? (over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
socks5 = tag equals "socks5"i address (username password)? (over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/fast_open/udp_relay/ip_mode/block_quic/others)* {
proxy.type = "socks5";
}
@@ -184,6 +184,7 @@ sni = comma "sni" equals match:[^,]+ { proxy.sni = match.join("").replace(/^"(.*
tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; }
tls_cert_sha256 = comma "tls-cert-sha256" equals match:[^,]+ { proxy["tls-fingerprint"] = match.join("").replace(/^"(.*)"$/, '$1'); }
tls_pubkey_sha256 = comma "tls-pubkey-sha256" equals match:[^,]+ { proxy["tls-pubkey-sha256"] = match.join("").replace(/^"(.*)"$/, '$1'); }
tls_profile = comma "tls-profile" equals match:[^,]+ { proxy["client-fingerprint"] = match.join("").replace(/^"(.*)"$/, '$1'); }
flow = comma "flow" equals match:[^,]+ { proxy["flow"] = match.join("").replace(/^"(.*)"$/, '$1'); }
public_key = comma "public-key" equals match:[^,]+ { proxy["reality-opts"] = proxy["reality-opts"] || {}; proxy["reality-opts"]["public-key"] = match.join("").replace(/^"(.*)"$/, '$1'); }
@@ -62,6 +62,15 @@ export default function Loon_Producer() {
return { produce };
}
function appendTlsProfile(result, proxy) {
if (
isPresent(proxy, 'client-fingerprint') &&
`${proxy['client-fingerprint']}`.trim() !== ''
) {
result.append(`,tls-profile=${proxy['client-fingerprint']}`);
}
}
function shadowsocks(proxy) {
const result = new Result(proxy);
if (
@@ -305,6 +314,7 @@ function trojan(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
appendTlsProfile(result, proxy);
// sni
result.appendIfPresent(`,tls-name=${proxy.sni}`, 'sni');
@@ -360,6 +370,7 @@ function anytls(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
appendTlsProfile(result, proxy);
// sni
result.appendIfPresent(`,tls-name=${proxy.sni}`, 'sni');
@@ -441,6 +452,9 @@ function vmess(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
if (proxy.tls || isReality) {
appendTlsProfile(result, proxy);
}
if (isReality) {
result.appendIfPresent(`,sni=${proxy.sni}`, 'sni');
@@ -551,6 +565,9 @@ function vless(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
if (proxy.tls || isReality || isXtls) {
appendTlsProfile(result, proxy);
}
if (isXtls) {
result.appendIfPresent(`,flow=${proxy.flow}`, 'flow');
@@ -612,6 +629,9 @@ function http(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
if (proxy.tls) {
appendTlsProfile(result, proxy);
}
// tfo
result.appendIfPresent(`,tfo=${proxy.tfo}`, 'tfo');
@@ -645,6 +665,9 @@ function socks5(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
if (proxy.tls) {
appendTlsProfile(result, proxy);
}
// tfo
result.appendIfPresent(`,tfo=${proxy.tfo}`, 'tfo');
@@ -774,6 +797,7 @@ function hysteria2(proxy) {
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
appendTlsProfile(result, proxy);
if (proxy['obfs-password'] && proxy.obfs == 'salamander') {
result.append(`,salamander-password=${proxy['obfs-password']}`);
@@ -727,6 +727,39 @@ const snellParser = (proxy = {}) => {
return parsedProxy;
};
const singBoxPacketEncodings = ['', 'packetaddr', 'xudp'];
const normalizeSingBoxPacketEncoding = (value) => {
const packetEncoding = `${value}`.trim().toLowerCase();
if (singBoxPacketEncodings.includes(packetEncoding)) {
return packetEncoding;
}
return undefined;
};
const vmessVlessPacketEncodingParser = (proxy, parsedProxy) => {
if (proxy['packet-encoding'] != null) {
const packetEncoding = normalizeSingBoxPacketEncoding(
proxy['packet-encoding'],
);
if (packetEncoding != null) parsedProxy.packet_encoding = packetEncoding;
} else if (proxy.xudp) {
parsedProxy.packet_encoding = 'xudp';
} else if (proxy['packet-addr']) {
parsedProxy.packet_encoding = 'packetaddr';
}
};
const vmessProtocolOptionsParser = (proxy, parsedProxy) => {
vmessVlessPacketEncodingParser(proxy, parsedProxy);
if (proxy['global-padding'] != null) {
parsedProxy.global_padding = !!proxy['global-padding'];
}
if (proxy['authenticated-length'] != null) {
parsedProxy.authenticated_length = !!proxy['authenticated-length'];
}
};
const vmessParser = (proxy = {}) => {
const parsedProxy = {
tag: proxy.name,
@@ -751,7 +784,7 @@ const vmessParser = (proxy = {}) => {
parsedProxy.security = 'auto';
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
throw 'invalid port';
if (proxy.xudp) parsedProxy.packet_encoding = 'xudp';
vmessProtocolOptionsParser(proxy, parsedProxy);
if (proxy['fast-open']) parsedProxy.udp_fragment = true;
if (proxy.network === 'ws') wsParser(proxy, parsedProxy);
if (proxy.network === 'h2') h2Parser(proxy, parsedProxy);
@@ -778,7 +811,7 @@ const vlessParser = (proxy = {}) => {
};
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
throw 'invalid port';
if (proxy.xudp) parsedProxy.packet_encoding = 'xudp';
vmessVlessPacketEncodingParser(proxy, parsedProxy);
if (proxy['fast-open']) parsedProxy.udp_fragment = true;
// if (['xtls-rprx-vision', ''].includes(proxy.flow)) parsedProxy.flow = proxy.flow;
if (proxy.flow != null) parsedProxy.flow = proxy.flow;
+25 -11
View File
@@ -134,13 +134,9 @@ function getTransportHost(network, transportOpts = {}) {
function normalizeVmessSecurity(security) {
if (
security &&
![
'aes-128-gcm',
'chacha20-poly1305',
'auto',
'none',
'zero',
].includes(security)
!['aes-128-gcm', 'chacha20-poly1305', 'auto', 'none', 'zero'].includes(
security,
)
) {
return 'auto';
}
@@ -749,10 +745,28 @@ function vless(proxy) {
}
let packetEncoding = '';
if (proxy['packet-addr']) {
packetEncoding = '&packetEncoding=packet';
} else if (proxy.udp === true && !proxy.xudp) {
packetEncoding = '&packetEncoding=none';
let canonicalPacketEncoding;
if (proxy['packet-encoding'] != null) {
canonicalPacketEncoding = `${proxy['packet-encoding']}`
.trim()
.toLowerCase();
} else if (proxy.xudp) {
canonicalPacketEncoding = 'xudp';
} else if (proxy['packet-addr']) {
canonicalPacketEncoding = 'packetaddr';
} else if (proxy.udp === true) {
canonicalPacketEncoding = '';
}
switch (canonicalPacketEncoding) {
case '':
packetEncoding = '&packetEncoding=none';
break;
case 'packetaddr':
packetEncoding = '&packetEncoding=packet';
break;
case 'xudp':
packetEncoding = '&packetEncoding=xudp';
break;
}
return `vless://${proxy.uuid}@${proxy.server}:${
@@ -202,6 +202,26 @@ FINAL,DIRECT
}
});
it('prefers xudp over packet-addr when normalizing legacy packet fields', function () {
const proxy = parseOne(
JSON.stringify({
name: 'vless-legacy-packet-conflict',
type: 'vless',
server: 'vless.example.com',
port: 443,
uuid: UUID,
xudp: true,
'packet-addr': true,
}),
);
expectSubset(proxy, {
type: 'vless',
name: 'vless-legacy-packet-conflict',
'packet-encoding': 'xudp',
});
});
it('accepts every Clash-supported proxy type as inline objects', function () {
const supportedTypes = [
'tailscale',
@@ -437,7 +437,7 @@ describe('VMess and VLESS parser coverage', function () {
'client-fingerprint': 'chrome',
alpn: ['h2'],
udp: true,
xudp: true,
'packet-encoding': 'xudp',
network: 'ws',
'ws-opts': {
path: '/ws',
@@ -465,7 +465,7 @@ describe('VMess and VLESS parser coverage', function () {
'client-fingerprint': 'chrome',
alpn: ['h2'],
udp: true,
xudp: true,
'packet-encoding': 'xudp',
network: 'ws',
'ws-opts': {
path: '/ws',
@@ -489,7 +489,7 @@ describe('VMess and VLESS parser coverage', function () {
uuid: UUID,
tls: true,
udp: true,
'packet-addr': true,
'packet-encoding': 'packetaddr',
network: 'ws',
'ws-opts': {
path: '/ws',
@@ -501,6 +501,31 @@ describe('VMess and VLESS parser coverage', function () {
},
});
expect(proxy).to.not.have.property('xudp');
expect(proxy).to.not.have.property('packet-addr');
});
it('parses websocket VLESS shares with xudp packet encoding', function () {
const proxy = parseOne(
`vless://${UUID}@vless-xudp.example.com:443?type=ws&security=tls&host=cdn.example.com&path=%2Fws&packetEncoding=xudp#VLESS%20WS%20XUDP`,
);
expectSubset(proxy, {
type: 'vless',
name: 'VLESS WS XUDP',
server: 'vless-xudp.example.com',
port: 443,
uuid: UUID,
tls: true,
udp: true,
'packet-encoding': 'xudp',
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'cdn.example.com',
},
},
});
});
it('parses websocket VLESS shares with pcs as tls fingerprint', function () {
@@ -516,7 +541,7 @@ describe('VMess and VLESS parser coverage', function () {
uuid: UUID,
tls: true,
udp: true,
xudp: true,
'packet-encoding': 'xudp',
'tls-fingerprint': 'fingerprint',
network: 'ws',
'ws-opts': {
@@ -838,6 +863,7 @@ describe('VMess and VLESS parser coverage', function () {
server: 'vless-h2.example.com',
port: 443,
udp: true,
'packet-encoding': '',
network: 'h2',
_h2: true,
'h2-opts': {
@@ -2658,7 +2684,7 @@ describe('Platform raw-format parser coverage', function () {
},
{
title: 'parses vmess http tls lines',
input: `Loon VMess=vmess,loon-vmess.example.com,443,auto,"${UUID}",transport=http,host=cdn.example.com,path=/http,over-tls=true,tls-name=sni.example.com,skip-cert-verify=true,alterId=0`,
input: `Loon VMess=vmess,loon-vmess.example.com,443,auto,"${UUID}",transport=http,host=cdn.example.com,path=/http,over-tls=true,tls-name=sni.example.com,skip-cert-verify=true,tls-profile=chrome,alterId=0`,
expected: {
type: 'vmess',
name: 'Loon VMess',
@@ -2670,6 +2696,7 @@ describe('Platform raw-format parser coverage', function () {
tls: true,
sni: 'sni.example.com',
'skip-cert-verify': true,
'client-fingerprint': 'chrome',
network: 'http',
'http-opts': {
path: ['/http'],
@@ -3671,6 +3671,229 @@ describe('Proxy structured producers', function () {
});
});
it('emits sing-box VMess and VLESS packet protocol options', function () {
const output = loadProducedJson('sing-box', [
{
type: 'vmess',
name: 'VMess Packet Options',
server: 'vmess-packet.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
'packet-encoding': 'packetaddr',
'global-padding': true,
'authenticated-length': false,
},
{
type: 'vless',
name: 'VLESS Packet Options',
server: 'vless-packet.example.com',
port: 443,
uuid: UUID,
'packet-encoding': 'packetaddr',
'global-padding': true,
'authenticated-length': false,
},
{
type: 'vmess',
name: 'VMess XUDP Packet Options',
server: 'vmess-xudp-packet.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
'packet-encoding': ' XUDP ',
'global-padding': false,
'authenticated-length': true,
},
{
type: 'vless',
name: 'VLESS XUDP Packet Options',
server: 'vless-xudp-packet.example.com',
port: 443,
uuid: UUID,
'packet-encoding': 'xudp',
'global-padding': false,
'authenticated-length': true,
},
{
type: 'vmess',
name: 'VMess Invalid Packet Encoding',
server: 'vmess-invalid-packet.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
xudp: true,
'packet-encoding': 'invalid',
'global-padding': 'yes',
'authenticated-length': 1,
},
{
type: 'vless',
name: 'VLESS Invalid Packet Encoding',
server: 'vless-invalid-packet.example.com',
port: 443,
uuid: UUID,
xudp: true,
'packet-encoding': 'invalid',
'global-padding': 'yes',
'authenticated-length': 1,
},
{
type: 'vmess',
name: 'VMess Empty Packet',
server: 'vmess-empty.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
xudp: true,
'packet-encoding': '',
},
{
type: 'vless',
name: 'VLESS Empty Packet',
server: 'vless-empty.example.com',
port: 443,
uuid: UUID,
xudp: true,
'packet-encoding': '',
},
{
type: 'vmess',
name: 'VMess Legacy XUDP',
server: 'vmess-xudp.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
xudp: true,
},
{
type: 'vless',
name: 'VLESS Legacy XUDP',
server: 'vless-xudp.example.com',
port: 443,
uuid: UUID,
xudp: true,
},
{
type: 'vmess',
name: 'VMess Legacy Packet Addr',
server: 'vmess-packet-addr.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
'packet-addr': true,
},
{
type: 'vless',
name: 'VLESS Legacy Packet Addr',
server: 'vless-packet-addr.example.com',
port: 443,
uuid: UUID,
'packet-addr': true,
},
{
type: 'vmess',
name: 'VMess Legacy XUDP Packet Addr',
server: 'vmess-xudp-packet-addr.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
alterId: 0,
xudp: true,
'packet-addr': true,
},
{
type: 'vless',
name: 'VLESS Legacy XUDP Packet Addr',
server: 'vless-xudp-packet-addr.example.com',
port: 443,
uuid: UUID,
xudp: true,
'packet-addr': true,
},
]);
const findOutbound = (tag) =>
output.outbounds.find((item) => item.tag === tag);
expectSubset(findOutbound('VMess Packet Options'), {
packet_encoding: 'packetaddr',
global_padding: true,
authenticated_length: false,
});
expectSubset(findOutbound('VLESS Packet Options'), {
packet_encoding: 'packetaddr',
});
expect(findOutbound('VLESS Packet Options')).to.not.have.property(
'global_padding',
);
expect(findOutbound('VLESS Packet Options')).to.not.have.property(
'authenticated_length',
);
expectSubset(findOutbound('VMess XUDP Packet Options'), {
packet_encoding: 'xudp',
global_padding: false,
authenticated_length: true,
});
expectSubset(findOutbound('VLESS XUDP Packet Options'), {
packet_encoding: 'xudp',
});
expect(findOutbound('VLESS XUDP Packet Options')).to.not.have.property(
'global_padding',
);
expect(findOutbound('VLESS XUDP Packet Options')).to.not.have.property(
'authenticated_length',
);
for (const tag of ['VMess Empty Packet', 'VLESS Empty Packet']) {
expectSubset(findOutbound(tag), {
packet_encoding: '',
});
expect(findOutbound(tag)).to.not.have.property('global_padding');
expect(findOutbound(tag)).to.not.have.property(
'authenticated_length',
);
}
expect(
findOutbound('VMess Invalid Packet Encoding'),
).to.not.have.property('packet_encoding');
expectSubset(findOutbound('VMess Invalid Packet Encoding'), {
global_padding: true,
authenticated_length: true,
});
expect(
findOutbound('VLESS Invalid Packet Encoding'),
).to.not.have.property('packet_encoding');
expect(
findOutbound('VLESS Invalid Packet Encoding'),
).to.not.have.property('global_padding');
expect(
findOutbound('VLESS Invalid Packet Encoding'),
).to.not.have.property('authenticated_length');
expectSubset(findOutbound('VMess Legacy XUDP'), {
packet_encoding: 'xudp',
});
expectSubset(findOutbound('VLESS Legacy XUDP'), {
packet_encoding: 'xudp',
});
expectSubset(findOutbound('VMess Legacy Packet Addr'), {
packet_encoding: 'packetaddr',
});
expectSubset(findOutbound('VLESS Legacy Packet Addr'), {
packet_encoding: 'packetaddr',
});
expectSubset(findOutbound('VMess Legacy XUDP Packet Addr'), {
packet_encoding: 'xudp',
});
expectSubset(findOutbound('VLESS Legacy XUDP Packet Addr'), {
packet_encoding: 'xudp',
});
});
it('emits sing-box httpupgrade transport without websocket early data fields', function () {
const output = loadProducedJson('sing-box', {
type: 'vless',
+193 -1
View File
@@ -433,6 +433,147 @@ describe('Proxy text producers', function () {
);
});
it('emits Loon tls-profile for TLS protocol outputs', function () {
const output = produceExternal('Loon', [
{
type: 'vmess',
name: 'Loon VMess TLS',
server: 'vmess.example.com',
port: 443,
cipher: 'auto',
uuid: UUID,
alterId: 0,
tls: true,
sni: 'sni.example.com',
'client-fingerprint': 'chrome',
},
{
type: 'vless',
name: 'Loon VLESS TLS',
server: 'vless.example.com',
port: 443,
uuid: UUID,
tls: true,
sni: 'sni.example.com',
'client-fingerprint': 'chrome',
},
{
type: 'vless',
name: 'Loon VLESS Reality',
server: 'vless-reality.example.com',
port: 443,
uuid: UUID,
tls: true,
sni: 'sni.example.com',
flow: 'xtls-rprx-vision',
'reality-opts': {
'public-key': 'pubkey',
'short-id': '08',
},
'client-fingerprint': 'chrome',
},
{
type: 'vless',
name: 'Loon VLESS XTLS',
server: 'vless-xtls.example.com',
port: 443,
uuid: UUID,
flow: 'xtls-rprx-vision',
sni: 'sni.example.com',
'client-fingerprint': 'chrome',
},
{
type: 'trojan',
name: 'Loon Trojan TLS',
server: 'trojan.example.com',
port: 443,
password: 'secret',
'client-fingerprint': 'chrome',
},
{
type: 'anytls',
name: 'Loon AnyTLS Profile',
server: 'anytls.example.com',
port: 443,
password: 'secret',
'client-fingerprint': 'chrome',
},
{
type: 'http',
name: 'Loon HTTPS Profile',
server: 'https.example.com',
port: 443,
tls: true,
'client-fingerprint': 'chrome',
},
{
type: 'socks5',
name: 'Loon SOCKS TLS',
server: 'socks.example.com',
port: 1080,
tls: true,
'client-fingerprint': 'chrome',
},
{
type: 'hysteria2',
name: 'Loon Hysteria2 Profile',
server: 'hy2.example.com',
port: 443,
password: 'secret',
'client-fingerprint': 'chrome',
},
]);
expect(output.match(/tls-profile=chrome/g)).to.have.length(9);
});
it('omits Loon tls-profile for non-TLS outputs and empty fingerprints', function () {
const output = produceExternal('Loon', [
{
type: 'http',
name: 'Loon HTTP Plain',
server: 'http.example.com',
port: 80,
'client-fingerprint': 'chrome',
},
{
type: 'socks5',
name: 'Loon SOCKS Plain',
server: 'socks.example.com',
port: 1080,
'client-fingerprint': 'chrome',
},
{
type: 'vmess',
name: 'Loon VMess Plain',
server: 'vmess.example.com',
port: 80,
cipher: 'auto',
uuid: UUID,
alterId: 0,
'client-fingerprint': 'chrome',
},
{
type: 'vless',
name: 'Loon VLESS Plain',
server: 'vless.example.com',
port: 80,
uuid: UUID,
'client-fingerprint': 'chrome',
},
{
type: 'trojan',
name: 'Loon Trojan Empty Profile',
server: 'trojan-empty.example.com',
port: 443,
password: 'secret',
'client-fingerprint': '',
},
]);
expect(output).to.not.include('tls-profile=');
});
it('produces Loon Hysteria2 lines with port hopping', function () {
const output = produceExternal('Loon', {
type: 'hysteria2',
@@ -1487,7 +1628,7 @@ describe('Proxy text producers', function () {
tls: true,
sni: 'sni.example.com',
udp: true,
'packet-addr': true,
'packet-encoding': 'packetaddr',
network: 'ws',
'ws-opts': {
path: '/ws',
@@ -1504,6 +1645,55 @@ describe('Proxy text producers', function () {
);
});
it('produces URI VLESS websocket links with xudp packet encoding', function () {
const output = produceExternal('URI', {
type: 'vless',
name: 'URI WS XUDP',
server: 'vless-xudp.example.com',
port: 443,
uuid: UUID,
tls: true,
udp: true,
'packet-encoding': 'xudp',
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'cdn.example.com',
},
},
});
expect(output).to.equal(
`vless://${UUID}@vless-xudp.example.com:443?security=tls&type=ws&path=%2Fws&host=cdn.example.com&packetEncoding=xudp#URI%20WS%20XUDP`,
);
});
it('prefers legacy xudp over legacy packet addr for URI VLESS links', function () {
const output = produceExternal('URI', {
type: 'vless',
name: 'URI WS Legacy XUDP',
server: 'vless-legacy-xudp.example.com',
port: 443,
uuid: UUID,
tls: true,
udp: true,
xudp: true,
'packet-addr': true,
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'cdn.example.com',
},
},
});
expect(output).to.equal(
`vless://${UUID}@vless-legacy-xudp.example.com:443?security=tls&type=ws&path=%2Fws&host=cdn.example.com&packetEncoding=xudp#URI%20WS%20Legacy%20XUDP`,
);
});
it('replaces stale URI VLESS websocket path early data with max-early-data', function () {
const output = produceExternal('URI', {
type: 'vless',
@@ -1708,6 +1898,7 @@ describe('Proxy text producers', function () {
uuid: UUID,
network: 'http',
udp: true,
'packet-encoding': '',
'http-opts': {
path: ['/edge'],
method: 'GET',
@@ -2044,6 +2235,7 @@ describe('Proxy text producers', function () {
uuid: UUID,
tls: true,
udp: true,
'packet-encoding': '',
network: 'h2',
_h2: true,
'h2-opts': {