Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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