diff --git a/README.md b/README.md index 73fb95e..014fb82 100644 --- a/README.md +++ b/README.md @@ -348,6 +348,17 @@ mihomo разбирает подписку (`luci/servers.js` — перенос сверяет с ним): reality, xhttp, ws, grpc и прочее — как в приложении. «Скопировать» отдаёт сервер как YAML для другого роутера. +AmneziaWG: туда же вставляется ключ AmneziaVPN `vpn://…` («Поделиться» в приложении; файл +`.vpn` тоже можно выбрать) или `.conf` AmneziaWG / обычного WireGuard (текст `[Interface]` … +`[Peer]` … или файл — тогда сервер называется по имени файла). Получается сервер +`type: wireguard` с `amnezia-wg-option` (AmneziaWG 1.0 / 1.5 / 2.0 / 3 — параметры как в +конфиге; без Jc/H1/… — обычный WireGuard) в упрощённом виде mihomo, с одним `[Peer]`; +`AllowedIPs` и `DNS` не переносятся — что куда идёт, решают правила kit. Из ключа берутся +только контейнеры AmneziaWG / WireGuard (Xray — его `vless://`-ссылкой), ключи Amnezia +Free / Premium не подходят: в них нет сервера. WireGuard — это UDP: на `whitelist` и с +телефона он идёт через `MY-EXIT`, поэтому нода там должна пропускать UDP (hysteria2, tuic, +ss, vless/trojan с UDP); на телефоне нужно ядро FlClash с поддержкой AmneziaWG. + Серверы хранятся в `/etc/nikki/my-servers` (права 600, по одному JSON-объекту прокси на строку) и переносятся экспортом настроек. Сборка вписывает их в `proxies:` профилей роутера и в конфиг телефона и собирает в группу `MY` (url-test: самый быстрый живой; в дашборде diff --git a/luci/mihomo-kit.js b/luci/mihomo-kit.js index 078867b..441a67a 100644 --- a/luci/mihomo-kit.js +++ b/luci/mihomo-kit.js @@ -789,20 +789,26 @@ return view.extend({ }; (cfg.pools || []).forEach(addPool); - // import: share links and/or YAML (or a file) -> cards + // import: share links, AmneziaVPN keys, YAML or a WireGuard / AmneziaWG .conf (or a + // file) -> cards; a .conf from a file is named after the file var importText = E('textarea', { 'class': 'cbi-input-textarea', 'rows': 8, 'spellcheck': 'false', 'style': 'width:100%;font-family:monospace', - 'placeholder': 'vless://…\ntrojan://…\nhysteria2://…\n\nили YAML, как в конфиге mihomo / Clash:\n- name: nl-1\n type: hysteria2\n server: vpn.example.com\n port: 443\n password: ...' }); - var importFile = E('input', { 'type': 'file', 'accept': '.yaml,.yml,.txt,.conf' }); + 'placeholder': 'vless://…\ntrojan://…\nhysteria2://…\nvpn://… (ключ AmneziaVPN)\n\nили .conf AmneziaWG / WireGuard ([Interface] … [Peer] …)\n\nили YAML, как в конфиге mihomo / Clash:\n- name: nl-1\n type: hysteria2\n server: vpn.example.com\n port: 443\n password: ...' }); + var importFile = E('input', { 'type': 'file', 'accept': '.yaml,.yml,.txt,.conf,.vpn' }); + var importName = ''; importFile.addEventListener('change', function() { - readFile(importFile).then(function(t) { importText.value = t; }); + readFile(importFile).then(function(t) { + importText.value = t; + importName = importFile.files[0] ? importFile.files[0].name.replace(/\.[^.]*$/, '') : ''; + }); }); + importText.addEventListener('input', function() { importName = ''; }); var importBox = E('div', { 'style': 'display:none;margin-bottom:.5em' }, [ importText, E('div', { 'style': 'display:flex;gap:.5em;align-items:center;flex-wrap:wrap;margin-top:.3em' }, [ E('span', 'или из файла:'), importFile, E('button', { 'class': 'btn cbi-button cbi-button-apply', 'click': function() { - var r = S.parseText(importText.value); + var r = S.parseText(importText.value, importName); r.servers.forEach(function(p) { addServer(p); }); var msg = [ E('p', r.servers.length ? 'Добавлено серверов: ' + r.servers.length + '. Проверь имена и нажми «Сохранить и применить».' : 'Серверов не нашёл.') ]; @@ -1038,7 +1044,8 @@ return view.extend({ E('h4', 'Свои серверы'), E('p', { 'class': 'cbi-value-description' }, 'Собираются в группу MY (автовыбор самого быстрого, в дашборде можно закрепить один). MY — пункт в MAIN ' + 'рядом с FOREIGN. К самим серверам на whitelist и с телефона — через MY-EXIT, на main — напрямую. Ссылки ' + - 'vless / vmess / trojan / ss / hysteria2 / tuic / anytls и YAML разбираются так же, как в mihomo; серверы ' + + 'vless / vmess / trojan / ss / hysteria2 / tuic / anytls и YAML разбираются так же, как в mihomo; ключ ' + + 'AmneziaVPN (vpn://) и .conf AmneziaWG / WireGuard становятся сервером wireguard; серверы ' + 'попадают и в конфиг телефона. Серверы из подписок с [MY] в имени (например «[MY] 🇩🇪 de-1») тоже попадают в MY.'), moved ? E('p', { 'class': 'alert-message warning' }, 'Перенесено из старых настроек (hysteria2 по полям, ссылки): ' + moved + '. Нажми «Сохранить и применить», чтобы сохранить их в новом виде.') : '', diff --git a/luci/servers.js b/luci/servers.js index 1b639c2..5c1083f 100644 --- a/luci/servers.js +++ b/luci/servers.js @@ -1,5 +1,6 @@ -// Own servers of the kit (LuCI "Свои серверы"): share links and YAML -> mihomo proxy -// objects, and one stored line per server (/etc/nikki/my-servers, see mihomo-kit.sh). +// Own servers of the kit (LuCI "Свои серверы"): share links, YAML, WireGuard / AmneziaWG +// .conf and AmneziaVPN keys (vpn://) -> mihomo proxy objects, and one stored line per +// server (/etc/nikki/my-servers, see mihomo-kit.sh). // parseLinks is a port of mihomo's common/convert (ConvertsV2Ray) so a link gives the // same proxy as in a subscription; tools/test.sh checks it against the Go converter. // Browser: a global "mkServers" (loaded like qrcode.js); node: module.exports. @@ -1307,22 +1308,310 @@ return indent + scalar(v); } + // --- WireGuard / AmneziaWG: .conf files and AmneziaVPN keys (vpn://) ------------- + + // zlib inflate (RFC 1950/1951) as zlib's puff.c: byte array -> byte array, throws + var LBASE = [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, + 131, 163, 195, 227, 258 ]; + var LEXT = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 ]; + var DBASE = [ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, + 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 ]; + var DEXT = [ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 ]; + var CLORDER = [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ]; + + // canonical Huffman code of the code lengths: count of codes per length, symbols in order + function huffman(lengths) { + var count = [], offs = [ 0, 0 ], sym = [], i; + for (i = 0; i < 16; i++) + count[i] = 0; + lengths.forEach(function (l) { count[l]++; }); + for (i = 1; i < 15; i++) + offs[i + 1] = offs[i] + count[i]; + lengths.forEach(function (l, s) { + if (l) + sym[offs[l]++] = s; + }); + return { count: count, sym: sym }; + } + + function inflate(data) { + if (data.length < 2 || (data[0] & 0x0f) != 8 || ((data[0] << 8) | data[1]) % 31) + throw new Error('not zlib'); + var pos = 2, bitbuf = 0, bitcnt = 0, out = [], fixed = null, i; + var bits = function (n) { + var v = bitbuf; + while (bitcnt < n) { + if (pos >= data.length) + throw new Error('truncated'); + v |= data[pos++] << bitcnt; + bitcnt += 8; + } + bitbuf = v >>> n; + bitcnt -= n; + return v & ((1 << n) - 1); + }; + var decode = function (h) { + for (var len = 1, code = 0, first = 0, index = 0; len < 16; len++) { + code |= bits(1); + if (code - h.count[len] < first) + return h.sym[index + code - first]; + index += h.count[len]; + first = (first + h.count[len]) << 1; + code <<= 1; + } + throw new Error('bad code'); + }; + var codes = function (lit, dist) { + for (;;) { + var s = decode(lit); + if (s < 256) { + out.push(s); + continue; + } + if (s == 256) + return; + if ((s -= 257) >= 29) + throw new Error('bad length'); + var len = LBASE[s] + bits(LEXT[s]); + if ((s = decode(dist)) >= 30) + throw new Error('bad distance'); + var d = DBASE[s] + bits(DEXT[s]); + if (d > out.length) + throw new Error('distance too far'); + while (len--) + out.push(out[out.length - d]); + } + }; + for (var last = 0; !last;) { + last = bits(1); + var type = bits(2); + if (type == 0) { + bitbuf = bitcnt = 0; + var n = data[pos] | data[pos + 1] << 8; + if (pos + 4 + n > data.length || (n ^ (data[pos + 2] | data[pos + 3] << 8)) != 0xffff) + throw new Error('bad stored block'); + for (pos += 4; n--;) + out.push(data[pos++]); + } else if (type == 1) { + if (!fixed) { + var l = []; + for (i = 0; i < 288; i++) + l[i] = i < 144 ? 8 : i < 256 ? 9 : i < 280 ? 7 : 8; + fixed = [ huffman(l), huffman(l.slice(0, 30).map(function () { return 5; })) ]; + } + codes(fixed[0], fixed[1]); + } else if (type == 2) { + var nlen = bits(5) + 257, ndist = bits(5) + 1, ncode = bits(4) + 4, lengths = []; + for (i = 0; i < 19; i++) + lengths[i] = 0; + for (i = 0; i < ncode; i++) + lengths[CLORDER[i]] = bits(3); + var lencode = huffman(lengths); + for (lengths = []; lengths.length < nlen + ndist;) { + var sym = decode(lencode), rep, prev = 0; + if (sym < 16) { + lengths.push(sym); + continue; + } + if (sym == 16) { + if (!lengths.length) + throw new Error('repeat with no length'); + prev = lengths[lengths.length - 1]; + rep = 3 + bits(2); + } else { + rep = sym == 17 ? 3 + bits(3) : 11 + bits(7); + } + while (rep--) + lengths.push(prev); + } + if (lengths.length > nlen + ndist) + throw new Error('too many lengths'); + codes(huffman(lengths.slice(0, nlen)), huffman(lengths.slice(nlen))); + } else { + throw new Error('bad block type'); + } + } + return out; + } + + // AmneziaWG keys of [Interface] (lower case) -> amnezia-wg-option of mihomo + var AWG = { jc: 'jc', jmin: 'jmin', jmax: 'jmax', s1: 's1', s2: 's2', s3: 's3', s4: 's4', + h1: 'h1', h2: 'h2', h3: 'h3', h4: 'h4', i1: 'i1', i2: 'i2', i3: 'i3', i4: 'i4', i5: 'i5', + j1: 'j1', j2: 'j2', j3: 'j3', itime: 'itime' }; + // AmneziaWG 3: mihomo needs "version: 3" with them + var AWG3 = { headerprotectionkey: 'header-protection-key', contentpaddingaddition: 'content-padding-addition', + rekeyaftertime: 'rekey-after-time', rekeytimeout: 'rekey-timeout', rejectaftertime: 'reject-after-time', + keepalivetimeout: 'keepalive-timeout', maxhandshakeattempts: 'max-handshake-attempts', + randomtrailers: 'random-trailers', disablecookies: 'disable-cookies' }; + + // [Interface] and the first [Peer] (keys in lower case) -> a wireguard proxy in the + // simplified syntax (one peer; AllowedIPs and DNS dropped: routing and DNS are the kit's) + function wgProxy(iface, peer, name) { + var need = function (v, what) { + if (!v) + throw new Error('нет ' + what); + return v; + }; + var ep = need(peer.endpoint, 'Endpoint в [Peer]'); + var m = /^\[([^\]]+)\]:([0-9]+)$/.exec(ep) || /^([^:\[\]]+):([0-9]+)$/.exec(ep); + if (!m) + throw new Error('Endpoint ' + ep + ': нужно адрес:порт'); + var p = { name: name || m[1], type: 'wireguard', server: m[1], port: +m[2] }; + need(iface.address, 'Address в [Interface]').split(',').forEach(function (a) { + a = a.trim(); + var v6 = a.indexOf(':') >= 0, k = v6 ? 'ipv6' : 'ip'; + if (a && !p[k]) + p[k] = a.replace(v6 ? /\/128$/ : /\/32$/, ''); + }); + p['private-key'] = need(iface.privatekey, 'PrivateKey в [Interface]'); + p['public-key'] = need(peer.publickey, 'PublicKey в [Peer]'); + if (peer.presharedkey) + p['pre-shared-key'] = peer.presharedkey; + if (/^[0-9]+$/.test(iface.mtu || '')) + p.mtu = +iface.mtu; + // AmneziaWG 3 gives a range ("25-35"): mihomo takes one number + m = /^([0-9]+)(-[0-9]+)?$/.exec(peer.persistentkeepalive || ''); + if (m && +m[1]) + p['persistent-keepalive'] = +m[1]; + p.udp = true; + var awg = {}, keys = Object.keys(iface).filter(function (k) { return (AWG[k] || AWG3[k]) && iface[k] !== ''; }); + if (keys.some(function (k) { return AWG3[k]; })) + awg.version = 3; + keys.forEach(function (k) { + var v = iface[k]; + if (k == 'randomtrailers' || k == 'disablecookies') + v = /^(1|true|on|yes)$/i.test(v); + else if (/^[0-9]+$/.test(v)) + v = +v; + awg[AWG[k] || AWG3[k]] = v; + }); + if (keys.length) + p['amnezia-wg-option'] = awg; + return p; + } + + // a wg-quick / AmneziaWG .conf -> proxy (name: default name), throws + function parseConf(text, name) { + var iface = null, peers = [], sec = null; + String(text).split(/\r?\n/).forEach(function (l) { + l = l.replace(/#.*/, '').trim(); + var m = /^\[\s*(\w+)\s*\]$/.exec(l), i = l.indexOf('='); + if (m) { + m = m[1].toLowerCase(); + sec = m == 'interface' ? (iface = iface || {}) : m == 'peer' ? (peers[peers.length] = {}) : null; + } else if (sec && i > 0) { + sec[l.slice(0, i).trim().toLowerCase()] = l.slice(i + 1).trim(); + } + }); + if (!iface || !peers.length) + throw new Error('нужны секции [Interface] и [Peer]'); + if (peers.length > 1) + throw new Error('несколько [Peer]: поддерживается один'); + return wgProxy(iface, peers[0], name); + } + + // an AmneziaVPN key: "vpn://" + base64url of qCompress(JSON) (4-byte length + zlib) or + // of the JSON itself; its AmneziaWG / WireGuard containers -> { servers, errors } + function parseAmnezia(line) { + var r = { servers: [], errors: [] }, o = null; + var raw = b64(urlSafe(line.trim().replace(/^vpn:\/\//i, '').replace(/[\s=]/g, '')), URLSAFE, false); + if (raw) { + try { + o = JSON.parse(utf8(inflate(raw.slice(4)))); + } catch (e) { + try { + o = JSON.parse(utf8(raw)); + } catch (e2) {} + } + } + if (!isObj(o)) { + r.errors.push('vpn://: не похоже на ключ AmneziaVPN'); + return r; + } + if (o.api_key || o.auth_data) { + r.errors.push('vpn://: ключ Amnezia Free / Premium — в нём доступ к их API, а не сервер. ' + + 'Нужен ключ своего сервера (AmneziaWG) или его .conf'); + return r; + } + var other = []; + (Array.isArray(o.containers) ? o.containers : []).forEach(function (c) { + var proto = isObj(c) && (c.awg || c.wireguard), last = null; + if (!isObj(proto)) { + other.push(isObj(c) && c.container || '?'); + return; + } + try { + last = JSON.parse(proto.last_config); + } catch (e) {} + if (!isObj(last)) { + r.errors.push('vpn://: ' + c.container + ' без настроек клиента (last_config)'); + return; + } + var name = o.description || o.hostName; + try { + var p; + if (last.config) { + p = parseConf(last.config, name); + } else { + // no wg config text: the same from the fields (AWG ones are named as in it) + var iface = { address: last.client_ip, privatekey: last.client_priv_key }; + Object.keys(last).forEach(function (k) { + if (AWG[k.toLowerCase()] || AWG3[k.toLowerCase()]) + iface[k.toLowerCase()] = String(last[k]); + }); + p = wgProxy(iface, { endpoint: (last.hostName || o.hostName) + ':' + (last.port || proto.port), + publickey: last.server_pub_key, presharedkey: last.psk_key, + persistentkeepalive: String(last.persistent_keep_alive || '') }, name); + } + // the client sets MTU from the key, not from the config text + if (!p.mtu && /^[0-9]+$/.test(String(last.mtu || ''))) + p.mtu = +last.mtu; + r.servers.push(p); + } catch (e) { + r.errors.push('vpn://: ' + c.container + ': ' + e.message); + } + }); + if (!r.servers.length && !r.errors.length) + r.errors.push('vpn://: нет AmneziaWG / WireGuard' + (other.length ? ' (есть: ' + other.join(', ') + + '; для Xray возьми vless://-ссылку)' : '')); + return r; + } + // --- servers of the form --------------------------------------------------------- var LINK = /^\s*[A-Za-z][A-Za-z0-9+.-]*:\/\//; + var VPN = /^\s*vpn:\/\//i; + var CONF = /^\s*\[\s*Interface\s*\]\s*$/im; - // pasted text: share links and/or mihomo YAML (a "proxies:" list, a list, one proxy) - // -> { servers: [...], errors: [...] } - function parseText(text) { - var links = [], rest = [], errors = []; + // pasted text: share links, AmneziaVPN keys (vpn://) and/or mihomo YAML (a "proxies:" + // list, a list, one proxy) or WireGuard / AmneziaWG .conf; name: default name of a + // .conf (the file name) -> { servers: [...], errors: [...] } + function parseText(text, name) { + var links = [], keys = [], rest = [], errors = []; String(text).split(/\r?\n/).forEach(function (l) { - (LINK.test(l) ? links : rest).push(l); + (VPN.test(l) ? keys : LINK.test(l) ? links : rest).push(l); }); var servers = links.length ? parseLinks(links.join('\n')) : []; if (links.length && servers.length < links.length) errors.push('не разобрано ссылок: ' + (links.length - servers.length) + ' из ' + links.length); + keys.forEach(function (l) { + var r = parseAmnezia(l); + servers = servers.concat(r.servers); + errors = errors.concat(r.errors); + }); var y = rest.join('\n'); - if (y.trim()) { + if (CONF.test(y)) { + // .conf: one per [Interface] (several files pasted one after another) + y.split(/^(?=\s*\[\s*Interface\s*\]\s*$)/im).forEach(function (c) { + if (!CONF.test(c)) + return; + try { + servers.push(parseConf(c, name)); + } catch (e) { + errors.push('.conf: ' + e.message); + } + }); + } else if (y.trim()) { var doc = null, list = []; try { doc = yamlLoad(y); @@ -1399,6 +1688,8 @@ return { parseLinks: parseLinks, parseText: parseText, + parseConf: parseConf, + parseAmnezia: parseAmnezia, yamlLoad: yamlLoad, yamlDump: yamlDump, toLine: toLine, diff --git a/tests/amnezia/awg2.conf b/tests/amnezia/awg2.conf new file mode 100644 index 0000000..b6dbf9b --- /dev/null +++ b/tests/amnezia/awg2.conf @@ -0,0 +1,24 @@ +[Interface] +Address = 10.8.1.2/32 +DNS = 1.1.1.1, 1.0.0.1 +PrivateKey = fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI= +Jc = 4 +Jmin = 10 +Jmax = 50 +S1 = 98 +S2 = 32 +S3 = 19 +S4 = 7 +H1 = 1458367412-1593426716 +H2 = 1863071624-1902347825 +H3 = 2091548318-2097143921 +H4 = 2112573893-2147191025 +I1 = +I2 = + +[Peer] +PublicKey = vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE= +PresharedKey = 6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E= +AllowedIPs = 0.0.0.0/0, ::/0 +Endpoint = 203.0.113.10:47613 +PersistentKeepalive = 25 diff --git a/tests/amnezia/awg2.expected.json b/tests/amnezia/awg2.expected.json new file mode 100644 index 0000000..eb65239 --- /dev/null +++ b/tests/amnezia/awg2.expected.json @@ -0,0 +1,31 @@ +{ + "servers": [ + { + "name": "awg2", + "type": "wireguard", + "server": "203.0.113.10", + "port": 47613, + "ip": "10.8.1.2", + "private-key": "fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=", + "public-key": "vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=", + "pre-shared-key": "6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=", + "persistent-keepalive": 25, + "udp": true, + "amnezia-wg-option": { + "jc": 4, + "jmin": 10, + "jmax": 50, + "s1": 98, + "s2": 32, + "s3": 19, + "s4": 7, + "h1": "1458367412-1593426716", + "h2": "1863071624-1902347825", + "h3": "2091548318-2097143921", + "h4": "2112573893-2147191025", + "i1": "" + } + } + ], + "errors": [] +} diff --git a/tests/amnezia/awg3.conf b/tests/amnezia/awg3.conf new file mode 100644 index 0000000..b6c695f --- /dev/null +++ b/tests/amnezia/awg3.conf @@ -0,0 +1,24 @@ +# AmneziaWG 3, IPv6 endpoint +[Interface] +PrivateKey = Se+IZIi2AQD3AZjN7AazYfi+j3yqITfYwkTkOzVj1Wo= +Address = 10.8.1.3/32, fd00:8:1::3/128 +MTU = 1280 +Jc = 3 +Jmin = 10 +Jmax = 50 +S1 = 0 +S2 = 0 +H1 = 1 +H2 = 2 +H3 = 3 +H4 = 4 +HeaderProtectionKey = odnCO5zIam/+bXlGAOclYIK0o4+FVxGscfwiHQIUVcU= +ContentPaddingAddition = 0-32 +RekeyAfterTime = 120 +RandomTrailers = true +DisableCookies = 1 + +[Peer] +PublicKey = zUr0LTfErDhhn+GgMPuF7VdeIpQ24pI1kihfwQjfnNg= +Endpoint = [2001:db8::10]:51820 # comment +PersistentKeepalive = 25-35 diff --git a/tests/amnezia/awg3.expected.json b/tests/amnezia/awg3.expected.json new file mode 100644 index 0000000..d92abc3 --- /dev/null +++ b/tests/amnezia/awg3.expected.json @@ -0,0 +1,35 @@ +{ + "servers": [ + { + "name": "awg3", + "type": "wireguard", + "server": "2001:db8::10", + "port": 51820, + "ip": "10.8.1.3", + "ipv6": "fd00:8:1::3", + "private-key": "Se+IZIi2AQD3AZjN7AazYfi+j3yqITfYwkTkOzVj1Wo=", + "public-key": "zUr0LTfErDhhn+GgMPuF7VdeIpQ24pI1kihfwQjfnNg=", + "mtu": 1280, + "persistent-keepalive": 25, + "udp": true, + "amnezia-wg-option": { + "version": 3, + "jc": 3, + "jmin": 10, + "jmax": 50, + "s1": 0, + "s2": 0, + "h1": 1, + "h2": 2, + "h3": 3, + "h4": 4, + "header-protection-key": "odnCO5zIam/+bXlGAOclYIK0o4+FVxGscfwiHQIUVcU=", + "content-padding-addition": "0-32", + "rekey-after-time": 120, + "random-trailers": true, + "disable-cookies": true + } + } + ], + "errors": [] +} diff --git a/tests/amnezia/broken.conf b/tests/amnezia/broken.conf new file mode 100644 index 0000000..c31c7c8 --- /dev/null +++ b/tests/amnezia/broken.conf @@ -0,0 +1,6 @@ +[Interface] +Address = 10.0.0.2/32 +PrivateKey = 9mpa7dajJsZ00c7XLuNEOM5MYGIlPWQn/WDqg0uGHtc= + +[Peer] +PublicKey = 9qAqsbJr88uWikvCYZjXRZZLmRwppEfyxr/s5y9YSP0= diff --git a/tests/amnezia/broken.expected.json b/tests/amnezia/broken.expected.json new file mode 100644 index 0000000..1b7fbc6 --- /dev/null +++ b/tests/amnezia/broken.expected.json @@ -0,0 +1,6 @@ +{ + "servers": [], + "errors": [ + ".conf: нет Endpoint в [Peer]" + ] +} diff --git a/tests/amnezia/key.expected.json b/tests/amnezia/key.expected.json new file mode 100644 index 0000000..12e273d --- /dev/null +++ b/tests/amnezia/key.expected.json @@ -0,0 +1,32 @@ +{ + "servers": [ + { + "name": "Амнезия NL", + "type": "wireguard", + "server": "198.51.100.7", + "port": 39125, + "ip": "10.8.1.5", + "private-key": "sJYaurvRLIjIzrNVHIxvzLMewcvxeregrDLiAh3mjxs=", + "public-key": "MkcJxkUHqF5oSmPPP4cKLJHqwk6m7iNQKEGvw9C4rMI=", + "pre-shared-key": "CTu0Yl8/YvvhDkqwszsHTZfEuzCKA83sSxtdn3hwggg=", + "persistent-keepalive": 25, + "udp": true, + "amnezia-wg-option": { + "jc": 4, + "jmin": 10, + "jmax": 50, + "s1": 98, + "s2": 32, + "s3": 19, + "s4": 7, + "h1": "1458367412-1593426716", + "h2": "1863071624-1902347825", + "h3": "2091548318-2097143921", + "h4": "2112573893-2147191025", + "i1": "" + }, + "mtu": 1376 + } + ], + "errors": [] +} diff --git a/tests/amnezia/key.vpn b/tests/amnezia/key.vpn new file mode 100644 index 0000000..98f6a60 --- /dev/null +++ b/tests/amnezia/key.vpn @@ -0,0 +1 @@ +vpn://AAAF9XjalVTbbuM2EP0VYp5lRaQk64L1AkGS1rcYbr1bIBsGhiIxttY2pZCSrNjIN7Q_U3Qf2n9w_2hB0nAXXe9DYECewzlzSA5nZg9pwask50xIiO_3_0GIIdlwtsuTTrJdgAXqG--hLEQFMbgRJj5YUImES7U2L0VRFRBDnZVggUZpsZ43TMi84BADAQvWiazmacGf8gXEsKdgbAoxhfsBr5h4SlL2QCm_zDLBpEQ9hB07tLHtX7iEUn49mak1W_8shG3HdmxMKZ-KvEkqNmIvqIfk8C6pRfPrePB5sBOT3_qDttmNb9k2bVom2EJcj_PLpbv53MoepXyYoh7ylLHJud5S20mLeshX9gyjHopCZRHUQ_okM1cxI2V5qIcCSnlf0bDnh2438DDpYD9yPdINcFc5VSQOu64T4C7xOjhyiOsFIfGVU4kRJ8K-F7o47BAnCrDnRkRdra_0CcbED9wwcjsEewGOsKMjB2rPdwKR9-8ekdOGfui8p5RTyu-njAmVy2n9uM5Tk5nbVTpsVx_7zz_5xWwznU69dDQe9p-3q-4myCe_jG5-brbRlSduBz2dVSaXiWCZib76UDt36_DirmmW16vnrdzJ_odPTzf17mp0Gbpy1lYZd5fbxWKhoi_X62LLssFUvaOjn8q5cCwUxxcqqzc8K4ucVzqPoe1jGzuOHcS6uNTmqnZkxXg1YqxM1nnDVCKUi4JFYVnIapJsmC6fbxW0V1UlBSNmUUjXOePVPC8N-1hUmnl0lSJv5iv2oglvqiAlIplomJiX9eNJ40251keWq1Pwm1KtgjdVba7mBl2jdkrffMVYOdcJ1BRi7j1MNfIM2OT8mJojTlqNfYNnWKMoNIho5BKD3OMTGORpZF6hb8LON4UmGKXzjaEJRvx8c2iC2e98gyjCwJzh_02iXImp0HleSgrxPYVTlWq3LlR4eIXXV-v8cGxF8gIW6L94__2AK-rqsah5puW10IMFGXtK6nV19cNhmzGZiryszOQ8_HH4-_DP4c_DX4cv__6OJmPF4BJDDMdBaBaIXtADEaxTd6jFb3oDXr8CPPbK8w diff --git a/tests/amnezia/keys.expected.json b/tests/amnezia/keys.expected.json new file mode 100644 index 0000000..fe6cca6 --- /dev/null +++ b/tests/amnezia/keys.expected.json @@ -0,0 +1,20 @@ +{ + "servers": [ + { + "name": "vpn.example.net", + "type": "wireguard", + "server": "vpn.example.net", + "port": 51820, + "ip": "10.9.0.2", + "private-key": "4Wy1vIZv6qyqd2STfzx/wX6a0hdMWghlV6a2DpbkUlM=", + "public-key": "L9Rfyw+PxD7/TW2mkh4C9jAimo8nHK6yRYPkHhZVY6s=", + "persistent-keepalive": 25, + "udp": true, + "mtu": 1420 + } + ], + "errors": [ + "vpn://: ключ Amnezia Free / Premium — в нём доступ к их API, а не сервер. Нужен ключ своего сервера (AmneziaWG) или его .conf", + "vpn://: не похоже на ключ AmneziaVPN" + ] +} diff --git a/tests/amnezia/keys.txt b/tests/amnezia/keys.txt new file mode 100644 index 0000000..29f895a --- /dev/null +++ b/tests/amnezia/keys.txt @@ -0,0 +1,3 @@ +vpn://AAABq3jahZBBT8JAEIX_y1ytpWygwiYeDBwwiiGIILimWeiUrm23y3ZbKE3_u7FVSbx4m8m8-fLeq2CXSsOFRJ0BfasuK1DgicSz4NdHoXGfc-2DBZeZVqBSbYBCvzsgDlgQ88x4u1QGYg8UKgZhmpknniADyqBQ0sYTT1SMtkTDwGINgAFtABaDXSxQGk-o5qHr2EPbsUmj_D4pLQovwrIR9FZlt7jfFO6hPPjkeRGcT53jq8ud0J-u9mG8dDkZq230Ek9vG0iGukDtqXz7y3gczoPyeDU7jW86ixVJorA3Gn7ciSQdyMmDW87Xs2gSbpZrN2sZiclbdz3itBlQZyIzX-4iROXxWBRtYtJnUENdv1vgY8Dz2Iz-afenMKB_64L6Eyw7kD4 +vpn://AAAAO3jaq1ZKLMiMz06tVLJSqlDSUUrOz0vLTI8vSy0qzszPU7Iy0lHKS8xNVbJScszNS63KTFQIKErNzSzNVaoFAFV2FB8 +vpn://not-a-key diff --git a/tests/amnezia/plain-wg.conf b/tests/amnezia/plain-wg.conf new file mode 100644 index 0000000..e74877e --- /dev/null +++ b/tests/amnezia/plain-wg.conf @@ -0,0 +1,9 @@ +[Interface] +Address = 172.16.0.2/32 +PrivateKey = SdgDFLQDksOZbdDs+sbQ/z06+65znzFrH5eUCoJUorc= +DNS = 1.1.1.1 + +[Peer] +PublicKey = b4J5nuV2f5PECf2vFOPNazXHGqkcZtMVZrYSUOD5ZgU= +AllowedIPs = 0.0.0.0/0 +Endpoint = wg.example.com:2408 diff --git a/tests/amnezia/plain-wg.expected.json b/tests/amnezia/plain-wg.expected.json new file mode 100644 index 0000000..26a896a --- /dev/null +++ b/tests/amnezia/plain-wg.expected.json @@ -0,0 +1,15 @@ +{ + "servers": [ + { + "name": "plain-wg", + "type": "wireguard", + "server": "wg.example.com", + "port": 2408, + "ip": "172.16.0.2", + "private-key": "SdgDFLQDksOZbdDs+sbQ/z06+65znzFrH5eUCoJUorc=", + "public-key": "b4J5nuV2f5PECf2vFOPNazXHGqkcZtMVZrYSUOD5ZgU=", + "udp": true + } + ], + "errors": [] +} diff --git a/tests/expected/mobile.yaml b/tests/expected/mobile.yaml index cd303d6..20e0228 100644 --- a/tests/expected/mobile.yaml +++ b/tests/expected/mobile.yaml @@ -20,6 +20,7 @@ proxies: - {"dialer-proxy": "MY-EXIT", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "MY-EXIT", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "MY-EXIT", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} + - {"dialer-proxy": "MY-EXIT", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} - {"dialer-proxy": "MY-EXIT", "name":"m1","type":"hysteria2","server":"m.example.com","port":443,"password":"p","udp":true} # copies of own servers for the chains (SVC__CHAIN, POOL__UPLINK): the same @@ -250,7 +251,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "m1"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "m1"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-csqtt-foreign.yaml b/tests/expected/router-csqtt-foreign.yaml index b1106ed..f415033 100644 --- a/tests/expected/router-csqtt-foreign.yaml +++ b/tests/expected/router-csqtt-foreign.yaml @@ -21,6 +21,7 @@ proxies: - {"dialer-proxy": "UPLINK", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "UPLINK", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "UPLINK", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} + - {"dialer-proxy": "UPLINK", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} - {"dialer-proxy": "UPLINK", "name":"nl-1","type":"hysteria2","server":"vpn.example.com","port":443,"password":"p","udp":true} # CSQTT (star-panel-csqtt): tunnel interface csqtt0 on the router, mihomo @@ -220,7 +221,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "nl-1"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "nl-1"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-csqtt.yaml b/tests/expected/router-csqtt.yaml index 9b5d463..7e3985c 100644 --- a/tests/expected/router-csqtt.yaml +++ b/tests/expected/router-csqtt.yaml @@ -21,6 +21,7 @@ proxies: - {"dialer-proxy": "MY-EXIT", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "MY-EXIT", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "MY-EXIT", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} + - {"dialer-proxy": "MY-EXIT", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} # CSQTT (star-panel-csqtt): tunnel interface csqtt0 on the router, mihomo # just sends the connection out of it (the interface does not change routes) @@ -222,7 +223,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-main.yaml b/tests/expected/router-main.yaml index 4e2b4e5..58e31c8 100644 --- a/tests/expected/router-main.yaml +++ b/tests/expected/router-main.yaml @@ -31,6 +31,7 @@ proxies: - {"name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} + - {"name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} - {"name":"home-hy","type":"hysteria2","server":"1.1.1.1","port":443,"password":"x","udp":true} proxy-providers: @@ -258,7 +259,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "home-hy"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own", "home-hy"] use: [example-my, example2-my] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/expected/router-whitelist-ts-my.yaml b/tests/expected/router-whitelist-ts-my.yaml index c9b499f..deed50e 100644 --- a/tests/expected/router-whitelist-ts-my.yaml +++ b/tests/expected/router-whitelist-ts-my.yaml @@ -36,6 +36,7 @@ proxies: - {"dialer-proxy": "MY-EXIT", "name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "MY-EXIT", "name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "MY-EXIT", "name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} + - {"dialer-proxy": "MY-EXIT", "name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} # copies of own servers for the chains (SVC__CHAIN, POOL__UPLINK): the same # server dialing through another entry, named " ⟶ " (group " ⟶ ") @@ -44,6 +45,7 @@ proxies: - {"dialer-proxy": "FOREIGN", "name":"🇩🇪 de 1 ⟶ FOREIGN","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} - {"dialer-proxy": "FOREIGN", "name":"tr \"q\" ⟶ FOREIGN","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} - {"dialer-proxy": "FOREIGN", "name":"hy-own ⟶ FOREIGN","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} + - {"dialer-proxy": "FOREIGN", "name":"awg-own ⟶ FOREIGN","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} proxy-providers: example: @@ -396,7 +398,7 @@ proxy-groups: # the subscriptions (providers -my); the fastest alive one; pin one in the dashboard if needed - name: MY type: url-test - proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own"] + proxies: ["🇩🇪 de 1", "tr \"q\"", "hy-own", "awg-own"] use: [example-my, example2-my, my-links] url: "https://www.gstatic.com/generate_204" interval: 300 @@ -451,7 +453,7 @@ proxy-groups: # nodes, each dialing through FOREIGN - name: "MY ⟶ FOREIGN" type: fallback - proxies: ["🇩🇪 de 1 ⟶ FOREIGN", "tr \"q\" ⟶ FOREIGN", "hy-own ⟶ FOREIGN"] + proxies: ["🇩🇪 de 1 ⟶ FOREIGN", "tr \"q\" ⟶ FOREIGN", "hy-own ⟶ FOREIGN", "awg-own ⟶ FOREIGN"] use: [example-my@FOREIGN, example2-my@FOREIGN, my-links@FOREIGN] url: "https://www.gstatic.com/generate_204" interval: 300 diff --git a/tests/fixtures/own.servers b/tests/fixtures/own.servers index 81b0a7d..2366ad5 100644 --- a/tests/fixtures/own.servers +++ b/tests/fixtures/own.servers @@ -1,3 +1,4 @@ {"name":"🇩🇪 de 1","type":"vless","server":"x.example.com","port":"443","uuid":"00000000-0000-0000-0000-000000000001","udp":true,"tls":true,"client-fingerprint":"chrome","servername":"www.example.com","reality-opts":{"public-key":"Nc9ZSDuQMwHN4M6TeDHjfJhgZ6SBTBbfMwx5iHQZ1ns","short-id":"ab"},"xudp":true,"network":"xhttp","xhttp-opts":{"path":"/x"}} {"name":"tr \"q\"","type":"trojan","server":"t.example.org","port":"443","password":"p\u0024w","udp":true,"skip-cert-verify":false,"sni":"t.example.org","network":"grpc","grpc-opts":{"grpc-service-name":"g"},"client-fingerprint":"chrome"} {"name":"hy-own","type":"hysteria2","server":"h.example.net","port":8443,"password":"a\u0024b","obfs":"salamander","obfs-password":"o","up":"50 mbps"} +{"name":"awg-own","type":"wireguard","server":"203.0.113.10","port":47613,"ip":"10.8.1.2","private-key":"fTo2df+b5vCuulh7pOXMWiWJY2VwSe2Kuup2nA34tfI=","public-key":"vGYpG72gCXPNfYzr/0iNfSoL83vbrVSGUC+v+MKRVyE=","pre-shared-key":"6ut/J6EuaJ97RMFcZuiJkzIo7a5uxR98htK5NdWJW6E=","persistent-keepalive":25,"udp":true,"amnezia-wg-option":{"jc":4,"jmin":10,"jmax":50,"s1":98,"s2":32,"s3":19,"s4":7,"h1":"1458367412-1593426716","h2":"1863071624-1902347825","h3":"2091548318-2097143921","h4":"2112573893-2147191025","i1":""}} diff --git a/tools/test-servers.js b/tools/test-servers.js index ea01303..deebf6f 100755 --- a/tools/test-servers.js +++ b/tools/test-servers.js @@ -34,6 +34,16 @@ for (const f of fs.readdirSync(path.join(root, "yaml"))) { // the editor shows yamlDump; it must read back the same check("yaml/" + f + " (dump)", want, s.yamlLoad(s.yamlDump(got))); } +// WireGuard / AmneziaWG .conf and AmneziaVPN keys (vpn://): parseText with the file name +// as the default name; tests/amnezia/.expected.json is checked by hand and with +// `mihomo -t` (key.vpn and keys.txt: qCompress'd JSON as the AmneziaVPN client makes it) +for (const f of fs.readdirSync(path.join(root, "amnezia"))) { + if (f.endsWith(".expected.json")) + continue; + const exp = path.join(root, "amnezia", f.replace(/\.[^.]+$/, ".expected.json")); + check("amnezia/" + f, JSON.parse(fs.readFileSync(exp, "utf8")), + s.parseText(fs.readFileSync(path.join(root, "amnezia", f), "utf8"), f.replace(/\.[^.]+$/, ""))); +} // a stored line reads back the same, without dialer-proxy, with no "$" left const p = { name: "a$b", type: "ss", server: "h", port: 1, password: "x${Y}", "dialer-proxy": "Z" }; const line = s.toLine(p);