Lines Matching full:data
59 static void eap_eke_state(struct eap_eke_data *data, int state) in eap_eke_state() argument
62 eap_eke_state_txt(data->state), in eap_eke_state()
64 data->state = state; in eap_eke_state()
68 static void eap_eke_fail(struct eap_eke_data *data, u32 code) in eap_eke_fail() argument
71 data->failure_code = code; in eap_eke_fail()
72 eap_eke_state(data, FAILURE_REPORT); in eap_eke_fail()
78 struct eap_eke_data *data; in eap_eke_init() local
81 data = os_zalloc(sizeof(*data)); in eap_eke_init()
82 if (data == NULL) in eap_eke_init()
84 eap_eke_state(data, IDENTITY); in eap_eke_init()
86 data->serverid_type = EAP_EKE_ID_OPAQUE; in eap_eke_init()
89 data->serverid_type == EAP_EKE_ID_OPAQUE) in eap_eke_init()
90 data->serverid_type = EAP_EKE_ID_FQDN; in eap_eke_init()
92 data->serverid_type = EAP_EKE_ID_NAI; in eap_eke_init()
95 data->phase2 = sm->init_phase2; in eap_eke_init()
97 return data; in eap_eke_init()
103 struct eap_eke_data *data = priv; in eap_eke_reset() local
104 eap_eke_session_clean(&data->sess); in eap_eke_reset()
105 os_free(data->peerid); in eap_eke_reset()
106 wpabuf_free(data->msgs); in eap_eke_reset()
107 bin_clear_free(data, sizeof(*data)); in eap_eke_reset()
111 static struct wpabuf * eap_eke_build_msg(struct eap_eke_data *data, in eap_eke_build_msg() argument
162 static struct wpabuf * eap_eke_build_failure(struct eap_eke_data *data, u8 id) in eap_eke_build_failure() argument
167 data->failure_code); in eap_eke_build_failure()
169 msg = eap_eke_build_msg(data, id, 4, EAP_EKE_FAILURE); in eap_eke_build_failure()
171 eap_eke_state(data, FAILURE); in eap_eke_build_failure()
174 wpabuf_put_be32(msg, data->failure_code); in eap_eke_build_failure()
181 struct eap_eke_data *data, in eap_eke_build_identity() argument
190 msg = eap_eke_build_msg(data, id, plen, EAP_EKE_ID); in eap_eke_build_identity()
225 wpabuf_put_u8(msg, data->serverid_type); in eap_eke_build_identity()
228 wpabuf_free(data->msgs); in eap_eke_build_identity()
229 data->msgs = wpabuf_dup(msg); in eap_eke_build_identity()
230 if (data->msgs == NULL) { in eap_eke_build_identity()
240 struct eap_eke_data *data, u8 id) in eap_eke_build_commit() argument
249 eap_eke_fail(data, EAP_EKE_FAIL_PASSWD_NOT_FOUND); in eap_eke_build_commit()
250 return eap_eke_build_failure(data, id); in eap_eke_build_commit()
253 if (eap_eke_derive_key(&data->sess, sm->user->password, in eap_eke_build_commit()
256 data->peerid, data->peerid_len, data->key) < 0) { in eap_eke_build_commit()
258 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_commit()
259 return eap_eke_build_failure(data, id); in eap_eke_build_commit()
262 msg = eap_eke_build_msg(data, id, data->sess.dhcomp_len, in eap_eke_build_commit()
265 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_commit()
266 return eap_eke_build_failure(data, id); in eap_eke_build_commit()
277 if (eap_eke_dh_init(data->sess.dhgroup, data->dh_priv, pub) < 0) { in eap_eke_build_commit()
280 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_commit()
281 return eap_eke_build_failure(data, id); in eap_eke_build_commit()
284 if (eap_eke_dhcomp(&data->sess, data->key, pub, in eap_eke_build_commit()
285 wpabuf_put(msg, data->sess.dhcomp_len)) in eap_eke_build_commit()
289 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_commit()
290 return eap_eke_build_failure(data, id); in eap_eke_build_commit()
293 if (wpabuf_resize(&data->msgs, wpabuf_len(msg)) < 0) { in eap_eke_build_commit()
295 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_commit()
296 return eap_eke_build_failure(data, id); in eap_eke_build_commit()
298 wpabuf_put_buf(data->msgs, msg); in eap_eke_build_commit()
305 struct eap_eke_data *data, u8 id) in eap_eke_build_confirm() argument
314 plen = data->sess.pnonce_ps_len + data->sess.prf_len; in eap_eke_build_confirm()
315 msg = eap_eke_build_msg(data, id, plen, EAP_EKE_CONFIRM); in eap_eke_build_confirm()
317 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_confirm()
318 return eap_eke_build_failure(data, id); in eap_eke_build_confirm()
321 if (random_get_bytes(data->nonce_s, data->sess.nonce_len)) { in eap_eke_build_confirm()
323 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_confirm()
324 return eap_eke_build_failure(data, id); in eap_eke_build_confirm()
327 data->nonce_s, data->sess.nonce_len); in eap_eke_build_confirm()
329 os_memcpy(nonces, data->nonce_p, data->sess.nonce_len); in eap_eke_build_confirm()
330 os_memcpy(nonces + data->sess.nonce_len, data->nonce_s, in eap_eke_build_confirm()
331 data->sess.nonce_len); in eap_eke_build_confirm()
333 if (eap_eke_prot(&data->sess, nonces, 2 * data->sess.nonce_len, in eap_eke_build_confirm()
336 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_confirm()
337 return eap_eke_build_failure(data, id); in eap_eke_build_confirm()
341 if (eap_eke_derive_ka(&data->sess, in eap_eke_build_confirm()
343 data->peerid, data->peerid_len, in eap_eke_build_confirm()
344 data->nonce_p, data->nonce_s) < 0) { in eap_eke_build_confirm()
346 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_confirm()
347 return eap_eke_build_failure(data, id); in eap_eke_build_confirm()
350 auth = wpabuf_put(msg, data->sess.prf_len); in eap_eke_build_confirm()
351 if (eap_eke_auth(&data->sess, "EAP-EKE server", data->msgs, auth) < 0) { in eap_eke_build_confirm()
353 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_build_confirm()
354 return eap_eke_build_failure(data, id); in eap_eke_build_confirm()
356 wpa_hexdump(MSG_DEBUG, "EAP-EKE: Auth_S", auth, data->sess.prf_len); in eap_eke_build_confirm()
364 struct eap_eke_data *data = priv; in eap_eke_buildReq() local
366 switch (data->state) { in eap_eke_buildReq()
368 return eap_eke_build_identity(sm, data, id); in eap_eke_buildReq()
370 return eap_eke_build_commit(sm, data, id); in eap_eke_buildReq()
372 return eap_eke_build_confirm(sm, data, id); in eap_eke_buildReq()
374 return eap_eke_build_failure(data, id); in eap_eke_buildReq()
377 data->state); in eap_eke_buildReq()
387 struct eap_eke_data *data = priv; in eap_eke_check() local
401 if (data->state == IDENTITY && eke_exch == EAP_EKE_ID) in eap_eke_check()
404 if (data->state == COMMIT && eke_exch == EAP_EKE_COMMIT) in eap_eke_check()
407 if (data->state == CONFIRM && eke_exch == EAP_EKE_CONFIRM) in eap_eke_check()
414 eke_exch, data->state); in eap_eke_check()
421 struct eap_eke_data *data, in eap_eke_process_identity() argument
430 if (data->state != IDENTITY) { in eap_eke_process_identity()
431 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_identity()
440 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_identity()
447 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_identity()
456 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_identity()
462 if (eap_eke_session_init(&data->sess, pos[0], pos[1], pos[2], pos[3]) < in eap_eke_process_identity()
464 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_identity()
469 data->peerid_type = *pos++; in eap_eke_process_identity()
470 os_free(data->peerid); in eap_eke_process_identity()
471 data->peerid = os_memdup(pos, end - pos); in eap_eke_process_identity()
472 if (data->peerid == NULL) { in eap_eke_process_identity()
474 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_identity()
477 data->peerid_len = end - pos; in eap_eke_process_identity()
478 wpa_printf(MSG_DEBUG, "EAP-EKE: Peer IDType %u", data->peerid_type); in eap_eke_process_identity()
480 data->peerid, data->peerid_len); in eap_eke_process_identity()
482 if (eap_user_get(sm, data->peerid, data->peerid_len, data->phase2)) { in eap_eke_process_identity()
484 eap_eke_fail(data, EAP_EKE_FAIL_PASSWD_NOT_FOUND); in eap_eke_process_identity()
495 eap_eke_fail(data, EAP_EKE_FAIL_PASSWD_NOT_FOUND); in eap_eke_process_identity()
501 eap_eke_fail(data, EAP_EKE_FAIL_PASSWD_NOT_FOUND); in eap_eke_process_identity()
505 if (wpabuf_resize(&data->msgs, wpabuf_len(respData)) < 0) { in eap_eke_process_identity()
506 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_identity()
509 wpabuf_put_buf(data->msgs, respData); in eap_eke_process_identity()
511 eap_eke_state(data, COMMIT); in eap_eke_process_identity()
516 struct eap_eke_data *data, in eap_eke_process_commit() argument
525 if (data->state != COMMIT) { in eap_eke_process_commit()
526 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_commit()
533 if (pos + data->sess.dhcomp_len + data->sess.pnonce_len > end) { in eap_eke_process_commit()
535 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_commit()
540 pos, data->sess.dhcomp_len); in eap_eke_process_commit()
542 pos += data->sess.dhcomp_len; in eap_eke_process_commit()
543 wpa_hexdump(MSG_DEBUG, "EAP-EKE: PNonce_P", pos, data->sess.pnonce_len); in eap_eke_process_commit()
545 pos += data->sess.pnonce_len; in eap_eke_process_commit()
548 if (eap_eke_shared_secret(&data->sess, data->key, data->dh_priv, dhcomp) in eap_eke_process_commit()
551 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_commit()
555 if (eap_eke_derive_ke_ki(&data->sess, in eap_eke_process_commit()
557 data->peerid, data->peerid_len) < 0) { in eap_eke_process_commit()
559 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_commit()
563 decrypt_len = sizeof(data->nonce_p); in eap_eke_process_commit()
564 if (eap_eke_decrypt_prot(&data->sess, pnonce, data->sess.pnonce_len, in eap_eke_process_commit()
565 data->nonce_p, &decrypt_len) < 0) { in eap_eke_process_commit()
567 eap_eke_fail(data, EAP_EKE_FAIL_AUTHENTICATION_FAIL); in eap_eke_process_commit()
570 if (decrypt_len < (size_t) data->sess.nonce_len) { in eap_eke_process_commit()
571 wpa_printf(MSG_INFO, "EAP-EKE: PNonce_P protected data too short to include Nonce_P"); in eap_eke_process_commit()
572 eap_eke_fail(data, EAP_EKE_FAIL_AUTHENTICATION_FAIL); in eap_eke_process_commit()
576 data->nonce_p, data->sess.nonce_len); in eap_eke_process_commit()
578 if (wpabuf_resize(&data->msgs, wpabuf_len(respData)) < 0) { in eap_eke_process_commit()
579 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_commit()
582 wpabuf_put_buf(data->msgs, respData); in eap_eke_process_commit()
584 eap_eke_state(data, CONFIRM); in eap_eke_process_commit()
589 struct eap_eke_data *data, in eap_eke_process_confirm() argument
599 if (data->state != CONFIRM) { in eap_eke_process_confirm()
600 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_confirm()
606 if (payloadlen < (size_t) data->sess.pnonce_len + data->sess.prf_len) { in eap_eke_process_confirm()
608 eap_eke_fail(data, EAP_EKE_FAIL_PROTO_ERROR); in eap_eke_process_confirm()
613 if (eap_eke_decrypt_prot(&data->sess, payload, data->sess.pnonce_len, in eap_eke_process_confirm()
616 eap_eke_fail(data, EAP_EKE_FAIL_AUTHENTICATION_FAIL); in eap_eke_process_confirm()
619 if (decrypt_len < (size_t) data->sess.nonce_len) { in eap_eke_process_confirm()
620 wpa_printf(MSG_INFO, "EAP-EKE: PNonce_S protected data too short to include Nonce_S"); in eap_eke_process_confirm()
621 eap_eke_fail(data, EAP_EKE_FAIL_AUTHENTICATION_FAIL); in eap_eke_process_confirm()
625 nonce, data->sess.nonce_len); in eap_eke_process_confirm()
626 if (os_memcmp(nonce, data->nonce_s, data->sess.nonce_len) != 0) { in eap_eke_process_confirm()
628 eap_eke_fail(data, EAP_EKE_FAIL_AUTHENTICATION_FAIL); in eap_eke_process_confirm()
632 if (eap_eke_auth(&data->sess, "EAP-EKE peer", data->msgs, auth_p) < 0) { in eap_eke_process_confirm()
634 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_confirm()
637 wpa_hexdump(MSG_DEBUG, "EAP-EKE: Auth_P", auth_p, data->sess.prf_len); in eap_eke_process_confirm()
638 if (os_memcmp_const(auth_p, payload + data->sess.pnonce_len, in eap_eke_process_confirm()
639 data->sess.prf_len) != 0) { in eap_eke_process_confirm()
641 eap_eke_fail(data, EAP_EKE_FAIL_AUTHENTICATION_FAIL); in eap_eke_process_confirm()
645 if (eap_eke_derive_msk(&data->sess, sm->cfg->server_id, in eap_eke_process_confirm()
647 data->peerid, data->peerid_len, in eap_eke_process_confirm()
648 data->nonce_s, data->nonce_p, in eap_eke_process_confirm()
649 data->msk, data->emsk) < 0) { in eap_eke_process_confirm()
651 eap_eke_fail(data, EAP_EKE_FAIL_PRIVATE_INTERNAL_ERROR); in eap_eke_process_confirm()
655 os_memset(data->dh_priv, 0, sizeof(data->dh_priv)); in eap_eke_process_confirm()
656 os_memset(data->key, 0, sizeof(data->key)); in eap_eke_process_confirm()
657 eap_eke_session_clean(&data->sess); in eap_eke_process_confirm()
659 eap_eke_state(data, SUCCESS); in eap_eke_process_confirm()
664 struct eap_eke_data *data, in eap_eke_process_failure() argument
674 eap_eke_state(data, FAILURE); in eap_eke_process_failure()
681 eap_eke_state(data, FAILURE); in eap_eke_process_failure()
688 struct eap_eke_data *data = priv; in eap_eke_process() local
705 eap_eke_process_identity(sm, data, respData, pos, end - pos); in eap_eke_process()
708 eap_eke_process_commit(sm, data, respData, pos, end - pos); in eap_eke_process()
711 eap_eke_process_confirm(sm, data, respData, pos, end - pos); in eap_eke_process()
714 eap_eke_process_failure(sm, data, respData, pos, end - pos); in eap_eke_process()
722 struct eap_eke_data *data = priv; in eap_eke_isDone() local
723 return data->state == SUCCESS || data->state == FAILURE; in eap_eke_isDone()
729 struct eap_eke_data *data = priv; in eap_eke_getKey() local
732 if (data->state != SUCCESS) in eap_eke_getKey()
735 key = os_memdup(data->msk, EAP_MSK_LEN); in eap_eke_getKey()
746 struct eap_eke_data *data = priv; in eap_eke_get_emsk() local
749 if (data->state != SUCCESS) in eap_eke_get_emsk()
752 key = os_memdup(data->emsk, EAP_EMSK_LEN); in eap_eke_get_emsk()
763 struct eap_eke_data *data = priv; in eap_eke_isSuccess() local
764 return data->state == SUCCESS; in eap_eke_isSuccess()
770 struct eap_eke_data *data = priv; in eap_eke_get_session_id() local
774 if (data->state != SUCCESS) in eap_eke_get_session_id()
777 sid_len = 1 + 2 * data->sess.nonce_len; in eap_eke_get_session_id()
782 os_memcpy(sid + 1, data->nonce_p, data->sess.nonce_len); in eap_eke_get_session_id()
783 os_memcpy(sid + 1 + data->sess.nonce_len, data->nonce_s, in eap_eke_get_session_id()
784 data->sess.nonce_len); in eap_eke_get_session_id()