Newer
Older
cmd5apoppw / ht.c
@yuuji yuuji on 22 Sep 2006 803 bytes Initial revision
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include "hmac_md5.h"
#include "base64.h"

#define L	(_PASSWORD_LEN+256)
int main(int argc, char *argv[])
{
  unsigned char digest[16];
  char d_str[L];
  char b6[L*2];
  char *pw, *p;
  int i;
  if (argc != 3) {
    printf("Usage: ht UserName ChallengeInBase64\n");
    exit(1);
  }
  pw = getpass("SMTP-AUTH Password: ");
  b64_pton(argv[2], b6, L*2);
  hmac_md5(b6, strlen(b6), pw, strlen(pw), digest);
  memset(pw, 0, strlen(pw));
  snprintf(d_str, sizeof d_str, "%s ", argv[1]);
  p = d_str+strlen(d_str);
  for (i=0; i<16 && p<d_str+sizeof d_str; i++, p+=2)
    sprintf(p, "%02x", digest[i]);
  *p = '\0';
  printf("%s\n", d_str);
  b64_ntop(d_str, strlen(d_str), b6, L*2);
  printf("%s\n", b6);
}