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