Skip to content

Commit

Permalink
fix: vmess cipher
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Mar 16, 2024
1 parent f09a66e commit 1618630
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/index.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Generated by [AVA](https://avajs.dev).
hkFilter: Function hkFilter {},
httpFilter: Function httpFilter {},
httpsFilter: Function httpsFilter {},
hysteria2Filter: Function hysteria2Filter {},
isAWS: Function isAWS {},
isAWSLambda: Function isAWSLambda {},
isClash: Function isClash {},
Expand Down Expand Up @@ -61,6 +62,7 @@ Generated by [AVA](https://avajs.dev).
useSortedKeywords: Function useSortedKeywords {},
v2rayFilter: Function v2rayFilter {},
validateFilter: Function validateFilter {},
vlessFilter: Function vlessFilter {},
vmessFilter: Function vmessFilter {},
wireguardFilter: Function wireguardFilter {},
youtubePremiumFilter: Function {},
Expand Down
Binary file modified src/__tests__/__snapshots__/index.test.ts.snap
Binary file not shown.
3 changes: 3 additions & 0 deletions src/filters/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const chinaBackFilter: NodeFilterType = (item) => {
'中国上海',
'中国北京',
'中国徐州',
'中国广州',
'中国东莞',
'中国中山',
'中国深圳',
'中国枣庄',
'中国郑州',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/loon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('getLoonNodes', (t) => {
},
},
]),
'测试 = vmess,1.1.1.1,443,method=chacha20-ietf-poly1305,"1386f85e-657b-4d6e-9d56-78badb75e1fd",transport=ws,path=/test,over-tls=true',
'测试 = vmess,1.1.1.1,443,method=chacha20-poly1305,"1386f85e-657b-4d6e-9d56-78badb75e1fd",transport=ws,path=/test,over-tls=true',
)
t.is(
getLoonNodes([
Expand Down
33 changes: 26 additions & 7 deletions src/utils/__tests__/quantumult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ test('getQuantumultXNodes', (t) => {

t.is(
schemeList[0],
'vmess=1.1.1.1:8080, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, obfs=ws, obfs-uri=/, obfs-host=example.com, tag=测试 1',
'vmess=1.1.1.1:8080, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, obfs=ws, obfs-uri=/, obfs-host=example.com, tag=测试 1',
)
t.is(
schemeList[1],
'vmess=1.1.1.1:8080, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, tag=测试 2',
'vmess=1.1.1.1:8080, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, tag=测试 2',
)
t.is(
schemeList[2],
'vmess=1.1.1.1:8080, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, tag=测试 3',
'vmess=1.1.1.1:8080, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, tag=测试 3',
)
t.is(
schemeList[3],
Expand All @@ -124,7 +124,7 @@ test('getQuantumultXNodes', (t) => {
)
t.is(
schemeList[6],
'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, obfs=over-tls, tls-verification=true, tag=测试 4',
'vmess=1.1.1.1:443, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, obfs=over-tls, tls-verification=true, tag=测试 4',
)

t.is(
Expand All @@ -143,7 +143,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, obfs=over-tls, tls-verification=true, tls13=true, tag=测试',
'vmess=1.1.1.1:443, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=over-tls, tls-verification=true, tls13=true, tag=测试',
)

t.is(
Expand All @@ -165,7 +165,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, tls-verification=true, tls13=true, tag=测试',
'vmess=1.1.1.1:443, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, aead=true, obfs=over-tls, tls-verification=true, tls13=true, tag=测试',
)
t.is(
quantumult.getQuantumultXNodes([
Expand Down Expand Up @@ -294,8 +294,27 @@ test('getQuantumultXNodes', (t) => {
testUrl: 'http://example.com',
},
]),
'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, server_check_url=http://example.com, tag=测试',
'vmess=1.1.1.1:443, method=chacha20-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, aead=true, obfs=over-tls, tls-verification=true, tls13=true, server_check_url=http://example.com, tag=测试',
)

t.is(
quantumult.getQuantumultXNodes([
{
type: NodeTypeEnum.Vless,
hostname: '1.1.1.1',
network: 'tcp',
nodeName: '测试',
method: 'none',
port: 443,
tls13: true,
udpRelay: true,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
testUrl: 'http://example.com',
},
]),
'vless=1.1.1.1:443, method=none, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=over-tls, tls-verification=true, tls13=true, server_check_url=http://example.com, tag=测试',
)

t.is(
quantumult.getQuantumultXNodes([
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils/loon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const getLoonNodes = function (
nodeConfig.hostname,
nodeConfig.port,
nodeConfig.method === 'auto'
? `method=chacha20-ietf-poly1305`
? `method=chacha20-poly1305`
: `method=${nodeConfig.method}`,
JSON.stringify(nodeConfig.uuid),
`transport=${nodeConfig.network}`,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/quantumult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function nodeListMapper(
`${nodeConfig.hostname}:${nodeConfig.port}`,
// method 为 auto 时 qx 会无法识别
nodeConfig.method === 'auto'
? `method=chacha20-ietf-poly1305`
? `method=chacha20-poly1305`
: `method=${nodeConfig.method}`,
`password=${nodeConfig.uuid}`,
...(nodeConfig.udpRelay ? ['udp-relay=true'] : []),
Expand Down
12 changes: 6 additions & 6 deletions src/utils/surge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ function nodeListMapper(
`username=${nodeConfig.uuid}`,
]

if (
['chacha20-ietf-poly1305', 'aes-128-gcm', 'chacha20-poly1305'].includes(
nodeConfig.method,
)
) {
result.push(`encrypt-method=${nodeConfig.method}`)
if (['chacha20-poly1305', 'aes-128-gcm'].includes(nodeConfig.method)) {
if (nodeConfig.method === 'chacha20-poly1305') {
result.push(`encrypt-method=chacha20-ietf-poly1305`)
} else {
result.push(`encrypt-method=${nodeConfig.method}`)
}
}

if (nodeConfig.network === 'ws') {
Expand Down
1 change: 0 additions & 1 deletion src/validators/vmess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const VmessNetworkValidator = z.union([
export const VmessMethodValidator = z.union([
z.literal('none'),
z.literal('aes-128-gcm'),
z.literal('chacha20-ietf-poly1305'),
z.literal('chacha20-poly1305'),
z.literal('auto'),
])
Expand Down

0 comments on commit 1618630

Please sign in to comment.