Skip to content

Commit

Permalink
feat: add support for QuantumultX vmess AEAD config
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Jan 11, 2022
1 parent 718caf9 commit 1e02c49
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 56 deletions.
7 changes: 7 additions & 0 deletions docs/guide/custom-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ module.exports = {
};
```

#### quantumultXConfig.vmessAEAD

- 类型: `boolean`
- 默认值: `true`

默认开启 Vmess AEAD 加密,如果您的服务器不支持 AEAD 加密,请关闭。

### clashConfig

- 类型: `object`
Expand Down
6 changes: 0 additions & 6 deletions docs/guide/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ sidebarDepth: 2
### `SURGIO_PROVIDER_CACHE_MAXAGE`

- 默认值: `600000`(10 分钟)

### `SURGIO_DISABLE_SURGE_VMESS_AEAD`

- 默认值: `false`

是否关闭 Surge Vmess AEAD 加密。默认开启,如果您的服务器不支持 AEAD 加密,请关闭(`SURGIO_DISABLE_SURGE_VMESS_AEAD=true`)。
3 changes: 0 additions & 3 deletions lib/constant/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ export const ENV_SURGIO_REMOTE_SNIPPET_CACHE_MAXAGE =
'SURGIO_REMOTE_SNIPPET_CACHE_MAXAGE';

export const ENV_SURGIO_PROVIDER_CACHE_MAXAGE = 'SURGIO_PROVIDER_CACHE_MAXAGE';

export const ENV_SURGIO_DISABLE_SURGE_VMESS_AEAD =
'SURGIO_DISABLE_SURGE_VMESS_AEAD';
1 change: 1 addition & 0 deletions lib/generator/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export class Artifact extends EventEmitter {
nodeConfig.provider = provider;
nodeConfig.surgeConfig = config.surgeConfig;
nodeConfig.clashConfig = config.clashConfig;
nodeConfig.quantumultXConfig = config.quantumultXConfig;

if (provider.renameNode) {
const newName = provider.renameNode(nodeConfig.nodeName);
Expand Down
2 changes: 2 additions & 0 deletions lib/misc/deprecation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export const DEP005 =
export const DEP006 =
'surgioConfig.surgeConfig.v2ray: "external" 已不推荐使用,请改为 "native"';
export const DEP007 = 'patchYamlArray 已不推荐使用,请改为 clash';
export const DEP008 =
'surgioConfig.clashConfig.ssrFormat: "legacy" 会在后续版本中移出,请使用原版 Clash 客户端';
6 changes: 5 additions & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ export interface CommandConfig {
readonly shadowsocksFormat?: 'ss' | 'custom';
readonly v2ray?: 'native' | 'external';
readonly resolveHostname?: boolean;
readonly vmessAEAD?: boolean;
};
readonly quantumultXConfig?: {
readonly vmessAEAD?: boolean;
};
readonly quantumultXConfig?: any;
readonly clashConfig?: {
readonly ssrFormat: 'native' | 'legacy';
};
Expand Down Expand Up @@ -275,6 +278,7 @@ export interface SimpleNodeConfig {
localPort?: number;
surgeConfig?: CommandConfig['surgeConfig'];
clashConfig?: CommandConfig['clashConfig'];
quantumultXConfig?: CommandConfig['quantumultXConfig'];
hostnameIp?: ReadonlyArray<string>;
provider?: Provider;
underlyingProxy?: string;
Expand Down
17 changes: 15 additions & 2 deletions lib/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';
import path from 'path';
import { URL } from 'url';
import { deprecate } from 'util';
import { DEP005, DEP006 } from '../misc/deprecation';
import { DEP005, DEP006, DEP008 } from '../misc/deprecation';

import { CommandConfig } from '../types';
import { PROXY_TEST_INTERVAL, PROXY_TEST_URL } from '../constant';
Expand All @@ -13,6 +13,7 @@ import { ensureConfigFolder } from './index';

const showDEP005 = deprecate(_.noop, DEP005, 'DEP005');
const showDEP006 = deprecate(_.noop, DEP006, 'DEP006');
const showDEP008 = deprecate(_.noop, DEP008, 'DEP008');

export const loadConfig = (
cwd: string,
Expand Down Expand Up @@ -72,10 +73,14 @@ export const normalizeConfig = (
shadowsocksFormat: 'ss',
v2ray: 'native',
resolveHostname: false,
vmessAEAD: false,
},
clashConfig: {
ssrFormat: 'native',
},
quantumultXConfig: {
vmessAEAD: true,
},
proxyTestUrl: PROXY_TEST_URL,
proxyTestInterval: PROXY_TEST_INTERVAL,
checkHostname: false,
Expand Down Expand Up @@ -112,6 +117,11 @@ export const normalizeConfig = (
showDEP006();
}

// istanbul ignore next
if (config.clashConfig?.ssrFormat === 'legacy') {
showDEP008();
}

return config;
};

Expand Down Expand Up @@ -162,8 +172,11 @@ export const validateConfig = (userConfig: Partial<CommandConfig>): void => {
shadowsocksFormat: Joi.string().valid('ss', 'custom'),
v2ray: Joi.string().valid('native', 'external'),
resolveHostname: Joi.boolean().strict(),
vmessAEAD: Joi.boolean().strict(),
}).unknown(),
quantumultXConfig: Joi.object({
vmessAEAD: Joi.boolean().strict(),
}).unknown(),
quantumultXConfig: Joi.object({}).unknown(),
clashConfig: Joi.object({
ssrFormat: Joi.string().valid('native', 'legacy'),
}).unknown(),
Expand Down
6 changes: 0 additions & 6 deletions lib/utils/env-flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ms from 'ms';
import {
ENV_NETWORK_RESOLVE_TIMEOUT,
ENV_NETWORK_TIMEOUT_KEY,
ENV_SURGIO_DISABLE_SURGE_VMESS_AEAD,
ENV_SURGIO_NETWORK_CLASH_UA,
ENV_SURGIO_NETWORK_CONCURRENCY,
ENV_SURGIO_NETWORK_RETRY,
Expand Down Expand Up @@ -43,8 +42,3 @@ export const getProviderCacheMaxage = (): number =>
process.env[ENV_SURGIO_PROVIDER_CACHE_MAXAGE]
? Number(process.env[ENV_SURGIO_PROVIDER_CACHE_MAXAGE])
: ms('10m');

export const getSurgeVmessAEADDisabled = (): boolean => {
const value = process.env[ENV_SURGIO_DISABLE_SURGE_VMESS_AEAD];
return value === 'true' || value === '1';
};
10 changes: 6 additions & 4 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from '../types';
import { ConfigCache } from './cache';
import { ERR_INVALID_FILTER, OBFS_UA } from '../constant';
import { getSurgeVmessAEADDisabled } from './env-flag';
import { validateFilter } from './filter';
import httpClient from './http-client';
import { formatVmessUri } from './v2ray';
Expand Down Expand Up @@ -415,10 +414,10 @@ export const getSurgeNodes = function (
configList.push(`test-url=${config['testUrl']}`);
}

if (getSurgeVmessAEADDisabled()) {
configList.push('vmess-aead=false');
} else {
if (nodeConfig?.surgeConfig?.vmessAEAD) {
configList.push('vmess-aead=true');
} else {
configList.push('vmess-aead=false');
}

return [config.nodeName, configList.join(', ')].join(' = ');
Expand Down Expand Up @@ -1101,6 +1100,9 @@ export const getQuantumultXNodes = function (
`password=${nodeConfig.uuid}`,
...(nodeConfig['udp-relay'] ? ['udp-relay=true'] : []),
...(nodeConfig.tfo ? ['fast-open=true'] : []),
...(nodeConfig.quantumultXConfig?.vmessAEAD
? ['aead=true']
: ['aead=false']),
];

switch (nodeConfig.network) {
Expand Down
Loading

0 comments on commit 1e02c49

Please sign in to comment.