diff --git a/src/eapol_supp/eapol_supp_sm.c b/src/eapol_supp/eapol_supp_sm.c index f5f576045..0bfe3c970 100644 --- a/src/eapol_supp/eapol_supp_sm.c +++ b/src/eapol_supp/eapol_supp_sm.c @@ -1296,6 +1296,14 @@ int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf, if (sm == NULL) return 0; + + if (encrypted == FRAME_NOT_ENCRYPTED && sm->ctx->encryption_required && + sm->ctx->encryption_required(sm->ctx->ctx)) { + wpa_printf(MSG_DEBUG, + "EAPOL: Discard unencrypted EAPOL frame when encryption since encryption was expected"); + return 0; + } + sm->dot1xSuppEapolFramesRx++; if (len < sizeof(*hdr)) { sm->dot1xSuppInvalidEapolFramesRx++; diff --git a/src/eapol_supp/eapol_supp_sm.h b/src/eapol_supp/eapol_supp_sm.h index ecc1ce70b..2b1aeff88 100644 --- a/src/eapol_supp/eapol_supp_sm.h +++ b/src/eapol_supp/eapol_supp_sm.h @@ -307,6 +307,13 @@ struct eapol_ctx { * Automatically triggers a reconnect when not. */ int (*confirm_auth_cb)(void *ctx); + + /** + * encryption_required - Check whether encryption is required + * @ctx: eapol_ctx from eap_peer_sm_init() call + * Returns: Whether the current session requires encryption + */ + bool (*encryption_required)(void *ctx); }; diff --git a/wpa_supplicant/wpas_glue.c b/wpa_supplicant/wpas_glue.c index 33bc831f3..d62914bc1 100644 --- a/wpa_supplicant/wpas_glue.c +++ b/wpa_supplicant/wpas_glue.c @@ -1157,6 +1157,17 @@ static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len) } } } + + +static bool wpas_encryption_required(void *ctx) +{ + struct wpa_supplicant *wpa_s = ctx; + + return wpa_s->wpa && + wpa_sm_has_ptk_installed(wpa_s->wpa) && + wpa_sm_pmf_enabled(wpa_s->wpa); +} + #endif /* IEEE8021X_EAPOL */ @@ -1203,6 +1214,7 @@ int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s) ctx->eap_error_cb = wpa_supplicant_eap_error_cb; ctx->confirm_auth_cb = wpa_supplicant_eap_auth_start_cb; ctx->set_anon_id = wpa_supplicant_set_anon_id; + ctx->encryption_required = wpas_encryption_required; ctx->cb_ctx = wpa_s; wpa_s->eapol = eapol_sm_init(ctx); if (wpa_s->eapol == NULL) {