mech-cram-md5.c revision 4b058f90f9e8a2c6b2eed275de4eb8cc5195a71d
/* Copyright (C) 2002,2003 Timo Sirainen / Joshua Goodall */
/* CRAM-MD5 SASL authentication, see RFC-2195
Joshua Goodall <joshua@roughtrade.net> */
#include "common.h"
#include "ioloop.h"
#include "buffer.h"
#include "hex-binary.h"
#include "hmac-md5.h"
#include "randgen.h"
#include "mech.h"
#include "passdb.h"
#include "hostpid.h"
#include <stdlib.h>
#include <time.h>
struct cram_auth_request {
struct auth_request auth_request;
/* requested: */
char *challenge;
/* received: */
char *username;
char *response;
unsigned long maxbuf;
};
static const char *get_cram_challenge(void)
{
unsigned char buf[17];
size_t i;
hostpid_init();
for (i = 0; i < sizeof(buf)-1; i++)
}
const char *credentials)
{
struct hmac_md5_context ctx;
const char *response_hex;
if (credentials == NULL)
return FALSE;
context_digest, sizeof(context_digest));
return FALSE;
if (verbose) {
i_info("cram-md5(%s): password mismatch",
}
return FALSE;
}
return TRUE;
}
const char **error_r)
{
/* <username> SPACE <response>. Username may contain spaces, so assume
the rightmost space is the response separator. */
if (data[i] == ' ')
space = i;
}
if (space == 0) {
*error_r = "missing digest";
return FALSE;
}
space++;
return TRUE;
}
static void credentials_callback(const char *result,
struct auth_request *request)
{
struct cram_auth_request *auth =
(struct cram_auth_request *) request;
else {
if (verbose) {
i_info("cram-md5(%s): authentication failed",
}
}
}
static int
{
struct cram_auth_request *auth =
(struct cram_auth_request *)auth_request;
const char *error;
auth_request->user =
return TRUE;
}
}
error = "authentication failed";
if (verbose) {
i_info("cram-md5(%s): %s",
}
/* failed */
return FALSE;
}
static int
struct auth_client_request_new *request,
const unsigned char *data __attr_unused__,
{
struct cram_auth_request *auth =
(struct cram_auth_request *)auth_request;
struct auth_client_request_reply reply;
/* No initial response in CRAM-MD5 */
return FALSE;
}
/* initialize reply */
/* send the initial challenge */
return TRUE;
}
{
}
static struct auth_request *mech_cram_md5_auth_new(void)
{
struct cram_auth_request *auth;
return &auth->auth_request;
}
struct mech_module mech_cram_md5 = {
"CRAM-MD5",
};