I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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