Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

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