Line data Source code
1 : /*
2 : * IEEE 802.1X-2004 Authenticator - EAPOL state machine
3 : * Copyright (c) 2002-2009, 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 "eloop.h"
13 : #include "state_machine.h"
14 : #include "common/eapol_common.h"
15 : #include "eap_common/eap_defs.h"
16 : #include "eap_common/eap_common.h"
17 : #include "eap_server/eap.h"
18 : #include "eapol_auth_sm.h"
19 : #include "eapol_auth_sm_i.h"
20 :
21 : #define STATE_MACHINE_DATA struct eapol_state_machine
22 : #define STATE_MACHINE_DEBUG_PREFIX "IEEE 802.1X"
23 : #define STATE_MACHINE_ADDR sm->addr
24 :
25 : static struct eapol_callbacks eapol_cb;
26 :
27 : /* EAPOL state machines are described in IEEE Std 802.1X-2004, Chap. 8.2 */
28 :
29 : #define setPortAuthorized() \
30 : sm->eapol->cb.set_port_authorized(sm->eapol->conf.ctx, sm->sta, 1)
31 : #define setPortUnauthorized() \
32 : sm->eapol->cb.set_port_authorized(sm->eapol->conf.ctx, sm->sta, 0)
33 :
34 : /* procedures */
35 : #define txCannedFail() eapol_auth_tx_canned_eap(sm, 0)
36 : #define txCannedSuccess() eapol_auth_tx_canned_eap(sm, 1)
37 : #define txReq() eapol_auth_tx_req(sm)
38 : #define abortAuth() sm->eapol->cb.abort_auth(sm->eapol->conf.ctx, sm->sta)
39 : #define txKey() sm->eapol->cb.tx_key(sm->eapol->conf.ctx, sm->sta)
40 : #define processKey() do { } while (0)
41 :
42 :
43 : static void eapol_sm_step_run(struct eapol_state_machine *sm);
44 : static void eapol_sm_step_cb(void *eloop_ctx, void *timeout_ctx);
45 : static void eapol_auth_initialize(struct eapol_state_machine *sm);
46 :
47 :
48 4234 : static void eapol_auth_logger(struct eapol_authenticator *eapol,
49 : const u8 *addr, eapol_logger_level level,
50 : const char *txt)
51 : {
52 4234 : if (eapol->cb.logger == NULL)
53 4234 : return;
54 4234 : eapol->cb.logger(eapol->conf.ctx, addr, level, txt);
55 : }
56 :
57 :
58 4234 : static void eapol_auth_vlogger(struct eapol_authenticator *eapol,
59 : const u8 *addr, eapol_logger_level level,
60 : const char *fmt, ...)
61 : {
62 : char *format;
63 : int maxlen;
64 : va_list ap;
65 :
66 4234 : if (eapol->cb.logger == NULL)
67 0 : return;
68 :
69 4234 : maxlen = os_strlen(fmt) + 100;
70 4234 : format = os_malloc(maxlen);
71 4234 : if (!format)
72 0 : return;
73 :
74 4234 : va_start(ap, fmt);
75 4234 : vsnprintf(format, maxlen, fmt, ap);
76 4234 : va_end(ap);
77 :
78 4234 : eapol_auth_logger(eapol, addr, level, format);
79 :
80 4234 : os_free(format);
81 : }
82 :
83 :
84 0 : static void eapol_auth_tx_canned_eap(struct eapol_state_machine *sm,
85 : int success)
86 : {
87 : struct eap_hdr eap;
88 :
89 0 : os_memset(&eap, 0, sizeof(eap));
90 :
91 0 : eap.code = success ? EAP_CODE_SUCCESS : EAP_CODE_FAILURE;
92 0 : eap.identifier = ++sm->last_eap_id;
93 0 : eap.length = host_to_be16(sizeof(eap));
94 :
95 0 : eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
96 : "Sending canned EAP packet %s (identifier %d)",
97 0 : success ? "SUCCESS" : "FAILURE", eap.identifier);
98 0 : sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
99 : IEEE802_1X_TYPE_EAP_PACKET,
100 : (u8 *) &eap, sizeof(eap));
101 0 : sm->dot1xAuthEapolFramesTx++;
102 0 : }
103 :
104 :
105 3486 : static void eapol_auth_tx_req(struct eapol_state_machine *sm)
106 : {
107 6972 : if (sm->eap_if->eapReqData == NULL ||
108 3486 : wpabuf_len(sm->eap_if->eapReqData) < sizeof(struct eap_hdr)) {
109 0 : eapol_auth_logger(sm->eapol, sm->addr,
110 : EAPOL_LOGGER_DEBUG,
111 : "TxReq called, but there is no EAP request "
112 : "from authentication server");
113 0 : return;
114 : }
115 :
116 3486 : if (sm->flags & EAPOL_SM_WAIT_START) {
117 6 : wpa_printf(MSG_DEBUG, "EAPOL: Drop EAPOL TX to " MACSTR
118 : " while waiting for EAPOL-Start",
119 6 : MAC2STR(sm->addr));
120 1 : return;
121 : }
122 :
123 3485 : sm->last_eap_id = eap_get_id(sm->eap_if->eapReqData);
124 3485 : eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_DEBUG,
125 : "Sending EAP Packet (identifier %d)",
126 3485 : sm->last_eap_id);
127 10455 : sm->eapol->cb.eapol_send(sm->eapol->conf.ctx, sm->sta,
128 : IEEE802_1X_TYPE_EAP_PACKET,
129 3485 : wpabuf_head(sm->eap_if->eapReqData),
130 3485 : wpabuf_len(sm->eap_if->eapReqData));
131 3485 : sm->dot1xAuthEapolFramesTx++;
132 3485 : if (eap_get_type(sm->eap_if->eapReqData) == EAP_TYPE_IDENTITY)
133 546 : sm->dot1xAuthEapolReqIdFramesTx++;
134 : else
135 2939 : sm->dot1xAuthEapolReqFramesTx++;
136 : }
137 :
138 :
139 : /**
140 : * eapol_port_timers_tick - Port Timers state machine
141 : * @eloop_ctx: struct eapol_state_machine *
142 : * @timeout_ctx: Not used
143 : *
144 : * This statemachine is implemented as a function that will be called
145 : * once a second as a registered event loop timeout.
146 : */
147 70 : static void eapol_port_timers_tick(void *eloop_ctx, void *timeout_ctx)
148 : {
149 70 : struct eapol_state_machine *state = timeout_ctx;
150 :
151 70 : if (state->aWhile > 0) {
152 69 : state->aWhile--;
153 69 : if (state->aWhile == 0) {
154 0 : wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR
155 : " - aWhile --> 0",
156 0 : MAC2STR(state->addr));
157 : }
158 : }
159 :
160 70 : if (state->quietWhile > 0) {
161 6 : state->quietWhile--;
162 6 : if (state->quietWhile == 0) {
163 0 : wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR
164 : " - quietWhile --> 0",
165 0 : MAC2STR(state->addr));
166 : }
167 : }
168 :
169 70 : if (state->reAuthWhen > 0) {
170 70 : state->reAuthWhen--;
171 70 : if (state->reAuthWhen == 0) {
172 6 : wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR
173 : " - reAuthWhen --> 0",
174 6 : MAC2STR(state->addr));
175 : }
176 : }
177 :
178 70 : if (state->eap_if->retransWhile > 0) {
179 55 : state->eap_if->retransWhile--;
180 55 : if (state->eap_if->retransWhile == 0) {
181 48 : wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR
182 : " - (EAP) retransWhile --> 0",
183 48 : MAC2STR(state->addr));
184 : }
185 : }
186 :
187 70 : eapol_sm_step_run(state);
188 :
189 70 : eloop_register_timeout(1, 0, eapol_port_timers_tick, eloop_ctx, state);
190 70 : }
191 :
192 :
193 :
194 : /* Authenticator PAE state machine */
195 :
196 2599 : SM_STATE(AUTH_PAE, INITIALIZE)
197 : {
198 2599 : SM_ENTRY_MA(AUTH_PAE, INITIALIZE, auth_pae);
199 2599 : sm->portMode = Auto;
200 2599 : }
201 :
202 :
203 488 : SM_STATE(AUTH_PAE, DISCONNECTED)
204 : {
205 488 : int from_initialize = sm->auth_pae_state == AUTH_PAE_INITIALIZE;
206 :
207 488 : if (sm->eapolLogoff) {
208 1 : if (sm->auth_pae_state == AUTH_PAE_CONNECTING)
209 0 : sm->authEapLogoffsWhileConnecting++;
210 1 : else if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED)
211 1 : sm->authAuthEapLogoffWhileAuthenticated++;
212 : }
213 :
214 488 : SM_ENTRY_MA(AUTH_PAE, DISCONNECTED, auth_pae);
215 :
216 488 : sm->authPortStatus = Unauthorized;
217 488 : setPortUnauthorized();
218 488 : sm->reAuthCount = 0;
219 488 : sm->eapolLogoff = FALSE;
220 488 : if (!from_initialize) {
221 2 : sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
222 1 : sm->flags & EAPOL_SM_PREAUTH,
223 : sm->remediation);
224 : }
225 488 : }
226 :
227 :
228 547 : SM_STATE(AUTH_PAE, RESTART)
229 : {
230 547 : if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED) {
231 56 : if (sm->reAuthenticate)
232 1 : sm->authAuthReauthsWhileAuthenticated++;
233 56 : if (sm->eapolStart)
234 55 : sm->authAuthEapStartsWhileAuthenticated++;
235 56 : if (sm->eapolLogoff)
236 0 : sm->authAuthEapLogoffWhileAuthenticated++;
237 : }
238 :
239 547 : SM_ENTRY_MA(AUTH_PAE, RESTART, auth_pae);
240 :
241 547 : sm->eap_if->eapRestart = TRUE;
242 547 : }
243 :
244 :
245 547 : SM_STATE(AUTH_PAE, CONNECTING)
246 : {
247 547 : if (sm->auth_pae_state != AUTH_PAE_CONNECTING)
248 547 : sm->authEntersConnecting++;
249 :
250 547 : SM_ENTRY_MA(AUTH_PAE, CONNECTING, auth_pae);
251 :
252 547 : sm->reAuthenticate = FALSE;
253 547 : sm->reAuthCount++;
254 547 : }
255 :
256 :
257 250 : SM_STATE(AUTH_PAE, HELD)
258 : {
259 250 : if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING && sm->authFail)
260 250 : sm->authAuthFailWhileAuthenticating++;
261 :
262 250 : SM_ENTRY_MA(AUTH_PAE, HELD, auth_pae);
263 :
264 250 : sm->authPortStatus = Unauthorized;
265 250 : setPortUnauthorized();
266 250 : sm->quietWhile = sm->quietPeriod;
267 250 : sm->eapolLogoff = FALSE;
268 :
269 500 : eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_WARNING,
270 : "authentication failed - EAP type: %d (%s)",
271 250 : sm->eap_type_authsrv,
272 250 : eap_server_get_name(0, sm->eap_type_authsrv));
273 250 : if (sm->eap_type_authsrv != sm->eap_type_supp) {
274 416 : eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
275 : "Supplicant used different EAP type: "
276 208 : "%d (%s)", sm->eap_type_supp,
277 208 : eap_server_get_name(0, sm->eap_type_supp));
278 : }
279 500 : sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 0,
280 250 : sm->flags & EAPOL_SM_PREAUTH, sm->remediation);
281 250 : }
282 :
283 :
284 291 : SM_STATE(AUTH_PAE, AUTHENTICATED)
285 : {
286 291 : char *extra = "";
287 :
288 291 : if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING && sm->authSuccess)
289 291 : sm->authAuthSuccessesWhileAuthenticating++;
290 :
291 291 : SM_ENTRY_MA(AUTH_PAE, AUTHENTICATED, auth_pae);
292 :
293 291 : sm->authPortStatus = Authorized;
294 291 : setPortAuthorized();
295 291 : sm->reAuthCount = 0;
296 291 : if (sm->flags & EAPOL_SM_PREAUTH)
297 1 : extra = " (pre-authentication)";
298 290 : else if (sm->flags & EAPOL_SM_FROM_PMKSA_CACHE)
299 10 : extra = " (PMKSA cache)";
300 582 : eapol_auth_vlogger(sm->eapol, sm->addr, EAPOL_LOGGER_INFO,
301 : "authenticated - EAP type: %d (%s)%s",
302 291 : sm->eap_type_authsrv,
303 291 : eap_server_get_name(0, sm->eap_type_authsrv),
304 : extra);
305 582 : sm->eapol->cb.finished(sm->eapol->conf.ctx, sm->sta, 1,
306 291 : sm->flags & EAPOL_SM_PREAUTH, sm->remediation);
307 291 : }
308 :
309 :
310 547 : SM_STATE(AUTH_PAE, AUTHENTICATING)
311 : {
312 547 : SM_ENTRY_MA(AUTH_PAE, AUTHENTICATING, auth_pae);
313 :
314 547 : sm->eapolStart = FALSE;
315 547 : sm->authSuccess = FALSE;
316 547 : sm->authFail = FALSE;
317 547 : sm->authTimeout = FALSE;
318 547 : sm->authStart = TRUE;
319 547 : sm->keyRun = FALSE;
320 547 : sm->keyDone = FALSE;
321 547 : }
322 :
323 :
324 4 : SM_STATE(AUTH_PAE, ABORTING)
325 : {
326 4 : if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATING) {
327 4 : if (sm->authTimeout)
328 0 : sm->authAuthTimeoutsWhileAuthenticating++;
329 4 : if (sm->eapolStart)
330 4 : sm->authAuthEapStartsWhileAuthenticating++;
331 4 : if (sm->eapolLogoff)
332 0 : sm->authAuthEapLogoffWhileAuthenticating++;
333 : }
334 :
335 4 : SM_ENTRY_MA(AUTH_PAE, ABORTING, auth_pae);
336 :
337 4 : sm->authAbort = TRUE;
338 4 : sm->keyRun = FALSE;
339 4 : sm->keyDone = FALSE;
340 4 : }
341 :
342 :
343 0 : SM_STATE(AUTH_PAE, FORCE_AUTH)
344 : {
345 0 : SM_ENTRY_MA(AUTH_PAE, FORCE_AUTH, auth_pae);
346 :
347 0 : sm->authPortStatus = Authorized;
348 0 : setPortAuthorized();
349 0 : sm->portMode = ForceAuthorized;
350 0 : sm->eapolStart = FALSE;
351 0 : txCannedSuccess();
352 0 : }
353 :
354 :
355 0 : SM_STATE(AUTH_PAE, FORCE_UNAUTH)
356 : {
357 0 : SM_ENTRY_MA(AUTH_PAE, FORCE_UNAUTH, auth_pae);
358 :
359 0 : sm->authPortStatus = Unauthorized;
360 0 : setPortUnauthorized();
361 0 : sm->portMode = ForceUnauthorized;
362 0 : sm->eapolStart = FALSE;
363 0 : txCannedFail();
364 0 : }
365 :
366 :
367 23055 : SM_STEP(AUTH_PAE)
368 : {
369 45621 : if ((sm->portControl == Auto && sm->portMode != sm->portControl) ||
370 45132 : sm->initialize || !sm->eap_if->portEnabled)
371 2599 : SM_ENTER_GLOBAL(AUTH_PAE, INITIALIZE);
372 20456 : else if (sm->portControl == ForceAuthorized &&
373 0 : sm->portMode != sm->portControl &&
374 0 : !(sm->initialize || !sm->eap_if->portEnabled))
375 0 : SM_ENTER_GLOBAL(AUTH_PAE, FORCE_AUTH);
376 20456 : else if (sm->portControl == ForceUnauthorized &&
377 0 : sm->portMode != sm->portControl &&
378 0 : !(sm->initialize || !sm->eap_if->portEnabled))
379 0 : SM_ENTER_GLOBAL(AUTH_PAE, FORCE_UNAUTH);
380 : else {
381 20456 : switch (sm->auth_pae_state) {
382 : case AUTH_PAE_INITIALIZE:
383 487 : SM_ENTER(AUTH_PAE, DISCONNECTED);
384 487 : break;
385 : case AUTH_PAE_DISCONNECTED:
386 487 : SM_ENTER(AUTH_PAE, RESTART);
387 487 : break;
388 : case AUTH_PAE_RESTART:
389 1094 : if (!sm->eap_if->eapRestart)
390 547 : SM_ENTER(AUTH_PAE, CONNECTING);
391 1094 : break;
392 : case AUTH_PAE_HELD:
393 0 : if (sm->quietWhile == 0)
394 0 : SM_ENTER(AUTH_PAE, RESTART);
395 0 : break;
396 : case AUTH_PAE_CONNECTING:
397 547 : if (sm->eapolLogoff || sm->reAuthCount > sm->reAuthMax)
398 0 : SM_ENTER(AUTH_PAE, DISCONNECTED);
399 1094 : else if ((sm->eap_if->eapReq &&
400 547 : sm->reAuthCount <= sm->reAuthMax) ||
401 0 : sm->eap_if->eapSuccess || sm->eap_if->eapFail)
402 547 : SM_ENTER(AUTH_PAE, AUTHENTICATING);
403 547 : break;
404 : case AUTH_PAE_AUTHENTICATED:
405 454 : if (sm->eapolStart || sm->reAuthenticate)
406 56 : SM_ENTER(AUTH_PAE, RESTART);
407 398 : else if (sm->eapolLogoff || !sm->portValid)
408 1 : SM_ENTER(AUTH_PAE, DISCONNECTED);
409 454 : break;
410 : case AUTH_PAE_AUTHENTICATING:
411 17383 : if (sm->authSuccess && sm->portValid)
412 291 : SM_ENTER(AUTH_PAE, AUTHENTICATED);
413 33934 : else if (sm->authFail ||
414 16842 : (sm->keyDone && !sm->portValid))
415 250 : SM_ENTER(AUTH_PAE, HELD);
416 33680 : else if (sm->eapolStart || sm->eapolLogoff ||
417 16838 : sm->authTimeout)
418 4 : SM_ENTER(AUTH_PAE, ABORTING);
419 17383 : break;
420 : case AUTH_PAE_ABORTING:
421 4 : if (sm->eapolLogoff && !sm->authAbort)
422 0 : SM_ENTER(AUTH_PAE, DISCONNECTED);
423 4 : else if (!sm->eapolLogoff && !sm->authAbort)
424 4 : SM_ENTER(AUTH_PAE, RESTART);
425 4 : break;
426 : case AUTH_PAE_FORCE_AUTH:
427 0 : if (sm->eapolStart)
428 0 : SM_ENTER(AUTH_PAE, FORCE_AUTH);
429 0 : break;
430 : case AUTH_PAE_FORCE_UNAUTH:
431 0 : if (sm->eapolStart)
432 0 : SM_ENTER(AUTH_PAE, FORCE_UNAUTH);
433 0 : break;
434 : }
435 : }
436 23055 : }
437 :
438 :
439 :
440 : /* Backend Authentication state machine */
441 :
442 493 : SM_STATE(BE_AUTH, INITIALIZE)
443 : {
444 493 : SM_ENTRY_MA(BE_AUTH, INITIALIZE, be_auth);
445 :
446 493 : abortAuth();
447 493 : sm->eap_if->eapNoReq = FALSE;
448 493 : sm->authAbort = FALSE;
449 493 : }
450 :
451 :
452 2954 : SM_STATE(BE_AUTH, REQUEST)
453 : {
454 2954 : SM_ENTRY_MA(BE_AUTH, REQUEST, be_auth);
455 :
456 2954 : txReq();
457 2954 : sm->eap_if->eapReq = FALSE;
458 2954 : sm->backendOtherRequestsToSupplicant++;
459 :
460 : /*
461 : * Clearing eapolEap here is not specified in IEEE Std 802.1X-2004, but
462 : * it looks like this would be logical thing to do there since the old
463 : * EAP response would not be valid anymore after the new EAP request
464 : * was sent out.
465 : *
466 : * A race condition has been reported, in which hostapd ended up
467 : * sending out EAP-Response/Identity as a response to the first
468 : * EAP-Request from the main EAP method. This can be avoided by
469 : * clearing eapolEap here.
470 : */
471 2954 : sm->eapolEap = FALSE;
472 2954 : }
473 :
474 :
475 2946 : SM_STATE(BE_AUTH, RESPONSE)
476 : {
477 2946 : SM_ENTRY_MA(BE_AUTH, RESPONSE, be_auth);
478 :
479 2946 : sm->authTimeout = FALSE;
480 2946 : sm->eapolEap = FALSE;
481 2946 : sm->eap_if->eapNoReq = FALSE;
482 2946 : sm->aWhile = sm->serverTimeout;
483 2946 : sm->eap_if->eapResp = TRUE;
484 : /* sendRespToServer(); */
485 2946 : sm->backendResponses++;
486 2946 : }
487 :
488 :
489 283 : SM_STATE(BE_AUTH, SUCCESS)
490 : {
491 283 : SM_ENTRY_MA(BE_AUTH, SUCCESS, be_auth);
492 :
493 283 : txReq();
494 283 : sm->authSuccess = TRUE;
495 283 : sm->keyRun = TRUE;
496 283 : }
497 :
498 :
499 249 : SM_STATE(BE_AUTH, FAIL)
500 : {
501 249 : SM_ENTRY_MA(BE_AUTH, FAIL, be_auth);
502 :
503 249 : txReq();
504 249 : sm->authFail = TRUE;
505 249 : }
506 :
507 :
508 0 : SM_STATE(BE_AUTH, TIMEOUT)
509 : {
510 0 : SM_ENTRY_MA(BE_AUTH, TIMEOUT, be_auth);
511 :
512 0 : sm->authTimeout = TRUE;
513 0 : }
514 :
515 :
516 1038 : SM_STATE(BE_AUTH, IDLE)
517 : {
518 1038 : SM_ENTRY_MA(BE_AUTH, IDLE, be_auth);
519 :
520 1038 : sm->authStart = FALSE;
521 1038 : }
522 :
523 :
524 2 : SM_STATE(BE_AUTH, IGNORE)
525 : {
526 2 : SM_ENTRY_MA(BE_AUTH, IGNORE, be_auth);
527 :
528 2 : sm->eap_if->eapNoReq = FALSE;
529 2 : }
530 :
531 :
532 23055 : SM_STEP(BE_AUTH)
533 : {
534 23055 : if (sm->portControl != Auto || sm->initialize || sm->authAbort) {
535 493 : SM_ENTER_GLOBAL(BE_AUTH, INITIALIZE);
536 23548 : return;
537 : }
538 :
539 22562 : switch (sm->be_auth_state) {
540 : case BE_AUTH_INITIALIZE:
541 493 : SM_ENTER(BE_AUTH, IDLE);
542 493 : break;
543 : case BE_AUTH_REQUEST:
544 7176 : if (sm->eapolEap)
545 2944 : SM_ENTER(BE_AUTH, RESPONSE);
546 4232 : else if (sm->eap_if->eapReq)
547 0 : SM_ENTER(BE_AUTH, REQUEST);
548 4232 : else if (sm->eap_if->eapTimeout)
549 0 : SM_ENTER(BE_AUTH, TIMEOUT);
550 7176 : break;
551 : case BE_AUTH_RESPONSE:
552 9168 : if (sm->eap_if->eapNoReq)
553 2 : SM_ENTER(BE_AUTH, IGNORE);
554 9168 : if (sm->eap_if->eapReq) {
555 2407 : sm->backendAccessChallenges++;
556 2407 : SM_ENTER(BE_AUTH, REQUEST);
557 6761 : } else if (sm->aWhile == 0)
558 0 : SM_ENTER(BE_AUTH, TIMEOUT);
559 6761 : else if (sm->eap_if->eapFail) {
560 249 : sm->backendAuthFails++;
561 249 : SM_ENTER(BE_AUTH, FAIL);
562 6512 : } else if (sm->eap_if->eapSuccess) {
563 283 : sm->backendAuthSuccesses++;
564 283 : SM_ENTER(BE_AUTH, SUCCESS);
565 : }
566 9168 : break;
567 : case BE_AUTH_SUCCESS:
568 296 : SM_ENTER(BE_AUTH, IDLE);
569 296 : break;
570 : case BE_AUTH_FAIL:
571 249 : SM_ENTER(BE_AUTH, IDLE);
572 249 : break;
573 : case BE_AUTH_TIMEOUT:
574 0 : SM_ENTER(BE_AUTH, IDLE);
575 0 : break;
576 : case BE_AUTH_IDLE:
577 5174 : if (sm->eap_if->eapFail && sm->authStart)
578 0 : SM_ENTER(BE_AUTH, FAIL);
579 5174 : else if (sm->eap_if->eapReq && sm->authStart)
580 547 : SM_ENTER(BE_AUTH, REQUEST);
581 4627 : else if (sm->eap_if->eapSuccess && sm->authStart)
582 0 : SM_ENTER(BE_AUTH, SUCCESS);
583 5174 : break;
584 : case BE_AUTH_IGNORE:
585 6 : if (sm->eapolEap)
586 2 : SM_ENTER(BE_AUTH, RESPONSE);
587 4 : else if (sm->eap_if->eapReq)
588 0 : SM_ENTER(BE_AUTH, REQUEST);
589 4 : else if (sm->eap_if->eapTimeout)
590 0 : SM_ENTER(BE_AUTH, TIMEOUT);
591 6 : break;
592 : }
593 : }
594 :
595 :
596 :
597 : /* Reauthentication Timer state machine */
598 :
599 19685 : SM_STATE(REAUTH_TIMER, INITIALIZE)
600 : {
601 19685 : SM_ENTRY_MA(REAUTH_TIMER, INITIALIZE, reauth_timer);
602 :
603 19685 : sm->reAuthWhen = sm->reAuthPeriod;
604 19685 : }
605 :
606 :
607 1 : SM_STATE(REAUTH_TIMER, REAUTHENTICATE)
608 : {
609 1 : SM_ENTRY_MA(REAUTH_TIMER, REAUTHENTICATE, reauth_timer);
610 :
611 1 : sm->reAuthenticate = TRUE;
612 1 : sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
613 : EAPOL_AUTH_REAUTHENTICATE);
614 1 : }
615 :
616 :
617 23055 : SM_STEP(REAUTH_TIMER)
618 : {
619 45621 : if (sm->portControl != Auto || sm->initialize ||
620 25937 : sm->authPortStatus == Unauthorized || !sm->reAuthEnabled) {
621 19684 : SM_ENTER_GLOBAL(REAUTH_TIMER, INITIALIZE);
622 42739 : return;
623 : }
624 :
625 3371 : switch (sm->reauth_timer_state) {
626 : case REAUTH_TIMER_INITIALIZE:
627 3370 : if (sm->reAuthWhen == 0)
628 1 : SM_ENTER(REAUTH_TIMER, REAUTHENTICATE);
629 3370 : break;
630 : case REAUTH_TIMER_REAUTHENTICATE:
631 1 : SM_ENTER(REAUTH_TIMER, INITIALIZE);
632 1 : break;
633 : }
634 : }
635 :
636 :
637 :
638 : /* Authenticator Key Transmit state machine */
639 :
640 489 : SM_STATE(AUTH_KEY_TX, NO_KEY_TRANSMIT)
641 : {
642 489 : SM_ENTRY_MA(AUTH_KEY_TX, NO_KEY_TRANSMIT, auth_key_tx);
643 489 : }
644 :
645 :
646 2 : SM_STATE(AUTH_KEY_TX, KEY_TRANSMIT)
647 : {
648 2 : SM_ENTRY_MA(AUTH_KEY_TX, KEY_TRANSMIT, auth_key_tx);
649 :
650 2 : txKey();
651 2 : sm->eap_if->eapKeyAvailable = FALSE;
652 2 : sm->keyDone = TRUE;
653 2 : }
654 :
655 :
656 23055 : SM_STEP(AUTH_KEY_TX)
657 : {
658 23055 : if (sm->initialize || sm->portControl != Auto) {
659 489 : SM_ENTER_GLOBAL(AUTH_KEY_TX, NO_KEY_TRANSMIT);
660 23544 : return;
661 : }
662 :
663 22566 : switch (sm->auth_key_tx_state) {
664 : case AUTH_KEY_TX_NO_KEY_TRANSMIT:
665 22564 : if (sm->keyTxEnabled && sm->eap_if->eapKeyAvailable &&
666 4 : sm->keyRun && !(sm->flags & EAPOL_SM_USES_WPA))
667 2 : SM_ENTER(AUTH_KEY_TX, KEY_TRANSMIT);
668 22562 : break;
669 : case AUTH_KEY_TX_KEY_TRANSMIT:
670 4 : if (!sm->keyTxEnabled || !sm->keyRun)
671 0 : SM_ENTER(AUTH_KEY_TX, NO_KEY_TRANSMIT);
672 4 : else if (sm->eap_if->eapKeyAvailable)
673 0 : SM_ENTER(AUTH_KEY_TX, KEY_TRANSMIT);
674 4 : break;
675 : }
676 : }
677 :
678 :
679 :
680 : /* Key Receive state machine */
681 :
682 2850 : SM_STATE(KEY_RX, NO_KEY_RECEIVE)
683 : {
684 2850 : SM_ENTRY_MA(KEY_RX, NO_KEY_RECEIVE, key_rx);
685 2850 : }
686 :
687 :
688 0 : SM_STATE(KEY_RX, KEY_RECEIVE)
689 : {
690 0 : SM_ENTRY_MA(KEY_RX, KEY_RECEIVE, key_rx);
691 :
692 : processKey();
693 0 : sm->rxKey = FALSE;
694 0 : }
695 :
696 :
697 23055 : SM_STEP(KEY_RX)
698 : {
699 23055 : if (sm->initialize || !sm->eap_if->portEnabled) {
700 2850 : SM_ENTER_GLOBAL(KEY_RX, NO_KEY_RECEIVE);
701 25905 : return;
702 : }
703 :
704 20205 : switch (sm->key_rx_state) {
705 : case KEY_RX_NO_KEY_RECEIVE:
706 20205 : if (sm->rxKey)
707 0 : SM_ENTER(KEY_RX, KEY_RECEIVE);
708 20205 : break;
709 : case KEY_RX_KEY_RECEIVE:
710 0 : if (sm->rxKey)
711 0 : SM_ENTER(KEY_RX, KEY_RECEIVE);
712 0 : break;
713 : }
714 : }
715 :
716 :
717 :
718 : /* Controlled Directions state machine */
719 :
720 489 : SM_STATE(CTRL_DIR, FORCE_BOTH)
721 : {
722 489 : SM_ENTRY_MA(CTRL_DIR, FORCE_BOTH, ctrl_dir);
723 489 : sm->operControlledDirections = Both;
724 489 : }
725 :
726 :
727 489 : SM_STATE(CTRL_DIR, IN_OR_BOTH)
728 : {
729 489 : SM_ENTRY_MA(CTRL_DIR, IN_OR_BOTH, ctrl_dir);
730 489 : sm->operControlledDirections = sm->adminControlledDirections;
731 489 : }
732 :
733 :
734 23055 : SM_STEP(CTRL_DIR)
735 : {
736 23055 : if (sm->initialize) {
737 489 : SM_ENTER_GLOBAL(CTRL_DIR, IN_OR_BOTH);
738 23544 : return;
739 : }
740 :
741 22566 : switch (sm->ctrl_dir_state) {
742 : case CTRL_DIR_FORCE_BOTH:
743 22077 : if (sm->eap_if->portEnabled && sm->operEdge)
744 0 : SM_ENTER(CTRL_DIR, IN_OR_BOTH);
745 22077 : break;
746 : case CTRL_DIR_IN_OR_BOTH:
747 978 : if (sm->operControlledDirections !=
748 489 : sm->adminControlledDirections)
749 0 : SM_ENTER(CTRL_DIR, IN_OR_BOTH);
750 489 : if (!sm->eap_if->portEnabled || !sm->operEdge)
751 489 : SM_ENTER(CTRL_DIR, FORCE_BOTH);
752 489 : break;
753 : }
754 : }
755 :
756 :
757 :
758 : struct eapol_state_machine *
759 489 : eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
760 : int flags, const struct wpabuf *assoc_wps_ie,
761 : const struct wpabuf *assoc_p2p_ie, void *sta_ctx,
762 : const char *identity, const char *radius_cui)
763 : {
764 : struct eapol_state_machine *sm;
765 : struct eap_config eap_conf;
766 :
767 489 : if (eapol == NULL)
768 0 : return NULL;
769 :
770 489 : sm = os_zalloc(sizeof(*sm));
771 489 : if (sm == NULL) {
772 0 : wpa_printf(MSG_DEBUG, "IEEE 802.1X state machine allocation "
773 : "failed");
774 0 : return NULL;
775 : }
776 489 : sm->radius_identifier = -1;
777 489 : os_memcpy(sm->addr, addr, ETH_ALEN);
778 489 : sm->flags = flags;
779 :
780 489 : sm->eapol = eapol;
781 489 : sm->sta = sta_ctx;
782 :
783 : /* Set default values for state machine constants */
784 489 : sm->auth_pae_state = AUTH_PAE_INITIALIZE;
785 489 : sm->quietPeriod = AUTH_PAE_DEFAULT_quietPeriod;
786 489 : sm->reAuthMax = AUTH_PAE_DEFAULT_reAuthMax;
787 :
788 489 : sm->be_auth_state = BE_AUTH_INITIALIZE;
789 489 : sm->serverTimeout = BE_AUTH_DEFAULT_serverTimeout;
790 :
791 489 : sm->reauth_timer_state = REAUTH_TIMER_INITIALIZE;
792 489 : sm->reAuthPeriod = eapol->conf.eap_reauth_period;
793 489 : sm->reAuthEnabled = eapol->conf.eap_reauth_period > 0 ? TRUE : FALSE;
794 :
795 489 : sm->auth_key_tx_state = AUTH_KEY_TX_NO_KEY_TRANSMIT;
796 :
797 489 : sm->key_rx_state = KEY_RX_NO_KEY_RECEIVE;
798 :
799 489 : sm->ctrl_dir_state = CTRL_DIR_IN_OR_BOTH;
800 :
801 489 : sm->portControl = Auto;
802 :
803 510 : if (!eapol->conf.wpa &&
804 40 : (eapol->default_wep_key || eapol->conf.individual_wep_key_len > 0))
805 2 : sm->keyTxEnabled = TRUE;
806 : else
807 487 : sm->keyTxEnabled = FALSE;
808 489 : if (eapol->conf.wpa)
809 468 : sm->portValid = FALSE;
810 : else
811 21 : sm->portValid = TRUE;
812 :
813 489 : os_memset(&eap_conf, 0, sizeof(eap_conf));
814 489 : eap_conf.eap_server = eapol->conf.eap_server;
815 489 : eap_conf.ssl_ctx = eapol->conf.ssl_ctx;
816 489 : eap_conf.msg_ctx = eapol->conf.msg_ctx;
817 489 : eap_conf.eap_sim_db_priv = eapol->conf.eap_sim_db_priv;
818 489 : eap_conf.pac_opaque_encr_key = eapol->conf.pac_opaque_encr_key;
819 489 : eap_conf.eap_fast_a_id = eapol->conf.eap_fast_a_id;
820 489 : eap_conf.eap_fast_a_id_len = eapol->conf.eap_fast_a_id_len;
821 489 : eap_conf.eap_fast_a_id_info = eapol->conf.eap_fast_a_id_info;
822 489 : eap_conf.eap_fast_prov = eapol->conf.eap_fast_prov;
823 489 : eap_conf.pac_key_lifetime = eapol->conf.pac_key_lifetime;
824 489 : eap_conf.pac_key_refresh_time = eapol->conf.pac_key_refresh_time;
825 489 : eap_conf.eap_sim_aka_result_ind = eapol->conf.eap_sim_aka_result_ind;
826 489 : eap_conf.tnc = eapol->conf.tnc;
827 489 : eap_conf.wps = eapol->conf.wps;
828 489 : eap_conf.assoc_wps_ie = assoc_wps_ie;
829 489 : eap_conf.assoc_p2p_ie = assoc_p2p_ie;
830 489 : eap_conf.peer_addr = addr;
831 489 : eap_conf.fragment_size = eapol->conf.fragment_size;
832 489 : eap_conf.pwd_group = eapol->conf.pwd_group;
833 489 : eap_conf.pbc_in_m1 = eapol->conf.pbc_in_m1;
834 489 : eap_conf.server_id = eapol->conf.server_id;
835 489 : eap_conf.server_id_len = eapol->conf.server_id_len;
836 489 : sm->eap = eap_server_sm_init(sm, &eapol_cb, &eap_conf);
837 489 : if (sm->eap == NULL) {
838 0 : eapol_auth_free(sm);
839 0 : return NULL;
840 : }
841 489 : sm->eap_if = eap_get_interface(sm->eap);
842 :
843 489 : eapol_auth_initialize(sm);
844 :
845 489 : if (identity) {
846 0 : sm->identity = (u8 *) os_strdup(identity);
847 0 : if (sm->identity)
848 0 : sm->identity_len = os_strlen(identity);
849 : }
850 489 : if (radius_cui)
851 0 : sm->radius_cui = wpabuf_alloc_copy(radius_cui,
852 : os_strlen(radius_cui));
853 :
854 489 : return sm;
855 : }
856 :
857 :
858 489 : void eapol_auth_free(struct eapol_state_machine *sm)
859 : {
860 489 : if (sm == NULL)
861 489 : return;
862 :
863 489 : eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
864 489 : eloop_cancel_timeout(eapol_sm_step_cb, sm, NULL);
865 489 : if (sm->eap)
866 489 : eap_server_sm_deinit(sm->eap);
867 489 : os_free(sm);
868 : }
869 :
870 :
871 129595 : static int eapol_sm_sta_entry_alive(struct eapol_authenticator *eapol,
872 : const u8 *addr)
873 : {
874 129595 : return eapol->cb.sta_entry_alive(eapol->conf.ctx, addr);
875 : }
876 :
877 :
878 8141 : static void eapol_sm_step_run(struct eapol_state_machine *sm)
879 : {
880 8141 : struct eapol_authenticator *eapol = sm->eapol;
881 : u8 addr[ETH_ALEN];
882 : unsigned int prev_auth_pae, prev_be_auth, prev_reauth_timer,
883 : prev_auth_key_tx, prev_key_rx, prev_ctrl_dir;
884 8141 : int max_steps = 100;
885 :
886 8141 : os_memcpy(addr, sm->addr, ETH_ALEN);
887 :
888 : /*
889 : * Allow EAPOL state machines to run as long as there are state
890 : * changes, but exit and return here through event loop if more than
891 : * 100 steps is needed as a precaution against infinite loops inside
892 : * eloop callback.
893 : */
894 : restart:
895 23055 : prev_auth_pae = sm->auth_pae_state;
896 23055 : prev_be_auth = sm->be_auth_state;
897 23055 : prev_reauth_timer = sm->reauth_timer_state;
898 23055 : prev_auth_key_tx = sm->auth_key_tx_state;
899 23055 : prev_key_rx = sm->key_rx_state;
900 23055 : prev_ctrl_dir = sm->ctrl_dir_state;
901 :
902 23055 : SM_STEP_RUN(AUTH_PAE);
903 23055 : if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
904 23055 : SM_STEP_RUN(BE_AUTH);
905 23055 : if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
906 23055 : SM_STEP_RUN(REAUTH_TIMER);
907 23055 : if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
908 23055 : SM_STEP_RUN(AUTH_KEY_TX);
909 23055 : if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
910 23055 : SM_STEP_RUN(KEY_RX);
911 23055 : if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))
912 23055 : SM_STEP_RUN(CTRL_DIR);
913 :
914 43185 : if (prev_auth_pae != sm->auth_pae_state ||
915 33645 : prev_be_auth != sm->be_auth_state ||
916 27029 : prev_reauth_timer != sm->reauth_timer_state ||
917 27028 : prev_auth_key_tx != sm->auth_key_tx_state ||
918 27028 : prev_key_rx != sm->key_rx_state ||
919 13514 : prev_ctrl_dir != sm->ctrl_dir_state) {
920 9541 : if (--max_steps > 0)
921 9541 : goto restart;
922 : /* Re-run from eloop timeout */
923 0 : eapol_auth_step(sm);
924 0 : return;
925 : }
926 :
927 13514 : if (eapol_sm_sta_entry_alive(eapol, addr) && sm->eap) {
928 12536 : if (eap_server_sm_step(sm->eap)) {
929 5373 : if (--max_steps > 0)
930 5373 : goto restart;
931 : /* Re-run from eloop timeout */
932 0 : eapol_auth_step(sm);
933 0 : return;
934 : }
935 :
936 : /* TODO: find a better location for this */
937 7163 : if (sm->eap_if->aaaEapResp) {
938 1604 : sm->eap_if->aaaEapResp = FALSE;
939 1604 : if (sm->eap_if->aaaEapRespData == NULL) {
940 0 : wpa_printf(MSG_DEBUG, "EAPOL: aaaEapResp set, "
941 : "but no aaaEapRespData available");
942 0 : return;
943 : }
944 6416 : sm->eapol->cb.aaa_send(
945 1604 : sm->eapol->conf.ctx, sm->sta,
946 1604 : wpabuf_head(sm->eap_if->aaaEapRespData),
947 1604 : wpabuf_len(sm->eap_if->aaaEapRespData));
948 : }
949 : }
950 :
951 8141 : if (eapol_sm_sta_entry_alive(eapol, addr))
952 7163 : sm->eapol->cb.eapol_event(sm->eapol->conf.ctx, sm->sta,
953 : EAPOL_AUTH_SM_CHANGE);
954 : }
955 :
956 :
957 7093 : static void eapol_sm_step_cb(void *eloop_ctx, void *timeout_ctx)
958 : {
959 7093 : struct eapol_state_machine *sm = eloop_ctx;
960 7093 : eapol_sm_step_run(sm);
961 7093 : }
962 :
963 :
964 : /**
965 : * eapol_auth_step - Advance EAPOL state machines
966 : * @sm: EAPOL state machine
967 : *
968 : * This function is called to advance EAPOL state machines after any change
969 : * that could affect their state.
970 : */
971 8000 : void eapol_auth_step(struct eapol_state_machine *sm)
972 : {
973 : /*
974 : * Run eapol_sm_step_run from a registered timeout to make sure that
975 : * other possible timeouts/events are processed and to avoid long
976 : * function call chains.
977 : */
978 :
979 8000 : eloop_register_timeout(0, 0, eapol_sm_step_cb, sm, NULL);
980 8000 : }
981 :
982 :
983 489 : static void eapol_auth_initialize(struct eapol_state_machine *sm)
984 : {
985 489 : sm->initializing = TRUE;
986 : /* Initialize the state machines by asserting initialize and then
987 : * deasserting it after one step */
988 489 : sm->initialize = TRUE;
989 489 : eapol_sm_step_run(sm);
990 489 : sm->initialize = FALSE;
991 489 : eapol_sm_step_run(sm);
992 489 : sm->initializing = FALSE;
993 :
994 : /* Start one second tick for port timers state machine */
995 489 : eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);
996 489 : eloop_register_timeout(1, 0, eapol_port_timers_tick, NULL, sm);
997 489 : }
998 :
999 :
1000 252 : static int eapol_sm_get_eap_user(void *ctx, const u8 *identity,
1001 : size_t identity_len, int phase2,
1002 : struct eap_user *user)
1003 : {
1004 252 : struct eapol_state_machine *sm = ctx;
1005 : int ret;
1006 :
1007 252 : ret = sm->eapol->cb.get_eap_user(sm->eapol->conf.ctx, identity,
1008 : identity_len, phase2, user);
1009 252 : if (user->remediation)
1010 0 : sm->remediation = 1;
1011 252 : return ret;
1012 : }
1013 :
1014 :
1015 551 : static const char * eapol_sm_get_eap_req_id_text(void *ctx, size_t *len)
1016 : {
1017 551 : struct eapol_state_machine *sm = ctx;
1018 551 : *len = sm->eapol->conf.eap_req_id_text_len;
1019 551 : return sm->eapol->conf.eap_req_id_text;
1020 : }
1021 :
1022 :
1023 : static struct eapol_callbacks eapol_cb =
1024 : {
1025 : eapol_sm_get_eap_user,
1026 : eapol_sm_get_eap_req_id_text,
1027 : NULL
1028 : };
1029 :
1030 :
1031 29 : int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx)
1032 : {
1033 29 : if (sm == NULL || ctx == NULL || ctx != sm->eap)
1034 0 : return -1;
1035 :
1036 29 : eap_sm_pending_cb(sm->eap);
1037 29 : eapol_auth_step(sm);
1038 :
1039 29 : return 0;
1040 : }
1041 :
1042 :
1043 678 : static int eapol_auth_conf_clone(struct eapol_auth_config *dst,
1044 : struct eapol_auth_config *src)
1045 : {
1046 678 : dst->ctx = src->ctx;
1047 678 : dst->eap_reauth_period = src->eap_reauth_period;
1048 678 : dst->wpa = src->wpa;
1049 678 : dst->individual_wep_key_len = src->individual_wep_key_len;
1050 678 : dst->eap_server = src->eap_server;
1051 678 : dst->ssl_ctx = src->ssl_ctx;
1052 678 : dst->msg_ctx = src->msg_ctx;
1053 678 : dst->eap_sim_db_priv = src->eap_sim_db_priv;
1054 678 : os_free(dst->eap_req_id_text);
1055 678 : dst->pwd_group = src->pwd_group;
1056 678 : dst->pbc_in_m1 = src->pbc_in_m1;
1057 678 : dst->server_id = src->server_id;
1058 678 : dst->server_id_len = src->server_id_len;
1059 678 : if (src->eap_req_id_text) {
1060 1 : dst->eap_req_id_text = os_malloc(src->eap_req_id_text_len);
1061 1 : if (dst->eap_req_id_text == NULL)
1062 0 : return -1;
1063 1 : os_memcpy(dst->eap_req_id_text, src->eap_req_id_text,
1064 : src->eap_req_id_text_len);
1065 1 : dst->eap_req_id_text_len = src->eap_req_id_text_len;
1066 : } else {
1067 677 : dst->eap_req_id_text = NULL;
1068 677 : dst->eap_req_id_text_len = 0;
1069 : }
1070 678 : if (src->pac_opaque_encr_key) {
1071 3 : dst->pac_opaque_encr_key = os_malloc(16);
1072 3 : if (dst->pac_opaque_encr_key == NULL) {
1073 0 : os_free(dst->eap_req_id_text);
1074 0 : return -1;
1075 : }
1076 3 : os_memcpy(dst->pac_opaque_encr_key, src->pac_opaque_encr_key,
1077 : 16);
1078 : } else
1079 675 : dst->pac_opaque_encr_key = NULL;
1080 678 : if (src->eap_fast_a_id) {
1081 3 : dst->eap_fast_a_id = os_malloc(src->eap_fast_a_id_len);
1082 3 : if (dst->eap_fast_a_id == NULL) {
1083 0 : os_free(dst->eap_req_id_text);
1084 0 : os_free(dst->pac_opaque_encr_key);
1085 0 : return -1;
1086 : }
1087 3 : os_memcpy(dst->eap_fast_a_id, src->eap_fast_a_id,
1088 : src->eap_fast_a_id_len);
1089 3 : dst->eap_fast_a_id_len = src->eap_fast_a_id_len;
1090 : } else
1091 675 : dst->eap_fast_a_id = NULL;
1092 678 : if (src->eap_fast_a_id_info) {
1093 3 : dst->eap_fast_a_id_info = os_strdup(src->eap_fast_a_id_info);
1094 3 : if (dst->eap_fast_a_id_info == NULL) {
1095 0 : os_free(dst->eap_req_id_text);
1096 0 : os_free(dst->pac_opaque_encr_key);
1097 0 : os_free(dst->eap_fast_a_id);
1098 0 : return -1;
1099 : }
1100 : } else
1101 675 : dst->eap_fast_a_id_info = NULL;
1102 678 : dst->eap_fast_prov = src->eap_fast_prov;
1103 678 : dst->pac_key_lifetime = src->pac_key_lifetime;
1104 678 : dst->pac_key_refresh_time = src->pac_key_refresh_time;
1105 678 : dst->eap_sim_aka_result_ind = src->eap_sim_aka_result_ind;
1106 678 : dst->tnc = src->tnc;
1107 678 : dst->wps = src->wps;
1108 678 : dst->fragment_size = src->fragment_size;
1109 678 : return 0;
1110 : }
1111 :
1112 :
1113 678 : static void eapol_auth_conf_free(struct eapol_auth_config *conf)
1114 : {
1115 678 : os_free(conf->eap_req_id_text);
1116 678 : conf->eap_req_id_text = NULL;
1117 678 : os_free(conf->pac_opaque_encr_key);
1118 678 : conf->pac_opaque_encr_key = NULL;
1119 678 : os_free(conf->eap_fast_a_id);
1120 678 : conf->eap_fast_a_id = NULL;
1121 678 : os_free(conf->eap_fast_a_id_info);
1122 678 : conf->eap_fast_a_id_info = NULL;
1123 678 : }
1124 :
1125 :
1126 678 : struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
1127 : struct eapol_auth_cb *cb)
1128 : {
1129 : struct eapol_authenticator *eapol;
1130 :
1131 678 : eapol = os_zalloc(sizeof(*eapol));
1132 678 : if (eapol == NULL)
1133 0 : return NULL;
1134 :
1135 678 : if (eapol_auth_conf_clone(&eapol->conf, conf) < 0) {
1136 0 : os_free(eapol);
1137 0 : return NULL;
1138 : }
1139 :
1140 678 : if (conf->individual_wep_key_len > 0) {
1141 : /* use key0 in individual key and key1 in broadcast key */
1142 2 : eapol->default_wep_key_idx = 1;
1143 : }
1144 :
1145 678 : eapol->cb.eapol_send = cb->eapol_send;
1146 678 : eapol->cb.aaa_send = cb->aaa_send;
1147 678 : eapol->cb.finished = cb->finished;
1148 678 : eapol->cb.get_eap_user = cb->get_eap_user;
1149 678 : eapol->cb.sta_entry_alive = cb->sta_entry_alive;
1150 678 : eapol->cb.logger = cb->logger;
1151 678 : eapol->cb.set_port_authorized = cb->set_port_authorized;
1152 678 : eapol->cb.abort_auth = cb->abort_auth;
1153 678 : eapol->cb.tx_key = cb->tx_key;
1154 678 : eapol->cb.eapol_event = cb->eapol_event;
1155 :
1156 678 : return eapol;
1157 : }
1158 :
1159 :
1160 682 : void eapol_auth_deinit(struct eapol_authenticator *eapol)
1161 : {
1162 682 : if (eapol == NULL)
1163 686 : return;
1164 :
1165 678 : eapol_auth_conf_free(&eapol->conf);
1166 678 : os_free(eapol->default_wep_key);
1167 678 : os_free(eapol);
1168 : }
|