help with newcamd card server client?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jansenjw
    Junior Member
    • May 2008
    • 21

    #1

    help with newcamd card server client?

    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 =====
    Last edited by jansenjw; 31 July, 2008, 21:35.
  • Devilfish
    Administrator
    • Feb 2008
    • 7872

    #2
    I'm no good with this sort of thing but maybe this will help you...

    newcamd cardsharing

    Comment

    • ocorvos
      Newbie
      • Mar 2009
      • 1

      #3
      Jansenjw,

      Could you fix your issues?

      I am writing a newcamd client card server and having similar questions.

      If you could do it, I can share my current code so you can help me.

      thanks in advance.

      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 =====

      Comment

      • asdf11
        Newbie
        • Jul 2010
        • 2

        #4
        Hi!
        usnlen =sizeof(username);
        Is it really what you want?
        Or does it work with
        usnlen=strlen(username)*sizeof(char);
        or
        usnlen=(strlen(username)+1)*sizeof(char)
        ?
        I like to help, if it helps.

        Comment

        • asdf11
          Newbie
          • Jul 2010
          • 2

          #5
          Oh i'm late.

          Comment

          • hanspoland
            Newbie
            • May 2011
            • 1

            #6
            Hi, I'm interested in your program. Is ready?

            Comment

            Working...