/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* CRAM-MD5 SASL plugin
* Rob Siemborski
* Tim Martin
* $Id: cram.c,v 1.79 2003/02/18 18:27:37 rjs3 Exp $
*/
/*
* Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The name "Carnegie Mellon University" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For permission or any other legal
* details, please contact
* Office of Technology Transfer
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213-3890
* (412) 268-4387, fax: (412) 268-7395
* tech-transfer@andrew.cmu.edu
*
* 4. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Computing Services
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifndef macintosh
#endif
#include <fcntl.h>
#include <sasl.h>
#include <saslplug.h>
#include <saslutil.h>
#ifdef _SUN_SDK_
#include <unistd.h>
#endif /* _SUN_SDK_ */
#include "plugin_common.h"
#ifdef macintosh
#include <sasl_cram_plugin_decl.h>
#endif
/***************************** Common Section *****************************/
#ifndef _SUN_SDK_
#endif /* !_SUN_SDK_ */
/* convert a string of 8bit chars to it's representation in hex
* using lowercase letters
*/
{
int lup;
char *out;
}
return out;
}
/***************************** Server Section *****************************/
typedef struct server_context {
int state;
char *challenge;
static int
void **conn_context)
{
/* holds state are in */
return SASL_NOMEM;
}
*conn_context = text;
return SASL_OK;
}
/*
* Returns the current time (or part of it) in string form
* maximum length=15
*/
{
char *ret;
time_t t;
/* the bottom bits are really the only random ones so if
we overflow we don't want to loose them */
return ret;
}
{
unsigned int num;
char *ret;
#if defined _DEV_URANDOM && defined _SUN_SDK_
{
int nread = 0;
if (fd != -1) {
}
if (nread != 4)
(char *) temp, 4);
}
#else
#endif /* _DEV_URANDOM && _SUN_SDK_ */
(temp[3] );
return ret;
}
static int
unsigned clientinlen,
const char **serverout,
unsigned *serveroutlen,
{
/* we shouldn't have received anything */
if (clientinlen != 0) {
#ifdef _SUN_SDK_
"CRAM-MD5 does not accept inital data");
#else
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* get time and a random number for the nonce */
return SASL_NOMEM;
}
/* allocate some space for the challenge */
return SASL_NOMEM;
}
/* create the challenge */
/* free stuff */
return SASL_CONTINUE;
}
static int
const char *clientin,
unsigned clientinlen,
{
"*cmusaslsecretCRAM-MD5",
NULL };
int clear_md5state = 0;
/* extract userid; everything before last space */
if (pos <= 0) {
#ifdef _SUN_SDK_
"need authentication name");
#else
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
return SASL_NOMEM;
}
/* copy authstr out */
/* this will trigger the getting of the aux properties */
oparams);
if (result < 0 ||
/* We didn't find this username */
#ifdef _INTEGRATED_SOLARIS_
gettext("no secret in database"));
#else
"no secret in database");
#endif /* _INTEGRATED_SOLARIS_ */
goto done;
}
if (len == 0) {
#ifdef _INTEGRATED_SOLARIS_
gettext("empty secret"));
#else
"empty secret");
#endif /* _INTEGRATED_SOLARIS_ */
goto done;
}
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
clear_md5state = 1;
/* Do precalculation on plaintext secret */
/* We have a precomputed secret */
sizeof(HMAC_MD5_STATE));
} else {
#ifdef _SUN_SDK_
"Have neither type of secret");
#else
"Have neither type of secret");
#endif /* _SUN_SDK_ */
return SASL_FAIL;
}
/* ok this is annoying:
so we have this half-way hmac transform instead of the plaintext
that means we half to:
-import it back into a md5 context
-do an md5update with the nonce
-finalize it
*/
/* convert to base 16 with lower case letters */
/* if same then verified
* - we know digest_str is null terminated but clientin might not be
*/
#ifdef _INTEGRATED_SOLARIS_
gettext("incorrect digest response"));
#else
"incorrect digest response");
#endif /* _INTEGRATED_SOLARIS_ */
goto done;
}
/* set oparams */
oparams->param_version = 0;
done:
return result;
}
const char *clientin,
unsigned clientinlen,
const char **serverout,
unsigned *serveroutlen,
{
*serveroutlen = 0;
/* this should be well more than is ever needed */
if (clientinlen > 1024) {
#ifdef _SUN_SDK_
"CRAM-MD5 input longer than 1024 bytes");
#else
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
case 1:
oparams);
case 2:
oparams);
default: /* should never get here */
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
return SASL_FAIL;
}
#ifndef _SUN_SDK_
return SASL_FAIL; /* should never get here */
#endif /* !_SUN_SDK_ */
}
const sasl_utils_t *utils)
{
if (!text) return;
}
{
{
"CRAM-MD5", /* mech_name */
0, /* max_ssf */
| SASL_SEC_NOANONYMOUS, /* security_flags */
SASL_FEAT_SERVER_FIRST, /* features */
NULL, /* glob_context */
&crammd5_server_mech_new, /* mech_new */
&crammd5_server_mech_step, /* mech_step */
&crammd5_server_mech_dispose, /* mech_dispose */
NULL, /* mech_free */
NULL, /* setpass */
NULL, /* user_query */
NULL, /* idle */
NULL, /* mech avail */
NULL /* spare */
}
};
int maxversion,
int *out_version,
int *plugcount)
{
if (maxversion < SASL_SERVER_PLUG_VERSION) {
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
return SASL_BADVERS;
}
*plugcount = 1;
return SASL_OK;
}
/***************************** Client Section *****************************/
typedef struct client_context {
char *out_buf;
unsigned out_buf_len;
#ifdef _INTEGRATED_SOLARIS_
void *h;
#endif /* _INTEGRATED_SOLARIS_ */
void **conn_context)
{
/* holds state are in */
return SASL_NOMEM;
}
*conn_context = text;
return SASL_OK;
}
const sasl_utils_t *utils)
{
int lup;
char *in16;
/* fill in rest with 0's */
} else {
}
/* do the hmac md5 hash output 128 bits */
/* convert that to hex form */
return in16;
}
const char *serverin,
unsigned serverinlen,
const char **clientout,
unsigned *clientoutlen,
{
const char *authid;
int result;
int maxsize;
*clientoutlen = 0;
/* First check for absurd lengths */
if (serverinlen > 1024) {
#ifdef _SUN_SDK_
"CRAM-MD5 input longer than 1024 bytes");
#else
"CRAM-MD5 input longer than 1024 bytes");
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* check if sec layer strong enough */
#ifdef _SUN_SDK_
"SSF requested of CRAM-MD5 plugin");
#else
#endif /* _SUN_SDK_ */
return SASL_TOOWEAK;
}
/* try to get the userid */
return auth_result;
}
/* try to get the password */
return pass_result;
}
/* free prompts we got */
if (prompt_need && *prompt_need) {
*prompt_need = NULL;
}
/* if there are prompts not filled in */
/* make the prompt list */
result =
#ifdef _INTEGRATED_SOLARIS_
auth_result == SASL_INTERACT ?
gettext("Please enter your authentication name"))
pass_result == SASL_INTERACT ?
gettext("Please enter your password"))
#else
auth_result == SASL_INTERACT ?
"Please enter your authentication name" : NULL,
NULL,
pass_result == SASL_INTERACT ?
#endif /* _INTEGRATED_SOLARIS_ */
return SASL_INTERACT;
}
if (!password) {
return SASL_BADPARAM;
}
/*
* username SP digest (keyed md5 where key is passwd)
*/
#ifdef _SUN_SDK_
"make_hashed failed");
#else
#endif /* _SUN_SDK_ */
goto cleanup;
}
/* set oparams */
oparams->param_version = 0;
/* get rid of private information */
/* get rid of all sensitive info */
return result;
}
const sasl_utils_t *utils)
{
if (!text) return;
#ifdef _INTEGRATED_SOLARIS_
#endif /* _INTEGRATED_SOLARIS_ */
}
{
{
"CRAM-MD5", /* mech_name */
0, /* max_ssf */
| SASL_SEC_NOANONYMOUS, /* security_flags */
SASL_FEAT_SERVER_FIRST, /* features */
NULL, /* required_prompts */
NULL, /* glob_context */
&crammd5_client_mech_new, /* mech_new */
&crammd5_client_mech_step, /* mech_step */
&crammd5_client_mech_dispose, /* mech_dispose */
NULL, /* mech_free */
NULL, /* idle */
NULL, /* spare */
NULL /* spare */
}
};
int maxversion,
int *out_version,
int *plugcount)
{
if (maxversion < SASL_CLIENT_PLUG_VERSION) {
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
return SASL_BADVERS;
}
*plugcount = 1;
return SASL_OK;
}