Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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