mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 00:29:20 +02:00
the seed wasnt saved in the server between it was sent to the client and the client logged in, extracted function for sending version_responses
This commit is contained in:
parent
a49e400ea9
commit
c538bd0b6d
|
@ -67,68 +67,91 @@ sigint(int sig)
|
||||||
static int
|
static int
|
||||||
tunnel_tun(int tun_fd, int dns_fd)
|
tunnel_tun(int tun_fd, int dns_fd)
|
||||||
{
|
{
|
||||||
|
unsigned long outlen;
|
||||||
char out[64*1024];
|
char out[64*1024];
|
||||||
char in[64*1024];
|
char in[64*1024];
|
||||||
long outlen;
|
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
|
if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
outlen = sizeof(out);
|
outlen = sizeof(out);
|
||||||
compress2(out, &outlen, in, read, 9);
|
compress2((uint8_t*)out, &outlen, (uint8_t*)in, read, 9);
|
||||||
memcpy(outpacket.data, out, outlen);
|
memcpy(outpacket.data, out, outlen);
|
||||||
outpacket.len = outlen;
|
outpacket.len = outlen;
|
||||||
|
|
||||||
return outlen;
|
return outlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VERSION_ACK,
|
||||||
|
VERSION_NACK
|
||||||
|
} version_ack_t;
|
||||||
|
|
||||||
|
static void
|
||||||
|
send_version_response(int fd, version_ack_t ack, uint32_t payload)
|
||||||
|
{
|
||||||
|
char out[8];
|
||||||
|
|
||||||
|
switch (ack) {
|
||||||
|
case VERSION_ACK:
|
||||||
|
strncpy(out, "VACK", sizeof(out));
|
||||||
|
break;
|
||||||
|
case VERSION_NACK:
|
||||||
|
strncpy(out, "VNAK", sizeof(out));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
out[4] = ((payload >> 24) & 0xff);
|
||||||
|
out[5] = ((payload >> 16) & 0xff);
|
||||||
|
out[6] = ((payload >> 8) & 0xff);
|
||||||
|
out[7] = ((payload) & 0xff);
|
||||||
|
|
||||||
|
write_dns(fd, &q, out, 8);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tunnel_dns(int tun_fd, int dns_fd)
|
tunnel_dns(int tun_fd, int dns_fd)
|
||||||
{
|
{
|
||||||
struct in_addr clientip;
|
struct in_addr clientip;
|
||||||
|
unsigned long outlen;
|
||||||
struct in_addr myip;
|
struct in_addr myip;
|
||||||
char logindata[16];
|
char logindata[16];
|
||||||
char out[64*1024];
|
char out[64*1024];
|
||||||
char in[64*1024];
|
char in[64*1024];
|
||||||
|
static int seed;
|
||||||
char *tmp[2];
|
char *tmp[2];
|
||||||
long outlen;
|
int version;
|
||||||
int read;
|
int read;
|
||||||
int code;
|
int code;
|
||||||
int version;
|
|
||||||
int seed;
|
|
||||||
int nseed;
|
|
||||||
|
|
||||||
if ((read = read_dns(dns_fd, &q, in, sizeof(in))) <= 0)
|
if ((read = read_dns(dns_fd, &q, in, sizeof(in))) <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(in[0] == 'V' || in[0] == 'v') {
|
if(in[0] == 'V' || in[0] == 'v') {
|
||||||
/* Version greeting, compare and send ack/nak */
|
/* Version greeting, compare and send ack/nak */
|
||||||
if (read >= 5) {
|
if (read > 4) {
|
||||||
/* Received V + 32bits version */
|
/* Received V + 32bits version */
|
||||||
memcpy(&version, in + 1, 4);
|
|
||||||
version = ntohl(version);
|
version = (((in[1] & 0xff) << 24) |
|
||||||
|
((in[2] & 0xff) << 16) |
|
||||||
|
((in[3] & 0xff) << 8) |
|
||||||
|
((in[4] & 0xff)));
|
||||||
|
|
||||||
if (version == VERSION) {
|
if (version == VERSION) {
|
||||||
seed = rand();
|
seed = rand();
|
||||||
nseed = htonl(seed);
|
|
||||||
strncpy(out, "VACK", sizeof(out));
|
send_version_response(dns_fd, VERSION_ACK, seed);
|
||||||
memcpy(out+4, &nseed, 4);
|
|
||||||
write_dns(dns_fd, &q, out, 8);
|
|
||||||
} else {
|
} else {
|
||||||
version = htonl(VERSION);
|
send_version_response(dns_fd, VERSION_NACK, VERSION);
|
||||||
strncpy(out, "VNAK", sizeof(out));
|
|
||||||
memcpy(out+4, &version, 4);
|
|
||||||
write_dns(dns_fd, &q, out, 8);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
version = htonl(VERSION);
|
send_version_response(dns_fd, VERSION_NACK, VERSION);
|
||||||
strncpy(out, "VNAK", sizeof(out));
|
|
||||||
memcpy(out+4, &version, 4);
|
|
||||||
write_dns(dns_fd, &q, out, 8);
|
|
||||||
}
|
}
|
||||||
} else if(in[0] == 'L' || in[0] == 'l') {
|
} else if(in[0] == 'L' || in[0] == 'l') {
|
||||||
/* Login phase, handle auth */
|
/* Login phase, handle auth */
|
||||||
login_calculate(logindata, 16, password, seed);
|
login_calculate(logindata, 16, password, seed);
|
||||||
|
|
||||||
if (read >= 17 && (memcmp(logindata, in+1, 16) == 0)) {
|
if (read >= 17 && (memcmp(logindata, in+1, 16) == 0)) {
|
||||||
/* Login ok, send ip/mtu info */
|
/* Login ok, send ip/mtu info */
|
||||||
myip.s_addr = my_ip;
|
myip.s_addr = my_ip;
|
||||||
|
@ -173,7 +196,8 @@ tunnel_dns(int tun_fd, int dns_fd)
|
||||||
|
|
||||||
if (code & 1) {
|
if (code & 1) {
|
||||||
outlen = sizeof(out);
|
outlen = sizeof(out);
|
||||||
uncompress(out, &outlen, packetbuf.data, packetbuf.len);
|
uncompress((uint8_t*)out, &outlen,
|
||||||
|
(uint8_t*)packetbuf.data, packetbuf.len);
|
||||||
|
|
||||||
write_tun(tun_fd, out, outlen);
|
write_tun(tun_fd, out, outlen);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue