|
version 1.1.1.1, 2011/10/04 22:37:46
|
version 1.1.1.1.2.2, 2011/10/10 09:11:48
|
|
Line 101 PrepareL3(const struct sockaddr *sa, int *bpflen)
|
Line 101 PrepareL3(const struct sockaddr *sa, int *bpflen)
|
| } |
} |
| |
|
| char |
char |
| icmpRecv(int s, u_short * __restrict id, u_char * __restrict data, | icmpRecv(int s, u_short * __restrict id, u_int * __restrict crypted, u_char * __restrict data, |
| int * __restrict datlen, struct sockaddr *sa, socklen_t *salen) |
int * __restrict datlen, struct sockaddr *sa, socklen_t *salen) |
| { |
{ |
| int ret = 0; |
int ret = 0; |
|
Line 136 icmpRecv(int s, u_short * __restrict id, u_char * __re
|
Line 136 icmpRecv(int s, u_short * __restrict id, u_char * __re
|
| VERB(3) LOG("Packet with wrong version ..."); |
VERB(3) LOG("Packet with wrong version ..."); |
| return ANSH_FLG_ERR; |
return ANSH_FLG_ERR; |
| } |
} |
| |
if (crypted) { |
| |
if (hdr->ansh_nonce && !*crypted) { |
| |
VERB(3) LOG("Channel INSECURED:: Crypted communication not supported at this moment ..."); |
| |
return ANSH_FLG_ERR; |
| |
} |
| |
if (!hdr->ansh_nonce && *crypted) { |
| |
VERB(3) LOG("Channel SECURED:: Plain text communication not supported at this moment ..."); |
| |
return ANSH_FLG_ERR; |
| |
} |
| |
|
| |
*crypted = ntohl(hdr->ansh_nonce); |
| |
} |
| |
|
| /* check crc of packet */ |
/* check crc of packet */ |
| crc = hdr->ansh_crc; |
crc = hdr->ansh_crc; |
| hdr->ansh_crc ^= hdr->ansh_crc; |
hdr->ansh_crc ^= hdr->ansh_crc; |
|
Line 159 icmpRecv(int s, u_short * __restrict id, u_char * __re
|
Line 171 icmpRecv(int s, u_short * __restrict id, u_char * __re
|
| } |
} |
| |
|
| int |
int |
| icmpSend(int s, u_short id, char flg, u_char *data, int datlen, struct sockaddr *sa, socklen_t salen) | icmpSend(int s, u_short id, char flg, u_int crypted, u_char *data, int datlen, struct sockaddr *sa, socklen_t salen) |
| { |
{ |
| u_char *pos, buf[USHRT_MAX] = { 0 }; |
u_char *pos, buf[USHRT_MAX] = { 0 }; |
| struct icmp *icmp; |
struct icmp *icmp; |
|
Line 179 icmpSend(int s, u_short id, char flg, u_char *data, in
|
Line 191 icmpSend(int s, u_short id, char flg, u_char *data, in
|
| hdr->ansh_ver = ANSH_VERSION; |
hdr->ansh_ver = ANSH_VERSION; |
| hdr->ansh_flg = flg; |
hdr->ansh_flg = flg; |
| hdr->ansh_len = htons(datlen + sizeof(struct ansh_hdr)); |
hdr->ansh_len = htons(datlen + sizeof(struct ansh_hdr)); |
| |
hdr->ansh_nonce = htonl(crypted); |
| hdr->ansh_crc = 0; |
hdr->ansh_crc = 0; |
| hdr->ansh_crc = htonl(crcAdler((u_char*) hdr, ntohs(hdr->ansh_len))); |
hdr->ansh_crc = htonl(crcAdler((u_char*) hdr, ntohs(hdr->ansh_len))); |
| |
|
|
Line 205 icmpSend(int s, u_short id, char flg, u_char *data, in
|
Line 218 icmpSend(int s, u_short id, char flg, u_char *data, in
|
| } |
} |
| |
|
| int |
int |
| pktSend(int s, u_short id, char flg, u_char *data, int datlen, struct ether_addr *ea) | pktSend(int s, u_short id, char flg, u_int crypted, u_char *data, int datlen, struct ether_addr *ea) |
| { |
{ |
| u_char *pos, buf[USHRT_MAX] = { 0 }; |
u_char *pos, buf[USHRT_MAX] = { 0 }; |
| struct ether_header *e = (struct ether_header*) buf; |
struct ether_header *e = (struct ether_header*) buf; |
|
Line 226 pktSend(int s, u_short id, char flg, u_char *data, int
|
Line 239 pktSend(int s, u_short id, char flg, u_char *data, int
|
| hdr->ansh_ver = ANSH_VERSION; |
hdr->ansh_ver = ANSH_VERSION; |
| hdr->ansh_flg = flg; |
hdr->ansh_flg = flg; |
| hdr->ansh_len = htons(datlen + sizeof(struct ansh_hdr)); |
hdr->ansh_len = htons(datlen + sizeof(struct ansh_hdr)); |
| |
hdr->ansh_nonce = htonl(crypted); |
| hdr->ansh_crc = 0; |
hdr->ansh_crc = 0; |
| hdr->ansh_crc = htonl(crcAdler((u_char*) hdr, ntohs(hdr->ansh_len))); |
hdr->ansh_crc = htonl(crcAdler((u_char*) hdr, ntohs(hdr->ansh_len))); |
| |
|
|
Line 244 pktSend(int s, u_short id, char flg, u_char *data, int
|
Line 258 pktSend(int s, u_short id, char flg, u_char *data, int
|
| } |
} |
| |
|
| char |
char |
| pktRecv(int s, u_char * __restrict data, int * __restrict datlen, struct ether_header *eth) | pktRecv(int s, u_int * __restrict crypted, u_char * __restrict data, int * __restrict datlen, |
| | struct ether_header *eth) |
| { |
{ |
| int ret = 0; |
int ret = 0; |
| struct bpf_hdr *bpf; |
struct bpf_hdr *bpf; |
|
Line 287 pktRecv(int s, u_char * __restrict data, int * __restr
|
Line 302 pktRecv(int s, u_char * __restrict data, int * __restr
|
| free(buf); |
free(buf); |
| return ANSH_FLG_ERR; |
return ANSH_FLG_ERR; |
| } |
} |
| |
if (crypted) { |
| |
if (hdr->ansh_nonce && !*crypted) { |
| |
VERB(3) LOG("Channel INSECURED:: Crypted communication not supported at this moment ..."); |
| |
return ANSH_FLG_ERR; |
| |
} |
| |
if (!hdr->ansh_nonce && *crypted) { |
| |
VERB(3) LOG("Channel SECURED:: Plain text communication not supported at this moment ..."); |
| |
return ANSH_FLG_ERR; |
| |
} |
| |
|
| |
*crypted = ntohl(hdr->ansh_nonce); |
| |
} |
| |
|
| /* check crc of packet */ |
/* check crc of packet */ |
| crc = hdr->ansh_crc; |
crc = hdr->ansh_crc; |
| hdr->ansh_crc ^= hdr->ansh_crc; |
hdr->ansh_crc ^= hdr->ansh_crc; |
|
Line 326 TOfunc(sched_task_t *task)
|
Line 354 TOfunc(sched_task_t *task)
|
| return NULL; |
return NULL; |
| } |
} |
| |
|
| |
u_char * |
| |
cryptBuffer(u_char *buf, int rlen, u_int ctr) |
| |
{ |
| |
u_char *str, ivec[AES_BLOCK_SIZE] = { 0 }; |
| |
u_int rctr = htonl(ctr); |
| |
|
| |
FTRACE(3); |
| |
|
| |
if (!buf) |
| |
return NULL; |
| |
|
| |
memcpy(ivec, &ctr, sizeof ctr); |
| |
memcpy(ivec + 4, &rctr, sizeof rctr); |
| |
memcpy(ivec + 8, &ctr, sizeof ctr); |
| |
memcpy(ivec + 12, &rctr, sizeof rctr); |
| |
|
| |
if (io_ctr_AES(buf, rlen, &str, (u_char*) "_ansh_ELWIX_", ivec) == -1) |
| |
return NULL; |
| |
|
| |
return str; |
| |
} |