[PATCH 08/55] AP: Derive the FT key hierarchy with IEEE 802.1X authentication

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


With IEEE 802.1X authentication in Authentication frames and
Association frame encryption, an FT AKM used the non-FT PTK
derivation, so no FT key hierarchy was created.

When the first Authentication frame has a valid MDE and an FT AKM,
take XXKey from the MSK, derive PMK-R0, PMK-R1 and the PTK with DHss,
and store the FT keys.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/ap/ieee802_11.c  | 69 ++++++++++++++++++++++++++++++++++++++++++--
 src/ap/sta_info.h    |  4 +++
 src/ap/wpa_auth.h    |  7 +++++
 src/ap/wpa_auth_ft.c | 67 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 145 insertions(+), 2 deletions(-)

diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index beff0d851ec7..e20a189ca95e 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -3483,6 +3483,31 @@ u16 wpa_auth_validate_802_1x_frame(struct hostapd_data *hapd,
 		return WLAN_STATUS_UNSPECIFIED_FAILURE;
 	}
 
+	sta->eap_auth_data.ft = false;
+
+#ifdef CONFIG_IEEE80211R_AP
+	if (enc_assoc && elems->mdie) {
+		if (!wpa_key_mgmt_ft(sta->eap_auth_data.akm)) {
+			wpa_printf(MSG_INFO, "MDE with a non-FT AKM 0x%x",
+				   sta->eap_auth_data.akm);
+			return WLAN_STATUS_INVALID_AKMP;
+		}
+
+		if (elems->mdie_len < sizeof(struct rsn_mdie) ||
+		    os_memcmp(elems->mdie, hapd->conf->mobility_domain,
+			      MOBILITY_DOMAIN_ID_LEN) != 0) {
+			wpa_printf(MSG_INFO, "Invalid MDE");
+			return WLAN_STATUS_INVALID_MDE;
+		}
+
+		sta->eap_auth_data.ft = true;
+	} else if (enc_assoc && wpa_key_mgmt_ft(sta->eap_auth_data.akm)) {
+		wpa_printf(MSG_INFO, "Missing MDE with an FT AKM 0x%x",
+			   sta->eap_auth_data.akm);
+		return WLAN_STATUS_INVALID_MDE;
+	}
+#endif /* CONFIG_IEEE80211R_AP */
+
 	if (elems->rsnxe) {
 		os_free(sta->eap_auth_data.rsnxe);
 		sta->eap_auth_data.rsnxe =
@@ -3631,6 +3656,30 @@ static int ieee80211_802_1x_derive_ptk(struct hostapd_data *hapd,
 	}
 #endif /* CONFIG_PQC */
 
+#ifdef CONFIG_IEEE80211R_AP
+	if (sta->eap_auth_data.ft) {
+		if (!sta->wpa_sm)
+			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
+							sta->addr, NULL);
+		if (!sta->wpa_sm ||
+		    wpa_auth_802_1x_ft_pmk_to_ptk(
+			    sta->wpa_sm, pmk, sta->eap_auth_data.pmk_len,
+			    sta->eap_auth_data.snonce,
+			    sta->eap_auth_data.anonce,
+			    sta->eap_auth_data.akm,
+			    sta->eap_auth_data.cipher,
+			    sta->eap_auth_data.rsnxe,
+			    sta->eap_auth_data.rsnxe_len,
+			    wpabuf_head_u8(sta->eap_auth_data.dhss),
+			    wpabuf_len(sta->eap_auth_data.dhss),
+			    &sta->eap_auth_data.ptk, kdk_len)) {
+			wpa_printf(MSG_INFO, "FT: Failed to derive the PTK");
+			return -1;
+		}
+		goto ptk_done;
+	}
+#endif /* CONFIG_IEEE80211R_AP */
+
 	if (wpa_auth_802_1x_pmk_to_ptk(
 		    pmk, sta->eap_auth_data.pmk_len,
 		    sta->addr, aa,
@@ -3644,9 +3693,9 @@ static int ieee80211_802_1x_derive_ptk(struct hostapd_data *hapd,
 		wpa_printf(MSG_INFO, "Failed to derive the PTK");
 		return -1;
 	}
-#ifdef CONFIG_PQC
+#if defined(CONFIG_PQC) || defined(CONFIG_IEEE80211R_AP)
 ptk_done:
-#endif /* CONFIG_PQC */
+#endif /* CONFIG_PQC || CONFIG_IEEE80211R_AP */
 
 	/* Delete DHss after successful PTK derivation */
 	wpabuf_clear_free(sta->eap_auth_data.dhss);
@@ -3770,6 +3819,22 @@ void ieee80211_send_eap_req(struct hostapd_data *hapd, struct sta_info *sta,
 			return;
 		}
 
+#ifdef CONFIG_IEEE80211R_AP
+		/* XXKey is the second 256 bits of the MSK for FT-EAP */
+		if (sta->eap_auth_data.ft &&
+		    !wpa_key_mgmt_sha384(sta->eap_auth_data.akm)) {
+			if (_len < 2 * PMK_LEN) {
+				wpa_printf(MSG_INFO,
+					   "FT: MSK too short (%zu) for XXKey",
+					   _len);
+				os_free(data);
+				return;
+			}
+
+			os_memmove(msk, msk + PMK_LEN, PMK_LEN);
+		}
+#endif /* CONFIG_IEEE80211R_AP */
+
 		sta->eap_auth_data.pmk_len = pmk_len;
 		os_memcpy(sta->eap_auth_data.pmk, msk, pmk_len);
 
diff --git a/src/ap/sta_info.h b/src/ap/sta_info.h
index 235f96b47cfd..c82c6bfc7a5e 100644
--- a/src/ap/sta_info.h
+++ b/src/ap/sta_info.h
@@ -87,6 +87,10 @@ struct eap_over_auth_data {
 	struct crypto_ecdh *ecdh;
 	struct wpabuf *dhss;
 	bool add_mic;
+
+	/* FT initial mobility domain association */
+	bool ft;
+
 	u8 epp_pmkid_cur[PMKID_LEN];
 	u8 epp_pmkid_next[PMKID_LEN];
 #ifdef CONFIG_PQC
diff --git a/src/ap/wpa_auth.h b/src/ap/wpa_auth.h
index 3434729d7dd2..aa0cd953029a 100644
--- a/src/ap/wpa_auth.h
+++ b/src/ap/wpa_auth.h
@@ -771,6 +771,13 @@ void wpa_auth_set_sae_pw_id(struct wpa_state_machine *sm,
 
 int wpa_auth_802_1x_get_msk(struct wpa_authenticator *wpa_auth,
 			     const u8 *addr, u8 *msk, size_t *len);
+int wpa_auth_802_1x_ft_pmk_to_ptk(struct wpa_state_machine *sm,
+				  const u8 *xxkey, size_t xxkey_len,
+				  const u8 *snonce, const u8 *anonce,
+				  int akmp, int cipher,
+				  const u8 *rsnxe, size_t rsnxe_len,
+				  const u8 *dhss, size_t dhss_len,
+				  struct wpa_ptk *ptk, size_t kdk_len);
 int wpa_auth_802_1x_set_key(struct wpa_authenticator *wpa_auth,
 			    enum wpa_alg alg, const u8 *addr,
 			    u8 *key, size_t key_len);
diff --git a/src/ap/wpa_auth_ft.c b/src/ap/wpa_auth_ft.c
index 794b5d8162e7..3b687ca69df4 100644
--- a/src/ap/wpa_auth_ft.c
+++ b/src/ap/wpa_auth_ft.c
@@ -2313,6 +2313,73 @@ void wpa_auth_ft_store_keys(struct wpa_state_machine *sm, const u8 *pmk_r0,
 }
 
 
+#ifdef CONFIG_IEEE8021X_AUTH
+
+int wpa_auth_802_1x_ft_pmk_to_ptk(struct wpa_state_machine *sm,
+				  const u8 *xxkey, size_t xxkey_len,
+				  const u8 *snonce, const u8 *anonce,
+				  int akmp, int cipher,
+				  const u8 *rsnxe, size_t rsnxe_len,
+				  const u8 *dhss, size_t dhss_len,
+				  struct wpa_ptk *ptk, size_t kdk_len)
+{
+	struct wpa_auth_config *conf = &sm->wpa_auth->conf;
+	u8 pmk_r0[PMK_LEN_MAX], pmk_r0_name[WPA_PMK_NAME_LEN];
+	u8 pmk_r1[PMK_LEN_MAX], ptk_name[WPA_PMK_NAME_LEN];
+	size_t key_len = wpa_key_mgmt_sha384(akmp) ? SHA384_MAC_LEN : PMK_LEN;
+	int ret = -1;
+
+	if (xxkey_len > sizeof(sm->xxkey))
+		return -1;
+
+	sm->wpa_key_mgmt = akmp;
+	sm->pairwise = cipher;
+
+	os_free(sm->rsnxe);
+	sm->rsnxe = NULL;
+	sm->rsnxe_len = 0;
+
+	if (rsnxe && rsnxe_len) {
+		sm->rsnxe = os_malloc(2 + rsnxe_len);
+		if (!sm->rsnxe)
+			return -1;
+
+		sm->rsnxe[0] = WLAN_EID_RSNX;
+		sm->rsnxe[1] = rsnxe_len;
+		os_memcpy(sm->rsnxe + 2, rsnxe, rsnxe_len);
+		sm->rsnxe_len = 2 + rsnxe_len;
+	}
+
+	os_memcpy(sm->xxkey, xxkey, xxkey_len);
+	sm->xxkey_len = xxkey_len;
+
+	if (wpa_derive_pmk_r0(xxkey, xxkey_len, conf->ssid, conf->ssid_len,
+			      conf->mobility_domain, conf->r0_key_holder,
+			      conf->r0_key_holder_len, sm->addr,
+			      pmk_r0, pmk_r0_name, akmp) < 0 ||
+	    wpa_derive_pmk_r1(pmk_r0, key_len, pmk_r0_name,
+			      conf->r1_key_holder, sm->addr,
+			      pmk_r1, sm->pmk_r1_name) < 0)
+		goto out;
+
+	sm->pmk_r1_name_valid = 1;
+
+	if (wpa_pmk_r1_to_ptk(pmk_r1, key_len, snonce, anonce, sm->addr,
+			      sm->wpa_auth->addr, sm->pmk_r1_name,
+			      dhss, dhss_len, ptk, ptk_name, akmp, cipher,
+			      kdk_len) < 0)
+		goto out;
+
+	wpa_auth_ft_store_keys(sm, pmk_r0, pmk_r1, pmk_r0_name, key_len);
+	ret = 0;
+out:
+	forced_memzero(pmk_r0, sizeof(pmk_r0));
+	forced_memzero(pmk_r1, sizeof(pmk_r1));
+	return ret;
+}
+
+#endif /* CONFIG_IEEE8021X_AUTH */
+
 static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
 				      const u8 *addr, int idx, u8 *seq)
 {
-- 
2.55.0




More information about the Hostap mailing list