mech-cram-md5.c revision d1414c09cf0d58ac983054e2f4e1a1f329272dcf
/* 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 "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)
{
const char *response_hex;
if (credentials == NULL)
return FALSE;
context_digest, sizeof(context_digest));
return FALSE;
#define CDGET(p, c) STMT_START { \
(c) = (*p++); \
(c) += (*p++ << 8); \
(c) += (*p++ << 16); \
(c) += (*p++ << 24); \
} STMT_END
if (verbose) {
i_info("cram-md5(%s): password mismatch",
}
return FALSE;
}
return TRUE;
}
const char **error_r)
{
size_t i;
for (i = 0; i < size; i++) {
if (data[i] == ' ')
break;
}
if (i == size) {
*error_r = "missing digest";
return FALSE;
}
i++;
return TRUE;
}
static void credentials_callback(const char *result,
struct auth_request *request)
{
struct cram_auth_request *auth =
(struct cram_auth_request *) request;
if (verbose) {
i_info("cram-md5(%s): authenticated",
}
} 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 = "invalid username";
}
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",
};