some fixes

This commit is contained in:
OfficialDakari 2024-04-30 11:28:45 +05:00
parent 056f7eef54
commit 2036c3be62
1 changed files with 52 additions and 72 deletions

View File

@ -32,7 +32,7 @@ tun.on('data', (buff) => {
const user = Object.values(config.users).find(x => x.addr == p.destinationIp);
//(user);
if (!user) return;
const targetIp = Object.entries(conns).find(x => x[1] == user.username)[0];
const targetIp = ips[user.username];
const targetPort = ports[user.username];
//(targetIp, targetPort);
if (!targetIp || !targetPort) return;
@ -45,40 +45,21 @@ sock.on('listening', () => {
});
sock.on('message', (msg, info) => {
if (!conns[info.address]) {
for (const uname in config.users) {
const u = config.users[uname];
const dec = decrypt(msg, u.key, config.iv, config.algorithm);
if (dec.length == 2 && dec[0] == 0x13 && dec[1] == 0x37) {
conns[info.address] = uname;
var dec;
var uname;
var acc;
for (const un in config.users) {
const u = config.users[un];
dec = decrypt(msg, u.key, config.iv, config.algorithm);
if (dec.length != 0) {
uname = un;
acc = u;
break;
}
}
ips[uname] = info.address;
const spl = u.addr.split('.').map(s => parseInt(s));
const buff = Buffer.from([
0x13,
0xb4,
0x37,
...spl
]);
const enc = encrypt(buff, u.key, config.iv, config.algorithm);
sock.send(enc, info.port, info.address);
return;
}
}
const buff = Buffer.from([
0xe7,
0x5a,
0x3d,
0xed
]);
const enc = encrypt(buff, config.globalKey, config.iv, config.algorithm);
sock.send(enc, info.port, info.address);
return;
} else {
const uname = conns[info.address];
ports[uname] = info.port;
ips[uname] = info.address;
const acc = config.users[uname];
const dec = decrypt(msg, acc.key, config.iv, config.algorithm);
//const dec = decrypt(msg, acc.key, config.iv, config.algorithm);
//(dec);
if (dec.length == 0) {
console.error(`Empty or malformed packet from ${uname}`);
@ -120,11 +101,10 @@ sock.on('message', (msg, info) => {
}
const user = Object.values(config.users).find(x => x.addr == packet.destinationIp);
if (!user) return;
const targetIp = conns[user.username];
const targetIp = ips[user.username];
const targetPort = ports[user.username];
if (!targetIp || !targetPort) return;
sock.send(encrypt(dec, user.key, config.iv, config.algorithm), targetPort, targetIp);
}
});
sock.bind(config.port);