From b24f071f46a71a8446bd097d2c286b5011cb163b Mon Sep 17 00:00:00 2001 From: Roy Li Date: Fri, 18 Mar 2022 18:32:45 +0100 Subject: [PATCH] feat: add tls-verification to quantumult x vmess config --- lib/utils/index.ts | 50 ++++++++++++++++++++++++++++++---------- test/utils/index.test.ts | 6 ++--- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/utils/index.ts b/lib/utils/index.ts index c441248f9..e7621143b 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -1114,6 +1114,17 @@ export const getQuantumultXNodes = function ( case 'ws': if (nodeConfig.tls) { config.push(`obfs=wss`); + + if (nodeConfig.skipCertVerify) { + config.push('tls-verification=false'); + } else { + config.push('tls-verification=true'); + } + + // istanbul ignore next + if (nodeConfig.tls13) { + config.push(`tls13=true`); + } } else { config.push(`obfs=ws`); } @@ -1121,19 +1132,22 @@ export const getQuantumultXNodes = function ( config.push( `obfs-host=${nodeConfig.host || nodeConfig.hostname}`, ); - // istanbul ignore next - if (nodeConfig.tls13) { - config.push(`tls13=true`); - } break; case 'tcp': if (nodeConfig.tls) { config.push(`obfs=over-tls`); - } - // istanbul ignore next - if (nodeConfig.tls13) { - config.push(`tls13=true`); + + if (nodeConfig.skipCertVerify) { + config.push('tls-verification=false'); + } else { + config.push('tls-verification=true'); + } + + // istanbul ignore next + if (nodeConfig.tls13) { + config.push(`tls13=true`); + } } break; @@ -1175,9 +1189,19 @@ export const getQuantumultXNodes = function ( : []), ...(nodeConfig['udp-relay'] ? [`udp-relay=true`] : []), ...(nodeConfig.tfo ? [`fast-open=${nodeConfig.tfo}`] : []), - ...(nodeConfig.tls13 ? [`tls13=${nodeConfig.tls13}`] : []), - `tag=${nodeConfig.nodeName}`, - ].join(', '); + ]; + + if (nodeConfig.obfs === 'wss') { + if (nodeConfig.skipCertVerify) { + config.push('tls-verification=false'); + } else { + config.push('tls-verification=true'); + } + + if (nodeConfig.tls13) { + config.push('tls13=true'); + } + } // istanbul ignore next if ( @@ -1189,7 +1213,9 @@ export const getQuantumultXNodes = function ( ); } - return `shadowsocks=${config}`; + config.push(`tag=${nodeConfig.nodeName}`); + + return `shadowsocks=${config.join(', ')}`; } case NodeTypeEnum.Shadowsocksr: { diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index c9bc4016b..a46522faf 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -1562,7 +1562,7 @@ test('getQuantumultXNodes', (t) => { ); t.is( schemeList[6], - 'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, aead=false, obfs=over-tls, tag=测试 4', + 'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, aead=false, obfs=over-tls, tls-verification=true, tag=测试 4', ); t.is( @@ -1581,7 +1581,7 @@ test('getQuantumultXNodes', (t) => { uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, ]), - 'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, aead=false, obfs=over-tls, tls13=true, tag=测试', + 'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, aead=false, obfs=over-tls, tls-verification=true, tls13=true, tag=测试', ); t.is( @@ -1603,7 +1603,7 @@ test('getQuantumultXNodes', (t) => { }, }, ]), - 'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, aead=true, obfs=over-tls, tls13=true, tag=测试', + 'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, aead=true, obfs=over-tls, tls-verification=true, tls13=true, tag=测试', ); t.is( utils.getQuantumultXNodes([