feat: VLESS/VMess URI 中支持使用 support-x25519mlkem768 设置 mihomo 参数

This commit is contained in:
xream committed 2026-09-10 22:08:21 +08:00
1 parent fb3088d9e0
commit 5d7126e9f3
5 files changed
+211 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.39.1",
"version": "2.39.2",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
+18 -9
View File
@@ -620,6 +620,9 @@ function URI_VMess() {
return /^vmess:\/\//.test(line);
};
const parse = (line) => {
if (/^vmess:\/\/[^/?#]+@/.test(line)) {
return URI_VLESS().parse(line, 'vmess');
}
let { content: lineWithoutFragment, fragment: fragmentName } =
splitURIFragment(line.split('vmess://')[1]);
let content = Base64.decode(lineWithoutFragment.replace(/\?.*?$/, ''));
@@ -909,7 +912,7 @@ function URI_VLESS() {
const test = (line) => {
return /^vless:\/\//.test(line);
};
const parse = (line) => {
const parse = (line, protocol = 'vless') => {
const mapXmuxToReuseSettings = (xmux) => {
if (!isPlainObject(xmux)) {
return undefined;
@@ -1809,7 +1812,7 @@ function URI_VLESS() {
: undefined;
};
line = line.split('vless://')[1];
line = line.split(`${protocol}://`)[1];
let isShadowrocket;
let parsed = /^(.*?)@(.*?):(\d+)\/?(\?(.*?))?(?:#(.*?))?$/.exec(line);
if (!parsed) {
@@ -1832,7 +1835,7 @@ function URI_VLESS() {
}
const proxy = {
type: 'vless',
type: protocol,
name,
server,
port,
@@ -1842,10 +1845,8 @@ function URI_VLESS() {
const params = {};
for (const addon of addons.split('&')) {
if (addon) {
const [key, valueRaw] = addon.split('=');
let value = valueRaw;
value = decodeURIComponent(valueRaw);
params[key] = value;
const [key, ...value] = addon.split('=');
params[key] = decodeURIComponent(value.join('='));
}
}
@@ -1853,7 +1854,7 @@ function URI_VLESS() {
name ??
params.remarks ??
params.remark ??
`VLESS ${server}:${port}`;
`${protocol === 'vmess' ? 'VMess' : 'VLESS'} ${server}:${port}`;
proxy.tls = params.security && params.security !== 'none';
if (params.pbk) {
@@ -1908,6 +1909,10 @@ function URI_VLESS() {
const opts = {};
if (params.pbk) {
opts['public-key'] = params.pbk;
const mlkem = params['support-x25519mlkem768'];
if (['1', 't', 'T', 'true', 'TRUE', 'True'].includes(mlkem)) {
opts['support-x25519mlkem768'] = true;
}
}
if (params.sid) {
opts['short-id'] = params.sid;
@@ -2084,7 +2089,11 @@ function URI_VLESS() {
proxy._mode = params.mode;
}
}
if (params.encryption) {
if (protocol === 'vmess') {
proxy.cipher = normalizeVmessSecurity(params.encryption);
proxy.alterId = 0;
delete proxy.flow;
} else if (params.encryption) {
proxy.encryption = params.encryption;
}
if (params.pqv) {
@@ -566,6 +566,10 @@ function vless(proxy) {
const publicKey = proxy['reality-opts']?.['public-key'];
if (publicKey) {
pbk = `&pbk=${encodeURIComponent(publicKey)}`;
const mlkem = proxy['reality-opts']['support-x25519mlkem768'];
if (mlkem) {
pbk += `&support-x25519mlkem768=${encodeURIComponent(mlkem)}`;
}
}
const shortId = proxy['reality-opts']?.['short-id'];
if (shortId) {
@@ -1020,6 +1024,27 @@ export default function URI_Producer() {
result = 'ssr://' + Base64.encode(result);
break;
case 'vmess':
if (proxy['reality-opts']) {
if (
proxy.aead === false ||
(proxy.aead !== true &&
Number(proxy.alterId || 0) !== 0)
) {
throw new Error(
'VMess REALITY URI requires AEAD (alterId=0)',
);
}
result = vless({
...proxy,
server: isIPv6(proxy.server)
? `[${proxy.server}]`
: proxy.server,
network: proxy.network || 'tcp',
encryption: normalizeVmessSecurity(proxy.cipher),
flow: undefined,
}).replace(/^vless:\/\//, 'vmess://');
break;
}
// V2RayN URI format
let type = '';
let net = proxy.network || 'tcp';
@@ -5,7 +5,86 @@ import { describe, it } from 'mocha';
import { UUID, expectSubset, parseAll, parseOne } from './helpers';
describe('VMess and VLESS parser coverage', function () {
it('keeps only enabled REALITY ML-KEM values in VLESS and VMess AEAD subscriptions', function () {
const cases = [
...['1', 't', 'T', 'true', 'TRUE', 'True'].map((value) => [
value,
true,
]),
...['0', 'f', 'F', 'false', 'FALSE', 'False'].map((value) => [
value,
undefined,
]),
...[undefined, '', 'invalid', 'TrUe', 'true=bad', 'true%0A'].map(
(value) => [value, undefined],
),
];
for (const protocol of ['vless', 'vmess']) {
for (const [value, expected] of cases) {
for (const publicKey of ['pubkey', '']) {
const uri = `${protocol}://${UUID}@example.com:443?security=reality&type=tcp${
publicKey ? `&pbk=${publicKey}&sid=08` : ''
}${
value == null ? '' : `&support-x25519mlkem768=${value}`
}`;
for (const input of [uri, Base64.encode(uri)]) {
const proxy = parseOne(input);
expect(proxy.type).to.equal(protocol);
expect(proxy['reality-opts']).to.deep.equal(
publicKey
? {
'public-key': publicKey,
'short-id': '08',
...(expected == null
? {}
: {
'support-x25519mlkem768':
expected,
}),
}
: undefined,
);
if (protocol === 'vmess') {
expect(proxy.name).to.equal(
'VMess example.com:443',
);
expect(proxy.cipher).to.equal('auto');
expect(proxy.alterId).to.equal(0);
}
}
}
}
}
});
describe('VMess URIs', function () {
it('parses VMess AEAD encryption, TLS and gRPC transport fields', function () {
const proxy = parseOne(
`vmess://${UUID}@[2001:db8::1]:8443?encryption=aes-128-gcm&security=tls&sni=sni.example.com&type=grpc&serviceName=svc&authority=grpc.example.com&mode=multi&allowInsecure=1&flow=xtls-rprx-vision#AEAD%20%23%20test`,
);
expectSubset(proxy, {
type: 'vmess',
name: 'AEAD # test',
server: '2001:db8::1',
port: 8443,
uuid: UUID,
cipher: 'aes-128-gcm',
alterId: 0,
tls: true,
sni: 'sni.example.com',
'skip-cert-verify': true,
network: 'grpc',
'grpc-opts': {
'grpc-service-name': 'svc',
'_grpc-authority': 'grpc.example.com',
'_grpc-type': 'multi',
},
});
expect(proxy).not.to.have.property('encryption');
expect(proxy).not.to.have.property('flow');
});
it('parses Quantumult VMess shares', function () {
const share = Base64.encode(
`QX VMess = vmess,vmess-qx.example.com,443,auto,"${UUID}",udp-relay=true,fast-open=true,tls-verification=false`,
@@ -2673,6 +2673,94 @@ describe('Proxy text producers', function () {
);
});
it('round-trips REALITY ML-KEM through URI, V2Ray and Mihomo exports', function () {
const cases = [
[true, 'true', true],
[false, null],
['true', 'true', true],
['false', 'false'],
[1, '1', true],
[0, null],
['0', '0'],
[undefined, null],
[null, null],
['', null],
['true&pbk=other', 'true&pbk=other'],
];
for (const type of ['vless', 'vmess']) {
for (const [mlkem, queryValue, enabled] of cases) {
const proxy = {
type,
name: 'ML-KEM # test',
server: '2001:db8::1',
port: 443,
uuid: UUID,
tls: true,
network: 'tcp',
...(type === 'vmess'
? { cipher: 'aes-128-gcm', alterId: 0 }
: {}),
'reality-opts': {
'public-key': 'pubkey',
'short-id': '08',
'support-x25519mlkem768': mlkem,
},
};
const [mihomo] = ProxyUtils.parse(
produceExternal('Mihomo', proxy),
);
for (const platform of ['URI', 'V2Ray']) {
const output = produceExternal(platform, mihomo);
const uri =
platform === 'V2Ray' ? Base64.decode(output) : output;
expect(uri).to.include(
`${type}://${UUID}@[2001:db8::1]:443?security=reality`,
);
expect(
new URL(uri).searchParams.get('support-x25519mlkem768'),
).to.equal(queryValue);
const [reparsed] = ProxyUtils.parse(output);
expect(reparsed.name).to.equal(proxy.name);
expect(reparsed.server).to.equal(proxy.server);
expect(reparsed['reality-opts']).to.deep.equal({
'public-key': 'pubkey',
'short-id': '08',
...(enabled ? { 'support-x25519mlkem768': true } : {}),
});
if (type === 'vmess') {
expect(reparsed.cipher).to.equal('aes-128-gcm');
expect(reparsed.alterId).to.equal(0);
}
}
}
}
});
it('rejects non-AEAD VMess REALITY URI exports without changing authentication', function () {
for (const auth of [{ alterId: 64 }, { aead: false }]) {
const { result, errors } = captureErrors(() =>
ProxyUtils.produce(
[
{
type: 'vmess',
name: 'Legacy VMess REALITY',
server: 'example.com',
port: 443,
uuid: UUID,
'reality-opts': { 'public-key': 'pubkey' },
...auth,
},
],
'URI',
),
);
expect(result).to.equal('');
expect(errors.join('\n')).to.include(
'VMess REALITY URI requires AEAD',
);
}
});
it('produces URI VLESS reality websocket links', function () {
const output = produceExternal('URI', {
type: 'vless',