lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * chap.h - Challenge Handshake Authentication Protocol definitions. |
| 3 | * |
| 4 | * Copyright (c) 1993 The Australian National University. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms are permitted |
| 8 | * provided that the above copyright notice and this paragraph are |
| 9 | * duplicated in all such forms and that any documentation, |
| 10 | * advertising materials, and other materials related to such |
| 11 | * distribution and use acknowledge that the software was developed |
| 12 | * by the Australian National University. The name of the University |
| 13 | * may not be used to endorse or promote products derived from this |
| 14 | * software without specific prior written permission. |
| 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 17 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 18 | * |
| 19 | * Copyright (c) 1991 Gregory M. Christy |
| 20 | * All rights reserved. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms are permitted |
| 23 | * provided that the above copyright notice and this paragraph are |
| 24 | * duplicated in all such forms and that any documentation, |
| 25 | * advertising materials, and other materials related to such |
| 26 | * distribution and use acknowledge that the software was developed |
| 27 | * by the author. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 30 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 31 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 32 | * |
| 33 | * $Id: chap.h,v 1.1 2008-08-04 06:11:51 winfred Exp $ |
| 34 | */ |
| 35 | |
| 36 | #ifndef __CHAP_INCLUDE__ |
| 37 | |
| 38 | /* Code + ID + length */ |
| 39 | #define CHAP_HEADERLEN 4 |
| 40 | |
| 41 | /* |
| 42 | * CHAP codes. |
| 43 | */ |
| 44 | |
| 45 | #define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */ |
| 46 | #define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */ |
| 47 | #define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */ |
| 48 | #define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */ |
| 49 | #define CHAP_MICROSOFT_V2 0x81 /* use MS-CHAP v2 */ |
| 50 | |
| 51 | #define CHAP_CHALLENGE 1 |
| 52 | #define CHAP_RESPONSE 2 |
| 53 | #define CHAP_SUCCESS 3 |
| 54 | #define CHAP_FAILURE 4 |
| 55 | #define CHAP_SUCCESS_R 13 /* Send response, not text message */ |
| 56 | |
| 57 | /* |
| 58 | * Challenge lengths (for challenges we send) and other limits. |
| 59 | */ |
| 60 | #define MIN_CHALLENGE_LENGTH 16 |
| 61 | #define MAX_CHALLENGE_LENGTH 24 |
| 62 | #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */ |
| 63 | |
| 64 | /* |
| 65 | * Each interface is described by a chap structure. |
| 66 | */ |
| 67 | |
| 68 | typedef struct chap_state { |
| 69 | int unit; /* Interface unit number */ |
| 70 | int clientstate; /* Client state */ |
| 71 | int serverstate; /* Server state */ |
| 72 | u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */ |
| 73 | u_char chal_len; /* challenge length */ |
| 74 | u_char chal_id; /* ID of last challenge */ |
| 75 | u_char chal_type; /* hash algorithm for challenges */ |
| 76 | u_char id; /* Current id */ |
| 77 | char *chal_name; /* Our name to use with challenge */ |
| 78 | int chal_interval; /* Time until we challenge peer again */ |
| 79 | int timeouttime; /* Timeout time in seconds */ |
| 80 | int max_transmits; /* Maximum # of challenge transmissions */ |
| 81 | int chal_transmits; /* Number of transmissions of challenge */ |
| 82 | int resp_transmits; /* Number of transmissions of response */ |
| 83 | u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */ |
| 84 | u_char resp_length; /* length of response */ |
| 85 | u_char resp_id; /* ID for response messages */ |
| 86 | u_char resp_type; /* hash algorithm for responses */ |
| 87 | char *resp_name; /* Our name to send with response */ |
| 88 | } chap_state; |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * Client (peer) states. |
| 93 | */ |
| 94 | #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */ |
| 95 | #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */ |
| 96 | #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */ |
| 97 | #define CHAPCS_LISTEN 3 /* Listening for a challenge */ |
| 98 | #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */ |
| 99 | #define CHAPCS_OPEN 5 /* We've received Success */ |
| 100 | |
| 101 | /* |
| 102 | * Server (authenticator) states. |
| 103 | */ |
| 104 | #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */ |
| 105 | #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */ |
| 106 | #define CHAPSS_PENDING 2 /* Auth peer when lower up */ |
| 107 | #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */ |
| 108 | #define CHAPSS_OPEN 4 /* We've sent a Success msg */ |
| 109 | #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */ |
| 110 | #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */ |
| 111 | |
| 112 | /* |
| 113 | * Timeouts. |
| 114 | */ |
| 115 | #define CHAP_DEFTIMEOUT 3 /* Timeout time in seconds */ |
| 116 | #define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ |
| 117 | |
| 118 | extern chap_state chap[]; |
| 119 | |
| 120 | void ChapAuthWithPeer __P((int, char *, int)); |
| 121 | void ChapAuthPeer __P((int, char *, int)); |
| 122 | void ChapGenChallenge __P((chap_state *)); |
| 123 | |
| 124 | int reqchap(char **); |
| 125 | |
| 126 | extern struct protent chap_protent; |
| 127 | |
| 128 | #define __CHAP_INCLUDE__ |
| 129 | #endif /* __CHAP_INCLUDE__ */ |