/* Authentication (Client side) */ int auth_client(int fd, struct vtun_host *host, int * reason) { char buf[VTUN_MESG_SIZE], chal[VTUN_CHAL_SIZE]; int stage, success=0 ; stage = ST_INIT; *reason = D_NOREAD; while( readn_t(fd, buf, VTUN_MESG_SIZE, vtun.timeout) > 0 ){ *reason = D_OTHER; buf[sizeof(buf)-1]='\0'; switch( stage ){ case ST_INIT: if (!strncmp(buf, "VTRUNKD", 7)) { stage = ST_HOST; print_p(fd,"HOST: %s\n",host->host); continue; } *reason = D_GREET; break; case ST_HOST: if( !strncmp(buf,"OK",2) && cs2cl(buf,chal)){ stage = ST_CHAL; encrypt_chal(chal,host->passwd); print_p(fd,"CHAL: %s\n", cl2cs(chal)); continue; } *reason = D_CHAL; break; case ST_CHAL: if( !strncmp(buf,"OK",2) && cf2bf(buf,host) ) success = 1; else *reason = D_PWD; break; } break; } return success; }
void inline decrypt_chal(char *chal, char *pwd) { encrypt_chal(chal, pwd); }
void decrypt_chal(char *chal, char *pwd) { encrypt_chal(chal, pwd); }