Skip to content

Commit eb4ae8d

Browse files
author
Neko
committed
Add handshake mechainism
1 parent f14d20a commit eb4ae8d

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

build/server/aplvpn/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ function handleAppleVPN(client, handshakeData, options) {
3838
catch (error) {
3939
return false;
4040
}
41-
if (addrHelper.isIllegalAddress(handshake.destHost)) {
42-
client.dispose();
43-
return true;
44-
}
45-
if (handshake.flags === 0x00) {
41+
if (handshake.flags === 0x00 && handshake.destHost === '0.0.0.0' && handshake.destPort === 0) {
4642
try {
4743
yield handleHandshake(client, handshake, options);
4844
}
@@ -51,6 +47,10 @@ function handleAppleVPN(client, handshakeData, options) {
5147
}
5248
return true;
5349
}
50+
if (addrHelper.isIllegalAddress(handshake.destHost)) {
51+
client.dispose();
52+
return true;
53+
}
5454
switch (handshake.payloadProtocol) {
5555
case protocols_1.Protocols.TCP:
5656
tcp_1.handleTCP(client, handshake, options);
@@ -79,6 +79,6 @@ function handleHandshake(client, handshake, options) {
7979
let cipher = cryptoEx.createCipher(options.cipherAlgorithm, options.password, handshake.extra).cipher;
8080
let md5 = crypto.createHash('md5').update(handshake.extra).digest();
8181
let randomPadding = new Buffer(Number((Math.random() * 128).toFixed()));
82-
yield client.writeAsync(Buffer.concat([md5, randomPadding]));
82+
yield client.writeAsync(Buffer.concat([cipher.update(md5), cipher.update(randomPadding)]));
8383
});
8484
}

server/aplvpn/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ export async function handleAppleVPN(client: net.Socket, handshakeData: Buffer,
3939
return false;
4040
}
4141

42-
if (addrHelper.isIllegalAddress(handshake.destHost)) {
43-
client.dispose();
42+
if (handshake.flags === 0x00 && handshake.destHost === '0.0.0.0' && handshake.destPort === 0) {
43+
try { await handleHandshake(client, handshake, options); } catch (error) { return false; }
4444
return true;
4545
}
4646

47-
if (handshake.flags === 0x00) {
48-
try { await handleHandshake(client, handshake, options); } catch (error) { return false; }
47+
if (addrHelper.isIllegalAddress(handshake.destHost)) {
48+
client.dispose();
4949
return true;
5050
}
5151

@@ -79,5 +79,6 @@ async function handleHandshake(client: net.Socket, handshake: VpnHandshake, opti
7979
let cipher = cryptoEx.createCipher(options.cipherAlgorithm, options.password, handshake.extra).cipher;
8080
let md5 = crypto.createHash('md5').update(handshake.extra).digest();
8181
let randomPadding = new Buffer(Number((Math.random() * 128).toFixed()));
82-
await client.writeAsync(Buffer.concat([md5, randomPadding]));
82+
83+
await client.writeAsync(Buffer.concat([cipher.update(md5), cipher.update(randomPadding)]));
8384
}

0 commit comments

Comments
 (0)