1 /* $Id: authsaslclientcram.c,v 1.4 2006/01/22 03:33:24 mrsam Exp $ */
4 ** Copyright 2000 Double Precision, Inc. See COPYING for
5 ** distribution information.
8 #include "courier_auth_config.h"
9 #include "courierauthsasl.h"
12 #include "libhmac/hmac.h"
15 #include "authsaslclient.h"
24 int authsaslclient_cram(const struct authsaslclientinfo
*info
,
25 const char *challenge
,
26 const struct hmac_hashinfo
*hashinfo
)
28 char *base64buf
=malloc(strlen(challenge
)+1);
29 unsigned char *keybuf
;
31 const char *userid
=info
->userid
? info
->userid
:"";
32 const char *password
=info
->password
? info
->password
:"";
38 return (AUTHSASL_ERROR
);
40 strcpy(base64buf
, challenge
);
42 if ( (i
=authsasl_frombase64(base64buf
))<0 ||
43 (keybuf
=(unsigned char *)malloc(hashinfo
->hh_L
*3)) == 0)
47 return (AUTHSASL_ERROR
);
50 hmac_hashkey( hashinfo
, password
, strlen(password
),
51 keybuf
, keybuf
+hashinfo
->hh_L
);
53 hmac_hashtext( hashinfo
, base64buf
, i
,
54 keybuf
, keybuf
+hashinfo
->hh_L
,
55 keybuf
+hashinfo
->hh_L
*2);
58 base64buf
=malloc(strlen(userid
)+2+hashinfo
->hh_L
*2);
63 return (AUTHSASL_ERROR
);
65 strcat(strcpy(base64buf
, userid
), " ");
66 p
=base64buf
+strlen(base64buf
);
67 for (i
=0; i
<hashinfo
->hh_L
; i
++)
69 static const char xdigit
[]="0123456789abcdef";
70 int c
=keybuf
[hashinfo
->hh_L
*2+i
];
72 *p
++ = xdigit
[ (c
>> 4) & 0x0F ];
73 *p
++ = xdigit
[c
& 0x0F];
77 keybuf
=(unsigned char *)authsasl_tobase64(base64buf
, -1);
84 return (AUTHSASL_ERROR
);
86 i
= (*info
->final_conv_func
)((char *)keybuf
, info
->conv_func_arg
);
95 int authsaslclient_cram(const struct authsaslclientinfo
*info
,
96 const char *challenge
,
97 const struct hmac_hashinfo
*hashinfo
)
99 return (AUTHSASL_NOMETHODS
);