mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 23:13:43 +00:00
feat: Egern 输出支持 shadowsocksr (#642)
Map SSR nodes to Egern shadowsocksr output, validate supported ciphers and plugins, and reuse ShadowTLS, QUIC, and UDP handling. Cover field mapping and unsupported values with producer tests.
This commit is contained in:
1 parent
1b0e4a6f62
commit
df46fefff4
2 files changed
+211
-1
No files matched your search
@@ -18,6 +18,7 @@ export default function Egern_Producer() {
|
||||
'https',
|
||||
'socks5',
|
||||
'ss',
|
||||
'ssr',
|
||||
'trojan',
|
||||
'hysteria2',
|
||||
'vless',
|
||||
@@ -92,6 +93,8 @@ export default function Egern_Producer() {
|
||||
normalizeSnellVersion(proxy.version) === null
|
||||
) {
|
||||
return false;
|
||||
} else if (proxy.type === 'ssr' && !isEgernSsr(proxy)) {
|
||||
return false;
|
||||
} else if (
|
||||
['anytls'].includes(proxy.type) &&
|
||||
proxy.network &&
|
||||
@@ -208,6 +211,21 @@ export default function Egern_Producer() {
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (proxy.type === 'ssr') {
|
||||
proxy = {
|
||||
type: 'shadowsocksr',
|
||||
name: proxy.name,
|
||||
method: normalizeSsrMethod(proxy.cipher),
|
||||
server: proxy.server,
|
||||
port: proxy.port,
|
||||
password: proxy.password,
|
||||
protocol: normalizeSsrPlugin(proxy.protocol),
|
||||
protocol_param: proxy['protocol-param'],
|
||||
obfs: normalizeSsrPlugin(proxy.obfs),
|
||||
obfs_param: proxy['obfs-param'],
|
||||
tfo: getTfo(proxy),
|
||||
udp_relay: getUdpRelay(proxy),
|
||||
};
|
||||
} else if (proxy.type === 'hysteria2') {
|
||||
proxy = {
|
||||
type: 'hysteria2',
|
||||
@@ -542,6 +560,7 @@ export default function Egern_Producer() {
|
||||
'https',
|
||||
'socks5',
|
||||
'ss',
|
||||
'ssr',
|
||||
'trojan',
|
||||
'vless',
|
||||
'vmess',
|
||||
@@ -578,6 +597,7 @@ export default function Egern_Producer() {
|
||||
[
|
||||
'socks5',
|
||||
'ss',
|
||||
'ssr',
|
||||
'trojan',
|
||||
'vless',
|
||||
'vmess',
|
||||
@@ -604,7 +624,7 @@ export default function Egern_Producer() {
|
||||
}
|
||||
}
|
||||
if (
|
||||
['ss'].includes(original.type) &&
|
||||
['ss', 'ssr'].includes(original.type) &&
|
||||
proxy.shadow_tls &&
|
||||
original['udp-port'] > 0 &&
|
||||
original['udp-port'] <= 65535
|
||||
@@ -727,6 +747,66 @@ function normalizeSnellVersion(version) {
|
||||
return parseInt(normalized, 10);
|
||||
}
|
||||
|
||||
// Egern 的 shadowsocksr 只支持流加密,protocol / obfs 沿用 SSR 上游插件名。
|
||||
const EGERN_SSR_METHODS = [
|
||||
'none',
|
||||
'dummy',
|
||||
'rc4-md5',
|
||||
'aes-128-cfb',
|
||||
'aes-192-cfb',
|
||||
'aes-256-cfb',
|
||||
'aes-128-ctr',
|
||||
'aes-192-ctr',
|
||||
'aes-256-ctr',
|
||||
'chacha20',
|
||||
'chacha20-ietf',
|
||||
'xchacha20',
|
||||
];
|
||||
|
||||
const EGERN_SSR_PROTOCOLS = [
|
||||
'origin',
|
||||
'auth_sha1_v4',
|
||||
'auth_aes128_md5',
|
||||
'auth_aes128_sha1',
|
||||
'auth_chain_a',
|
||||
'auth_chain_b',
|
||||
];
|
||||
|
||||
const EGERN_SSR_OBFS = [
|
||||
'plain',
|
||||
'http_simple',
|
||||
'http_post',
|
||||
'random_head',
|
||||
'tls1.2_ticket_auth',
|
||||
'tls1.2_ticket_fastauth',
|
||||
];
|
||||
|
||||
function normalizeSsrPlugin(value) {
|
||||
if (value == null) return undefined;
|
||||
|
||||
const normalized = `${value}`.trim().toLowerCase();
|
||||
return normalized.length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
function normalizeSsrMethod(cipher) {
|
||||
const method = normalizeSsrPlugin(cipher);
|
||||
// Egern 的空加密写作 none / dummy
|
||||
return method === 'plain' ? 'none' : method;
|
||||
}
|
||||
|
||||
function isEgernSsr(proxy) {
|
||||
if (!EGERN_SSR_METHODS.includes(normalizeSsrMethod(proxy.cipher))) {
|
||||
return false;
|
||||
}
|
||||
// protocol / obfs 留空时由 Egern 补 origin / plain
|
||||
const protocol = normalizeSsrPlugin(proxy.protocol);
|
||||
if (protocol != null && !EGERN_SSR_PROTOCOLS.includes(protocol)) {
|
||||
return false;
|
||||
}
|
||||
const obfs = normalizeSsrPlugin(proxy.obfs);
|
||||
return obfs == null || EGERN_SSR_OBFS.includes(obfs);
|
||||
}
|
||||
|
||||
function getFirstHeaderValue(headers, ...keys) {
|
||||
for (const key of keys) {
|
||||
const value = getFirstValue(headers?.[key]);
|
||||
|
||||
@@ -2804,6 +2804,136 @@ describe('Proxy structured producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('emits Egern shadowsocksr nodes with plugin params and shadow-tls', function () {
|
||||
const proxies = [
|
||||
{
|
||||
type: 'ssr',
|
||||
name: 'Egern SSR Full',
|
||||
server: 'ssr.example.com',
|
||||
port: 8388,
|
||||
cipher: 'AES-128-CFB',
|
||||
password: 'secret',
|
||||
protocol: 'auth_aes128_md5',
|
||||
'protocol-param': '64:Xxxxx',
|
||||
obfs: 'tls1.2_ticket_auth',
|
||||
'obfs-param': 'www.bing.com',
|
||||
udp: true,
|
||||
tfo: true,
|
||||
'block-quic': 'on',
|
||||
'udp-port': 8389,
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'ssr',
|
||||
name: 'Egern SSR Min',
|
||||
server: 'ssr2.example.com',
|
||||
port: 443,
|
||||
cipher: 'plain',
|
||||
password: 'secret',
|
||||
},
|
||||
];
|
||||
|
||||
const internal = produceInternal('Egern', proxies);
|
||||
const external = loadProducedYaml('Egern', proxies);
|
||||
|
||||
for (const output of [internal, external.proxies]) {
|
||||
expect(output).to.have.length(2);
|
||||
expectSubset(output[0], {
|
||||
shadowsocksr: {
|
||||
name: 'Egern SSR Full',
|
||||
server: 'ssr.example.com',
|
||||
port: 8388,
|
||||
method: 'aes-128-cfb',
|
||||
password: 'secret',
|
||||
protocol: 'auth_aes128_md5',
|
||||
protocol_param: '64:Xxxxx',
|
||||
obfs: 'tls1.2_ticket_auth',
|
||||
obfs_param: 'www.bing.com',
|
||||
tfo: true,
|
||||
udp_relay: true,
|
||||
block_quic: true,
|
||||
udp_port: 8389,
|
||||
shadow_tls: {
|
||||
password: 'shadow-pass',
|
||||
sni: 'mask.example.com',
|
||||
},
|
||||
},
|
||||
});
|
||||
// 空加密统一写成 none;protocol / obfs 留空交给 Egern 补 origin / plain
|
||||
expectSubset(output[1], {
|
||||
shadowsocksr: {
|
||||
name: 'Egern SSR Min',
|
||||
method: 'none',
|
||||
},
|
||||
});
|
||||
}
|
||||
expect(external.proxies[1].shadowsocksr).to.not.have.property(
|
||||
'protocol',
|
||||
);
|
||||
expect(external.proxies[1].shadowsocksr).to.not.have.property('obfs');
|
||||
});
|
||||
|
||||
it('skips Egern shadowsocksr with unsupported cipher or plugins', function () {
|
||||
const proxies = [
|
||||
{
|
||||
type: 'ssr',
|
||||
name: 'SSR AEAD',
|
||||
server: 'ssr.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-gcm',
|
||||
password: 'secret',
|
||||
},
|
||||
{
|
||||
type: 'ssr',
|
||||
name: 'SSR Unknown Protocol',
|
||||
server: 'ssr.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-cfb',
|
||||
password: 'secret',
|
||||
protocol: 'auth_chain_c',
|
||||
},
|
||||
{
|
||||
type: 'ssr',
|
||||
name: 'SSR Unknown Obfs',
|
||||
server: 'ssr.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-cfb',
|
||||
password: 'secret',
|
||||
obfs: 'tls1.0_session_auth',
|
||||
},
|
||||
{
|
||||
type: 'ssr',
|
||||
name: 'SSR Healthy',
|
||||
server: 'ssr.example.com',
|
||||
port: 8388,
|
||||
cipher: 'chacha20-ietf',
|
||||
password: 'secret',
|
||||
protocol: 'auth_chain_a',
|
||||
obfs: 'http_simple',
|
||||
},
|
||||
];
|
||||
|
||||
const internal = produceInternal('Egern', proxies);
|
||||
const external = loadProducedYaml('Egern', proxies);
|
||||
|
||||
for (const output of [internal, external.proxies]) {
|
||||
expect(output).to.have.length(1);
|
||||
expectSubset(output[0], {
|
||||
shadowsocksr: {
|
||||
name: 'SSR Healthy',
|
||||
method: 'chacha20-ietf',
|
||||
protocol: 'auth_chain_a',
|
||||
obfs: 'http_simple',
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('emits Egern SSH nodes with auth, host keys, flags, and shadow-tls', function () {
|
||||
const proxies = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user