/* * CRAM-MD5 authentication test tool * Copyright (C) 2003 Oliver Hitz * * Compilation against libplaton library: * gcc -pedantic -L ../../platon/ -I ../../ -o cram-md5 cram-md5.c -lplaton */ #include #include #include #include #include int main(int argc, char *argv[]) { char *username; char *password; char *challenge; char digest[16]; char digasc[33]; int i; static char hextab[] = "0123456789abcdef"; char *decoded; char *encoded; char *greeting; if (argc != 4) { fprintf(stderr, "Usage: %s username password auth-greeting\n", argv[0]); return 1; } username = argv[1]; password = argv[2]; greeting = argv[3]; challenge = base64_decode_alloc(greeting); base64_decode(greeting, challenge); printf("username: %s\n", username); printf("password: %s\n", password); printf("challenge: %s\n", challenge); hmac_md5(challenge, strlen(challenge), password, strlen(password), digest); digasc[32] = 0; for (i = 0; i < 16; i++) { digasc[2*i] = hextab[digest[i] >> 4]; digasc[2*i+1] = hextab[digest[i] & 0xf]; } printf("digest: %s\n", digasc); decoded = (char *) malloc(strlen(username) + strlen(digasc) + 2); strcpy(decoded, username); decoded[strlen(username)] = ' '; strcpy(decoded+strlen(username)+1, digasc); decoded[strlen(username)+strlen(digasc)+1] = 0; printf("base64 decoded: %s\n", decoded); encoded = base64_encode_alloc(decoded); base64_encode(decoded, encoded); printf("base64 encoded: %s\n", encoded); return 0; } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=3: * }}} */