feat: 完善 VLESS/Trojan URI 与 mihomo 转换

This commit is contained in:
xream committed 2026-04-10 13:48:51 +08:00
1 parent d6b0791440
commit bdd5635abc
7 files changed
+107 -5

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.21.84",
"version": "2.21.85",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
@@ -868,7 +868,7 @@ function URI_VLESS() {
proxy.alpn = params.alpn ? params.alpn.split(',') : undefined;
proxy['skip-cert-verify'] = /(TRUE)|1/i.test(params.allowInsecure);
proxy._echConfigList = getIfPresent(params.ech);
proxy._pcs = getIfPresent(params.pcs);
proxy['tls-fingerprint'] = getIfPresent(params.pcs);
proxy._h2 = /(TRUE)|1/i.test(params.h2);
switch (`${params.packetEncoding || ''}`.toLowerCase()) {
@@ -86,6 +86,7 @@ params = "?" head:param tail:("&"@param)* {
proxy["skip-cert-verify"] = toBool(params["allowInsecure"]);
proxy.sni = params["sni"] || params["peer"];
proxy['client-fingerprint'] = params.fp;
proxy['tls-fingerprint'] = params.pcs;
proxy.alpn = params.alpn ? decodeURIComponent(params.alpn).split(',') : undefined;
if (toBool(params["ws"])) {
@@ -194,8 +194,8 @@ function vless(proxy) {
h2 = `&h2=1`;
}
let pcs = '';
if (proxy._pcs) {
pcs = `&pcs=${encodeURIComponent(proxy._pcs)}`;
if (proxy['tls-fingerprint']) {
pcs = `&pcs=${encodeURIComponent(proxy['tls-fingerprint'])}`;
}
let ech = '';
if (proxy._echConfigList) {
@@ -697,6 +697,12 @@ export default function URI_Producer() {
proxy['client-fingerprint'],
)}`;
}
let trojanPcs = '';
if (proxy['tls-fingerprint']) {
trojanPcs = `&pcs=${encodeURIComponent(
proxy['tls-fingerprint'],
)}`;
}
let trojanAlpn = '';
if (proxy.alpn) {
trojanAlpn = `&alpn=${encodeURIComponent(
@@ -739,7 +745,7 @@ export default function URI_Producer() {
proxy.port
}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${
proxy['skip-cert-verify'] ? '&allowInsecure=1' : ''
}${trojanTransport}${trojanAlpn}${trojanFp}${trojanSecurity}${trojanSid}${trojanPbk}${trojanSpx}${trojanMode}${trojanExtra}#${encodeURIComponent(
}${trojanTransport}${trojanAlpn}${trojanFp}${trojanPcs}${trojanSecurity}${trojanSid}${trojanPbk}${trojanSpx}${trojanMode}${trojanExtra}#${encodeURIComponent(
proxy.name,
)}`;
break;
@@ -367,6 +367,28 @@ describe('Proxy URI parser coverage', function () {
});
});
it('parses Trojan URIs with pcs as tls fingerprint', function () {
const proxy = parseOne(
'trojan://trojan-pass@trojan-ws.example.com?type=ws&host=ws.example.com&path=%2Fws&pcs=fingerprint#Trojan%20WS%20PCS',
);
expectSubset(proxy, {
type: 'trojan',
name: 'Trojan WS PCS',
server: 'trojan-ws.example.com',
port: 443,
password: 'trojan-pass',
'tls-fingerprint': 'fingerprint',
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'ws.example.com',
},
},
});
});
it('parses Trojan URIs with grpc reality metadata', function () {
const proxy = parseOne(
'trojan://trojan-pass@trojan-grpc.example.com?type=grpc&serviceName=grpc-service&authority=grpc.example.com&mode=multi&security=reality&pbk=pubkey&sid=08&spx=%2Fspider&udp=1&tfo=1#Trojan%20Reality',
@@ -284,6 +284,31 @@ describe('VMess and VLESS parser coverage', function () {
expect(proxy).to.not.have.property('xudp');
});
it('parses websocket VLESS shares with pcs as tls fingerprint', function () {
const proxy = parseOne(
`vless://${UUID}@vless-ws.example.com:443?type=ws&security=tls&host=cdn.example.com&path=%2Fws&pcs=fingerprint#VLESS%20WS%20PCS`,
);
expectSubset(proxy, {
type: 'vless',
name: 'VLESS WS PCS',
server: 'vless-ws.example.com',
port: 443,
uuid: UUID,
tls: true,
udp: true,
xudp: true,
'tls-fingerprint': 'fingerprint',
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'cdn.example.com',
},
},
});
});
it('rejects websocket VLESS shares with malformed early data size', function () {
expect(
parseAll(
@@ -475,6 +475,30 @@ describe('Proxy text producers', function () {
);
});
it('produces URI VLESS websocket links with pcs from tls fingerprint', function () {
const output = produceExternal('URI', {
type: 'vless',
name: 'URI WS PCS',
server: 'vless.example.com',
port: 443,
uuid: UUID,
tls: true,
sni: 'sni.example.com',
'tls-fingerprint': 'fingerprint',
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'cdn.example.com',
},
},
});
expect(output).to.equal(
`vless://${UUID}@vless.example.com:443?security=tls&type=ws&path=%2Fws&host=cdn.example.com&pcs=fingerprint&sni=sni.example.com#URI%20WS%20PCS`,
);
});
it('produces URI VLESS fake-http links with method and headerType', function () {
const output = produceExternal('URI', {
type: 'vless',
@@ -687,6 +711,30 @@ describe('Proxy text producers', function () {
);
});
it('produces URI Trojan websocket links with pcs from tls fingerprint', function () {
const output = produceExternal('URI', {
type: 'trojan',
name: 'URI Trojan PCS',
server: 'trojan.example.com',
port: 443,
password: 'secret',
tls: true,
sni: 'sni.example.com',
'tls-fingerprint': 'fingerprint',
network: 'ws',
'ws-opts': {
path: '/ws',
headers: {
Host: 'cdn.example.com',
},
},
});
expect(output).to.equal(
'trojan://secret@trojan.example.com:443?sni=sni.example.com&type=ws&path=%2Fws&host=cdn.example.com&pcs=fingerprint#URI%20Trojan%20PCS',
);
});
it('produces V2Ray exports as base64 encoded URI lists', function () {
const output = produceExternal('V2Ray', {
type: 'vless',