Skip to content

Commit 37fc7ac

Browse files
committed
feat: VMess 支持 kcp/quic(正确处理 type, host, path, fp, alpn, tls等参数)
1 parent 9e00282 commit 37fc7ac

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.19.52",
3+
"version": "2.19.54",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/core/proxy-utils/parsers/index.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,16 @@ function URI_VMess() {
439439
type: 'vmess',
440440
server,
441441
port,
442-
cipher: getIfPresent(params.scy, 'auto'),
442+
// https://github.com/2dust/v2rayN/wiki/Description-of-VMess-share-link
443+
// https://github.com/XTLS/Xray-core/issues/91
444+
cipher: [
445+
'auto',
446+
'aes-128-gcm',
447+
'chacha20-poly1305',
448+
'none',
449+
].includes(params.scy)
450+
? params.scy
451+
: 'auto',
443452
uuid: params.id,
444453
alterId: parseInt(
445454
getIfPresent(params.aid ?? params.alterId, 0),
@@ -473,8 +482,8 @@ function URI_VMess() {
473482
['http'].includes(params.type)
474483
) {
475484
proxy.network = 'http';
476-
} else if (['grpc'].includes(params.net)) {
477-
proxy.network = 'grpc';
485+
} else if (['grpc', 'kcp', 'quic'].includes(params.net)) {
486+
proxy.network = params.net;
478487
} else if (
479488
params.net === 'httpupgrade' ||
480489
proxy.network === 'httpupgrade'
@@ -524,13 +533,28 @@ function URI_VMess() {
524533
}
525534
}
526535
// 传输层应该有配置, 暂时不考虑兼容不给配置的节点
527-
if (transportPath || transportHost) {
536+
if (
537+
transportPath ||
538+
transportHost ||
539+
['kcp', 'quic'].includes(proxy.network)
540+
) {
528541
if (['grpc'].includes(proxy.network)) {
529542
proxy[`${proxy.network}-opts`] = {
530543
'grpc-service-name': getIfNotBlank(transportPath),
531544
'_grpc-type': getIfNotBlank(params.type),
532545
'_grpc-authority': getIfNotBlank(params.authority),
533546
};
547+
} else if (['kcp', 'quic'].includes(proxy.network)) {
548+
proxy[`${proxy.network}-opts`] = {
549+
[`_${proxy.network}-type`]: getIfNotBlank(
550+
params.type,
551+
),
552+
[`_${proxy.network}-host`]: getIfNotBlank(
553+
getIfNotBlank(transportHost),
554+
),
555+
[`_${proxy.network}-path`]:
556+
getIfNotBlank(transportPath),
557+
};
534558
} else {
535559
const opts = {
536560
path: getIfNotBlank(transportPath),
@@ -546,6 +570,12 @@ function URI_VMess() {
546570
delete proxy.network;
547571
}
548572
}
573+
574+
proxy['client-fingerprint'] = params.fp;
575+
proxy.alpn = params.alpn ? params.alpn.split(',') : undefined;
576+
// 然而 wiki 和 app 实测中都没有字段表示这个
577+
// proxy['skip-cert-verify'] = /(TRUE)|1/i.test(params.allowInsecure);
578+
549579
return proxy;
550580
}
551581
};

backend/src/core/proxy-utils/producers/uri.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,17 @@ export default function URI_Producer() {
119119
v: '2',
120120
ps: proxy.name,
121121
add: proxy.server,
122-
port: proxy.port,
122+
port: `${proxy.port}`,
123123
id: proxy.uuid,
124-
type,
125-
aid: proxy.alterId || 0,
124+
aid: `${proxy.alterId || 0}`,
125+
scy: proxy.cipher,
126126
net,
127+
type,
127128
tls: proxy.tls ? 'tls' : '',
129+
alpn: Array.isArray(proxy.alpn)
130+
? proxy.alpn.join(',')
131+
: proxy.alpn,
132+
fp: proxy['client-fingerprint'],
128133
};
129134
if (proxy.tls && proxy.sni) {
130135
result.sni = proxy.sni;
@@ -135,16 +140,7 @@ export default function URI_Producer() {
135140
proxy[`${proxy.network}-opts`]?.path;
136141
let vmessTransportHost =
137142
proxy[`${proxy.network}-opts`]?.headers?.Host;
138-
if (vmessTransportPath) {
139-
result.path = Array.isArray(vmessTransportPath)
140-
? vmessTransportPath[0]
141-
: vmessTransportPath;
142-
}
143-
if (vmessTransportHost) {
144-
result.host = Array.isArray(vmessTransportHost)
145-
? vmessTransportHost[0]
146-
: vmessTransportHost;
147-
}
143+
148144
if (['grpc'].includes(proxy.network)) {
149145
result.path =
150146
proxy[`${proxy.network}-opts`]?.[
@@ -156,6 +152,31 @@ export default function URI_Producer() {
156152
'gun';
157153
result.host =
158154
proxy[`${proxy.network}-opts`]?.['_grpc-authority'];
155+
} else if (['kcp', 'quic'].includes(proxy.network)) {
156+
// https://github.com/XTLS/Xray-core/issues/91
157+
result.type =
158+
proxy[`${proxy.network}-opts`]?.[
159+
`_${proxy.network}-type`
160+
] || 'none';
161+
result.host =
162+
proxy[`${proxy.network}-opts`]?.[
163+
`_${proxy.network}-host`
164+
];
165+
result.path =
166+
proxy[`${proxy.network}-opts`]?.[
167+
`_${proxy.network}-path`
168+
];
169+
} else {
170+
if (vmessTransportPath) {
171+
result.path = Array.isArray(vmessTransportPath)
172+
? vmessTransportPath[0]
173+
: vmessTransportPath;
174+
}
175+
if (vmessTransportHost) {
176+
result.host = Array.isArray(vmessTransportHost)
177+
? vmessTransportHost[0]
178+
: vmessTransportHost;
179+
}
159180
}
160181
}
161182
result = 'vmess://' + Base64.encode(JSON.stringify(result));

0 commit comments

Comments
 (0)