NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hexley 0:281d6ff68967 1 /*** WARNING - THIS CODE HAS NOT BEEN FINISHED! ***/
hexley 0:281d6ff68967 2 /*** The original PPPD code is written in a way to require either the UNIX DES
hexley 0:281d6ff68967 3 encryption functions encrypt(3) and setkey(3) or the DES library libdes.
hexley 0:281d6ff68967 4 Since both is not included in lwIP, MSCHAP currently does not work! */
hexley 0:281d6ff68967 5 /*****************************************************************************
hexley 0:281d6ff68967 6 * chpms.c - Network MicroSoft Challenge Handshake Authentication Protocol program file.
hexley 0:281d6ff68967 7 *
hexley 0:281d6ff68967 8 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
hexley 0:281d6ff68967 9 * Copyright (c) 1997 by Global Election Systems Inc. All rights reserved.
hexley 0:281d6ff68967 10 *
hexley 0:281d6ff68967 11 * The authors hereby grant permission to use, copy, modify, distribute,
hexley 0:281d6ff68967 12 * and license this software and its documentation for any purpose, provided
hexley 0:281d6ff68967 13 * that existing copyright notices are retained in all copies and that this
hexley 0:281d6ff68967 14 * notice and the following disclaimer are included verbatim in any
hexley 0:281d6ff68967 15 * distributions. No written agreement, license, or royalty fee is required
hexley 0:281d6ff68967 16 * for any of the authorized uses.
hexley 0:281d6ff68967 17 *
hexley 0:281d6ff68967 18 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
hexley 0:281d6ff68967 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
hexley 0:281d6ff68967 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
hexley 0:281d6ff68967 21 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
hexley 0:281d6ff68967 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
hexley 0:281d6ff68967 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
hexley 0:281d6ff68967 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
hexley 0:281d6ff68967 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
hexley 0:281d6ff68967 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
hexley 0:281d6ff68967 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hexley 0:281d6ff68967 28 *
hexley 0:281d6ff68967 29 ******************************************************************************
hexley 0:281d6ff68967 30 * REVISION HISTORY
hexley 0:281d6ff68967 31 *
hexley 0:281d6ff68967 32 * 03-01-01 Marc Boucher <marc@mbsi.ca>
hexley 0:281d6ff68967 33 * Ported to lwIP.
hexley 0:281d6ff68967 34 * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
hexley 0:281d6ff68967 35 * Original based on BSD chap_ms.c.
hexley 0:281d6ff68967 36 *****************************************************************************/
hexley 0:281d6ff68967 37 /*
hexley 0:281d6ff68967 38 * chap_ms.c - Microsoft MS-CHAP compatible implementation.
hexley 0:281d6ff68967 39 *
hexley 0:281d6ff68967 40 * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
hexley 0:281d6ff68967 41 * http://www.strataware.com/
hexley 0:281d6ff68967 42 *
hexley 0:281d6ff68967 43 * All rights reserved.
hexley 0:281d6ff68967 44 *
hexley 0:281d6ff68967 45 * Redistribution and use in source and binary forms are permitted
hexley 0:281d6ff68967 46 * provided that the above copyright notice and this paragraph are
hexley 0:281d6ff68967 47 * duplicated in all such forms and that any documentation,
hexley 0:281d6ff68967 48 * advertising materials, and other materials related to such
hexley 0:281d6ff68967 49 * distribution and use acknowledge that the software was developed
hexley 0:281d6ff68967 50 * by Eric Rosenquist. The name of the author may not be used to
hexley 0:281d6ff68967 51 * endorse or promote products derived from this software without
hexley 0:281d6ff68967 52 * specific prior written permission.
hexley 0:281d6ff68967 53 *
hexley 0:281d6ff68967 54 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
hexley 0:281d6ff68967 55 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
hexley 0:281d6ff68967 56 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
hexley 0:281d6ff68967 57 */
hexley 0:281d6ff68967 58
hexley 0:281d6ff68967 59 /*
hexley 0:281d6ff68967 60 * Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997
hexley 0:281d6ff68967 61 *
hexley 0:281d6ff68967 62 * Implemented LANManager type password response to MS-CHAP challenges.
hexley 0:281d6ff68967 63 * Now pppd provides both NT style and LANMan style blocks, and the
hexley 0:281d6ff68967 64 * prefered is set by option "ms-lanman". Default is to use NT.
hexley 0:281d6ff68967 65 * The hash text (StdText) was taken from Win95 RASAPI32.DLL.
hexley 0:281d6ff68967 66 *
hexley 0:281d6ff68967 67 * You should also use DOMAIN\\USERNAME as described in README.MSCHAP80
hexley 0:281d6ff68967 68 */
hexley 0:281d6ff68967 69
hexley 0:281d6ff68967 70 #define USE_CRYPT
hexley 0:281d6ff68967 71
hexley 0:281d6ff68967 72 #include "lwip/opt.h"
hexley 0:281d6ff68967 73
hexley 0:281d6ff68967 74 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
hexley 0:281d6ff68967 75
hexley 0:281d6ff68967 76 #if MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
hexley 0:281d6ff68967 77
hexley 0:281d6ff68967 78 #include "ppp.h"
hexley 0:281d6ff68967 79 #include "pppdebug.h"
hexley 0:281d6ff68967 80
hexley 0:281d6ff68967 81 #include "md4.h"
hexley 0:281d6ff68967 82 #ifndef USE_CRYPT
hexley 0:281d6ff68967 83 #include "des.h"
hexley 0:281d6ff68967 84 #endif
hexley 0:281d6ff68967 85 #include "chap.h"
hexley 0:281d6ff68967 86 #include "chpms.h"
hexley 0:281d6ff68967 87
hexley 0:281d6ff68967 88 #include <string.h>
hexley 0:281d6ff68967 89
hexley 0:281d6ff68967 90
hexley 0:281d6ff68967 91 /*************************/
hexley 0:281d6ff68967 92 /*** LOCAL DEFINITIONS ***/
hexley 0:281d6ff68967 93 /*************************/
hexley 0:281d6ff68967 94
hexley 0:281d6ff68967 95
hexley 0:281d6ff68967 96 /************************/
hexley 0:281d6ff68967 97 /*** LOCAL DATA TYPES ***/
hexley 0:281d6ff68967 98 /************************/
hexley 0:281d6ff68967 99 typedef struct {
hexley 0:281d6ff68967 100 u_char LANManResp[24];
hexley 0:281d6ff68967 101 u_char NTResp[24];
hexley 0:281d6ff68967 102 u_char UseNT; /* If 1, ignore the LANMan response field */
hexley 0:281d6ff68967 103 } MS_ChapResponse;
hexley 0:281d6ff68967 104 /* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
hexley 0:281d6ff68967 105 in case this struct gets padded. */
hexley 0:281d6ff68967 106
hexley 0:281d6ff68967 107
hexley 0:281d6ff68967 108
hexley 0:281d6ff68967 109 /***********************************/
hexley 0:281d6ff68967 110 /*** LOCAL FUNCTION DECLARATIONS ***/
hexley 0:281d6ff68967 111 /***********************************/
hexley 0:281d6ff68967 112
hexley 0:281d6ff68967 113 /* XXX Don't know what to do with these. */
hexley 0:281d6ff68967 114 extern void setkey(const char *);
hexley 0:281d6ff68967 115 extern void encrypt(char *, int);
hexley 0:281d6ff68967 116
hexley 0:281d6ff68967 117 static void DesEncrypt (u_char *, u_char *, u_char *);
hexley 0:281d6ff68967 118 static void MakeKey (u_char *, u_char *);
hexley 0:281d6ff68967 119
hexley 0:281d6ff68967 120 #ifdef USE_CRYPT
hexley 0:281d6ff68967 121 static void Expand (u_char *, u_char *);
hexley 0:281d6ff68967 122 static void Collapse (u_char *, u_char *);
hexley 0:281d6ff68967 123 #endif
hexley 0:281d6ff68967 124
hexley 0:281d6ff68967 125 static void ChallengeResponse(
hexley 0:281d6ff68967 126 u_char *challenge, /* IN 8 octets */
hexley 0:281d6ff68967 127 u_char *pwHash, /* IN 16 octets */
hexley 0:281d6ff68967 128 u_char *response /* OUT 24 octets */
hexley 0:281d6ff68967 129 );
hexley 0:281d6ff68967 130 static void ChapMS_NT(
hexley 0:281d6ff68967 131 char *rchallenge,
hexley 0:281d6ff68967 132 int rchallenge_len,
hexley 0:281d6ff68967 133 char *secret,
hexley 0:281d6ff68967 134 int secret_len,
hexley 0:281d6ff68967 135 MS_ChapResponse *response
hexley 0:281d6ff68967 136 );
hexley 0:281d6ff68967 137 static u_char Get7Bits(
hexley 0:281d6ff68967 138 u_char *input,
hexley 0:281d6ff68967 139 int startBit
hexley 0:281d6ff68967 140 );
hexley 0:281d6ff68967 141
hexley 0:281d6ff68967 142 static void
hexley 0:281d6ff68967 143 ChallengeResponse( u_char *challenge, /* IN 8 octets */
hexley 0:281d6ff68967 144 u_char *pwHash, /* IN 16 octets */
hexley 0:281d6ff68967 145 u_char *response /* OUT 24 octets */)
hexley 0:281d6ff68967 146 {
hexley 0:281d6ff68967 147 u_char ZPasswordHash[21];
hexley 0:281d6ff68967 148
hexley 0:281d6ff68967 149 BZERO(ZPasswordHash, sizeof(ZPasswordHash));
hexley 0:281d6ff68967 150 BCOPY(pwHash, ZPasswordHash, 16);
hexley 0:281d6ff68967 151
hexley 0:281d6ff68967 152 #if 0
hexley 0:281d6ff68967 153 log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
hexley 0:281d6ff68967 154 #endif
hexley 0:281d6ff68967 155
hexley 0:281d6ff68967 156 DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
hexley 0:281d6ff68967 157 DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
hexley 0:281d6ff68967 158 DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
hexley 0:281d6ff68967 159
hexley 0:281d6ff68967 160 #if 0
hexley 0:281d6ff68967 161 log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
hexley 0:281d6ff68967 162 #endif
hexley 0:281d6ff68967 163 }
hexley 0:281d6ff68967 164
hexley 0:281d6ff68967 165
hexley 0:281d6ff68967 166 #ifdef USE_CRYPT
hexley 0:281d6ff68967 167 static void
hexley 0:281d6ff68967 168 DesEncrypt( u_char *clear, /* IN 8 octets */
hexley 0:281d6ff68967 169 u_char *key, /* IN 7 octets */
hexley 0:281d6ff68967 170 u_char *cipher /* OUT 8 octets */)
hexley 0:281d6ff68967 171 {
hexley 0:281d6ff68967 172 u_char des_key[8];
hexley 0:281d6ff68967 173 u_char crypt_key[66];
hexley 0:281d6ff68967 174 u_char des_input[66];
hexley 0:281d6ff68967 175
hexley 0:281d6ff68967 176 MakeKey(key, des_key);
hexley 0:281d6ff68967 177
hexley 0:281d6ff68967 178 Expand(des_key, crypt_key);
hexley 0:281d6ff68967 179 setkey((char*)crypt_key);
hexley 0:281d6ff68967 180
hexley 0:281d6ff68967 181 #if 0
hexley 0:281d6ff68967 182 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
hexley 0:281d6ff68967 183 clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
hexley 0:281d6ff68967 184 #endif
hexley 0:281d6ff68967 185
hexley 0:281d6ff68967 186 Expand(clear, des_input);
hexley 0:281d6ff68967 187 encrypt((char*)des_input, 0);
hexley 0:281d6ff68967 188 Collapse(des_input, cipher);
hexley 0:281d6ff68967 189
hexley 0:281d6ff68967 190 #if 0
hexley 0:281d6ff68967 191 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
hexley 0:281d6ff68967 192 cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
hexley 0:281d6ff68967 193 #endif
hexley 0:281d6ff68967 194 }
hexley 0:281d6ff68967 195
hexley 0:281d6ff68967 196 #else /* USE_CRYPT */
hexley 0:281d6ff68967 197
hexley 0:281d6ff68967 198 static void
hexley 0:281d6ff68967 199 DesEncrypt( u_char *clear, /* IN 8 octets */
hexley 0:281d6ff68967 200 u_char *key, /* IN 7 octets */
hexley 0:281d6ff68967 201 u_char *cipher /* OUT 8 octets */)
hexley 0:281d6ff68967 202 {
hexley 0:281d6ff68967 203 des_cblock des_key;
hexley 0:281d6ff68967 204 des_key_schedule key_schedule;
hexley 0:281d6ff68967 205
hexley 0:281d6ff68967 206 MakeKey(key, des_key);
hexley 0:281d6ff68967 207
hexley 0:281d6ff68967 208 des_set_key(&des_key, key_schedule);
hexley 0:281d6ff68967 209
hexley 0:281d6ff68967 210 #if 0
hexley 0:281d6ff68967 211 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
hexley 0:281d6ff68967 212 clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
hexley 0:281d6ff68967 213 #endif
hexley 0:281d6ff68967 214
hexley 0:281d6ff68967 215 des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
hexley 0:281d6ff68967 216
hexley 0:281d6ff68967 217 #if 0
hexley 0:281d6ff68967 218 CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
hexley 0:281d6ff68967 219 cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
hexley 0:281d6ff68967 220 #endif
hexley 0:281d6ff68967 221 }
hexley 0:281d6ff68967 222
hexley 0:281d6ff68967 223 #endif /* USE_CRYPT */
hexley 0:281d6ff68967 224
hexley 0:281d6ff68967 225
hexley 0:281d6ff68967 226 static u_char
hexley 0:281d6ff68967 227 Get7Bits( u_char *input, int startBit)
hexley 0:281d6ff68967 228 {
hexley 0:281d6ff68967 229 register unsigned int word;
hexley 0:281d6ff68967 230
hexley 0:281d6ff68967 231 word = (unsigned)input[startBit / 8] << 8;
hexley 0:281d6ff68967 232 word |= (unsigned)input[startBit / 8 + 1];
hexley 0:281d6ff68967 233
hexley 0:281d6ff68967 234 word >>= 15 - (startBit % 8 + 7);
hexley 0:281d6ff68967 235
hexley 0:281d6ff68967 236 return word & 0xFE;
hexley 0:281d6ff68967 237 }
hexley 0:281d6ff68967 238
hexley 0:281d6ff68967 239 #ifdef USE_CRYPT
hexley 0:281d6ff68967 240
hexley 0:281d6ff68967 241 /* in == 8-byte string (expanded version of the 56-bit key)
hexley 0:281d6ff68967 242 * out == 64-byte string where each byte is either 1 or 0
hexley 0:281d6ff68967 243 * Note that the low-order "bit" is always ignored by by setkey()
hexley 0:281d6ff68967 244 */
hexley 0:281d6ff68967 245 static void
hexley 0:281d6ff68967 246 Expand(u_char *in, u_char *out)
hexley 0:281d6ff68967 247 {
hexley 0:281d6ff68967 248 int j, c;
hexley 0:281d6ff68967 249 int i;
hexley 0:281d6ff68967 250
hexley 0:281d6ff68967 251 for(i = 0; i < 64; in++){
hexley 0:281d6ff68967 252 c = *in;
hexley 0:281d6ff68967 253 for(j = 7; j >= 0; j--) {
hexley 0:281d6ff68967 254 *out++ = (c >> j) & 01;
hexley 0:281d6ff68967 255 }
hexley 0:281d6ff68967 256 i += 8;
hexley 0:281d6ff68967 257 }
hexley 0:281d6ff68967 258 }
hexley 0:281d6ff68967 259
hexley 0:281d6ff68967 260 /* The inverse of Expand
hexley 0:281d6ff68967 261 */
hexley 0:281d6ff68967 262 static void
hexley 0:281d6ff68967 263 Collapse(u_char *in, u_char *out)
hexley 0:281d6ff68967 264 {
hexley 0:281d6ff68967 265 int j;
hexley 0:281d6ff68967 266 int i;
hexley 0:281d6ff68967 267 unsigned int c;
hexley 0:281d6ff68967 268
hexley 0:281d6ff68967 269 for (i = 0; i < 64; i += 8, out++) {
hexley 0:281d6ff68967 270 c = 0;
hexley 0:281d6ff68967 271 for (j = 7; j >= 0; j--, in++) {
hexley 0:281d6ff68967 272 c |= *in << j;
hexley 0:281d6ff68967 273 }
hexley 0:281d6ff68967 274 *out = c & 0xff;
hexley 0:281d6ff68967 275 }
hexley 0:281d6ff68967 276 }
hexley 0:281d6ff68967 277 #endif
hexley 0:281d6ff68967 278
hexley 0:281d6ff68967 279 static void
hexley 0:281d6ff68967 280 MakeKey( u_char *key, /* IN 56 bit DES key missing parity bits */
hexley 0:281d6ff68967 281 u_char *des_key /* OUT 64 bit DES key with parity bits added */)
hexley 0:281d6ff68967 282 {
hexley 0:281d6ff68967 283 des_key[0] = Get7Bits(key, 0);
hexley 0:281d6ff68967 284 des_key[1] = Get7Bits(key, 7);
hexley 0:281d6ff68967 285 des_key[2] = Get7Bits(key, 14);
hexley 0:281d6ff68967 286 des_key[3] = Get7Bits(key, 21);
hexley 0:281d6ff68967 287 des_key[4] = Get7Bits(key, 28);
hexley 0:281d6ff68967 288 des_key[5] = Get7Bits(key, 35);
hexley 0:281d6ff68967 289 des_key[6] = Get7Bits(key, 42);
hexley 0:281d6ff68967 290 des_key[7] = Get7Bits(key, 49);
hexley 0:281d6ff68967 291
hexley 0:281d6ff68967 292 #ifndef USE_CRYPT
hexley 0:281d6ff68967 293 des_set_odd_parity((des_cblock *)des_key);
hexley 0:281d6ff68967 294 #endif
hexley 0:281d6ff68967 295
hexley 0:281d6ff68967 296 #if 0
hexley 0:281d6ff68967 297 CHAPDEBUG(LOG_INFO, ("MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n",
hexley 0:281d6ff68967 298 key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
hexley 0:281d6ff68967 299 CHAPDEBUG(LOG_INFO, ("MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
hexley 0:281d6ff68967 300 des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
hexley 0:281d6ff68967 301 #endif
hexley 0:281d6ff68967 302 }
hexley 0:281d6ff68967 303
hexley 0:281d6ff68967 304 static void
hexley 0:281d6ff68967 305 ChapMS_NT( char *rchallenge,
hexley 0:281d6ff68967 306 int rchallenge_len,
hexley 0:281d6ff68967 307 char *secret,
hexley 0:281d6ff68967 308 int secret_len,
hexley 0:281d6ff68967 309 MS_ChapResponse *response)
hexley 0:281d6ff68967 310 {
hexley 0:281d6ff68967 311 int i;
hexley 0:281d6ff68967 312 MDstruct md4Context;
hexley 0:281d6ff68967 313 u_char unicodePassword[MAX_NT_PASSWORD * 2];
hexley 0:281d6ff68967 314 static int low_byte_first = -1;
hexley 0:281d6ff68967 315
hexley 0:281d6ff68967 316 LWIP_UNUSED_ARG(rchallenge_len);
hexley 0:281d6ff68967 317
hexley 0:281d6ff68967 318 /* Initialize the Unicode version of the secret (== password). */
hexley 0:281d6ff68967 319 /* This implicitly supports 8-bit ISO8859/1 characters. */
hexley 0:281d6ff68967 320 BZERO(unicodePassword, sizeof(unicodePassword));
hexley 0:281d6ff68967 321 for (i = 0; i < secret_len; i++) {
hexley 0:281d6ff68967 322 unicodePassword[i * 2] = (u_char)secret[i];
hexley 0:281d6ff68967 323 }
hexley 0:281d6ff68967 324 MDbegin(&md4Context);
hexley 0:281d6ff68967 325 MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */
hexley 0:281d6ff68967 326
hexley 0:281d6ff68967 327 if (low_byte_first == -1) {
hexley 0:281d6ff68967 328 low_byte_first = (PP_HTONS((unsigned short int)1) != 1);
hexley 0:281d6ff68967 329 }
hexley 0:281d6ff68967 330 if (low_byte_first == 0) {
hexley 0:281d6ff68967 331 /* @todo: arg type - u_long* or u_int* ? */
hexley 0:281d6ff68967 332 MDreverse((unsigned int*)&md4Context); /* sfb 961105 */
hexley 0:281d6ff68967 333 }
hexley 0:281d6ff68967 334
hexley 0:281d6ff68967 335 MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */
hexley 0:281d6ff68967 336
hexley 0:281d6ff68967 337 ChallengeResponse((u_char*)rchallenge, (u_char*)md4Context.buffer, response->NTResp);
hexley 0:281d6ff68967 338 }
hexley 0:281d6ff68967 339
hexley 0:281d6ff68967 340 #ifdef MSLANMAN
hexley 0:281d6ff68967 341 static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
hexley 0:281d6ff68967 342
hexley 0:281d6ff68967 343 static void
hexley 0:281d6ff68967 344 ChapMS_LANMan( char *rchallenge,
hexley 0:281d6ff68967 345 int rchallenge_len,
hexley 0:281d6ff68967 346 char *secret,
hexley 0:281d6ff68967 347 int secret_len,
hexley 0:281d6ff68967 348 MS_ChapResponse *response)
hexley 0:281d6ff68967 349 {
hexley 0:281d6ff68967 350 int i;
hexley 0:281d6ff68967 351 u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
hexley 0:281d6ff68967 352 u_char PasswordHash[16];
hexley 0:281d6ff68967 353
hexley 0:281d6ff68967 354 /* LANMan password is case insensitive */
hexley 0:281d6ff68967 355 BZERO(UcasePassword, sizeof(UcasePassword));
hexley 0:281d6ff68967 356 for (i = 0; i < secret_len; i++) {
hexley 0:281d6ff68967 357 UcasePassword[i] = (u_char)toupper(secret[i]);
hexley 0:281d6ff68967 358 }
hexley 0:281d6ff68967 359 DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
hexley 0:281d6ff68967 360 DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
hexley 0:281d6ff68967 361 ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
hexley 0:281d6ff68967 362 }
hexley 0:281d6ff68967 363 #endif
hexley 0:281d6ff68967 364
hexley 0:281d6ff68967 365 void
hexley 0:281d6ff68967 366 ChapMS( chap_state *cstate, char *rchallenge, int rchallenge_len, char *secret, int secret_len)
hexley 0:281d6ff68967 367 {
hexley 0:281d6ff68967 368 MS_ChapResponse response;
hexley 0:281d6ff68967 369 #ifdef MSLANMAN
hexley 0:281d6ff68967 370 extern int ms_lanman;
hexley 0:281d6ff68967 371 #endif
hexley 0:281d6ff68967 372
hexley 0:281d6ff68967 373 #if 0
hexley 0:281d6ff68967 374 CHAPDEBUG(LOG_INFO, ("ChapMS: secret is '%.*s'\n", secret_len, secret));
hexley 0:281d6ff68967 375 #endif
hexley 0:281d6ff68967 376 BZERO(&response, sizeof(response));
hexley 0:281d6ff68967 377
hexley 0:281d6ff68967 378 /* Calculate both always */
hexley 0:281d6ff68967 379 ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
hexley 0:281d6ff68967 380
hexley 0:281d6ff68967 381 #ifdef MSLANMAN
hexley 0:281d6ff68967 382 ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
hexley 0:281d6ff68967 383
hexley 0:281d6ff68967 384 /* prefered method is set by option */
hexley 0:281d6ff68967 385 response.UseNT = !ms_lanman;
hexley 0:281d6ff68967 386 #else
hexley 0:281d6ff68967 387 response.UseNT = 1;
hexley 0:281d6ff68967 388 #endif
hexley 0:281d6ff68967 389
hexley 0:281d6ff68967 390 BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
hexley 0:281d6ff68967 391 cstate->resp_length = MS_CHAP_RESPONSE_LEN;
hexley 0:281d6ff68967 392 }
hexley 0:281d6ff68967 393
hexley 0:281d6ff68967 394 #endif /* MSCHAP_SUPPORT */
hexley 0:281d6ff68967 395
hexley 0:281d6ff68967 396 #endif /* PPP_SUPPORT */