--- ansh/src/utils.c 2011/10/07 13:41:26 1.1.1.1.2.1 +++ ansh/src/utils.c 2011/10/10 09:11:48 1.1.1.1.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: utils.c,v 1.1.1.1.2.1 2011/10/07 13:41:26 misho Exp $ + * $Id: utils.c,v 1.1.1.1.2.2 2011/10/10 09:11:48 misho Exp $ * *************************************************************************/ #include "global.h" @@ -218,7 +218,7 @@ icmpSend(int s, u_short id, char flg, u_int crypted, u } 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 }; struct ether_header *e = (struct ether_header*) buf; @@ -239,6 +239,7 @@ pktSend(int s, u_short id, char flg, u_char *data, int hdr->ansh_ver = ANSH_VERSION; hdr->ansh_flg = flg; hdr->ansh_len = htons(datlen + sizeof(struct ansh_hdr)); + hdr->ansh_nonce = htonl(crypted); hdr->ansh_crc = 0; hdr->ansh_crc = htonl(crcAdler((u_char*) hdr, ntohs(hdr->ansh_len))); @@ -257,7 +258,8 @@ pktSend(int s, u_short id, char flg, u_char *data, int } 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; struct bpf_hdr *bpf; @@ -300,6 +302,19 @@ pktRecv(int s, u_char * __restrict data, int * __restr free(buf); 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 */ crc = hdr->ansh_crc; hdr->ansh_crc ^= hdr->ansh_crc;