00001 /***************************************************************************** 00002 * chap.h - Network Challenge Handshake Authentication Protocol header file. 00003 * 00004 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. 00005 * portions Copyright (c) 1998 Global Election Systems Inc. 00006 * 00007 * The authors hereby grant permission to use, copy, modify, distribute, 00008 * and license this software and its documentation for any purpose, provided 00009 * that existing copyright notices are retained in all copies and that this 00010 * notice and the following disclaimer are included verbatim in any 00011 * distributions. No written agreement, license, or royalty fee is required 00012 * for any of the authorized uses. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR 00015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00017 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 ****************************************************************************** 00026 * REVISION HISTORY 00027 * 00028 * 03-01-01 Marc Boucher <marc@mbsi.ca> 00029 * Ported to lwIP. 00030 * 97-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. 00031 * Original built from BSD network code. 00032 ******************************************************************************/ 00033 /* 00034 * chap.h - Challenge Handshake Authentication Protocol definitions. 00035 * 00036 * Copyright (c) 1993 The Australian National University. 00037 * All rights reserved. 00038 * 00039 * Redistribution and use in source and binary forms are permitted 00040 * provided that the above copyright notice and this paragraph are 00041 * duplicated in all such forms and that any documentation, 00042 * advertising materials, and other materials related to such 00043 * distribution and use acknowledge that the software was developed 00044 * by the Australian National University. The name of the University 00045 * may not be used to endorse or promote products derived from this 00046 * software without specific prior written permission. 00047 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 00048 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 00049 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00050 * 00051 * Copyright (c) 1991 Gregory M. Christy 00052 * All rights reserved. 00053 * 00054 * Redistribution and use in source and binary forms are permitted 00055 * provided that the above copyright notice and this paragraph are 00056 * duplicated in all such forms and that any documentation, 00057 * advertising materials, and other materials related to such 00058 * distribution and use acknowledge that the software was developed 00059 * by the author. 00060 * 00061 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 00062 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 00063 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00064 * 00065 * $Id: chap.h,v 1.4 2007/12/19 20:47:22 fbernon Exp $ 00066 */ 00067 00068 #ifndef CHAP_H 00069 #define CHAP_H 00070 00071 /************************* 00072 *** PUBLIC DEFINITIONS *** 00073 *************************/ 00074 00075 /* Code + ID + length */ 00076 #define CHAP_HEADERLEN 4 00077 00078 /* 00079 * CHAP codes. 00080 */ 00081 00082 #define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */ 00083 #define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */ 00084 #define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */ 00085 #define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */ 00086 00087 #define CHAP_CHALLENGE 1 00088 #define CHAP_RESPONSE 2 00089 #define CHAP_SUCCESS 3 00090 #define CHAP_FAILURE 4 00091 00092 /* 00093 * Challenge lengths (for challenges we send) and other limits. 00094 */ 00095 #define MIN_CHALLENGE_LENGTH 32 00096 #define MAX_CHALLENGE_LENGTH 64 00097 #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */ 00098 00099 /* 00100 * Client (peer) states. 00101 */ 00102 #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */ 00103 #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */ 00104 #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */ 00105 #define CHAPCS_LISTEN 3 /* Listening for a challenge */ 00106 #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */ 00107 #define CHAPCS_OPEN 5 /* We've received Success */ 00108 00109 /* 00110 * Server (authenticator) states. 00111 */ 00112 #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */ 00113 #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */ 00114 #define CHAPSS_PENDING 2 /* Auth peer when lower up */ 00115 #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */ 00116 #define CHAPSS_OPEN 4 /* We've sent a Success msg */ 00117 #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */ 00118 #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */ 00119 00120 /************************ 00121 *** PUBLIC DATA TYPES *** 00122 ************************/ 00123 00124 /* 00125 * Each interface is described by a chap structure. 00126 */ 00127 00128 typedef struct chap_state { 00129 int unit; /* Interface unit number */ 00130 int clientstate; /* Client state */ 00131 int serverstate; /* Server state */ 00132 u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */ 00133 u_char chal_len; /* challenge length */ 00134 u_char chal_id; /* ID of last challenge */ 00135 u_char chal_type; /* hash algorithm for challenges */ 00136 u_char id; /* Current id */ 00137 char *chal_name; /* Our name to use with challenge */ 00138 int chal_interval; /* Time until we challenge peer again */ 00139 int timeouttime; /* Timeout time in seconds */ 00140 int max_transmits; /* Maximum # of challenge transmissions */ 00141 int chal_transmits; /* Number of transmissions of challenge */ 00142 int resp_transmits; /* Number of transmissions of response */ 00143 u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */ 00144 u_char resp_length; /* length of response */ 00145 u_char resp_id; /* ID for response messages */ 00146 u_char resp_type; /* hash algorithm for responses */ 00147 char *resp_name; /* Our name to send with response */ 00148 } chap_state; 00149 00150 00151 /****************** 00152 *** PUBLIC DATA *** 00153 ******************/ 00154 extern chap_state chap[]; 00155 00156 extern struct protent chap_protent; 00157 00158 00159 /*********************** 00160 *** PUBLIC FUNCTIONS *** 00161 ***********************/ 00162 00163 void ChapAuthWithPeer (int, char *, int); 00164 void ChapAuthPeer (int, char *, int); 00165 00166 #endif /* CHAP_H */