
Originally Posted by
jansenjw
Hi
I am trying to write a newcamd card server client, but have trouble logging in. Somehow there is an issue with the DES encryption. The protocol in protocol.txt is very vague around the encryption of the packet and the sample source code does not really help either. ANyone has some knowledge about the newcamd client?
Thanks!
Here is the code snippet:
//LOGIN
char salt[]="$1$abcdefgh$"; //$1$ indicates that DES encryption should be used by glibc
char buf[1024]; //unencrypted command buffer for I/O
int len; //buffer length
int usnlen, cpwdlen;
char DESkey[14];
char username[]="local";
char pwd[]="local";
char *cpwd, loginkey[16];
cpwd =crypt(pwd,salt); //crypt the password as described in the newcamd protocol
usnlen =sizeof(username);
cpwdlen =34; //glibc crypt generates 34 byte result code
len =usnlen+cpwdlen;
//now build the packet
buf[0]=MSG_CLIENT_2_SERVER_LOGIN;
buf[1]=(len>>8)&0x0f; //length: first 4 bits
buf[2]=len&0xff; //length: last 8 bits
memcpy(&buf[3],username,usnlen);
memcpy(&buf[3+usnlen],cpwd,cpwdlen);
buf[3+len]=0;
len+=4; //1 additional 0
printf("\tBuf:"); for (i=0;i<len;i++) printf("%02x ",buf[i]); printf("\n");
for (i=0;i<14;i++) DESkey[i]=i+1; //as defined in /var/keys/newcamd.list
printf("\tDESkey:"); for (i=0;i<14;i++) printf("%02d ",DESkey[i]); printf("\n");
printf("\tDESkey generated, ");
for (i=0;i<14;i++) loginkey[i]=buf1[i]^DESkey[i];
send(handle,buf,len,0);
//now hope the server answers
i=recv(handle, buf1,1024,0);
printf("%d bytes received from server\n",i);
======== server does not answer, so i returns -1 =====
Bookmarks