chap_ms.c revision eedefb957fd12dc52be22145a83874a71050e784
/*
* chap_ms.c - Microsoft MS-CHAP compatible implementation.
*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Eric Rosenquist. The name of the author may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* This module implements MS-CHAPv1 (RFC 2433) and MS-CHAPv2 (RFC 2759).
*
* Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997
*
* Implemented LANManager type password response to MS-CHAP challenges.
* Now pppd provides both NT style and LANMan style blocks, and the
* prefered is set by option "ms-lanman". Default is to use NT.
* The hash text (StdText) was taken from Win95 RASAPI32.DLL.
*
* You should also use DOMAIN\\USERNAME as described in README.MSCHAP80
*
* Modifications by James Carlson / james.d.carlson@sun.com, June 1st, 2000.
*
* Added MS-CHAPv2 support.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
#ifdef CHAPMSV2
#include "sha1.h"
#endif
#ifndef USE_CRYPT
#include <des.h>
#endif
#include "pppd.h"
#include "chap.h"
#include "chap_ms.h"
#include "md4.h"
#endif
typedef struct {
/* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
in case this struct gets padded. */
typedef struct {
/* We use MS_CHAPV2_RESPONSE_LEN, rather than sizeof(MS_Chapv2Response),
in case this struct gets padded. */
#ifdef CHAPMS
#ifdef MSLANMAN
#endif
#endif
#ifdef CHAPMSV2
MS_Chapv2Response *));
#endif
#ifdef USE_CRYPT
#endif
bool ms_lanman = 0; /* Use LanMan password instead of NT */
/* Has meaning only with MS-CHAP challenges */
#endif
#ifdef CHAPMSV2
/* Specially-formatted Microsoft CHAP response message. */
static char status_message[256];
#endif
static void
{
#if 0
dbglog("ChallengeResponse - ZPasswordHash %.*B",
sizeof(ZPasswordHash), ZPasswordHash);
#endif
#if 0
#endif
}
#ifdef USE_CRYPT
static void
{
char crypt_key[66];
char des_input[66];
#if 0
#endif
#if 0
#endif
}
#else /* USE_CRYPT */
static void
{
#if 0
#endif
#if 0
#endif
}
#endif /* USE_CRYPT */
int startBit;
{
register unsigned int word;
return word & 0xFE;
}
#ifdef USE_CRYPT
/* in == 8-byte string (expanded version of the 56-bit key)
* out == 64-byte string where each byte is either 1 or 0
* Note that the low-order "bit" is always ignored by by setkey()
*/
char *out;
{
int j, c;
int i;
for(i = 0; i < 64; in++){
c = *in;
for(j = 7; j >= 0; j--)
*out++ = (c >> j) & 01;
i += 8;
}
}
/* The inverse of Expand
*/
char *in;
{
int j;
int i;
unsigned int c;
c = 0;
for (j = 7; j >= 0; j--, in++)
*out = c & 0xff;
}
}
#endif
{
#ifndef USE_CRYPT
#endif
#if 0
#endif
}
#ifdef CHAPMS
static void
char *secret;
int secret_len;
{
int i;
#if defined(__NetBSD__) || defined(HAVE_LIBMD)
/* NetBSD uses the libc md4 routines which take bytes instead of bits */
#else
#endif
/* Initialize the Unicode version of the secret (== password). */
/* This implicitly supports 8-bit ISO8859/1 characters. */
for (i = 0; i < secret_len; i++)
}
#ifdef MSLANMAN
static void
char *secret;
int secret_len;
{
int i;
/* LANMan password is case insensitive */
for (i = 0; i < secret_len; i++)
UcasePassword[i] = (u_char)(
}
#endif
void
int rchallenge_len;
char *secret;
int secret_len;
{
if (rchallenge_len < 8) {
cstate->resp_length = 0;
return;
}
#if 0
#endif
/* Calculate both always */
#ifdef MSLANMAN
/* prefered method is set by option */
#else
#endif
}
static int
int flag;
{
if (flag != 0) {
cstate->stat_length = 0;
} else {
}
return (flag);
}
int
int response_len;
char *secret;
int secret_len;
{
return (0);
24) == 0));
}
#ifdef MSLANMAN
return (ChapMSStatus(cstate,
#else
return (ChapMSStatus(cstate, 0));
#endif
}
#endif /* CHAPMS */
#ifdef CHAPMSV2
static void
char *username;
{
char *cp;
/*
* Only the user name (as presented by the peer and
* excluding any prepended domain name)
* is used as input to SHAUpdate().
*/
}
static void
char *username;
char *secret;
int secret_len;
{
int i;
#if defined(__NetBSD__) || defined(HAVE_LIBMD)
/* NetBSD uses the libc md4 routines that take bytes instead of bits */
#else
#endif
/* Initialize the Unicode version of the secret (== password). */
/* This implicitly supports 8-bit ISO8859/1 characters. */
for (i = 0; i < secret_len && i < MAX_NT_PASSWORD; i++)
break;
}
void
int rchallenge_len;
char *secret;
int secret_len;
{
int i;
if (rchallenge_len < 8) {
cstate->resp_length = 0;
return;
}
for (i = 0; i < 16; i++)
}
static void
int secret_len;
{
"Pad to make it do more than one iteration";
#if defined(__NetBSD__) || defined(HAVE_LIBMD)
/* NetBSD uses the libc md4 routines that take bytes instead of bits */
int mdlen = 1;
#else
int mdlen = 8;
#endif
char *cp;
static const char hexdig[] = "0123456789ABCDEF";
int i;
/* Initialize the Unicode version of the secret (== password). */
/* This implicitly supports 8-bit ISO8859/1 characters. */
for (i = 0; i < secret_len && i < MAX_NT_PASSWORD; i++)
break;
/* Hash the password with MD4 */
/* Now hash the hash */
cp = status_message;
*cp++ = 'S';
*cp++ = '=';
for (i = 0; i < 20; i++) {
}
/*
* RFC 2759 says that a M=<string> greeting message is possible
* here. It lies. Any such greeting causes Windoze-98 to give
* error number 742, "Dial-Up Networking was unable to complete
* the connection. The computer you're dialing in to does not
* support the data encryption requirements specified. Please
* check your encryption settings in the properties of the
* connection. If this problem persists, contact your network
* administrator."
*/
*cp = '\0';
#if 0
"M=\"Welcome to %s.\"", hostname);
#endif
}
int
char *rhostname;
int response_len;
char *secret;
int secret_len;
{
if (response_len < MS_CHAPV2_RESPONSE_LEN ||
cstate->stat_length = 0;
return 0;
}
cstate->stat_message = "E=691 R=0 C=11111111111111111111111111111111 V=3 M=\"Authentication failed\"";
return (0);
}
return (1);
}
#endif /* CHAPMSV2 */
#endif /* CHAPMS or CHAPMSV2 */