[PATCH 21/55] wpa_supplicant: Support encrypted association with the FT protocol

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


Implement the FTO side of the encrypted association exchange. When
both the FTO and the FTR support association frame encryption:

- Include a Diffie-Hellman Parameter element in the first FT message
- Include DHss in the PTK derivation
- Indicate to the driver that the AP is an EPP peer so the following
  reassociation is encrypted.

Notes:

- Currently, group 19 is used.
- No support for FT over the DS.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/rsn_supp/wpa.c    |   3 +
 src/rsn_supp/wpa.h    |  11 +++
 src/rsn_supp/wpa_ft.c | 154 +++++++++++++++++++++++++++++++++++++++++-
 wpa_supplicant/sme.c  |   1 +
 4 files changed, 168 insertions(+), 1 deletion(-)

diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
index a380dfcae799..115cacb63170 100644
--- a/src/rsn_supp/wpa.c
+++ b/src/rsn_supp/wpa.c
@@ -4615,6 +4615,9 @@ void wpa_sm_deinit(struct wpa_sm *sm)
 #ifdef CONFIG_IEEE80211R
 	os_free(sm->assoc_resp_ies);
 	os_free(sm->ft_auth2_ies);
+#ifdef CONFIG_ENC_ASSOC
+	crypto_ecdh_deinit(sm->ft_ecdh);
+#endif /* CONFIG_ENC_ASSOC */
 #endif /* CONFIG_IEEE80211R */
 #ifdef CONFIG_TESTING_OPTIONS
 	wpabuf_free(sm->test_assoc_ie);
diff --git a/src/rsn_supp/wpa.h b/src/rsn_supp/wpa.h
index 3834bb10b7bb..3a2e12201549 100644
--- a/src/rsn_supp/wpa.h
+++ b/src/rsn_supp/wpa.h
@@ -606,6 +606,8 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
 			    int ft_action, const u8 *target_ap,
 			    const u8 *ric_ies, size_t ric_ies_len,
 			    const u8 *frame_body, size_t frame_body_len);
+void wpa_sm_set_ft_dh_group(struct wpa_sm *sm, u16 group);
+bool wpa_ft_uses_enc_assoc(struct wpa_sm *sm);
 int wpa_sm_802_1x_ft_pmk_to_ptk(struct wpa_sm *sm, const u8 *xxkey,
 				size_t xxkey_len, const u8 *snonce,
 				const u8 *anonce, const u8 *aa,
@@ -663,6 +665,15 @@ wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
 	return 0;
 }
 
+static inline void wpa_sm_set_ft_dh_group(struct wpa_sm *sm, u16 group)
+{
+}
+
+static inline bool wpa_ft_uses_enc_assoc(struct wpa_sm *sm)
+{
+	return false;
+}
+
 static inline int wpa_ft_is_completed(struct wpa_sm *sm)
 {
 	return 0;
diff --git a/src/rsn_supp/wpa_ft.c b/src/rsn_supp/wpa_ft.c
index 96cbf2a81aa6..ed49516bcfc7 100644
--- a/src/rsn_supp/wpa_ft.c
+++ b/src/rsn_supp/wpa_ft.c
@@ -9,6 +9,7 @@
 #include "includes.h"
 
 #include "common.h"
+#include "crypto/crypto.h"
 #include "crypto/aes_wrap.h"
 #include "crypto/sha384.h"
 #include "crypto/sha512.h"
@@ -608,6 +609,86 @@ static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
 }
 
 
+void wpa_sm_set_ft_dh_group(struct wpa_sm *sm, u16 group)
+{
+#ifdef CONFIG_ENC_ASSOC
+	if (sm)
+		sm->ft_dh_group = group;
+#endif /* CONFIG_ENC_ASSOC */
+}
+
+
+bool wpa_ft_uses_enc_assoc(struct wpa_sm *sm)
+{
+#ifdef CONFIG_ENC_ASSOC
+	return sm && sm->ft_enc_assoc;
+#endif /* CONFIG_ENC_ASSOC */
+	return false;
+}
+
+#ifdef CONFIG_ENC_ASSOC
+
+static u8 * wpa_ft_add_dh_param(struct wpa_sm *sm, u8 *ft_ies,
+				size_t *ft_ies_len)
+{
+	struct wpabuf *pub;
+	u8 *buf, *pos;
+
+	sm->ft_enc_assoc = false;
+	crypto_ecdh_deinit(sm->ft_ecdh);
+	sm->ft_ecdh = NULL;
+
+	if (!sm->assoc_encryption ||
+	    !ieee802_11_rsnx_capab(sm->ap_rsnxe,
+				   WLAN_RSNX_CAPAB_ASSOC_FRAME_ENCRYPTION))
+		return ft_ies;
+
+	/* TODO: support other groups */
+	if (!sm->ft_dh_group)
+		sm->ft_dh_group = 19;
+
+	sm->ft_ecdh = crypto_ecdh_init(sm->ft_dh_group);
+	if (!sm->ft_ecdh)
+		goto fail;
+
+	pub = crypto_ecdh_get_pubkey(sm->ft_ecdh, 0);
+	if (!pub)
+		goto fail;
+
+	buf = os_realloc(ft_ies, *ft_ies_len + 3 + 2 + wpabuf_len(pub));
+	if (!buf) {
+		wpabuf_free(pub);
+		goto fail;
+	}
+
+	pos = buf + *ft_ies_len;
+	*pos++ = WLAN_EID_EXTENSION;
+	*pos++ = 1 + 2 + wpabuf_len(pub);
+	*pos++ = WLAN_EID_EXT_OWE_DH_PARAM;
+
+	WPA_PUT_LE16(pos, sm->ft_dh_group);
+	pos += 2;
+
+	os_memcpy(pos, wpabuf_head(pub), wpabuf_len(pub));
+	*ft_ies_len += 3 + 2 + wpabuf_len(pub);
+	wpabuf_free(pub);
+
+	sm->ft_enc_assoc = true;
+
+	wpa_printf(MSG_DEBUG, "FT: Use Diffie-Hellman group %u",
+		   sm->ft_dh_group);
+
+	return buf;
+
+fail:
+	crypto_ecdh_deinit(sm->ft_ecdh);
+	sm->ft_ecdh = NULL;
+	os_free(ft_ies);
+	return NULL;
+}
+
+#endif /* CONFIG_ENC_ASSOC */
+
 /**
  * wpa_ft_prepare_auth_request - Generate over-the-air auth request
  * @sm: Pointer to WPA state machine data from wpa_sm_init()
@@ -627,6 +708,10 @@ int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie)
 
 	ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
 				    NULL, 0, sm->bssid, NULL, 0, mdie, 0);
+#ifdef CONFIG_ENC_ASSOC
+	if (ft_ies)
+		ft_ies = wpa_ft_add_dh_param(sm, ft_ies, &ft_ies_len);
+#endif /* CONFIG_ENC_ASSOC */
 	if (ft_ies) {
 		wpa_sm_update_ft_ies(sm, sm->mobility_domain,
 				     ft_ies, ft_ies_len);
@@ -670,6 +755,50 @@ const u8 * wpa_sm_get_ft_md(struct wpa_sm *sm)
 
 #ifdef CONFIG_ENC_ASSOC
 
+static int wpa_ft_process_dh(struct wpa_sm *sm, const u8 *ies,
+			     size_t ies_len, struct wpabuf **dhss)
+{
+	struct ieee802_11_elems elems;
+
+	*dhss = NULL;
+
+	if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == ParseFailed)
+		return -1;
+
+	if (!sm->ft_enc_assoc) {
+		if (elems.owe_dh) {
+			wpa_printf(MSG_DEBUG,
+				   "FT: Unexpected Diffie-Hellman Parameter element");
+			return -1;
+		}
+
+		return 0;
+	}
+
+	if (!elems.owe_dh) {
+		wpa_printf(MSG_DEBUG,
+			   "FT: Missing Diffie-Hellman Parameter element");
+		return -1;
+	}
+
+	if (WPA_GET_LE16(elems.owe_dh) != sm->ft_dh_group) {
+		wpa_printf(MSG_DEBUG, "FT: DH group mismatch (%u != %u)",
+			   WPA_GET_LE16(elems.owe_dh), sm->ft_dh_group);
+		return -1;
+	}
+
+	*dhss = crypto_ecdh_set_peerkey(sm->ft_ecdh, 0, elems.owe_dh + 2,
+					elems.owe_dh_len - 2);
+	if (!*dhss) {
+		wpa_printf(MSG_DEBUG, "FT: Invalid DH public key");
+		return -1;
+	}
+
+	wpa_hexdump_buf_key(MSG_DEBUG, "FT: DHss", *dhss);
+	return 0;
+}
+
+
 static int wpa_ft_check_msg2_mic(struct wpa_sm *sm, const u8 *bssid,
 				 const u8 *frame_body, size_t body_len,
 				 const struct wpa_ft_ies *parse)
@@ -725,6 +854,7 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
 	const u8 *bssid;
 	const u8 *kck;
 	size_t kck_len, kdk_len;
+	struct wpabuf *dhss = NULL;
 
 	os_memset(&parse, 0, sizeof(parse));
 
@@ -816,6 +946,15 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
 		goto fail;
 	}
 
+#ifdef CONFIG_ENC_ASSOC
+	/* Note: FT over the DS flow is not supported*/
+	if (ft_action)
+		sm->ft_enc_assoc = false;
+
+	if (wpa_ft_process_dh(sm, ies, ies_len, &dhss) < 0)
+		goto fail;
+#endif /* CONFIG_ENC_ASSOC */
+
 	os_memcpy(sm->r1kh_id, parse.r1kh_id, FT_R1KH_ID_LEN);
 	wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", sm->r1kh_id, FT_R1KH_ID_LEN);
 	wpa_hexdump(MSG_DEBUG, "FT: SNonce", sm->snonce, WPA_NONCE_LEN);
@@ -847,7 +986,10 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
 	/* TODO: AP MLD address for MLO */
 	if (wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->pmk_r1_len, sm->snonce,
 			      parse.fte_anonce, sm->own_addr, bssid,
-			      sm->pmk_r1_name, NULL, 0, &sm->ptk, ptk_name,
+			      sm->pmk_r1_name,
+			      dhss ? wpabuf_head(dhss) : NULL,
+			      dhss ? wpabuf_len(dhss) : 0,
+			      &sm->ptk, ptk_name,
 			      sm->key_mgmt, sm->pairwise_cipher,
 			      kdk_len) < 0)
 		goto fail;
@@ -916,6 +1058,13 @@ int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
 
 	ret = 0;
 fail:
+	wpabuf_clear_free(dhss);
+#ifdef CONFIG_ENC_ASSOC
+	crypto_ecdh_deinit(sm->ft_ecdh);
+	sm->ft_ecdh = NULL;
+	if (ret)
+		sm->ft_enc_assoc = false;
+#endif /* CONFIG_ENC_ASSOC */
 	wpa_ft_parse_ies_free(&parse);
 	return ret;
 }
@@ -1453,6 +1602,9 @@ int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
 		return -1;
 	}
 
+#ifdef CONFIG_ENC_ASSOC
+	sm->ft_enc_assoc = false;
+#endif /* CONFIG_ENC_ASSOC */
 	ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
 				    NULL, 0, target_ap, NULL, 0, mdie, 0);
 	if (ft_ies) {
diff --git a/wpa_supplicant/sme.c b/wpa_supplicant/sme.c
index 591b2995e807..410025944d08 100644
--- a/wpa_supplicant/sme.c
+++ b/wpa_supplicant/sme.c
@@ -2416,6 +2416,7 @@ static void sme_send_authentication(struct wpa_supplicant *wpa_s,
 			params.auth_alg = WPA_AUTH_ALG_FT;
 			params.ie = wpa_s->sme.ft_ies;
 			params.ie_len = wpa_s->sme.ft_ies_len;
+			params.epp_peer = wpa_ft_uses_enc_assoc(wpa_s->wpa);
 		}
 	}
 #endif /* CONFIG_IEEE80211R */
-- 
2.55.0




More information about the Hostap mailing list