2 * EAP peer method: EAP-TTLS (RFC 5281)
3 * Copyright (c) 2004-2011, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/ms_funcs.h"
13 #include "crypto/sha1.h"
14 #include "crypto/tls.h"
15 #include "eap_common/chap.h"
16 #include "eap_common/eap_ttls.h"
19 #include "eap_tls_common.h"
20 #include "eap_config.h"
23 #define EAP_TTLS_VERSION 0
26 static void eap_ttls_deinit(struct eap_sm *sm, void *priv);
29 struct eap_ttls_data {
30 struct eap_ssl_data ssl;
34 const struct eap_method *phase2_method;
41 EAP_TTLS_PHASE2_MSCHAPV2,
42 EAP_TTLS_PHASE2_MSCHAP,
46 struct eap_method_type phase2_eap_type;
47 struct eap_method_type *phase2_eap_types;
48 size_t num_phase2_eap_types;
50 u8 auth_response[MSCHAPV2_AUTH_RESPONSE_LEN];
51 int auth_response_valid;
52 u8 master_key[MSCHAPV2_MASTER_KEY_LEN]; /* MSCHAPv2 master key */
54 int resuming; /* starting a resumed session */
55 int reauth; /* reauthentication */
58 struct wpabuf *pending_phase2_req;
67 static void * eap_ttls_init(struct eap_sm *sm)
69 struct eap_ttls_data *data;
70 struct eap_peer_config *config = eap_get_config(sm);
73 data = os_zalloc(sizeof(*data));
76 data->ttls_version = EAP_TTLS_VERSION;
78 data->phase2_type = EAP_TTLS_PHASE2_EAP;
80 if (config && config->phase2) {
81 if (os_strstr(config->phase2, "autheap=")) {
83 data->phase2_type = EAP_TTLS_PHASE2_EAP;
84 } else if (os_strstr(config->phase2, "auth=MSCHAPV2")) {
85 selected = "MSCHAPV2";
86 data->phase2_type = EAP_TTLS_PHASE2_MSCHAPV2;
87 } else if (os_strstr(config->phase2, "auth=MSCHAP")) {
89 data->phase2_type = EAP_TTLS_PHASE2_MSCHAP;
90 } else if (os_strstr(config->phase2, "auth=PAP")) {
92 data->phase2_type = EAP_TTLS_PHASE2_PAP;
93 } else if (os_strstr(config->phase2, "auth=CHAP")) {
95 data->phase2_type = EAP_TTLS_PHASE2_CHAP;
98 wpa_printf(MSG_DEBUG, "EAP-TTLS: Phase2 type: %s", selected);
100 if (data->phase2_type == EAP_TTLS_PHASE2_EAP) {
101 if (eap_peer_select_phase2_methods(config, "autheap=",
102 &data->phase2_eap_types,
103 &data->num_phase2_eap_types)
105 eap_ttls_deinit(sm, data);
109 data->phase2_eap_type.vendor = EAP_VENDOR_IETF;
110 data->phase2_eap_type.method = EAP_TYPE_NONE;
113 if (eap_peer_tls_ssl_init(sm, &data->ssl, config, EAP_TYPE_TTLS)) {
114 wpa_printf(MSG_INFO, "EAP-TTLS: Failed to initialize SSL.");
115 eap_ttls_deinit(sm, data);
123 static void eap_ttls_phase2_eap_deinit(struct eap_sm *sm,
124 struct eap_ttls_data *data)
126 if (data->phase2_priv && data->phase2_method) {
127 data->phase2_method->deinit(sm, data->phase2_priv);
128 data->phase2_method = NULL;
129 data->phase2_priv = NULL;
134 static void eap_ttls_deinit(struct eap_sm *sm, void *priv)
136 struct eap_ttls_data *data = priv;
139 eap_ttls_phase2_eap_deinit(sm, data);
140 os_free(data->phase2_eap_types);
141 eap_peer_tls_ssl_deinit(sm, &data->ssl);
142 os_free(data->key_data);
143 wpabuf_free(data->pending_phase2_req);
148 static u8 * eap_ttls_avp_hdr(u8 *avphdr, u32 avp_code, u32 vendor_id,
149 int mandatory, size_t len)
151 struct ttls_avp_vendor *avp;
155 avp = (struct ttls_avp_vendor *) avphdr;
156 flags = mandatory ? AVP_FLAGS_MANDATORY : 0;
158 flags |= AVP_FLAGS_VENDOR;
159 hdrlen = sizeof(*avp);
160 avp->vendor_id = host_to_be32(vendor_id);
162 hdrlen = sizeof(struct ttls_avp);
165 avp->avp_code = host_to_be32(avp_code);
166 avp->avp_length = host_to_be32((flags << 24) | (u32) (hdrlen + len));
168 return avphdr + hdrlen;
172 static u8 * eap_ttls_avp_add(u8 *start, u8 *avphdr, u32 avp_code,
173 u32 vendor_id, int mandatory,
174 const u8 *data, size_t len)
177 pos = eap_ttls_avp_hdr(avphdr, avp_code, vendor_id, mandatory, len);
178 os_memcpy(pos, data, len);
185 static int eap_ttls_avp_encapsulate(struct wpabuf **resp, u32 avp_code,
191 msg = wpabuf_alloc(sizeof(struct ttls_avp) + wpabuf_len(*resp) + 4);
198 avp = wpabuf_mhead(msg);
199 pos = eap_ttls_avp_hdr(avp, avp_code, 0, mandatory, wpabuf_len(*resp));
200 os_memcpy(pos, wpabuf_head(*resp), wpabuf_len(*resp));
201 pos += wpabuf_len(*resp);
204 wpabuf_put(msg, pos - avp);
210 static int eap_ttls_v0_derive_key(struct eap_sm *sm,
211 struct eap_ttls_data *data)
213 os_free(data->key_data);
214 data->key_data = eap_peer_tls_derive_key(sm, &data->ssl,
215 "ttls keying material",
217 if (!data->key_data) {
218 wpa_printf(MSG_INFO, "EAP-TTLS: Failed to derive key");
222 wpa_hexdump_key(MSG_DEBUG, "EAP-TTLS: Derived key",
223 data->key_data, EAP_TLS_KEY_LEN);
229 static u8 * eap_ttls_implicit_challenge(struct eap_sm *sm,
230 struct eap_ttls_data *data, size_t len)
232 return eap_peer_tls_derive_key(sm, &data->ssl, "ttls challenge", len);
236 static void eap_ttls_phase2_select_eap_method(struct eap_ttls_data *data,
240 for (i = 0; i < data->num_phase2_eap_types; i++) {
241 if (data->phase2_eap_types[i].vendor != EAP_VENDOR_IETF ||
242 data->phase2_eap_types[i].method != method)
245 data->phase2_eap_type.vendor =
246 data->phase2_eap_types[i].vendor;
247 data->phase2_eap_type.method =
248 data->phase2_eap_types[i].method;
249 wpa_printf(MSG_DEBUG, "EAP-TTLS: Selected "
250 "Phase 2 EAP vendor %d method %d",
251 data->phase2_eap_type.vendor,
252 data->phase2_eap_type.method);
258 static int eap_ttls_phase2_eap_process(struct eap_sm *sm,
259 struct eap_ttls_data *data,
260 struct eap_method_ret *ret,
261 struct eap_hdr *hdr, size_t len,
262 struct wpabuf **resp)
265 struct eap_method_ret iret;
267 os_memset(&iret, 0, sizeof(iret));
268 wpabuf_set(&msg, hdr, len);
269 *resp = data->phase2_method->process(sm, data->phase2_priv, &iret,
271 if ((iret.methodState == METHOD_DONE ||
272 iret.methodState == METHOD_MAY_CONT) &&
273 (iret.decision == DECISION_UNCOND_SUCC ||
274 iret.decision == DECISION_COND_SUCC ||
275 iret.decision == DECISION_FAIL)) {
276 ret->methodState = iret.methodState;
277 ret->decision = iret.decision;
284 static int eap_ttls_phase2_request_eap_method(struct eap_sm *sm,
285 struct eap_ttls_data *data,
286 struct eap_method_ret *ret,
287 struct eap_hdr *hdr, size_t len,
288 u8 method, struct wpabuf **resp)
291 if (data->tnc_started && data->phase2_method &&
292 data->phase2_priv && method == EAP_TYPE_TNC &&
293 data->phase2_eap_type.method == EAP_TYPE_TNC)
294 return eap_ttls_phase2_eap_process(sm, data, ret, hdr, len,
297 if (data->ready_for_tnc && !data->tnc_started &&
298 method == EAP_TYPE_TNC) {
299 wpa_printf(MSG_DEBUG, "EAP-TTLS: Start TNC after completed "
301 data->tnc_started = 1;
304 if (data->tnc_started) {
305 if (data->phase2_eap_type.vendor != EAP_VENDOR_IETF ||
306 data->phase2_eap_type.method == EAP_TYPE_TNC) {
307 wpa_printf(MSG_DEBUG, "EAP-TTLS: Unexpected EAP "
308 "type %d for TNC", method);
312 data->phase2_eap_type.vendor = EAP_VENDOR_IETF;
313 data->phase2_eap_type.method = method;
314 wpa_printf(MSG_DEBUG, "EAP-TTLS: Selected "
315 "Phase 2 EAP vendor %d method %d (TNC)",
316 data->phase2_eap_type.vendor,
317 data->phase2_eap_type.method);
319 if (data->phase2_type == EAP_TTLS_PHASE2_EAP)
320 eap_ttls_phase2_eap_deinit(sm, data);
324 if (data->phase2_eap_type.vendor == EAP_VENDOR_IETF &&
325 data->phase2_eap_type.method == EAP_TYPE_NONE)
326 eap_ttls_phase2_select_eap_method(data, method);
328 if (method != data->phase2_eap_type.method || method == EAP_TYPE_NONE)
330 if (eap_peer_tls_phase2_nak(data->phase2_eap_types,
331 data->num_phase2_eap_types,
337 if (data->phase2_priv == NULL) {
338 data->phase2_method = eap_peer_get_eap_method(
339 EAP_VENDOR_IETF, method);
340 if (data->phase2_method) {
342 data->phase2_priv = data->phase2_method->init(sm);
346 if (data->phase2_priv == NULL || data->phase2_method == NULL) {
347 wpa_printf(MSG_INFO, "EAP-TTLS: failed to initialize "
348 "Phase 2 EAP method %d", method);
352 return eap_ttls_phase2_eap_process(sm, data, ret, hdr, len, resp);
356 static int eap_ttls_phase2_request_eap(struct eap_sm *sm,
357 struct eap_ttls_data *data,
358 struct eap_method_ret *ret,
360 struct wpabuf **resp)
362 size_t len = be_to_host16(hdr->length);
364 struct eap_peer_config *config = eap_get_config(sm);
366 if (len <= sizeof(struct eap_hdr)) {
367 wpa_printf(MSG_INFO, "EAP-TTLS: too short "
368 "Phase 2 request (len=%lu)", (unsigned long) len);
371 pos = (u8 *) (hdr + 1);
372 wpa_printf(MSG_DEBUG, "EAP-TTLS: Phase 2 EAP Request: type=%d", *pos);
374 case EAP_TYPE_IDENTITY:
375 *resp = eap_sm_buildIdentity(sm, hdr->identifier, 1);
378 if (eap_ttls_phase2_request_eap_method(sm, data, ret, hdr, len,
385 (config->pending_req_identity || config->pending_req_password ||
386 config->pending_req_otp)) {
393 wpa_hexdump_buf(MSG_DEBUG, "EAP-TTLS: AVP encapsulate EAP Response",
395 return eap_ttls_avp_encapsulate(resp, RADIUS_ATTR_EAP_MESSAGE, 1);
399 static int eap_ttls_phase2_request_mschapv2(struct eap_sm *sm,
400 struct eap_ttls_data *data,
401 struct eap_method_ret *ret,
402 struct wpabuf **resp)
406 u8 *buf, *pos, *challenge, *peer_challenge;
407 const u8 *identity, *password;
408 size_t identity_len, password_len;
411 wpa_printf(MSG_DEBUG, "EAP-TTLS: Phase 2 MSCHAPV2 Request");
413 identity = eap_get_config_identity(sm, &identity_len);
414 password = eap_get_config_password2(sm, &password_len, &pwhash);
415 if (identity == NULL || password == NULL)
418 msg = wpabuf_alloc(identity_len + 1000);
420 wpa_printf(MSG_ERROR,
421 "EAP-TTLS/MSCHAPV2: Failed to allocate memory");
424 pos = buf = wpabuf_mhead(msg);
427 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_USER_NAME, 0, 1,
428 identity, identity_len);
430 /* MS-CHAP-Challenge */
431 challenge = eap_ttls_implicit_challenge(
432 sm, data, EAP_TTLS_MSCHAPV2_CHALLENGE_LEN + 1);
433 if (challenge == NULL) {
435 wpa_printf(MSG_ERROR, "EAP-TTLS/MSCHAPV2: Failed to derive "
436 "implicit challenge");
440 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_MS_CHAP_CHALLENGE,
441 RADIUS_VENDOR_ID_MICROSOFT, 1,
442 challenge, EAP_TTLS_MSCHAPV2_CHALLENGE_LEN);
444 /* MS-CHAP2-Response */
445 pos = eap_ttls_avp_hdr(pos, RADIUS_ATTR_MS_CHAP2_RESPONSE,
446 RADIUS_VENDOR_ID_MICROSOFT, 1,
447 EAP_TTLS_MSCHAPV2_RESPONSE_LEN);
448 data->ident = challenge[EAP_TTLS_MSCHAPV2_CHALLENGE_LEN];
449 *pos++ = data->ident;
450 *pos++ = 0; /* Flags */
451 if (os_get_random(pos, EAP_TTLS_MSCHAPV2_CHALLENGE_LEN) < 0) {
454 wpa_printf(MSG_ERROR, "EAP-TTLS/MSCHAPV2: Failed to get "
455 "random data for peer challenge");
458 peer_challenge = pos;
459 pos += EAP_TTLS_MSCHAPV2_CHALLENGE_LEN;
460 os_memset(pos, 0, 8); /* Reserved, must be zero */
462 if (mschapv2_derive_response(identity, identity_len, password,
463 password_len, pwhash, challenge,
464 peer_challenge, pos, data->auth_response,
468 wpa_printf(MSG_ERROR, "EAP-TTLS/MSCHAPV2: Failed to derive "
472 data->auth_response_valid = 1;
478 wpabuf_put(msg, pos - buf);
481 if (sm->workaround) {
482 /* At least FreeRADIUS seems to be terminating
483 * EAP-TTLS/MSHCAPV2 without the expected MS-CHAP-v2 Success
485 wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAPV2: EAP workaround - "
486 "allow success without tunneled response");
487 ret->methodState = METHOD_MAY_CONT;
488 ret->decision = DECISION_COND_SUCC;
492 #else /* EAP_MSCHAPv2 */
493 wpa_printf(MSG_ERROR, "EAP-TTLS: MSCHAPv2 not included in the build");
495 #endif /* EAP_MSCHAPv2 */
499 static int eap_ttls_phase2_request_mschap(struct eap_sm *sm,
500 struct eap_ttls_data *data,
501 struct eap_method_ret *ret,
502 struct wpabuf **resp)
505 u8 *buf, *pos, *challenge;
506 const u8 *identity, *password;
507 size_t identity_len, password_len;
510 wpa_printf(MSG_DEBUG, "EAP-TTLS: Phase 2 MSCHAP Request");
512 identity = eap_get_config_identity(sm, &identity_len);
513 password = eap_get_config_password2(sm, &password_len, &pwhash);
514 if (identity == NULL || password == NULL)
517 msg = wpabuf_alloc(identity_len + 1000);
519 wpa_printf(MSG_ERROR,
520 "EAP-TTLS/MSCHAP: Failed to allocate memory");
523 pos = buf = wpabuf_mhead(msg);
526 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_USER_NAME, 0, 1,
527 identity, identity_len);
529 /* MS-CHAP-Challenge */
530 challenge = eap_ttls_implicit_challenge(
531 sm, data, EAP_TTLS_MSCHAP_CHALLENGE_LEN + 1);
532 if (challenge == NULL) {
534 wpa_printf(MSG_ERROR, "EAP-TTLS/MSCHAP: Failed to derive "
535 "implicit challenge");
539 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_MS_CHAP_CHALLENGE,
540 RADIUS_VENDOR_ID_MICROSOFT, 1,
541 challenge, EAP_TTLS_MSCHAP_CHALLENGE_LEN);
543 /* MS-CHAP-Response */
544 pos = eap_ttls_avp_hdr(pos, RADIUS_ATTR_MS_CHAP_RESPONSE,
545 RADIUS_VENDOR_ID_MICROSOFT, 1,
546 EAP_TTLS_MSCHAP_RESPONSE_LEN);
547 data->ident = challenge[EAP_TTLS_MSCHAP_CHALLENGE_LEN];
548 *pos++ = data->ident;
549 *pos++ = 1; /* Flags: Use NT style passwords */
550 os_memset(pos, 0, 24); /* LM-Response */
553 challenge_response(challenge, password, pos); /* NT-Response */
554 wpa_hexdump_key(MSG_DEBUG, "EAP-TTLS: MSCHAP password hash",
557 nt_challenge_response(challenge, password, password_len,
558 pos); /* NT-Response */
559 wpa_hexdump_ascii_key(MSG_DEBUG, "EAP-TTLS: MSCHAP password",
560 password, password_len);
562 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: MSCHAP implicit challenge",
563 challenge, EAP_TTLS_MSCHAP_CHALLENGE_LEN);
564 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: MSCHAP response", pos, 24);
569 wpabuf_put(msg, pos - buf);
572 /* EAP-TTLS/MSCHAP does not provide tunneled success
573 * notification, so assume that Phase2 succeeds. */
574 ret->methodState = METHOD_DONE;
575 ret->decision = DECISION_COND_SUCC;
581 static int eap_ttls_phase2_request_pap(struct eap_sm *sm,
582 struct eap_ttls_data *data,
583 struct eap_method_ret *ret,
584 struct wpabuf **resp)
589 const u8 *identity, *password;
590 size_t identity_len, password_len;
592 wpa_printf(MSG_DEBUG, "EAP-TTLS: Phase 2 PAP Request");
594 identity = eap_get_config_identity(sm, &identity_len);
595 password = eap_get_config_password(sm, &password_len);
596 if (identity == NULL || password == NULL)
599 msg = wpabuf_alloc(identity_len + password_len + 100);
601 wpa_printf(MSG_ERROR,
602 "EAP-TTLS/PAP: Failed to allocate memory");
605 pos = buf = wpabuf_mhead(msg);
608 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_USER_NAME, 0, 1,
609 identity, identity_len);
611 /* User-Password; in RADIUS, this is encrypted, but EAP-TTLS encrypts
612 * the data, so no separate encryption is used in the AVP itself.
613 * However, the password is padded to obfuscate its length. */
614 pad = password_len == 0 ? 16 : (16 - (password_len & 15)) & 15;
615 pos = eap_ttls_avp_hdr(pos, RADIUS_ATTR_USER_PASSWORD, 0, 1,
617 os_memcpy(pos, password, password_len);
619 os_memset(pos, 0, pad);
623 wpabuf_put(msg, pos - buf);
626 /* EAP-TTLS/PAP does not provide tunneled success notification,
627 * so assume that Phase2 succeeds. */
628 ret->methodState = METHOD_DONE;
629 ret->decision = DECISION_COND_SUCC;
635 static int eap_ttls_phase2_request_chap(struct eap_sm *sm,
636 struct eap_ttls_data *data,
637 struct eap_method_ret *ret,
638 struct wpabuf **resp)
641 u8 *buf, *pos, *challenge;
642 const u8 *identity, *password;
643 size_t identity_len, password_len;
645 wpa_printf(MSG_DEBUG, "EAP-TTLS: Phase 2 CHAP Request");
647 identity = eap_get_config_identity(sm, &identity_len);
648 password = eap_get_config_password(sm, &password_len);
649 if (identity == NULL || password == NULL)
652 msg = wpabuf_alloc(identity_len + 1000);
654 wpa_printf(MSG_ERROR,
655 "EAP-TTLS/CHAP: Failed to allocate memory");
658 pos = buf = wpabuf_mhead(msg);
661 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_USER_NAME, 0, 1,
662 identity, identity_len);
665 challenge = eap_ttls_implicit_challenge(
666 sm, data, EAP_TTLS_CHAP_CHALLENGE_LEN + 1);
667 if (challenge == NULL) {
669 wpa_printf(MSG_ERROR, "EAP-TTLS/CHAP: Failed to derive "
670 "implicit challenge");
674 pos = eap_ttls_avp_add(buf, pos, RADIUS_ATTR_CHAP_CHALLENGE, 0, 1,
675 challenge, EAP_TTLS_CHAP_CHALLENGE_LEN);
678 pos = eap_ttls_avp_hdr(pos, RADIUS_ATTR_CHAP_PASSWORD, 0, 1,
679 1 + EAP_TTLS_CHAP_PASSWORD_LEN);
680 data->ident = challenge[EAP_TTLS_CHAP_CHALLENGE_LEN];
681 *pos++ = data->ident;
683 /* MD5(Ident + Password + Challenge) */
684 chap_md5(data->ident, password, password_len, challenge,
685 EAP_TTLS_CHAP_CHALLENGE_LEN, pos);
687 wpa_hexdump_ascii(MSG_DEBUG, "EAP-TTLS: CHAP username",
688 identity, identity_len);
689 wpa_hexdump_ascii_key(MSG_DEBUG, "EAP-TTLS: CHAP password",
690 password, password_len);
691 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: CHAP implicit challenge",
692 challenge, EAP_TTLS_CHAP_CHALLENGE_LEN);
693 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: CHAP password",
694 pos, EAP_TTLS_CHAP_PASSWORD_LEN);
695 pos += EAP_TTLS_CHAP_PASSWORD_LEN;
699 wpabuf_put(msg, pos - buf);
702 /* EAP-TTLS/CHAP does not provide tunneled success
703 * notification, so assume that Phase2 succeeds. */
704 ret->methodState = METHOD_DONE;
705 ret->decision = DECISION_COND_SUCC;
711 static int eap_ttls_phase2_request(struct eap_sm *sm,
712 struct eap_ttls_data *data,
713 struct eap_method_ret *ret,
715 struct wpabuf **resp)
719 enum phase2_types phase2_type = data->phase2_type;
722 if (data->tnc_started) {
723 wpa_printf(MSG_DEBUG, "EAP-TTLS: Processing TNC");
724 phase2_type = EAP_TTLS_PHASE2_EAP;
728 if (phase2_type == EAP_TTLS_PHASE2_MSCHAPV2 ||
729 phase2_type == EAP_TTLS_PHASE2_MSCHAP ||
730 phase2_type == EAP_TTLS_PHASE2_PAP ||
731 phase2_type == EAP_TTLS_PHASE2_CHAP) {
732 if (eap_get_config_identity(sm, &len) == NULL) {
734 "EAP-TTLS: Identity not configured");
735 eap_sm_request_identity(sm);
736 if (eap_get_config_password(sm, &len) == NULL)
737 eap_sm_request_password(sm);
741 if (eap_get_config_password(sm, &len) == NULL) {
743 "EAP-TTLS: Password not configured");
744 eap_sm_request_password(sm);
749 switch (phase2_type) {
750 case EAP_TTLS_PHASE2_EAP:
751 res = eap_ttls_phase2_request_eap(sm, data, ret, hdr, resp);
753 case EAP_TTLS_PHASE2_MSCHAPV2:
754 res = eap_ttls_phase2_request_mschapv2(sm, data, ret, resp);
756 case EAP_TTLS_PHASE2_MSCHAP:
757 res = eap_ttls_phase2_request_mschap(sm, data, ret, resp);
759 case EAP_TTLS_PHASE2_PAP:
760 res = eap_ttls_phase2_request_pap(sm, data, ret, resp);
762 case EAP_TTLS_PHASE2_CHAP:
763 res = eap_ttls_phase2_request_chap(sm, data, ret, resp);
766 wpa_printf(MSG_ERROR, "EAP-TTLS: Phase 2 - Unknown");
772 ret->methodState = METHOD_DONE;
773 ret->decision = DECISION_FAIL;
780 struct ttls_parse_avp {
788 static int eap_ttls_parse_attr_eap(const u8 *dpos, size_t dlen,
789 struct ttls_parse_avp *parse)
791 wpa_printf(MSG_DEBUG, "EAP-TTLS: AVP - EAP Message");
792 if (parse->eapdata == NULL) {
793 parse->eapdata = os_malloc(dlen);
794 if (parse->eapdata == NULL) {
795 wpa_printf(MSG_WARNING, "EAP-TTLS: Failed to allocate "
796 "memory for Phase 2 EAP data");
799 os_memcpy(parse->eapdata, dpos, dlen);
800 parse->eap_len = dlen;
802 u8 *neweap = os_realloc(parse->eapdata, parse->eap_len + dlen);
803 if (neweap == NULL) {
804 wpa_printf(MSG_WARNING, "EAP-TTLS: Failed to allocate "
805 "memory for Phase 2 EAP data");
808 os_memcpy(neweap + parse->eap_len, dpos, dlen);
809 parse->eapdata = neweap;
810 parse->eap_len += dlen;
817 static int eap_ttls_parse_avp(u8 *pos, size_t left,
818 struct ttls_parse_avp *parse)
820 struct ttls_avp *avp;
821 u32 avp_code, avp_length, vendor_id = 0;
825 avp = (struct ttls_avp *) pos;
826 avp_code = be_to_host32(avp->avp_code);
827 avp_length = be_to_host32(avp->avp_length);
828 avp_flags = (avp_length >> 24) & 0xff;
829 avp_length &= 0xffffff;
830 wpa_printf(MSG_DEBUG, "EAP-TTLS: AVP: code=%d flags=0x%02x "
831 "length=%d", (int) avp_code, avp_flags,
834 if (avp_length > left) {
835 wpa_printf(MSG_WARNING, "EAP-TTLS: AVP overflow "
836 "(len=%d, left=%lu) - dropped",
837 (int) avp_length, (unsigned long) left);
841 if (avp_length < sizeof(*avp)) {
842 wpa_printf(MSG_WARNING, "EAP-TTLS: Invalid AVP length %d",
847 dpos = (u8 *) (avp + 1);
848 dlen = avp_length - sizeof(*avp);
849 if (avp_flags & AVP_FLAGS_VENDOR) {
851 wpa_printf(MSG_WARNING, "EAP-TTLS: Vendor AVP "
855 vendor_id = WPA_GET_BE32(dpos);
856 wpa_printf(MSG_DEBUG, "EAP-TTLS: AVP vendor_id %d",
862 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: AVP data", dpos, dlen);
864 if (vendor_id == 0 && avp_code == RADIUS_ATTR_EAP_MESSAGE) {
865 if (eap_ttls_parse_attr_eap(dpos, dlen, parse) < 0)
867 } else if (vendor_id == 0 && avp_code == RADIUS_ATTR_REPLY_MESSAGE) {
868 /* This is an optional message that can be displayed to
870 wpa_hexdump_ascii(MSG_DEBUG, "EAP-TTLS: AVP - Reply-Message",
872 } else if (vendor_id == RADIUS_VENDOR_ID_MICROSOFT &&
873 avp_code == RADIUS_ATTR_MS_CHAP2_SUCCESS) {
874 wpa_hexdump_ascii(MSG_DEBUG, "EAP-TTLS: MS-CHAP2-Success",
877 wpa_printf(MSG_WARNING, "EAP-TTLS: Unexpected "
878 "MS-CHAP2-Success length "
879 "(len=%lu, expected 43)",
880 (unsigned long) dlen);
883 parse->mschapv2 = dpos;
884 } else if (vendor_id == RADIUS_VENDOR_ID_MICROSOFT &&
885 avp_code == RADIUS_ATTR_MS_CHAP_ERROR) {
886 wpa_hexdump_ascii(MSG_DEBUG, "EAP-TTLS: MS-CHAP-Error",
888 parse->mschapv2_error = 1;
889 } else if (avp_flags & AVP_FLAGS_MANDATORY) {
890 wpa_printf(MSG_WARNING, "EAP-TTLS: Unsupported mandatory AVP "
891 "code %d vendor_id %d - dropped",
892 (int) avp_code, (int) vendor_id);
895 wpa_printf(MSG_DEBUG, "EAP-TTLS: Ignoring unsupported AVP "
896 "code %d vendor_id %d",
897 (int) avp_code, (int) vendor_id);
904 static int eap_ttls_parse_avps(struct wpabuf *in_decrypted,
905 struct ttls_parse_avp *parse)
911 pos = wpabuf_mhead(in_decrypted);
912 left = wpabuf_len(in_decrypted);
913 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: Decrypted Phase 2 AVPs", pos, left);
914 if (left < sizeof(struct ttls_avp)) {
915 wpa_printf(MSG_WARNING, "EAP-TTLS: Too short Phase 2 AVP frame"
916 " len=%lu expected %lu or more - dropped",
917 (unsigned long) left,
918 (unsigned long) sizeof(struct ttls_avp));
923 os_memset(parse, 0, sizeof(*parse));
926 avp_length = eap_ttls_parse_avp(pos, left, parse);
930 pad = (4 - (avp_length & 3)) & 3;
931 pos += avp_length + pad;
932 if (left < avp_length + pad)
935 left -= avp_length + pad;
942 static u8 * eap_ttls_fake_identity_request(void)
947 wpa_printf(MSG_DEBUG, "EAP-TTLS: empty data in beginning of "
948 "Phase 2 - use fake EAP-Request Identity");
949 buf = os_malloc(sizeof(*hdr) + 1);
951 wpa_printf(MSG_WARNING, "EAP-TTLS: failed to allocate "
952 "memory for fake EAP-Identity Request");
956 hdr = (struct eap_hdr *) buf;
957 hdr->code = EAP_CODE_REQUEST;
959 hdr->length = host_to_be16(sizeof(*hdr) + 1);
960 buf[sizeof(*hdr)] = EAP_TYPE_IDENTITY;
966 static int eap_ttls_encrypt_response(struct eap_sm *sm,
967 struct eap_ttls_data *data,
968 struct wpabuf *resp, u8 identifier,
969 struct wpabuf **out_data)
974 wpa_hexdump_buf_key(MSG_DEBUG, "EAP-TTLS: Encrypting Phase 2 data",
976 if (eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_TTLS,
977 data->ttls_version, identifier,
979 wpa_printf(MSG_INFO, "EAP-TTLS: Failed to encrypt a Phase 2 "
989 static int eap_ttls_process_phase2_eap(struct eap_sm *sm,
990 struct eap_ttls_data *data,
991 struct eap_method_ret *ret,
992 struct ttls_parse_avp *parse,
993 struct wpabuf **resp)
998 if (parse->eapdata == NULL) {
999 wpa_printf(MSG_WARNING, "EAP-TTLS: No EAP Message in the "
1000 "packet - dropped");
1004 wpa_hexdump(MSG_DEBUG, "EAP-TTLS: Phase 2 EAP",
1005 parse->eapdata, parse->eap_len);
1006 hdr = (struct eap_hdr *) parse->eapdata;
1008 if (parse->eap_len < sizeof(*hdr)) {
1009 wpa_printf(MSG_WARNING, "EAP-TTLS: Too short Phase 2 EAP "
1010 "frame (len=%lu, expected %lu or more) - dropped",
1011 (unsigned long) parse->eap_len,
1012 (unsigned long) sizeof(*hdr));
1015 len = be_to_host16(hdr->length);
1016 if (len > parse->eap_len) {
1017 wpa_printf(MSG_INFO, "EAP-TTLS: Length mismatch in Phase 2 "
1018 "EAP frame (EAP hdr len=%lu, EAP data len in "
1020 (unsigned long) len,
1021 (unsigned long) parse->eap_len);
1024 wpa_printf(MSG_DEBUG, "EAP-TTLS: received Phase 2: code=%d "
1025 "identifier=%d length=%lu",
1026 hdr->code, hdr->identifier, (unsigned long) len);
1027 switch (hdr->code) {
1028 case EAP_CODE_REQUEST:
1029 if (eap_ttls_phase2_request(sm, data, ret, hdr, resp)) {
1030 wpa_printf(MSG_INFO, "EAP-TTLS: Phase2 Request "
1031 "processing failed");
1036 wpa_printf(MSG_INFO, "EAP-TTLS: Unexpected code=%d in "
1037 "Phase 2 EAP header", hdr->code);
1045 static int eap_ttls_process_phase2_mschapv2(struct eap_sm *sm,
1046 struct eap_ttls_data *data,
1047 struct eap_method_ret *ret,
1048 struct ttls_parse_avp *parse)
1051 if (parse->mschapv2_error) {
1052 wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAPV2: Received "
1053 "MS-CHAP-Error - failed");
1054 ret->methodState = METHOD_DONE;
1055 ret->decision = DECISION_FAIL;
1056 /* Reply with empty data to ACK error */
1060 if (parse->mschapv2 == NULL) {
1062 if (data->phase2_success && parse->eapdata) {
1064 * Allow EAP-TNC to be started after successfully
1065 * completed MSCHAPV2.
1069 #endif /* EAP_TNC */
1070 wpa_printf(MSG_WARNING, "EAP-TTLS: no MS-CHAP2-Success AVP "
1071 "received for Phase2 MSCHAPV2");
1074 if (parse->mschapv2[0] != data->ident) {
1075 wpa_printf(MSG_WARNING, "EAP-TTLS: Ident mismatch for Phase 2 "
1076 "MSCHAPV2 (received Ident 0x%02x, expected 0x%02x)",
1077 parse->mschapv2[0], data->ident);
1080 if (!data->auth_response_valid ||
1081 mschapv2_verify_auth_response(data->auth_response,
1082 parse->mschapv2 + 1, 42)) {
1083 wpa_printf(MSG_WARNING, "EAP-TTLS: Invalid authenticator "
1084 "response in Phase 2 MSCHAPV2 success request");
1088 wpa_printf(MSG_INFO, "EAP-TTLS: Phase 2 MSCHAPV2 "
1089 "authentication succeeded");
1090 ret->methodState = METHOD_DONE;
1091 ret->decision = DECISION_UNCOND_SUCC;
1092 data->phase2_success = 1;
1095 * Reply with empty data; authentication server will reply
1096 * with EAP-Success after this.
1099 #else /* EAP_MSCHAPv2 */
1100 wpa_printf(MSG_ERROR, "EAP-TTLS: MSCHAPv2 not included in the build");
1102 #endif /* EAP_MSCHAPv2 */
1107 static int eap_ttls_process_tnc_start(struct eap_sm *sm,
1108 struct eap_ttls_data *data,
1109 struct eap_method_ret *ret,
1110 struct ttls_parse_avp *parse,
1111 struct wpabuf **resp)
1113 /* TNC uses inner EAP method after non-EAP TTLS phase 2. */
1114 if (parse->eapdata == NULL) {
1115 wpa_printf(MSG_INFO, "EAP-TTLS: Phase 2 received "
1116 "unexpected tunneled data (no EAP)");
1120 if (!data->ready_for_tnc) {
1121 wpa_printf(MSG_INFO, "EAP-TTLS: Phase 2 received "
1122 "EAP after non-EAP, but not ready for TNC");
1126 wpa_printf(MSG_DEBUG, "EAP-TTLS: Start TNC after completed "
1128 data->tnc_started = 1;
1130 if (eap_ttls_process_phase2_eap(sm, data, ret, parse, resp) < 0)
1135 #endif /* EAP_TNC */
1138 static int eap_ttls_process_decrypted(struct eap_sm *sm,
1139 struct eap_ttls_data *data,
1140 struct eap_method_ret *ret,
1142 struct ttls_parse_avp *parse,
1143 struct wpabuf *in_decrypted,
1144 struct wpabuf **out_data)
1146 struct wpabuf *resp = NULL;
1147 struct eap_peer_config *config = eap_get_config(sm);
1149 enum phase2_types phase2_type = data->phase2_type;
1152 if (data->tnc_started)
1153 phase2_type = EAP_TTLS_PHASE2_EAP;
1154 #endif /* EAP_TNC */
1156 switch (phase2_type) {
1157 case EAP_TTLS_PHASE2_EAP:
1158 if (eap_ttls_process_phase2_eap(sm, data, ret, parse, &resp) <
1162 case EAP_TTLS_PHASE2_MSCHAPV2:
1163 res = eap_ttls_process_phase2_mschapv2(sm, data, ret, parse);
1165 if (res == 1 && parse->eapdata && data->phase2_success) {
1167 * TNC may be required as the next
1168 * authentication method within the tunnel.
1170 ret->methodState = METHOD_MAY_CONT;
1171 data->ready_for_tnc = 1;
1172 if (eap_ttls_process_tnc_start(sm, data, ret, parse,
1176 #endif /* EAP_TNC */
1178 case EAP_TTLS_PHASE2_MSCHAP:
1179 case EAP_TTLS_PHASE2_PAP:
1180 case EAP_TTLS_PHASE2_CHAP:
1182 if (eap_ttls_process_tnc_start(sm, data, ret, parse, &resp) <
1187 /* EAP-TTLS/{MSCHAP,PAP,CHAP} should not send any TLS tunneled
1188 * requests to the supplicant */
1189 wpa_printf(MSG_INFO, "EAP-TTLS: Phase 2 received unexpected "
1192 #endif /* EAP_TNC */
1196 if (eap_ttls_encrypt_response(sm, data, resp, identifier,
1199 } else if (config->pending_req_identity ||
1200 config->pending_req_password ||
1201 config->pending_req_otp ||
1202 config->pending_req_new_password) {
1203 wpabuf_free(data->pending_phase2_req);
1204 data->pending_phase2_req = wpabuf_dup(in_decrypted);
1211 static int eap_ttls_implicit_identity_request(struct eap_sm *sm,
1212 struct eap_ttls_data *data,
1213 struct eap_method_ret *ret,
1215 struct wpabuf **out_data)
1218 struct eap_hdr *hdr;
1219 struct wpabuf *resp;
1221 hdr = (struct eap_hdr *) eap_ttls_fake_identity_request();
1223 ret->methodState = METHOD_DONE;
1224 ret->decision = DECISION_FAIL;
1229 if (eap_ttls_phase2_request(sm, data, ret, hdr, &resp)) {
1230 wpa_printf(MSG_INFO, "EAP-TTLS: Phase2 Request "
1231 "processing failed");
1234 struct eap_peer_config *config = eap_get_config(sm);
1236 (config->pending_req_identity ||
1237 config->pending_req_password ||
1238 config->pending_req_otp ||
1239 config->pending_req_new_password)) {
1241 * Use empty buffer to force implicit request
1242 * processing when EAP request is re-processed after
1245 wpabuf_free(data->pending_phase2_req);
1246 data->pending_phase2_req = wpabuf_alloc(0);
1249 retval = eap_ttls_encrypt_response(sm, data, resp, identifier,
1256 ret->methodState = METHOD_DONE;
1257 ret->decision = DECISION_FAIL;
1264 static int eap_ttls_phase2_start(struct eap_sm *sm, struct eap_ttls_data *data,
1265 struct eap_method_ret *ret, u8 identifier,
1266 struct wpabuf **out_data)
1268 data->phase2_start = 0;
1271 * EAP-TTLS does not use Phase2 on fast re-auth; this must be done only
1272 * if TLS part was indeed resuming a previous session. Most
1273 * Authentication Servers terminate EAP-TTLS before reaching this
1274 * point, but some do not. Make wpa_supplicant stop phase 2 here, if
1278 tls_connection_resumed(sm->ssl_ctx, data->ssl.conn)) {
1279 wpa_printf(MSG_DEBUG, "EAP-TTLS: Session resumption - "
1281 *out_data = eap_peer_tls_build_ack(identifier, EAP_TYPE_TTLS,
1282 data->ttls_version);
1283 ret->methodState = METHOD_DONE;
1284 ret->decision = DECISION_UNCOND_SUCC;
1285 data->phase2_success = 1;
1289 return eap_ttls_implicit_identity_request(sm, data, ret, identifier,
1294 static int eap_ttls_decrypt(struct eap_sm *sm, struct eap_ttls_data *data,
1295 struct eap_method_ret *ret, u8 identifier,
1296 const struct wpabuf *in_data,
1297 struct wpabuf **out_data)
1299 struct wpabuf *in_decrypted = NULL;
1301 struct ttls_parse_avp parse;
1303 os_memset(&parse, 0, sizeof(parse));
1305 wpa_printf(MSG_DEBUG, "EAP-TTLS: received %lu bytes encrypted data for"
1307 in_data ? (unsigned long) wpabuf_len(in_data) : 0);
1309 if (data->pending_phase2_req) {
1310 wpa_printf(MSG_DEBUG, "EAP-TTLS: Pending Phase 2 request - "
1311 "skip decryption and use old data");
1312 /* Clear TLS reassembly state. */
1313 eap_peer_tls_reset_input(&data->ssl);
1315 in_decrypted = data->pending_phase2_req;
1316 data->pending_phase2_req = NULL;
1317 if (wpabuf_len(in_decrypted) == 0) {
1318 wpabuf_free(in_decrypted);
1319 return eap_ttls_implicit_identity_request(
1320 sm, data, ret, identifier, out_data);
1325 if ((in_data == NULL || wpabuf_len(in_data) == 0) &&
1326 data->phase2_start) {
1327 return eap_ttls_phase2_start(sm, data, ret, identifier,
1331 if (in_data == NULL || wpabuf_len(in_data) == 0) {
1332 /* Received TLS ACK - requesting more fragments */
1333 return eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_TTLS,
1335 identifier, NULL, out_data);
1338 retval = eap_peer_tls_decrypt(sm, &data->ssl, in_data, &in_decrypted);
1343 data->phase2_start = 0;
1345 if (eap_ttls_parse_avps(in_decrypted, &parse) < 0) {
1350 retval = eap_ttls_process_decrypted(sm, data, ret, identifier,
1351 &parse, in_decrypted, out_data);
1354 wpabuf_free(in_decrypted);
1355 os_free(parse.eapdata);
1358 ret->methodState = METHOD_DONE;
1359 ret->decision = DECISION_FAIL;
1366 static int eap_ttls_process_handshake(struct eap_sm *sm,
1367 struct eap_ttls_data *data,
1368 struct eap_method_ret *ret,
1370 const u8 *in_data, size_t in_len,
1371 struct wpabuf **out_data)
1375 res = eap_peer_tls_process_helper(sm, &data->ssl, EAP_TYPE_TTLS,
1376 data->ttls_version, identifier,
1377 in_data, in_len, out_data);
1379 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
1380 wpa_printf(MSG_DEBUG, "EAP-TTLS: TLS done, proceed to "
1382 if (data->resuming) {
1383 wpa_printf(MSG_DEBUG, "EAP-TTLS: fast reauth - may "
1385 ret->decision = DECISION_COND_SUCC;
1386 ret->methodState = METHOD_MAY_CONT;
1388 data->phase2_start = 1;
1389 eap_ttls_v0_derive_key(sm, data);
1391 if (*out_data == NULL || wpabuf_len(*out_data) == 0) {
1392 if (eap_ttls_decrypt(sm, data, ret, identifier,
1394 wpa_printf(MSG_WARNING, "EAP-TTLS: "
1395 "failed to process early "
1396 "start for Phase 2");
1406 * Application data included in the handshake message.
1408 wpabuf_free(data->pending_phase2_req);
1409 data->pending_phase2_req = *out_data;
1411 wpabuf_set(&msg, in_data, in_len);
1412 res = eap_ttls_decrypt(sm, data, ret, identifier, &msg,
1420 static void eap_ttls_check_auth_status(struct eap_sm *sm,
1421 struct eap_ttls_data *data,
1422 struct eap_method_ret *ret)
1424 if (ret->methodState == METHOD_DONE) {
1425 ret->allowNotifications = FALSE;
1426 if (ret->decision == DECISION_UNCOND_SUCC ||
1427 ret->decision == DECISION_COND_SUCC) {
1428 wpa_printf(MSG_DEBUG, "EAP-TTLS: Authentication "
1429 "completed successfully");
1430 data->phase2_success = 1;
1432 if (!data->ready_for_tnc && !data->tnc_started) {
1434 * TNC may be required as the next
1435 * authentication method within the tunnel.
1437 ret->methodState = METHOD_MAY_CONT;
1438 data->ready_for_tnc = 1;
1440 #endif /* EAP_TNC */
1442 } else if (ret->methodState == METHOD_MAY_CONT &&
1443 (ret->decision == DECISION_UNCOND_SUCC ||
1444 ret->decision == DECISION_COND_SUCC)) {
1445 wpa_printf(MSG_DEBUG, "EAP-TTLS: Authentication "
1446 "completed successfully (MAY_CONT)");
1447 data->phase2_success = 1;
1452 static struct wpabuf * eap_ttls_process(struct eap_sm *sm, void *priv,
1453 struct eap_method_ret *ret,
1454 const struct wpabuf *reqData)
1459 struct wpabuf *resp;
1461 struct eap_ttls_data *data = priv;
1463 pos = eap_peer_tls_process_init(sm, &data->ssl, EAP_TYPE_TTLS, ret,
1464 reqData, &left, &flags);
1467 id = eap_get_id(reqData);
1469 if (flags & EAP_TLS_FLAGS_START) {
1470 wpa_printf(MSG_DEBUG, "EAP-TTLS: Start (server ver=%d, own "
1471 "ver=%d)", flags & EAP_TLS_VERSION_MASK,
1472 data->ttls_version);
1474 /* RFC 5281, Ch. 9.2:
1475 * "This packet MAY contain additional information in the form
1476 * of AVPs, which may provide useful hints to the client"
1477 * For now, ignore any potential extra data.
1483 if (tls_connection_established(sm->ssl_ctx, data->ssl.conn) &&
1486 wpabuf_set(&msg, pos, left);
1487 res = eap_ttls_decrypt(sm, data, ret, id, &msg, &resp);
1489 res = eap_ttls_process_handshake(sm, data, ret, id,
1493 eap_ttls_check_auth_status(sm, data, ret);
1495 /* FIX: what about res == -1? Could just move all error processing into
1496 * the other functions and get rid of this res==1 case here. */
1499 return eap_peer_tls_build_ack(id, EAP_TYPE_TTLS,
1500 data->ttls_version);
1506 static Boolean eap_ttls_has_reauth_data(struct eap_sm *sm, void *priv)
1508 struct eap_ttls_data *data = priv;
1509 return tls_connection_established(sm->ssl_ctx, data->ssl.conn) &&
1510 data->phase2_success;
1514 static void eap_ttls_deinit_for_reauth(struct eap_sm *sm, void *priv)
1516 struct eap_ttls_data *data = priv;
1517 wpabuf_free(data->pending_phase2_req);
1518 data->pending_phase2_req = NULL;
1520 data->ready_for_tnc = 0;
1521 data->tnc_started = 0;
1522 #endif /* EAP_TNC */
1526 static void * eap_ttls_init_for_reauth(struct eap_sm *sm, void *priv)
1528 struct eap_ttls_data *data = priv;
1529 os_free(data->key_data);
1530 data->key_data = NULL;
1531 if (eap_peer_tls_reauth_init(sm, &data->ssl)) {
1535 if (data->phase2_priv && data->phase2_method &&
1536 data->phase2_method->init_for_reauth)
1537 data->phase2_method->init_for_reauth(sm, data->phase2_priv);
1538 data->phase2_start = 0;
1539 data->phase2_success = 0;
1546 static int eap_ttls_get_status(struct eap_sm *sm, void *priv, char *buf,
1547 size_t buflen, int verbose)
1549 struct eap_ttls_data *data = priv;
1552 len = eap_peer_tls_status(sm, &data->ssl, buf, buflen, verbose);
1553 ret = os_snprintf(buf + len, buflen - len,
1554 "EAP-TTLSv%d Phase2 method=",
1555 data->ttls_version);
1556 if (ret < 0 || (size_t) ret >= buflen - len)
1559 switch (data->phase2_type) {
1560 case EAP_TTLS_PHASE2_EAP:
1561 ret = os_snprintf(buf + len, buflen - len, "EAP-%s\n",
1562 data->phase2_method ?
1563 data->phase2_method->name : "?");
1565 case EAP_TTLS_PHASE2_MSCHAPV2:
1566 ret = os_snprintf(buf + len, buflen - len, "MSCHAPV2\n");
1568 case EAP_TTLS_PHASE2_MSCHAP:
1569 ret = os_snprintf(buf + len, buflen - len, "MSCHAP\n");
1571 case EAP_TTLS_PHASE2_PAP:
1572 ret = os_snprintf(buf + len, buflen - len, "PAP\n");
1574 case EAP_TTLS_PHASE2_CHAP:
1575 ret = os_snprintf(buf + len, buflen - len, "CHAP\n");
1581 if (ret < 0 || (size_t) ret >= buflen - len)
1589 static Boolean eap_ttls_isKeyAvailable(struct eap_sm *sm, void *priv)
1591 struct eap_ttls_data *data = priv;
1592 return data->key_data != NULL && data->phase2_success;
1596 static u8 * eap_ttls_getKey(struct eap_sm *sm, void *priv, size_t *len)
1598 struct eap_ttls_data *data = priv;
1601 if (data->key_data == NULL || !data->phase2_success)
1604 key = os_malloc(EAP_TLS_KEY_LEN);
1608 *len = EAP_TLS_KEY_LEN;
1609 os_memcpy(key, data->key_data, EAP_TLS_KEY_LEN);
1615 int eap_peer_ttls_register(void)
1617 struct eap_method *eap;
1620 eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
1621 EAP_VENDOR_IETF, EAP_TYPE_TTLS, "TTLS");
1625 eap->init = eap_ttls_init;
1626 eap->deinit = eap_ttls_deinit;
1627 eap->process = eap_ttls_process;
1628 eap->isKeyAvailable = eap_ttls_isKeyAvailable;
1629 eap->getKey = eap_ttls_getKey;
1630 eap->get_status = eap_ttls_get_status;
1631 eap->has_reauth_data = eap_ttls_has_reauth_data;
1632 eap->deinit_for_reauth = eap_ttls_deinit_for_reauth;
1633 eap->init_for_reauth = eap_ttls_init_for_reauth;
1635 ret = eap_peer_method_register(eap);
1637 eap_peer_method_free(eap);