feat: 支持 TUIC v5 URI

This commit is contained in:
xream 2024-02-03 16:17:26 +08:00
parent d23bc7663e
commit 5d3fc499ce
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
5 changed files with 139 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.202",
"version": "2.14.203",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -545,6 +545,55 @@ function URI_Hysteria2() {
};
return { name, test, parse };
}
function URI_TUIC() {
const name = 'URI TUIC Parser';
const test = (line) => {
return /^tuic:\/\//.test(line);
};
const parse = (line) => {
line = line.split(/tuic:\/\//)[1];
console.log(line);
// eslint-disable-next-line no-unused-vars
let [__, uuid, password, server, ___, port, ____, addons = '', name] =
/^(.*?):(.*?)@(.*?)(:(\d+))?\/?(\?(.*?))?(?:#(.*?))?$/.exec(line);
port = parseInt(`${port}`, 10);
if (isNaN(port)) {
port = 443;
}
password = decodeURIComponent(password);
if (name != null) {
name = decodeURIComponent(name);
}
name = name ?? `TUIC ${server}:${port}`;
const proxy = {
type: 'tuic',
name,
server,
port,
password,
uuid,
};
for (const addon of addons.split('&')) {
let [key, value] = addon.split('=');
key = key.replace(/_/, '-');
value = decodeURIComponent(value);
if (['alpn'].includes(key)) {
proxy[key] = value ? value.split(',') : undefined;
} else if (['allow-insecure'].includes(key)) {
proxy['skip-cert-verify'] = /(TRUE)|1/i.test(value);
} else if (['disable-sni', 'reduce-rtt'].includes(key)) {
proxy[key] = /(TRUE)|1/i.test(value);
} else {
proxy[key] = value;
}
}
return proxy;
};
return { name, test, parse };
}
// Trojan URI format
function URI_Trojan() {
@ -1051,6 +1100,7 @@ export default [
URI_SSR(),
URI_VMess(),
URI_VLESS(),
URI_TUIC(),
URI_Hysteria2(),
URI_Trojan(),
Clash_All(),

View File

@ -93,6 +93,7 @@ function QuickSettingOperator(args) {
return proxies.map((proxy) => {
proxy.udp = get(args.udp, proxy.udp);
proxy.tfo = get(args.tfo, proxy.tfo);
proxy['fast-open'] = get(args.tfo, proxy['fast-open']);
proxy['skip-cert-verify'] = get(
args.scert,
proxy['skip-cert-verify'],

View File

@ -637,6 +637,35 @@ export default function singbox_Producer() {
}
break;
case 'ss':
// if (!proxy.cipher) {
// proxy.cipher = 'none';
// }
// if (
// ![
// '2022-blake3-aes-128-gcm',
// '2022-blake3-aes-256-gcm',
// '2022-blake3-chacha20-poly1305',
// 'aes-128-cfb',
// 'aes-128-ctr',
// 'aes-128-gcm',
// 'aes-192-cfb',
// 'aes-192-ctr',
// 'aes-192-gcm',
// 'aes-256-cfb',
// 'aes-256-ctr',
// 'aes-256-gcm',
// 'chacha20-ietf',
// 'chacha20-ietf-poly1305',
// 'none',
// 'rc4-md5',
// 'xchacha20',
// 'xchacha20-ietf-poly1305',
// ].includes(proxy.cipher)
// ) {
// throw new Error(
// `cipher ${proxy.cipher} is not supported`,
// );
// }
if (proxy.plugin === 'shadow-tls') {
const { ssPart, stPart } =
shadowTLSParser(proxy);

View File

@ -285,6 +285,64 @@ export default function URI_Producer() {
'&',
)}#${encodeURIComponent(proxy.name)}`;
break;
case 'tuic':
if (!proxy.token || proxy.token.length === 0) {
let tuicParams = [];
Object.keys(proxy).forEach((key) => {
if (
![
'name',
'type',
'uuid',
'password',
'server',
'port',
].includes(key)
) {
const i = key.replace(/-/, '_');
if (['alpn'].includes(key)) {
if (proxy[key]) {
tuicParams.push(
`${i}=${encodeURIComponent(
Array.isArray(proxy[key])
? proxy[key][0]
: proxy[key],
)}`,
);
}
} else if (['skip-cert-verify'].includes(key)) {
if (proxy[key]) {
tuicParams.push(`allow_insecure=1`);
}
} else if (['tfo', 'fast-open'].includes(key)) {
if (
proxy[key] &&
!tuicParams.includes('fast_open=1')
) {
tuicParams.push(`fast_open=1`);
}
} else if (
['disable-sni', 'reduce-rtt'].includes(key) &&
proxy[key]
) {
tuicParams.push(`${i}=1`);
} else if (proxy[key]) {
tuicParams.push(
`${i}=${encodeURIComponent(proxy[key])}`,
);
}
}
});
result = `tuic://${encodeURIComponent(
proxy.uuid,
)}:${encodeURIComponent(proxy.password)}@${proxy.server}:${
proxy.port
}?${tuicParams.join('&')}#${encodeURIComponent(
proxy.name,
)}`;
break;
}
}
return result;
};