diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 6b03be54..9f972ab2 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -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', diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index e2a42249..4905b985 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -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; } diff --git a/backend/src/core/proxy-utils/parsers/peggy/loon.js b/backend/src/core/proxy-utils/parsers/peggy/loon.js index 52612ec7..dc5c5e3a 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/loon.js +++ b/backend/src/core/proxy-utils/parsers/peggy/loon.js @@ -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'); } diff --git a/backend/src/core/proxy-utils/producers/loon.js b/backend/src/core/proxy-utils/producers/loon.js index 7dc3f735..20db49a1 100644 --- a/backend/src/core/proxy-utils/producers/loon.js +++ b/backend/src/core/proxy-utils/producers/loon.js @@ -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']}`); diff --git a/backend/src/core/proxy-utils/producers/sing-box.js b/backend/src/core/proxy-utils/producers/sing-box.js index 2c52116f..1d79f5e2 100644 --- a/backend/src/core/proxy-utils/producers/sing-box.js +++ b/backend/src/core/proxy-utils/producers/sing-box.js @@ -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; diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index ea41ccaa..fd75770a 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -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}:${ diff --git a/backend/src/test/proxy-parsers/pipeline.spec.js b/backend/src/test/proxy-parsers/pipeline.spec.js index 2039ac3d..4509aa0d 100644 --- a/backend/src/test/proxy-parsers/pipeline.spec.js +++ b/backend/src/test/proxy-parsers/pipeline.spec.js @@ -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', diff --git a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js index e18b939d..08cd61a4 100644 --- a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js +++ b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js @@ -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'], diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 00476eb3..6672b42b 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -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', diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 1aade626..0fbe9bb9 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -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': {