1 /*
2  * IEEE 802.1X-2004 Authenticator - State dump
3  * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "includes.h"
10 
11 #include "common.h"
12 #include "eap_server/eap.h"
13 #include "eapol_auth_sm.h"
14 #include "eapol_auth_sm_i.h"
15 
port_type_txt(PortTypes pt)16 static inline const char * port_type_txt(PortTypes pt)
17 {
18 	switch (pt) {
19 	case ForceUnauthorized: return "ForceUnauthorized";
20 	case ForceAuthorized: return "ForceAuthorized";
21 	case Auto: return "Auto";
22 	default: return "Unknown";
23 	}
24 }
25 
26 
port_state_txt(PortState ps)27 static inline const char * port_state_txt(PortState ps)
28 {
29 	switch (ps) {
30 	case Unauthorized: return "Unauthorized";
31 	case Authorized: return "Authorized";
32 	default: return "Unknown";
33 	}
34 }
35 
36 
ctrl_dir_txt(ControlledDirection dir)37 static inline const char * ctrl_dir_txt(ControlledDirection dir)
38 {
39 	switch (dir) {
40 	case Both: return "Both";
41 	case In: return "In";
42 	default: return "Unknown";
43 	}
44 }
45 
46 
auth_pae_state_txt(int s)47 static inline const char * auth_pae_state_txt(int s)
48 {
49 	switch (s) {
50 	case AUTH_PAE_INITIALIZE: return "INITIALIZE";
51 	case AUTH_PAE_DISCONNECTED: return "DISCONNECTED";
52 	case AUTH_PAE_CONNECTING: return "CONNECTING";
53 	case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";
54 	case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";
55 	case AUTH_PAE_ABORTING: return "ABORTING";
56 	case AUTH_PAE_HELD: return "HELD";
57 	case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";
58 	case AUTH_PAE_FORCE_UNAUTH: return "FORCE_UNAUTH";
59 	case AUTH_PAE_RESTART: return "RESTART";
60 	default: return "Unknown";
61 	}
62 }
63 
64 
be_auth_state_txt(int s)65 static inline const char * be_auth_state_txt(int s)
66 {
67 	switch (s) {
68 	case BE_AUTH_REQUEST: return "REQUEST";
69 	case BE_AUTH_RESPONSE: return "RESPONSE";
70 	case BE_AUTH_SUCCESS: return "SUCCESS";
71 	case BE_AUTH_FAIL: return "FAIL";
72 	case BE_AUTH_TIMEOUT: return "TIMEOUT";
73 	case BE_AUTH_IDLE: return "IDLE";
74 	case BE_AUTH_INITIALIZE: return "INITIALIZE";
75 	case BE_AUTH_IGNORE: return "IGNORE";
76 	default: return "Unknown";
77 	}
78 }
79 
80 
reauth_timer_state_txt(int s)81 static inline const char * reauth_timer_state_txt(int s)
82 {
83 	switch (s) {
84 	case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";
85 	case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";
86 	default: return "Unknown";
87 	}
88 }
89 
90 
auth_key_tx_state_txt(int s)91 static inline const char * auth_key_tx_state_txt(int s)
92 {
93 	switch (s) {
94 	case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";
95 	case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";
96 	default: return "Unknown";
97 	}
98 }
99 
100 
key_rx_state_txt(int s)101 static inline const char * key_rx_state_txt(int s)
102 {
103 	switch (s) {
104 	case KEY_RX_NO_KEY_RECEIVE: return "NO_KEY_RECEIVE";
105 	case KEY_RX_KEY_RECEIVE: return "KEY_RECEIVE";
106 	default: return "Unknown";
107 	}
108 }
109 
110 
ctrl_dir_state_txt(int s)111 static inline const char * ctrl_dir_state_txt(int s)
112 {
113 	switch (s) {
114 	case CTRL_DIR_FORCE_BOTH: return "FORCE_BOTH";
115 	case CTRL_DIR_IN_OR_BOTH: return "IN_OR_BOTH";
116 	default: return "Unknown";
117 	}
118 }
119 
120 
eapol_auth_dump_state(struct eapol_state_machine * sm,char * buf,size_t buflen)121 int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
122 			  size_t buflen)
123 {
124 	char *pos, *end;
125 	int ret;
126 
127 	pos = buf;
128 	end = pos + buflen;
129 
130 	ret = os_snprintf(pos, end - pos, "aWhile=%d\nquietWhile=%d\n"
131 			  "reAuthWhen=%d\n",
132 			  sm->aWhile, sm->quietWhile, sm->reAuthWhen);
133 	if (os_snprintf_error(end - pos, ret))
134 		return pos - buf;
135 	pos += ret;
136 
137 #define _SB(b) ((b) ? "TRUE" : "FALSE")
138 	ret = os_snprintf(pos, end - pos,
139 			  "authAbort=%s\n"
140 			  "authFail=%s\n"
141 			  "authPortStatus=%s\n"
142 			  "authStart=%s\n"
143 			  "authTimeout=%s\n"
144 			  "authSuccess=%s\n"
145 			  "eapFail=%s\n"
146 			  "eapolEap=%s\n"
147 			  "eapSuccess=%s\n"
148 			  "eapTimeout=%s\n"
149 			  "initialize=%s\n"
150 			  "keyAvailable=%s\n"
151 			  "keyDone=%s\n"
152 			  "keyRun=%s\n"
153 			  "keyTxEnabled=%s\n"
154 			  "portControl=%s\n"
155 			  "portEnabled=%s\n"
156 			  "portValid=%s\n"
157 			  "reAuthenticate=%s\n",
158 			  _SB(sm->authAbort),
159 			  _SB(sm->authFail),
160 			  port_state_txt(sm->authPortStatus),
161 			  _SB(sm->authStart),
162 			  _SB(sm->authTimeout),
163 			  _SB(sm->authSuccess),
164 			  _SB(sm->eap_if->eapFail),
165 			  _SB(sm->eapolEap),
166 			  _SB(sm->eap_if->eapSuccess),
167 			  _SB(sm->eap_if->eapTimeout),
168 			  _SB(sm->initialize),
169 			  _SB(sm->eap_if->eapKeyAvailable),
170 			  _SB(sm->keyDone), _SB(sm->keyRun),
171 			  _SB(sm->keyTxEnabled),
172 			  port_type_txt(sm->portControl),
173 			  _SB(sm->eap_if->portEnabled),
174 			  _SB(sm->portValid),
175 			  _SB(sm->reAuthenticate));
176 	if (os_snprintf_error(end - pos, ret))
177 		return pos - buf;
178 	pos += ret;
179 
180 	ret = os_snprintf(pos, end - pos,
181 			  "auth_pae_state=%s\n"
182 			  "eapolLogoff=%s\n"
183 			  "eapolStart=%s\n"
184 			  "eapRestart=%s\n"
185 			  "portMode=%s\n"
186 			  "reAuthCount=%d\n"
187 			  "quietPeriod=%d\n"
188 			  "reAuthMax=%d\n"
189 			  "authEntersConnecting=%d\n"
190 			  "authEapLogoffsWhileConnecting=%d\n"
191 			  "authEntersAuthenticating=%d\n"
192 			  "authAuthSuccessesWhileAuthenticating=%d\n"
193 			  "authAuthTimeoutsWhileAuthenticating=%d\n"
194 			  "authAuthFailWhileAuthenticating=%d\n"
195 			  "authAuthEapStartsWhileAuthenticating=%d\n"
196 			  "authAuthEapLogoffWhileAuthenticating=%d\n"
197 			  "authAuthReauthsWhileAuthenticated=%d\n"
198 			  "authAuthEapStartsWhileAuthenticated=%d\n"
199 			  "authAuthEapLogoffWhileAuthenticated=%d\n",
200 			  auth_pae_state_txt(sm->auth_pae_state),
201 			  _SB(sm->eapolLogoff),
202 			  _SB(sm->eapolStart),
203 			  _SB(sm->eap_if->eapRestart),
204 			  port_type_txt(sm->portMode),
205 			  sm->reAuthCount,
206 			  sm->quietPeriod, sm->reAuthMax,
207 			  sm->authEntersConnecting,
208 			  sm->authEapLogoffsWhileConnecting,
209 			  sm->authEntersAuthenticating,
210 			  sm->authAuthSuccessesWhileAuthenticating,
211 			  sm->authAuthTimeoutsWhileAuthenticating,
212 			  sm->authAuthFailWhileAuthenticating,
213 			  sm->authAuthEapStartsWhileAuthenticating,
214 			  sm->authAuthEapLogoffWhileAuthenticating,
215 			  sm->authAuthReauthsWhileAuthenticated,
216 			  sm->authAuthEapStartsWhileAuthenticated,
217 			  sm->authAuthEapLogoffWhileAuthenticated);
218 	if (os_snprintf_error(end - pos, ret))
219 		return pos - buf;
220 	pos += ret;
221 
222 	ret = os_snprintf(pos, end - pos,
223 			  "be_auth_state=%s\n"
224 			  "eapNoReq=%s\n"
225 			  "eapReq=%s\n"
226 			  "eapResp=%s\n"
227 			  "serverTimeout=%d\n"
228 			  "backendResponses=%d\n"
229 			  "backendAccessChallenges=%d\n"
230 			  "backendOtherRequestsToSupplicant=%d\n"
231 			  "backendAuthSuccesses=%d\n"
232 			  "backendAuthFails=%d\n",
233 			  be_auth_state_txt(sm->be_auth_state),
234 			  _SB(sm->eap_if->eapNoReq),
235 			  _SB(sm->eap_if->eapReq),
236 			  _SB(sm->eap_if->eapResp),
237 			  sm->serverTimeout,
238 			  sm->backendResponses,
239 			  sm->backendAccessChallenges,
240 			  sm->backendOtherRequestsToSupplicant,
241 			  sm->backendAuthSuccesses,
242 			  sm->backendAuthFails);
243 	if (os_snprintf_error(end - pos, ret))
244 		return pos - buf;
245 	pos += ret;
246 
247 	ret = os_snprintf(pos, end - pos,
248 			  "reauth_timer_state=%s\n"
249 			  "reAuthPeriod=%d\n"
250 			  "reAuthEnabled=%s\n",
251 			  reauth_timer_state_txt(sm->reauth_timer_state),
252 			  sm->reAuthPeriod,
253 			  _SB(sm->reAuthEnabled));
254 	if (os_snprintf_error(end - pos, ret))
255 		return pos - buf;
256 	pos += ret;
257 
258 	ret = os_snprintf(pos, end - pos,
259 			  "auth_key_tx_state=%s\n",
260 			  auth_key_tx_state_txt(sm->auth_key_tx_state));
261 	if (os_snprintf_error(end - pos, ret))
262 		return pos - buf;
263 	pos += ret;
264 
265 	ret = os_snprintf(pos, end - pos,
266 			  "key_rx_state=%s\n"
267 			  "rxKey=%s\n",
268 			  key_rx_state_txt(sm->key_rx_state),
269 			  _SB(sm->rxKey));
270 	if (os_snprintf_error(end - pos, ret))
271 		return pos - buf;
272 	pos += ret;
273 
274 	ret = os_snprintf(pos, end - pos,
275 			  "ctrl_dir_state=%s\n"
276 			  "adminControlledDirections=%s\n"
277 			  "operControlledDirections=%s\n"
278 			  "operEdge=%s\n",
279 			  ctrl_dir_state_txt(sm->ctrl_dir_state),
280 			  ctrl_dir_txt(sm->adminControlledDirections),
281 			  ctrl_dir_txt(sm->operControlledDirections),
282 			  _SB(sm->operEdge));
283 	if (os_snprintf_error(end - pos, ret))
284 		return pos - buf;
285 	pos += ret;
286 #undef _SB
287 
288 	return pos - buf;
289 }
290