Skip to content

Commit

Permalink
feat(): add tls13 config support to clash provider
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Jun 13, 2020
1 parent 7f4bb8d commit 481c7e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/provider/ClashProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const logger = createLogger({
export default class ClashProvider extends Provider {
public readonly _url: string;
public readonly udpRelay?: boolean;
public readonly tls13?: boolean;

constructor(name: string, config: ClashProviderConfig) {
super(name, config);
Expand All @@ -45,6 +46,8 @@ export default class ClashProvider extends Provider {
],
})
.required(),
udpRelay: Joi.bool(),
tls13: Joi.bool(),
})
.unknown();

Expand All @@ -56,6 +59,7 @@ export default class ClashProvider extends Provider {

this._url = config.url;
this.udpRelay = config.udpRelay;
this.tls13 = config.tls13;
this.supportGetSubscriptionUserInfo = true;
}

Expand Down Expand Up @@ -85,6 +89,7 @@ export default class ClashProvider extends Provider {
export const getClashSubscription = async (
url: string,
udpRelay?: boolean,
tls13?: boolean,
): Promise<{
readonly nodeList: ReadonlyArray<SupportConfigTypes>;
readonly subscriptionUserinfo?: SubscriptionUserinfo;
Expand Down Expand Up @@ -145,12 +150,16 @@ export const getClashSubscription = async (
}

return {
nodeList: parseClashConfig(proxyList, udpRelay),
nodeList: parseClashConfig(proxyList, udpRelay, tls13),
subscriptionUserinfo: response.subscriptionUserinfo,
};
};

export const parseClashConfig = (proxyList: ReadonlyArray<any>, udpRelay?: boolean): ReadonlyArray<SupportConfigTypes> => {
export const parseClashConfig = (
proxyList: ReadonlyArray<any>,
udpRelay?: boolean,
tls13?: boolean
): ReadonlyArray<SupportConfigTypes> => {
const nodeList: ReadonlyArray<SupportConfigTypes|undefined> = proxyList
.map(item => {
switch (item.type) {
Expand All @@ -176,21 +185,28 @@ export const parseClashConfig = (proxyList: ReadonlyArray<any>, udpRelay?: boole
method: item.cipher,
password: item.password,
'udp-relay': resolveUdpRelay(item.udp, udpRelay),

// obfs-local 新格式
...(item.plugin && item.plugin === 'obfs' ? {
obfs: item['plugin-opts'].mode,
'obfs-host': item['plugin-opts'].host || 'www.bing.com',
} : null),

// obfs-local 旧格式
...(item.obfs ? {
obfs: item.obfs,
'obfs-host': item['obfs-host'] || 'www.bing.com',
} : null),

// v2ray-plugin
...(item.plugin && item.plugin === 'v2ray-plugin' && item['plugin-opts'].mode === 'websocket' ? {
obfs: item['plugin-opts'].tls === true ? 'wss' : 'ws',
'obfs-host': item['plugin-opts'].host || item.server,
'obfs-uri': item['plugin-opts'].path || '/',
wsHeaders,
...(item['plugin-opts'].tls === true ? {
skipCertVerify: item['plugin-opts']['skip-cert-verify'] === true,
tls13: tls13 ?? false,
} : null),
...(typeof item['plugin-opts'].mux === 'boolean' ? {
mux: item['plugin-opts'].mux,
Expand Down Expand Up @@ -226,6 +242,7 @@ export const parseClashConfig = (proxyList: ReadonlyArray<any>, udpRelay?: boole
} : null),
...(item.tls ? {
skipCertVerify: item['skip-cert-verify'] === true,
tls13: tls13 ?? false,
} : null),
} as VmessNodeConfig;
}
Expand All @@ -249,6 +266,7 @@ export const parseClashConfig = (proxyList: ReadonlyArray<any>, udpRelay?: boole
port: item.port,
username: item.username || '',
password: item.password || '',
tls13: tls13 ?? false,
skipCertVerify: item['skip-cert-verify'] === true,
} as HttpsNodeConfig;

Expand Down Expand Up @@ -290,6 +308,7 @@ export const parseClashConfig = (proxyList: ReadonlyArray<any>, udpRelay?: boole
...('alpn' in item ? { alpn: item.alpn } : null),
...('sni' in item ? { sni: item.sni } : null),
...('udp' in item ? { 'udp-relay': item.udp } : null),
tls13: tls13 ?? false,
} as TrojanNodeConfig;

default:
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export interface V2rayNSubscribeProviderConfig extends ProviderConfig {
export interface ClashProviderConfig extends ProviderConfig {
readonly url: string;
readonly udpRelay?: boolean;
readonly tls13?: boolean;
}

export interface CustomProviderConfig extends ProviderConfig {
Expand Down

0 comments on commit 481c7e7

Please sign in to comment.