Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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