31 #include "netif/ppp/ppp_opts.h" 32 #if PPP_SUPPORT && CHAP_SUPPORT 47 #define CHAP_CHALLENGE 1 48 #define CHAP_RESPONSE 2 49 #define CHAP_SUCCESS 3 50 #define CHAP_FAILURE 4 57 #define CHAP_MICROSOFT 0x80 58 #define CHAP_MICROSOFT_V2 0x81 64 #define MAX_CHALLENGE_LEN 64 65 #define MAX_RESPONSE_LEN 64 71 #define CHAL_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN) 72 #define RESP_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN) 76 #define MDTYPE_MICROSOFT_V2 0x1 77 #define MDTYPE_MICROSOFT 0x2 79 #define MDTYPE_MD5 0x4 84 #define CHAP_DIGEST(mdtype) \ 85 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ 86 ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \ 87 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \ 90 #define CHAP_DIGEST(mdtype) \ 91 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ 96 #define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype) 100 #define CHAP_MDTYPE_D(digest) \ 101 ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \ 102 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \ 103 ((digest) == CHAP_MD5)? MDTYPE_MD5: \ 106 #define CHAP_MDTYPE_D(digest) \ 107 ((digest) == CHAP_MD5)? MDTYPE_MD5: \ 113 #define CHAP_CANDIGEST(mdtype, digest) \ 114 ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \ 115 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \ 116 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ 119 #define CHAP_CANDIGEST(mdtype, digest) \ 120 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ 127 struct chap_digest_type {
135 void (*generate_challenge)(ppp_pcb *pcb,
unsigned char *challenge);
136 int (*verify_response)(ppp_pcb *pcb,
int id,
const char *name,
137 const unsigned char *secret,
int secret_len,
138 const unsigned char *challenge,
const unsigned char *response,
139 char *message,
int message_space);
141 void (*make_response)(ppp_pcb *pcb,
unsigned char *response,
int id,
const char *our_name,
142 const unsigned char *challenge,
const char *secret,
int secret_len,
143 unsigned char *priv);
144 int (*check_success)(ppp_pcb *pcb,
unsigned char *pkt,
int len,
unsigned char *priv);
145 void (*handle_failure)(ppp_pcb *pcb,
unsigned char *pkt,
int len);
152 typedef struct chap_client_state {
155 const struct chap_digest_type *digest;
156 unsigned char priv[64];
160 typedef struct chap_server_state {
164 const struct chap_digest_type *digest;
166 int challenge_pktlen;
167 unsigned char challenge[CHAL_MAX_PKTLEN];
174 extern int (*chap_verify_hook)(
char *name,
char *ourname,
int id,
175 const struct chap_digest_type *digest,
176 unsigned char *challenge,
unsigned char *response,
177 char *message,
int message_space);
182 extern void chap_auth_peer(ppp_pcb *pcb,
const char *our_name,
int digest_code);
186 extern void chap_auth_with_peer(ppp_pcb *pcb,
const char *our_name,
int digest_code);
189 extern const struct protent chap_protent;