2 * chap-new.c - New CHAP implementation.
4 * Copyright (c) 2003 Paul Mackerras. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name(s) of the authors of this software must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission.
22 * 4. Redistributions of any form whatsoever must retain the following
24 * "This product includes software developed by Paul Mackerras
25 * <paulus@samba.org>".
27 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37 * CHAP packets begin with a standard header with code, id, len (2 bytes).
42 * Values for the code field.
44 #define CHAP_CHALLENGE 1
45 #define CHAP_RESPONSE 2
46 #define CHAP_SUCCESS 3
47 #define CHAP_FAILURE 4
53 #define CHAP_MICROSOFT 0x80
54 #define CHAP_MICROSOFT_V2 0x81
57 * Semi-arbitrary limits on challenge and response fields.
59 #define MAX_CHALLENGE_LEN 64
60 #define MAX_RESPONSE_LEN 64
62 /* bitmask of supported algorithms */
63 #define MDTYPE_MICROSOFT_V2 0x1
64 #define MDTYPE_MICROSOFT 0x2
65 #define MDTYPE_MD5 0x4
68 #define MDTYPE_ALL (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
70 #define MDTYPE_ALL (MDTYPE_MD5)
74 /* Return the digest alg. ID for the most preferred digest type. */
75 #define CHAP_DIGEST(mdtype) \
76 ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
77 ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
78 ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
81 /* Return the bit flag (lsb set) for our most preferred digest type. */
82 #define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
84 /* Return the bit flag for a given digest algorithm ID. */
85 #define CHAP_MDTYPE_D(digest) \
86 ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
87 ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
88 ((digest) == CHAP_MD5)? MDTYPE_MD5: \
91 /* Can we do the requested digest? */
92 #define CHAP_CANDIGEST(mdtype, digest) \
93 ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
94 ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
95 ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
99 * The code for each digest type has to supply one of these.
101 struct chap_digest_type {
105 * Note: challenge and response arguments below are formatted as
106 * a length byte followed by the actual challenge/response data.
108 void (*generate_challenge)(unsigned char *challenge);
109 int (*verify_response)(int id, char *name,
110 unsigned char *secret, int secret_len,
111 unsigned char *challenge, unsigned char *response,
112 char *message, int message_space);
113 void (*make_response)(unsigned char *response, int id, char *our_name,
114 unsigned char *challenge, char *secret, int secret_len,
115 unsigned char *priv);
116 int (*check_success)(unsigned char *pkt, int len, unsigned char *priv);
117 void (*handle_failure)(unsigned char *pkt, int len);
119 struct chap_digest_type *next;
122 /* Hook for a plugin to validate CHAP challenge */
123 extern int (*chap_verify_hook)(char *name, char *ourname, int id,
124 struct chap_digest_type *digest,
125 unsigned char *challenge, unsigned char *response,
126 char *message, int message_space);
128 /* Called by digest code to register a digest type */
129 extern void chap_register_digest(struct chap_digest_type *);
131 /* Called by authentication code to start authenticating the peer. */
132 extern void chap_auth_peer(int unit, char *our_name, int digest_code);
134 /* Called by auth. code to start authenticating us to the peer. */
135 extern void chap_auth_with_peer(int unit, char *our_name, int digest_code);
137 /* Represents the CHAP protocol to the main pppd code */
138 extern struct protent chap_protent;