Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
chap-new.h
00001 /* 00002 * chap-new.c - New CHAP implementation. 00003 * 00004 * Copyright (c) 2003 Paul Mackerras. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * 2. The name(s) of the authors of this software must not be used to 00014 * endorse or promote products derived from this software without 00015 * prior written permission. 00016 * 00017 * 3. Redistributions of any form whatsoever must retain the following 00018 * acknowledgment: 00019 * "This product includes software developed by Paul Mackerras 00020 * <paulus@samba.org>". 00021 * 00022 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 00023 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00024 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 00025 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00026 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 00027 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 00028 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00029 */ 00030 00031 #include "ppp_opts.h" 00032 #if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ 00033 00034 #ifndef CHAP_H 00035 #define CHAP_H 00036 00037 #include "ppp.h" 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 /* 00044 * CHAP packets begin with a standard header with code, id, len (2 bytes). 00045 */ 00046 #define CHAP_HDRLEN 4 00047 00048 /* 00049 * Values for the code field. 00050 */ 00051 #define CHAP_CHALLENGE 1 00052 #define CHAP_RESPONSE 2 00053 #define CHAP_SUCCESS 3 00054 #define CHAP_FAILURE 4 00055 00056 /* 00057 * CHAP digest codes. 00058 */ 00059 #define CHAP_MD5 5 00060 #if MSCHAP_SUPPORT 00061 #define CHAP_MICROSOFT 0x80 00062 #define CHAP_MICROSOFT_V2 0x81 00063 #endif /* MSCHAP_SUPPORT */ 00064 00065 /* 00066 * Semi-arbitrary limits on challenge and response fields. 00067 */ 00068 #define MAX_CHALLENGE_LEN 64 00069 #define MAX_RESPONSE_LEN 64 00070 00071 /* 00072 * These limits apply to challenge and response packets we send. 00073 * The +4 is the +1 that we actually need rounded up. 00074 */ 00075 #define CHAL_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN) 00076 #define RESP_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN) 00077 00078 /* bitmask of supported algorithms */ 00079 #if MSCHAP_SUPPORT 00080 #define MDTYPE_MICROSOFT_V2 0x1 00081 #define MDTYPE_MICROSOFT 0x2 00082 #endif /* MSCHAP_SUPPORT */ 00083 #define MDTYPE_MD5 0x4 00084 #define MDTYPE_NONE 0 00085 00086 #if MSCHAP_SUPPORT 00087 /* Return the digest alg. ID for the most preferred digest type. */ 00088 #define CHAP_DIGEST(mdtype) \ 00089 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ 00090 ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \ 00091 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \ 00092 0 00093 #else /* !MSCHAP_SUPPORT */ 00094 #define CHAP_DIGEST(mdtype) \ 00095 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ 00096 0 00097 #endif /* MSCHAP_SUPPORT */ 00098 00099 /* Return the bit flag (lsb set) for our most preferred digest type. */ 00100 #define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype) 00101 00102 /* Return the bit flag for a given digest algorithm ID. */ 00103 #if MSCHAP_SUPPORT 00104 #define CHAP_MDTYPE_D(digest) \ 00105 ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \ 00106 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \ 00107 ((digest) == CHAP_MD5)? MDTYPE_MD5: \ 00108 0 00109 #else /* !MSCHAP_SUPPORT */ 00110 #define CHAP_MDTYPE_D(digest) \ 00111 ((digest) == CHAP_MD5)? MDTYPE_MD5: \ 00112 0 00113 #endif /* MSCHAP_SUPPORT */ 00114 00115 /* Can we do the requested digest? */ 00116 #if MSCHAP_SUPPORT 00117 #define CHAP_CANDIGEST(mdtype, digest) \ 00118 ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \ 00119 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \ 00120 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ 00121 0 00122 #else /* !MSCHAP_SUPPORT */ 00123 #define CHAP_CANDIGEST(mdtype, digest) \ 00124 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ 00125 0 00126 #endif /* MSCHAP_SUPPORT */ 00127 00128 /* 00129 * The code for each digest type has to supply one of these. 00130 */ 00131 struct chap_digest_type { 00132 int code; 00133 00134 #if PPP_SERVER 00135 /* 00136 * Note: challenge and response arguments below are formatted as 00137 * a length byte followed by the actual challenge/response data. 00138 */ 00139 void (*generate_challenge)(ppp_pcb *pcb, unsigned char *challenge); 00140 int (*verify_response)(ppp_pcb *pcb, int id, const char *name, 00141 const unsigned char *secret, int secret_len, 00142 const unsigned char *challenge, const unsigned char *response, 00143 char *message, int message_space); 00144 #endif /* PPP_SERVER */ 00145 void (*make_response)(ppp_pcb *pcb, unsigned char *response, int id, const char *our_name, 00146 const unsigned char *challenge, const char *secret, int secret_len, 00147 unsigned char *priv); 00148 int (*check_success)(ppp_pcb *pcb, unsigned char *pkt, int len, unsigned char *priv); 00149 void (*handle_failure)(ppp_pcb *pcb, unsigned char *pkt, int len); 00150 }; 00151 00152 /* 00153 * Each interface is described by chap structure. 00154 */ 00155 #if CHAP_SUPPORT 00156 typedef struct chap_client_state { 00157 u8_t flags; 00158 const char *name; 00159 const struct chap_digest_type *digest; 00160 unsigned char priv[64]; /* private area for digest's use */ 00161 } chap_client_state; 00162 00163 #if PPP_SERVER 00164 typedef struct chap_server_state { 00165 u8_t flags; 00166 u8_t id; 00167 const char *name; 00168 const struct chap_digest_type *digest; 00169 int challenge_xmits; 00170 int challenge_pktlen; 00171 unsigned char challenge[CHAL_MAX_PKTLEN]; 00172 } chap_server_state; 00173 #endif /* PPP_SERVER */ 00174 #endif /* CHAP_SUPPORT */ 00175 00176 #if 0 /* UNUSED */ 00177 /* Hook for a plugin to validate CHAP challenge */ 00178 extern int (*chap_verify_hook)(char *name, char *ourname, int id, 00179 const struct chap_digest_type *digest, 00180 unsigned char *challenge, unsigned char *response, 00181 char *message, int message_space); 00182 #endif /* UNUSED */ 00183 00184 #if PPP_SERVER 00185 /* Called by authentication code to start authenticating the peer. */ 00186 extern void chap_auth_peer(ppp_pcb *pcb, const char *our_name, int digest_code); 00187 #endif /* PPP_SERVER */ 00188 00189 /* Called by auth. code to start authenticating us to the peer. */ 00190 extern void chap_auth_with_peer(ppp_pcb *pcb, const char *our_name, int digest_code); 00191 00192 /* Represents the CHAP protocol to the main pppd code */ 00193 extern const struct protent chap_protent; 00194 00195 #ifdef __cplusplus 00196 } 00197 #endif 00198 00199 #endif /* CHAP_H */ 00200 #endif /* PPP_SUPPORT && CHAP_SUPPORT */
Generated on Tue Jul 12 2022 13:54:06 by
