HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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