Experimental HTTPClient with proxy support

Committer:
igorsk
Date:
Wed Jun 29 16:01:58 2011 +0000
Revision:
0:b56b6a05cad4

        

Who changed what in which revision?

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