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