[PATCH 16/55] AP: Support Association frame encryption in the FT protocol

Ilan Peer ilan.peer at intel.com
Thu Dec 3 02:44:15 PST 2026


Process the Diffie-Hellman Parameter element in the first FT message,
use DHss in the PTK derivation, and add the Diffie-Hellman Parameter
and Supported Groups elements to the second message. Unsupported
groups are rejected.

The groups come from ieee8021x_auth_groups.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 hostapd/hostapd.conf   |   7 +-
 src/ap/wpa_auth.h      |   5 ++
 src/ap/wpa_auth_ft.c   | 189 ++++++++++++++++++++++++++++++++++++++++-
 src/ap/wpa_auth_glue.c |   3 +
 src/ap/wpa_auth_i.h    |   4 +
 5 files changed, 203 insertions(+), 5 deletions(-)

diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index 700b3bb88366..802d6ca51686 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -2816,9 +2816,10 @@ own_ip_addr=127.0.0.1
 #eap_using_authentication_frames=0
 
 # Finite cyclic groups accepted in the Diffie-Hellman Parameter element of IEEE
-# 802.1X authentication utilizing Authentication frames, as a space separated
-# list of group numbers. The default is group 19 only. Only the ECC groups 19,
-# 20 and 21 are supported.
+# 802.1X authentication utilizing Authentication frames and of the FT protocol
+# when Association frame encryption is used, as a space separated list of group
+# numbers. The default is group 19 only. Only the ECC groups 19, 20 and 21
+# are supported.
 #ieee8021x_auth_groups=19 20 21
 
 ##### Neighbor table ##########################################################
diff --git a/src/ap/wpa_auth.h b/src/ap/wpa_auth.h
index a7d1163f48c2..eb14e943d798 100644
--- a/src/ap/wpa_auth.h
+++ b/src/ap/wpa_auth.h
@@ -294,6 +294,8 @@ struct wpa_auth_config {
 	unsigned int assoc_frame_encryption:1;
 	unsigned int pmksa_caching_privacy:1;
 	unsigned int eap_using_authentication_frames:1;
+
+	const int *ft_dh_groups;
 #ifdef CONFIG_PASN
 	/* Whether to allow unauthenticated EPPKE (EPPKE without base AKM) */
 	bool eppke_unauth;
@@ -599,6 +601,9 @@ void wpa_ft_process_auth(struct wpa_state_machine *sm,
 				    u16 auth_transaction, u16 resp,
 				    const u8 *ies, size_t ies_len),
 			 void *ctx);
+bool wpa_ft_auth_uses_enc_assoc(const struct wpa_authenticator *wpa_auth,
+				const u8 *ies, size_t ies_len);
+bool wpa_auth_sta_ft_enc_assoc(struct wpa_state_machine *sm);
 int wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
 			    size_t ies_len);
 int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
diff --git a/src/ap/wpa_auth_ft.c b/src/ap/wpa_auth_ft.c
index 25f84898bfc5..83e40f2392db 100644
--- a/src/ap/wpa_auth_ft.c
+++ b/src/ap/wpa_auth_ft.c
@@ -16,6 +16,7 @@
 #include "common/ocv.h"
 #include "common/wpa_ctrl.h"
 #include "drivers/driver.h"
+#include "crypto/crypto.h"
 #include "crypto/aes.h"
 #include "crypto/aes_siv.h"
 #include "crypto/aes_wrap.h"
@@ -3294,6 +3295,12 @@ static int wpa_ft_set_key_mgmt(struct wpa_state_machine *sm,
 #endif /* CONFIG_SHA384 */
 	else if (key_mgmt & WPA_KEY_MGMT_FT_PSK)
 		sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_PSK;
+#ifdef CONFIG_SAE
+	else if (key_mgmt & WPA_KEY_MGMT_FT_SAE)
+		sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_SAE;
+	else if (key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY)
+		sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_SAE_EXT_KEY;
+#endif /* CONFIG_SAE */
 #ifdef CONFIG_FILS
 	else if (key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256)
 		sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256;
@@ -3388,6 +3395,124 @@ static int wpa_ft_local_derive_pmk_r1(struct wpa_authenticator *wpa_auth,
 }
 
 
+#ifdef CONFIG_ENC_ASSOC
+
+static bool wpa_ft_auth_req_enc_assoc(const struct wpa_auth_config *conf,
+				      const u8 *rsnxe, size_t rsnxe_len)
+{
+	return conf->assoc_frame_encryption &&
+		ieee802_11_rsnx_capab_len(
+			rsnxe, rsnxe_len,
+			WLAN_RSNX_CAPAB_ASSOC_FRAME_ENCRYPTION);
+}
+
+
+bool wpa_ft_auth_uses_enc_assoc(const struct wpa_authenticator *wpa_auth,
+				const u8 *ies, size_t ies_len)
+{
+	const u8 *rsnxe = get_ie(ies, ies_len, WLAN_EID_RSNX);
+
+	return rsnxe && wpa_ft_auth_req_enc_assoc(&wpa_auth->conf, rsnxe + 2,
+						  rsnxe[1]);
+}
+
+
+static u16 wpa_ft_process_dh(struct wpa_state_machine *sm,
+			     const u8 *ies, size_t ies_len, u16 *group,
+			     struct crypto_ecdh **ecdh, struct wpabuf **dhss)
+{
+	struct ieee802_11_elems elems;
+	const int *groups = sm->wpa_auth->conf.ft_dh_groups;
+	static const int default_groups[] = { 19, 0 };
+
+	if (!groups)
+		groups = default_groups;
+
+	if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == ParseFailed)
+		return WLAN_STATUS_UNSPECIFIED_FAILURE;
+
+	if (!elems.owe_dh) {
+		wpa_printf(MSG_DEBUG,
+			   "FT: No Diffie-Hellman Parameter element with encrypted reassociation");
+
+		return WLAN_STATUS_UNSPECIFIED_FAILURE;
+	}
+
+	*group = WPA_GET_LE16(elems.owe_dh);
+	if (!int_array_includes(groups, *group)) {
+		wpa_printf(MSG_DEBUG, "FT: Unsupported DH group=%u", *group);
+
+		return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
+	}
+
+	*ecdh = crypto_ecdh_init(*group);
+	if (!*ecdh)
+		return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
+
+	*dhss = crypto_ecdh_set_peerkey(*ecdh, 0, elems.owe_dh + 2,
+					elems.owe_dh_len - 2);
+	if (!*dhss) {
+		wpa_printf(MSG_DEBUG, "FT: Invalid DH public key");
+
+		return WLAN_STATUS_INVALID_PUBLIC_KEY;
+	}
+
+	wpa_hexdump_buf_key(MSG_DEBUG, "FT: DHss", *dhss);
+
+	return WLAN_STATUS_SUCCESS;
+}
+
+
+static int wpa_ft_add_dh_elems(struct wpa_state_machine *sm, u16 group,
+			       struct crypto_ecdh *ecdh,
+			       u8 **resp_ies, size_t *resp_ies_len)
+{
+	struct wpabuf *buf, *pub = NULL;
+	size_t len = *resp_ies_len + 3 + 2 * 32;
+
+	if (ecdh) {
+		pub = crypto_ecdh_get_pubkey(ecdh, 0);
+		if (!pub)
+			return -1;
+
+		len += 3 + 2 + wpabuf_len(pub);
+	}
+
+	buf = wpabuf_alloc(len);
+	if (!buf) {
+		wpabuf_free(pub);
+		return -1;
+	}
+
+	if (*resp_ies)
+		wpabuf_put_data(buf, *resp_ies, *resp_ies_len);
+
+	if (pub) {
+		wpabuf_put_u8(buf, WLAN_EID_EXTENSION);
+		wpabuf_put_u8(buf, 1 + 2 + wpabuf_len(pub));
+		wpabuf_put_u8(buf, WLAN_EID_EXT_OWE_DH_PARAM);
+		wpabuf_put_le16(buf, group);
+		wpabuf_put_buf(buf, pub);
+		wpabuf_free(pub);
+	}
+
+	wpa_add_supported_groups(buf, sm->wpa_auth->conf.ft_dh_groups);
+	os_free(*resp_ies);
+
+	*resp_ies_len = wpabuf_len(buf);
+	*resp_ies = os_memdup(wpabuf_head(buf), wpabuf_len(buf));
+	wpabuf_free(buf);
+
+	if (!*resp_ies) {
+		*resp_ies_len = 0;
+		return -1;
+	}
+
+	return 0;
+}
+
+#endif /* CONFIG_ENC_ASSOC */
+
 static int wpa_ft_process_auth_req(struct wpa_state_machine *sm,
 				   const u8 *ies, size_t ies_len,
 				   u8 **resp_ies, size_t *resp_ies_len)
@@ -3406,6 +3531,13 @@ static int wpa_ft_process_auth_req(struct wpa_state_machine *sm,
 	size_t identity_len = 0, radius_cui_len = 0;
 	size_t pmk_r1_len, kdk_len, len;
 	int retval = WLAN_STATUS_UNSPECIFIED_FAILURE;
+	const u8 *dhss = NULL;
+	size_t dhss_len = 0;
+#ifdef CONFIG_ENC_ASSOC
+	struct crypto_ecdh *ecdh = NULL;
+	struct wpabuf *dhss_buf = NULL;
+	u16 group = 0;
+#endif /* CONFIG_ENC_ASSOC */
 
 	*resp_ies = NULL;
 	*resp_ies_len = 0;
@@ -3457,6 +3589,32 @@ static int wpa_ft_process_auth_req(struct wpa_state_machine *sm,
 	if (wpa_ft_set_key_mgmt(sm, &parse) < 0)
 		goto out;
 
+#ifdef CONFIG_ENC_ASSOC
+	/* TODO: Support also with FT over the DS */
+	sm->ft_enc_assoc = sm->ft_over_air &&
+		wpa_ft_auth_req_enc_assoc(conf, parse.rsnxe, parse.rsnxe_len);
+
+	if (sm->ft_enc_assoc) {
+		u16 status;
+
+		status = wpa_ft_process_dh(sm, ies, ies_len, &group, &ecdh,
+					   &dhss_buf);
+		if (status != WLAN_STATUS_SUCCESS) {
+			retval = status;
+			if (status ==
+			    WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
+			    wpa_ft_add_dh_elems(sm, 0, NULL, resp_ies,
+						resp_ies_len) < 0)
+				retval = WLAN_STATUS_UNSPECIFIED_FAILURE;
+
+			goto out;
+		}
+
+		dhss = wpabuf_head(dhss_buf);
+		dhss_len = wpabuf_len(dhss_buf);
+	}
+#endif /* CONFIG_ENC_ASSOC */
+
 	wpa_hexdump(MSG_DEBUG, "FT: Requested PMKR0Name",
 		    parse.rsn_pmkid, WPA_PMK_NAME_LEN);
 
@@ -3613,8 +3771,8 @@ pmk_r1_derived:
 
 	if (wpa_pmk_r1_to_ptk(pmk_r1, pmk_r1_len, sm->SNonce, sm->ANonce,
 			      sm->addr, sm->wpa_auth->addr, pmk_r1_name,
-			      NULL, 0, &sm->PTK, ptk_name, parse.key_mgmt,
-			      pairwise, kdk_len) < 0)
+			      dhss, dhss_len, &sm->PTK, ptk_name,
+			      parse.key_mgmt, pairwise, kdk_len) < 0)
 		goto out;
 
 #ifdef CONFIG_PASN
@@ -3673,17 +3831,38 @@ pmk_r1_derived:
 
 	*resp_ies_len = pos - *resp_ies;
 
+#ifdef CONFIG_ENC_ASSOC
+	if (sm->ft_enc_assoc &&
+	    wpa_ft_add_dh_elems(sm, group, ecdh, resp_ies, resp_ies_len) < 0)
+		goto fail;
+#endif /* CONFIG_ENC_ASSOC */
+
 	retval = WLAN_STATUS_SUCCESS;
 	goto out;
 fail:
 	os_free(*resp_ies);
 	*resp_ies = NULL;
+	*resp_ies_len = 0;
 out:
+#ifdef CONFIG_ENC_ASSOC
+	crypto_ecdh_deinit(ecdh);
+	wpabuf_clear_free(dhss_buf);
+#endif /* CONFIG_ENC_ASSOC */
 	wpa_ft_parse_ies_free(&parse);
 	return retval;
 }
 
 
+bool wpa_auth_sta_ft_enc_assoc(struct wpa_state_machine *sm)
+{
+#ifdef CONFIG_ENC_ASSOC
+	return sm && sm->ft_enc_assoc;
+#else /* CONFIG_ENC_ASSOC */
+	return false;
+#endif /* CONFIG_ENC_ASSOC */
+}
+
+
 void wpa_ft_process_auth(struct wpa_state_machine *sm,
 			 u16 auth_transaction, const u8 *ies, size_t ies_len,
 			 void (*cb)(void *ctx, const u8 *dst,
@@ -3709,6 +3888,9 @@ void wpa_ft_process_auth(struct wpa_state_machine *sm,
 	sm->ft_pending_cb = cb;
 	sm->ft_pending_cb_ctx = ctx;
 	sm->ft_pending_auth_transaction = auth_transaction;
+#ifdef CONFIG_ENC_ASSOC
+	sm->ft_over_air = true;
+#endif /* CONFIG_ENC_ASSOC */
 	sm->ft_pending_pull_left_retries = sm->wpa_auth->conf.rkh_pull_retries;
 	res = wpa_ft_process_auth_req(sm, ies, ies_len, &resp_ies,
 				      &resp_ies_len);
@@ -4085,6 +4267,9 @@ static int wpa_ft_rrb_rx_request(struct wpa_authenticator *wpa_auth,
 
 	sm->ft_pending_cb = wpa_ft_rrb_rx_request_cb;
 	sm->ft_pending_cb_ctx = sm;
+#ifdef CONFIG_ENC_ASSOC
+	sm->ft_over_air = false;
+#endif /* CONFIG_ENC_ASSOC */
 	os_memcpy(sm->ft_pending_current_ap, current_ap, ETH_ALEN);
 	sm->ft_pending_pull_left_retries = sm->wpa_auth->conf.rkh_pull_retries;
 	res = wpa_ft_process_auth_req(sm, body, len, &resp_ies,
diff --git a/src/ap/wpa_auth_glue.c b/src/ap/wpa_auth_glue.c
index 9da2e6d2069a..603da9b1a8e5 100644
--- a/src/ap/wpa_auth_glue.c
+++ b/src/ap/wpa_auth_glue.c
@@ -128,6 +128,9 @@ static void hostapd_wpa_auth_conf(struct hostapd_iface *iface,
 	wconf->pmksa_caching_privacy = conf->pmksa_caching_privacy;
 	wconf->eap_using_authentication_frames =
 		conf->eap_using_authentication_frames;
+#ifdef CONFIG_IEEE8021X_AUTH
+	wconf->ft_dh_groups = conf->ieee8021x_auth_groups;
+#endif /* CONFIG_IEEE8021X_AUTH */
 #endif /* CONFIG_ENC_ASSOC */
 	wconf->extended_key_id = conf->extended_key_id;
 	wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
diff --git a/src/ap/wpa_auth_i.h b/src/ap/wpa_auth_i.h
index f21a9cd9d324..3f5c4538f2e6 100644
--- a/src/ap/wpa_auth_i.h
+++ b/src/ap/wpa_auth_i.h
@@ -143,6 +143,10 @@ struct wpa_state_machine {
 	u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
 	size_t r0kh_id_len;
 	u8 *assoc_resp_ftie;
+#ifdef CONFIG_ENC_ASSOC
+	bool ft_enc_assoc;
+	bool ft_over_air;
+#endif /* CONFIG_ENC_ASSOC */
 
 	void (*ft_pending_cb)(void *ctx, const u8 *dst,
 			      u16 auth_transaction, u16 status,
-- 
2.55.0




More information about the Hostap mailing list