Skip to contentSkip to conversation

wiphy: change wiphy_control_port_capable -> enabled

PATCH Applied James Prestwood 2 participants 22 messages Oct 7, 2021 – Oct 8, 2021

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH v3 1/13 wiphy: change wiphy_control_port_capable -> enabled

Move the reading of ControlPortOverNL80211 into wiphy itself and renamed wiphy_control_port_capable to wiphy_control_port_enabled. This makes things easier for any modules interested in control port support since they will only have to check this one API rather than read the settings and check capability.

---
 src/netdev.c |  7 +------
 src/wiphy.c  | 16 +++++++++++++---
 src/wiphy.h  |  2 +-
 3 files changed, 15 insertions(+), 10 deletions(-)
src/netdev.c +1 -6
index fbf3b067..de155da1 100644
@@ -203,7 +203,6 @@ static struct l_netlink *rtnl = NULL;
 static struct l_genl_family *nl80211;
 static struct l_queue *netdev_list;
 static struct watchlist netdev_watches;
-static bool pae_over_nl80211;
 static bool mac_per_ssid;
 
 static unsigned int iov_ie_append(struct iovec *iov,
@@ -6096,7 +6095,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
 		return NULL;
 	}
 
-	if (!pae_over_nl80211 || !wiphy_control_port_capable(wiphy)) {
+	if (!wiphy_control_port_enabled(wiphy)) {
 		pae_io = pae_open(ifindex);
 		if (!pae_io) {
 			l_error("Unable to open PAE interface");
@@ -6233,10 +6232,6 @@ static int netdev_init(void)
 					&LOW_SIGNAL_THRESHOLD_5GHZ))
 		LOW_SIGNAL_THRESHOLD_5GHZ = -76;
 
-	if (!l_settings_get_bool(settings, "General", "ControlPortOverNL80211",
-					&pae_over_nl80211))
-		pae_over_nl80211 = true;
-
 	rand_addr_str = l_settings_get_value(settings, "General",
 						"AddressRandomization");
 	if (rand_addr_str && !strcmp(rand_addr_str, "network"))
src/wiphy.c +13 -3
index 84d2a152..1a333aad 100644
@@ -555,8 +555,11 @@ bool wiphy_uses_default_if(struct wiphy *wiphy)
 	return false;
 }
 
-bool wiphy_control_port_capable(struct wiphy *wiphy)
+bool wiphy_control_port_enabled(struct wiphy *wiphy)
 {
+	const struct l_settings *settings = iwd_get_config();
+	bool enabled;
+
 	if (wiphy->driver_info &&
 			wiphy->driver_info->flags & FORCE_PAE) {
 		l_info("Not using Control Port due to driver quirks: %s",
@@ -564,8 +567,15 @@ bool wiphy_control_port_capable(struct wiphy *wiphy)
 		return false;
 	}
 
-	return wiphy_has_ext_feature(wiphy,
-			NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211);
+	if (!wiphy_has_ext_feature(wiphy,
+			NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
+		return false;
+
+	if (!l_settings_get_bool(settings, "General",
+					"ControlPortOverNL80211", &enabled))
+		enabled = true;
+
+	return enabled;
 }
 
 const uint8_t *wiphy_get_permanent_address(struct wiphy *wiphy)
src/wiphy.h +1 -1
index d6487074..f7b6e1c4 100644
@@ -102,7 +102,7 @@ bool wiphy_supports_firmware_roam(struct wiphy *wiphy);
 const char *wiphy_get_driver(struct wiphy *wiphy);
 const char *wiphy_get_name(struct wiphy *wiphy);
 bool wiphy_uses_default_if(struct wiphy *wiphy);
-bool wiphy_control_port_capable(struct wiphy *wiphy);
+bool wiphy_control_port_enabled(struct wiphy *wiphy);
 const uint8_t *wiphy_get_permanent_address(struct wiphy *wiphy);
 const uint8_t *wiphy_get_extended_capabilities(struct wiphy *wiphy,
 							uint32_t iftype);
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH v3 2/13 handshake: add flags/key index for extended key IDs

ext_key_id_capable indicates the handshake has set the capability bit in the RSN info. This will only be set if the AP also has the capability set.

active_tk_index is the key index the AP chose in message 3. This is now used for both legacy (always zero) and extended key IDs.

---
 src/handshake.h | 2 ++
 1 file changed, 2 insertions(+)
src/handshake.h +2 -0
index 36ccc3a2..d57a3794 100644
@@ -128,6 +128,7 @@ struct handshake_state {
 	bool support_fils : 1;
 	bool authenticator_ocvc : 1;
 	bool supplicant_ocvc : 1;
+	bool ext_key_id_capable : 1;
 	uint8_t ssid[32];
 	size_t ssid_len;
 	char *passphrase;
@@ -138,6 +139,7 @@ struct handshake_state {
 	uint8_t gtk_rsc[6];
 	uint8_t proto_version : 2;
 	unsigned int gtk_index;
+	uint8_t active_tk_index;
 	struct erp_cache_entry *erp_cache;
 	bool support_ip_allocation : 1;
 	uint32_t client_ip_addr;
Signature · 1 line
2.31.1
Applied
#2 lore raw

Re: [PATCH v3 02/13] handshake: add flags/key index for extended key IDs

Hi James,

Quoted 10 lines · James Prestwood

ext_key_id_capable indicates the handshake has set the capability bit in the RSN info. This will only be set if the AP also has the capability set.

active_tk_index is the key index the AP chose in message 3. This is now used for both legacy (always zero) and extended key IDs.

---
  src/handshake.h | 2 ++
  1 file changed, 2 insertions(+)

I merged this patch with patch 8 since they seem to go logically together. Applied, thanks.

Regards,
-Denis

author
#3 lore raw

PATCH v3 3/13 handshake: add callback for extended key IDs

In reply to James Prestwood

The procedure for setting extended key IDs is different from the single PTK key. The key ID is toggled between 0 and 1 and the new key is set as RX only, then set to RX/TX after message 4/4 goes out.

Since netdev needs to set this new key before sending message 4, eapol can include a built message which netdev will store if required (i.e. using PAE).

---
 src/handshake.c | 23 +++++++++++++++++++++++
 src/handshake.h | 12 ++++++++++++
 2 files changed, 35 insertions(+)
src/handshake.c +23 -0
index 642a25a7..58326dcd 100644
@@ -76,6 +76,7 @@ static handshake_get_nonce_func_t get_nonce = handshake_get_nonce;
 static handshake_install_tk_func_t install_tk = NULL;
 static handshake_install_gtk_func_t install_gtk = NULL;
 static handshake_install_igtk_func_t install_igtk = NULL;
+static handshake_install_ext_tk_func_t install_ext_tk = NULL;
 
 void __handshake_set_get_nonce_func(handshake_get_nonce_func_t func)
 {
@@ -97,6 +98,11 @@ void __handshake_set_install_igtk_func(handshake_install_igtk_func_t func)
 	install_igtk = func;
 }
 
+void __handshake_set_install_ext_tk_func(handshake_install_ext_tk_func_t func)
+{
+	install_ext_tk = func;
+}
+
 void handshake_state_free(struct handshake_state *s)
 {
 	__typeof__(s->free) destroy = s->free;
@@ -663,6 +669,23 @@ void handshake_state_install_ptk(struct handshake_state *s)
 	}
 }
 
+void handshake_state_install_ext_ptk(struct handshake_state *s,
+				uint8_t key_idx,
+				struct eapol_frame *ek, uint16_t proto,
+				bool noencrypt)
+{
+	s->ptk_complete = true;
+
+	if (install_ext_tk) {
+		uint32_t cipher =
+			ie_rsn_cipher_suite_to_cipher(s->pairwise_cipher);
+
+		install_ext_tk(s, key_idx, handshake_get_tk(s), cipher, ek,
+				proto, noencrypt);
+	}
+}
+
+
 void handshake_state_install_gtk(struct handshake_state *s,
 					uint16_t gtk_key_index,
 					const uint8_t *gtk, size_t gtk_len,
src/handshake.h +12 -0
index d57a3794..4cf2ec63 100644
@@ -27,6 +27,7 @@
 
 struct handshake_state;
 enum crypto_cipher;
+struct eapol_frame;
 
 enum handshake_kde {
 	/* 802.11-2020 Table 12-9 in section 12.7.2 */
@@ -78,11 +79,17 @@ typedef void (*handshake_install_igtk_func_t)(struct handshake_state *hs,
 					const uint8_t *igtk, uint8_t igtk_len,
 					const uint8_t *ipn, uint8_t ipn_len,
 					uint32_t cipher);
+typedef void (*handshake_install_ext_tk_func_t)(struct handshake_state *hs,
+					uint8_t key_idx, const uint8_t *tk,
+					uint32_t cipher,
+					const struct eapol_frame *step4,
+					uint16_t proto, bool noencrypt);
 
 void __handshake_set_get_nonce_func(handshake_get_nonce_func_t func);
 void __handshake_set_install_tk_func(handshake_install_tk_func_t func);
 void __handshake_set_install_gtk_func(handshake_install_gtk_func_t func);
 void __handshake_set_install_igtk_func(handshake_install_igtk_func_t func);
+void __handshake_set_install_ext_tk_func(handshake_install_ext_tk_func_t func);
 
 struct handshake_state {
 	uint32_t ifindex;
@@ -226,6 +233,11 @@ size_t handshake_state_get_kek_len(struct handshake_state *s);
 const uint8_t *handshake_state_get_kek(struct handshake_state *s);
 void handshake_state_install_ptk(struct handshake_state *s);
 
+void handshake_state_install_ext_ptk(struct handshake_state *s,
+				uint8_t key_idx,
+				struct eapol_frame *ek, uint16_t proto,
+				bool noencrypt);
+
 void handshake_state_install_gtk(struct handshake_state *s,
 					uint16_t gtk_key_index,
 					const uint8_t *gtk, size_t gtk_len,
Signature · 1 line
2.31.1
Applied
#4 lore raw

Re: [PATCH v3 03/13] handshake: add callback for extended key IDs

Hi James,

Quoted 5 lines · James Prestwood

The procedure for setting extended key IDs is different from the single PTK key. The key ID is toggled between 0 and 1 and the new key is set as RX only, then set to RX/TX after message 4/4 goes out.

Quoted 8 lines

Since netdev needs to set this new key before sending message 4, eapol can include a built message which netdev will store if required (i.e. using PAE).

---
  src/handshake.c | 23 +++++++++++++++++++++++
  src/handshake.h | 12 ++++++++++++
  2 files changed, 35 insertions(+)

Applied, thanks.

Regards,
-Denis

author
#5 lore raw

PATCH v3 4/13 eapol: support extended key IDs

In reply to James Prestwood

802.11 added Extended Key IDs which aim to solve the issue of PTK key replacement during rekeys. Since swapping out the existing PTK may result in data loss because there may be in flight packets still using the old PTK.

Extended Key IDs use two key IDs for the PTK, which toggle between 0 and 1. During a rekey a new PTK is derived which uses the key ID not already taken by the existing PTK. This new PTK is added as RX only, then message 4/4 is sent. This ensure message 4 is encrypted using the previous PTK. Once sent, the new PTK can be modified to both RX and TX and the rekey is complete.

To handle this in eapol the extended key ID KDE is parsed which gives us the new PTK key index. Using the new handshake callback (handshake_state_set_ext_tk) the new TK is installed. The 4th message is also included as an argument which is taken care of by netdev (in case waiting for NEW_KEY is required due to PAE socekts).

---
 src/eapol.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 63 insertions(+), 9 deletions(-)
src/eapol.c +63 -9
index 07120fdb..cd481317 100644
@@ -860,6 +860,7 @@ struct eapol_sm {
 	uint8_t installed_igtk_len;
 	uint8_t installed_igtk[CRYPTO_MAX_IGTK_LEN];
 	unsigned int mic_len;
+	bool rekey : 1;
 };
 
 static void eapol_sm_destroy(void *value)
@@ -1223,6 +1224,9 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
 			return;
 		}
 
+		if (sm->handshake->ptk_complete)
+			sm->rekey = true;
+
 		handshake_state_new_snonce(sm->handshake);
 		handshake_state_set_anonce(sm->handshake, ek->key_nonce);
 
@@ -1643,12 +1647,14 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
 	struct handshake_state *hs = sm->handshake;
 	const uint8_t *kck;
 	const uint8_t *kek;
-	struct eapol_key *step4;
+	_auto_(l_free) struct eapol_key *step4 = NULL;
 	uint8_t mic[MIC_MAXLEN];
 	const uint8_t *gtk = NULL;
 	size_t gtk_len;
 	const uint8_t *igtk = NULL;
 	size_t igtk_len;
+	const uint8_t *key_id = NULL;
+	size_t key_id_len;
 	const uint8_t *rsne;
 	struct ie_rsn_info rsn_info;
 	const uint8_t *optional_rsne = NULL;
@@ -1856,6 +1862,44 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
 	} else
 		igtk = NULL;
 
+	key_id = handshake_util_find_kde(HANDSHAKE_KDE_KEY_ID,
+					decrypted_key_data,
+					decrypted_key_data_size, &key_id_len);
+	if (hs->ext_key_id_capable) {
+		uint8_t idx;
+
+		if (!key_id) {
+			l_debug("No extended key KDE in frame 3/4");
+			handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+			return;
+		}
+
+		if (key_id_len != 2) {
+			l_error("invalid Key ID KDE format");
+			handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+			return;
+		}
+
+		idx = bit_field(key_id[0], 0, 2);
+
+		/*
+		 * IEEE 802.11-2020 - 12.7.6.4 4-way handshake message 3
+		 * "... the Authenticator assigns a new Key ID for the PTKSA in
+		 * the range of 0 to 1 that is different from the Key ID
+		 * assigned in the previous handshake"
+		 */
+		if ((idx != 0 && idx != 1) || (sm->rekey &&
+						idx == hs->active_tk_index)) {
+			l_error("invalid Key ID KDE value (%u)", idx);
+			handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+			return;
+		}
+
+		hs->active_tk_index = idx;
+
+		l_debug("using Extended key ID %u", hs->active_tk_index);
+	}
+
 	if (hs->support_ip_allocation) {
 		size_t len;
 		const uint8_t *ip_alloc_kde =
@@ -1917,7 +1961,6 @@ retransmit:
 		if (!eapol_calculate_mic(hs->akm_suite, kck,
 						step4, mic, sm->mic_len)) {
 			l_debug("MIC Calculation failed");
-			l_free(step4);
 			handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);
 			return;
 		}
@@ -1928,18 +1971,11 @@ retransmit:
 						handshake_state_get_kek_len(hs),
 						step4, NULL, 0)) {
 			l_debug("AES-SIV encryption failed");
-			l_free(step4);
 			handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);
 			return;
 		}
 	}
 
-	eapol_sm_write(sm, (struct eapol_frame *) step4, unencrypted);
-	l_free(step4);
-
-	if (hs->ptk_complete)
-		return;
-
 	/*
 	 * For WPA1 the group handshake should be happening after we set the
 	 * ptk, this flag tells netdev to wait for the gtk/igtk before
@@ -1954,6 +1990,24 @@ retransmit:
 	if (igtk)
 		eapol_install_igtk(sm, igtk_key_index, igtk, igtk_len);
 
+	/*
+	 * Only install if this is the first 3/4 message (not retransmitting)
+	 * and a rekey. Initial associations don't need the special RX -> TX
+	 * procedure and can install the TK normally
+	 */
+	if (key_id && hs->ext_key_id_capable && sm->rekey) {
+		handshake_state_install_ext_ptk(hs, hs->active_tk_index,
+						(struct eapol_frame *) step4,
+						ETH_P_PAE, unencrypted);
+
+		return;
+	}
+
+	eapol_sm_write(sm, (struct eapol_frame *) step4, unencrypted);
+
+	if (hs->ptk_complete)
+		return;
+
 	handshake_state_install_ptk(hs);
 
 	if (rekey_offload)
Signature · 1 line
2.31.1
#6 lore raw

Re: [PATCH v3 04/13] eapol: support extended key IDs

Hi James,

<snip>

Quoted 22 lines
src/eapol.c +18 -0
@@ -1856,6 +1862,44 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
  	} else
  		igtk = NULL;
 
+	key_id = handshake_util_find_kde(HANDSHAKE_KDE_KEY_ID,
+					decrypted_key_data,
+					decrypted_key_data_size, &key_id_len);
+	if (hs->ext_key_id_capable) {
+		uint8_t idx;
+
+		if (!key_id) {
+			l_debug("No extended key KDE in frame 3/4");
+			handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+			return;
+		}
+
+		if (key_id_len != 2) {
+			l_error("invalid Key ID KDE format");
+			handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+			return;
+		}
+

src/eapol.c static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, · line 1892

Quoted 10 lines
src/eapol.c +10 -0
+		idx = bit_field(key_id[0], 0, 2);
+
+		/*
+		 * IEEE 802.11-2020 - 12.7.6.4 4-way handshake message 3
+		 * "... the Authenticator assigns a new Key ID for the PTKSA in
+		 * the range of 0 to 1 that is different from the Key ID
+		 * assigned in the previous handshake"
+		 */
+		if ((idx != 0 && idx != 1) || (sm->rekey &&
+						idx == hs->active_tk_index)) {

I still don't see how this can work for retransmits? Consider the following sequence of events and correct me if I'm wrong:

Initial connection:
PTK 1/4
PTK 3/4 -> AP sends Extended Key Index 0
Retransmit of PTK 3/4 -> This condition is never entered because rekey is set to false.
... Rekey:
PTK 1/4
PTK 3/4 -> AP Sends Extended Key Index 1
Retransmit of PTK 3/4 -> We fail ?

Quoted 13 lines
src/eapol.c +10 -0
+			l_error("invalid Key ID KDE value (%u)", idx);
+			handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+			return;
+		}
+
+		hs->active_tk_index = idx;
+
+		l_debug("using Extended key ID %u", hs->active_tk_index);
+	}
+
  	if (hs->support_ip_allocation) {
  		size_t len;
  		const uint8_t *ip_alloc_kde =

<snip>

Quoted 6 lines
src/eapol.c +0 -1
@@ -1928,18 +1971,11 @@ retransmit:
  						handshake_state_get_kek_len(hs),
  						step4, NULL, 0)) {
  			l_debug("AES-SIV encryption failed");
-			l_free(step4);
  			handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);

src/eapol.c retransmit: · line 1942

Quoted 10 lines
src/eapol.c +0 -6
  			return;
  		}
  	}
 
-	eapol_sm_write(sm, (struct eapol_frame *) step4, unencrypted);
-	l_free(step4);
-
-	if (hs->ptk_complete)
-		return;
-

So we shouldn't set any keys, including gtk or igtk, on a retransmitted frame 3/4.

Quoted 19 lines
src/eapol.c +11 -0
  	/*
  	 * For WPA1 the group handshake should be happening after we set the
  	 * ptk, this flag tells netdev to wait for the gtk/igtk before
@@ -1954,6 +1990,24 @@ retransmit:
  	if (igtk)
  		eapol_install_igtk(sm, igtk_key_index, igtk, igtk_len);
 
+	/*
+	 * Only install if this is the first 3/4 message (not retransmitting)
+	 * and a rekey. Initial associations don't need the special RX -> TX
+	 * procedure and can install the TK normally
+	 */
+	if (key_id && hs->ext_key_id_capable && sm->rekey) {
+		handshake_state_install_ext_ptk(hs, hs->active_tk_index,
+						(struct eapol_frame *) step4,
+						ETH_P_PAE, unencrypted);
+
+		return;

src/eapol.c retransmit: · line 2013

Quoted 10 lines
src/eapol.c +7 -0
+	}
+
+	eapol_sm_write(sm, (struct eapol_frame *) step4, unencrypted);
+
+	if (hs->ptk_complete)
+		return;
+
  	handshake_state_install_ptk(hs);
 
  	if (rekey_offload)

Regards,
-Denis

author
#7 lore raw

Re: [PATCH v3 04/13] eapol: support extended key IDs

Hi Denis,

Quoted 50 lines · Denis Kenzior

Hi James,

<snip>

Quoted 32 lines
src/eapol.c +0 -0
@@ -1856,6 +1862,44 @@ static void eapol_handle_ptk_3_of_4(struct
 eapol_sm *sm,
         } else
                 igtk = NULL;


+       key_id = handshake_util_find_kde(HANDSHAKE_KDE_KEY_ID, +                                       decrypted_key_data, +                                       decrypted_key_data_size, &key_id_len);
+       if (hs->ext_key_id_capable) {
+               uint8_t idx;
+
+               if (!key_id) {
+                       l_debug("No extended key KDE in frame 3/4");
+                       handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+                       return;
+               }
+
+               if (key_id_len != 2) {
+                       l_error("invalid Key ID KDE format"); +                       handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+                       return;
+               }

src/eapol.c +5 -0
+
+               idx = bit_field(key_id[0], 0, 2);
+
+               /*
+                * IEEE 802.11-2020 - 12.7.6.4 4-way handshake

message 3

Quoted 9 lines

+                * "... the Authenticator assigns a new Key ID for the PTKSA in
+                * the range of 0 to 1 that is different from the Key ID
+                * assigned in the previous handshake" +                */
+               if ((idx != 0 && idx != 1) || (sm->rekey && +                                               idx == hs-

Quoted 1 line

active_tk_index)) {

I still don't see how this can work for retransmits?  Consider the following
sequence of events and correct me if I'm wrong:

Quoted 10 lines

Initial connection:
PTK 1/4
PTK 3/4 -> AP sends Extended Key Index 0
Retransmit of PTK 3/4 -> This condition is never entered because rekey is set to
false.
... Rekey:
PTK 1/4
PTK 3/4 -> AP Sends Extended Key Index 1
Retransmit of PTK 3/4 -> We fail ?

So all the KDE parsing is completely skipped on retransmissions. So we never even get to this if block at all. And same with below...

Quoted 34 lines
Quoted 17 lines

+                       l_error("invalid Key ID KDE value (%u)", idx);
+                       handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
+                       return;
+               }

src/eapol.c +4 -0
+
+               hs->active_tk_index = idx;
+
+               l_debug("using Extended key ID %u", hs-
Quoted 1 line

active_tk_index);

+       }
+
        if (hs->support_ip_allocation) {
                size_t len;
                const uint8_t *ip_alloc_kde =

<snip>

Quoted 14 lines
(quoted diff) +0 -0
@@ -1928,18 +1971,11 @@ retransmit:

                                                handshake_state_get _kek_len(hs),
                                                step4, NULL, 0)) { l_debug("AES-SIV encryption failed"); -                       l_free(step4); handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);
                        return;
                }
        }

-       eapol_sm_write(sm, (struct eapol_frame *) step4, unencrypted);

Quoted 8 lines

src/eapol.c retransmit: · line 1942

Quoted 5 lines

-       l_free(step4);

src/eapol.c +0 -4
-
-       if (hs->ptk_complete)
-               return;
-

So we shouldn't set any keys, including gtk or igtk, on a retransmitted frame 3/4.

gtk/igtk/key_id pointers wont be set on a retransmission so I think this is safe right?

Quoted 42 lines
Quoted 35 lines

        /*
         * For WPA1 the group handshake should be happening after we set the
         * ptk, this flag tells netdev to wait for the gtk/igtk before

(quoted diff) +0 -0
@@ -1954,6 +1990,24 @@ retransmit:
         if (igtk)
                 eapol_install_igtk(sm, igtk_key_index, igtk,
 igtk_len);


+       /*
+        * Only install if this is the first 3/4 message (not retransmitting)
+        * and a rekey. Initial associations don't need the special RX -> TX
+        * procedure and can install the TK normally
+        */
+       if (key_id && hs->ext_key_id_capable && sm->rekey) { +               handshake_state_install_ext_ptk(hs, hs-

Quoted 1 line

active_tk_index,

+                                               (struct eapol_frame *) step4,
+                                               ETH_P_PAE, unencrypted);

src/eapol.c +5 -0
+
+               return;
+       }
+
+       eapol_sm_write(sm, (struct eapol_frame *) step4,

unencrypted);

src/eapol.c +4 -0
+
+       if (hs->ptk_complete)
+               return;
+
Quoted 4 lines

        handshake_state_install_ptk(hs);

        if (rekey_offload)

Regards,
-Denis

#8 lore raw

Re: [PATCH v3 04/13] eapol: support extended key IDs

Hi James,

Quoted 3 lines

So all the KDE parsing is completely skipped on retransmissions. So we never even get to this if block at all. And same with below...

Ah right, forgot we do that.

I went ahead and applied this one as well.

Regards,
-Denis

author
#9 lore raw

PATCH v3 5/13 netdev: support extended key IDs

In reply to James Prestwood

This implements the new handshake callback for setting a TK with an extended key ID. The procedure is different from legacy zero index TKs.

First the new TK is set as RX only. Then message 4 should be sent out (so it uses the existing TK). This poses a slight issue with PAE sockets since message order is not guaranteed. In this case the 4th message is stored and sent after the new TK is installed. Then the new TK is modified using SET_KEY to both send and receive.

In the case of control port over NL80211 the above can be avoided and we can simply install the new key, send message 4, and modify the TK as TX + RX all in sequence, without waiting for any callbacks.

---
 src/netdev.c | 401 ++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 297 insertions(+), 104 deletions(-)
src/netdev.c +297 -104
index de155da1..0bfc4c10 100644
@@ -87,6 +87,7 @@ struct netdev_handshake_state {
 	uint32_t group_management_new_key_cmd_id;
 	uint32_t set_station_cmd_id;
 	uint32_t set_pmk_cmd_id;
+	uint32_t pairwise_set_key_tx_cmd_id;
 	bool ptk_installed;
 	bool gtk_installed;
 	bool igtk_installed;
@@ -102,6 +103,12 @@ struct netdev_ft_over_ds_info {
 	bool parsed : 1;
 };
 
+struct netdev_ext_key_info {
+	uint16_t proto;
+	bool noencrypt;
+	struct eapol_frame frame[0];
+};
+
 struct netdev {
 	uint32_t index;
 	uint64_t wdev_id;
@@ -170,6 +177,8 @@ struct netdev {
 
 	struct l_queue *ft_ds_list;
 
+	struct netdev_ext_key_info *ext_key_info;
+
 	bool connected : 1;
 	bool associated : 1;
 	bool operational : 1;
@@ -336,6 +345,11 @@ static void netdev_handshake_state_cancel_all(
 		l_genl_family_cancel(nl80211, nhs->set_pmk_cmd_id);
 		nhs->set_pmk_cmd_id = 0;
 	}
+
+	if (nhs->pairwise_set_key_tx_cmd_id) {
+		l_genl_family_cancel(nl80211, nhs->pairwise_set_key_tx_cmd_id);
+		nhs->pairwise_set_key_tx_cmd_id = 0;
+	}
 }
 
 static void netdev_handshake_state_free(struct handshake_state *hs)
@@ -766,6 +780,11 @@ static void netdev_connect_free(struct netdev *netdev)
 		netdev->handshake = NULL;
 	}
 
+	if (netdev->ext_key_info) {
+		l_free(netdev->ext_key_info);
+		netdev->ext_key_info = NULL;
+	}
+
 	if (netdev->neighbor_report_cb) {
 		netdev->neighbor_report_cb(netdev, -ENOTCONN, NULL, 0,
 						netdev->user_data);
@@ -1693,6 +1712,24 @@ static void netdev_set_igtk(struct handshake_state *hs, uint16_t key_index,
 	netdev_setting_keys_failed(nhs, -EIO);
 }
 
+static struct l_genl_msg *netdev_build_cmd_set_key_tx(struct netdev *netdev)
+{
+	uint8_t key_mode = NL80211_KEY_SET_TX;
+	struct l_genl_msg *msg = l_genl_msg_new_sized(NL80211_CMD_SET_KEY, 512);
+
+	l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN,
+					netdev->handshake->aa);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
+
+	l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY);
+	l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1,
+				&netdev->handshake->active_tk_index);
+	l_genl_msg_append_attr(msg, NL80211_KEY_MODE, 1, &key_mode);
+	l_genl_msg_leave_nested(msg);
+
+	return msg;
+}
+
 static void netdev_new_pairwise_key_cb(struct l_genl_msg *msg, void *data)
 {
 	struct netdev_handshake_state *nhs = data;
@@ -1730,14 +1767,171 @@ error:
 	netdev_setting_keys_failed(nhs, err);
 }
 
+static struct l_genl_msg *netdev_build_control_port_frame(struct netdev *netdev,
+							const uint8_t *to,
+							uint16_t proto,
+							bool unencrypted,
+							const void *body,
+							size_t body_len)
+{
+	struct l_genl_msg *msg;
+
+	msg = l_genl_msg_new_sized(NL80211_CMD_CONTROL_PORT_FRAME,
+							128 + body_len);
+
+	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_FRAME, body_len, body);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, 2,
+				&proto);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, to);
+
+	if (unencrypted)
+		l_genl_msg_append_attr(msg,
+				NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT, 0, NULL);
+
+	return msg;
+}
+
+static void netdev_control_port_frame_cb(struct l_genl_msg *msg,
+							void *user_data)
+{
+	int err = l_genl_msg_get_error(msg);
+	const char *ext_error;
+
+	if (err >= 0)
+		return;
+
+	ext_error = l_genl_msg_get_extended_error(msg);
+	l_error("CMD_CONTROL_PORT failed: %s",
+			ext_error ? ext_error : strerror(-err));
+}
+
+static int netdev_control_port_write_pae(struct netdev *netdev,
+						const uint8_t *dest,
+						uint16_t proto,
+						const struct eapol_frame *ef,
+						bool noencrypt)
+{
+	int fd = l_io_get_fd(netdev->pae_io);
+	struct sockaddr_ll sll;
+	size_t frame_size = sizeof(struct eapol_header) +
+					L_BE16_TO_CPU(ef->header.packet_len);
+	ssize_t r;
+
+	memset(&sll, 0, sizeof(sll));
+	sll.sll_family = AF_PACKET;
+	sll.sll_ifindex = netdev->index;
+	sll.sll_protocol = htons(proto);
+	sll.sll_halen = ETH_ALEN;
+	memcpy(sll.sll_addr, dest, ETH_ALEN);
+
+	r = sendto(fd, ef, frame_size, 0,
+			(struct sockaddr *) &sll, sizeof(sll));
+	if (r < 0)
+		l_error("EAPoL write socket: %s", strerror(errno));
+
+	return r;
+}
+
+static int netdev_control_port_frame(uint32_t ifindex,
+					const uint8_t *dest, uint16_t proto,
+					const struct eapol_frame *ef,
+					bool noencrypt,
+					void *user_data)
+{
+	struct l_genl_msg *msg;
+	struct netdev *netdev;
+	size_t frame_size;
+
+	netdev = netdev_find(ifindex);
+	if (!netdev)
+		return -ENOENT;
+
+	frame_size = sizeof(struct eapol_header) +
+			L_BE16_TO_CPU(ef->header.packet_len);
+
+	if (!netdev->pae_over_nl80211)
+		return netdev_control_port_write_pae(netdev, dest, proto,
+							ef, noencrypt);
+
+	msg = netdev_build_control_port_frame(netdev, dest, proto, noencrypt,
+						ef, frame_size);
+	if (!msg)
+		return -ENOMEM;
+
+	if (!l_genl_family_send(nl80211, msg, netdev_control_port_frame_cb,
+				netdev, NULL)) {
+		l_genl_msg_unref(msg);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int netdev_set_key_tx(struct netdev *netdev)
+{
+	struct netdev_handshake_state *nhs = l_container_of(netdev->handshake,
+					struct netdev_handshake_state, super);
+	struct l_genl_msg *msg = netdev_build_cmd_set_key_tx(netdev);
+
+	nhs->pairwise_set_key_tx_cmd_id = l_genl_family_send(nl80211, msg,
+						netdev_new_pairwise_key_cb,
+						nhs, NULL);
+	if (nhs->pairwise_set_key_tx_cmd_id > 0)
+		return 0;
+
+	l_genl_msg_unref(msg);
+
+	return -EIO;
+}
+
+static void netdev_new_rx_pairwise_key_cb(struct l_genl_msg *msg, void *data)
+{
+	struct netdev_handshake_state *nhs = data;
+	struct netdev *netdev = nhs->netdev;
+	struct netdev_ext_key_info *info = netdev->ext_key_info;
+	int err = l_genl_msg_get_error(msg);
+
+	nhs->pairwise_new_key_cmd_id = 0;
+
+	if (err < 0) {
+		const char *ext_error = l_genl_msg_get_extended_error(msg);
+
+		l_error("New Key for RX Pairwise Key failed for ifindex: %d:%s",
+				netdev->index,
+				ext_error ? ext_error : strerror(-err));
+		goto error;
+	}
+
+	if (!info)
+		return;
+
+	err = netdev_control_port_write_pae(netdev, nhs->super.aa, info->proto,
+						info->frame, info->noencrypt);
+	l_free(netdev->ext_key_info);
+	netdev->ext_key_info = NULL;
+
+	if (err < 0)
+		goto error;
+
+	err = netdev_set_key_tx(netdev);
+	if (err < 0)
+		goto error;
+
+	return;
+
+error:
+	netdev_setting_keys_failed(nhs, err);
+}
+
 static struct l_genl_msg *netdev_build_cmd_new_key_pairwise(
 							struct netdev *netdev,
 							uint32_t cipher,
 							const uint8_t *aa,
 							const uint8_t *tk,
-							size_t tk_len)
+							size_t tk_len,
+							uint8_t key_id)
 {
-	uint8_t key_id = 0;
 	struct l_genl_msg *msg;
 
 	msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
@@ -1751,6 +1945,36 @@ static struct l_genl_msg *netdev_build_cmd_new_key_pairwise(
 	return msg;
 }
 
+static struct l_genl_msg *netdev_build_cmd_new_rx_key_pairwise(
+							struct netdev *netdev,
+							uint32_t cipher,
+							const uint8_t *aa,
+							const uint8_t *tk,
+							size_t tk_len,
+							uint8_t key_id)
+{
+	uint8_t key_mode = NL80211_KEY_NO_TX;
+	uint32_t key_type = NL80211_KEYTYPE_PAIRWISE;
+	struct l_genl_msg *msg;
+
+	msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
+
+	l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, aa);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
+
+	l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY);
+
+	l_genl_msg_append_attr(msg, NL80211_KEY_DATA, tk_len, tk);
+	l_genl_msg_append_attr(msg, NL80211_KEY_CIPHER, 4, &cipher);
+	l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_id);
+	l_genl_msg_append_attr(msg, NL80211_KEY_MODE, 1, &key_mode);
+	l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &key_type);
+
+	l_genl_msg_leave_nested(msg);
+
+	return msg;
+}
+
 static void netdev_group_timeout_cb(struct l_timeout *timeout, void *user_data)
 {
 	struct netdev_handshake_state *nhs = user_data;
@@ -1823,7 +2047,8 @@ static void netdev_set_tk(struct handshake_state *hs,
 		goto invalid_key;
 
 	msg = netdev_build_cmd_new_key_pairwise(netdev, cipher, addr, tk_buf,
-						crypto_cipher_key_len(cipher));
+						crypto_cipher_key_len(cipher),
+						hs->active_tk_index);
 	nhs->pairwise_new_key_cmd_id =
 		l_genl_family_send(nl80211, msg, netdev_new_pairwise_key_cb,
 						nhs, NULL);
@@ -1836,6 +2061,74 @@ invalid_key:
 	netdev_setting_keys_failed(nhs, err);
 }
 
+static void netdev_set_ext_tk(struct handshake_state *hs, uint8_t key_idx,
+				const uint8_t *tk, uint32_t cipher,
+				const struct eapol_frame *step4, uint16_t proto,
+				bool noencrypt)
+{
+	struct netdev_handshake_state *nhs =
+		l_container_of(hs, struct netdev_handshake_state, super);
+	uint8_t tk_buf[32];
+	struct netdev *netdev = nhs->netdev;
+	struct l_genl_msg *msg;
+	const uint8_t *addr = netdev_choose_key_address(nhs);
+	int err;
+	size_t frame_size = sizeof(struct eapol_header) +
+				L_BE16_TO_CPU(step4->header.packet_len);
+
+	err = -ENOENT;
+	if (!netdev_copy_tk(tk_buf, tk, cipher, false))
+		goto error;
+
+	msg = netdev_build_cmd_new_rx_key_pairwise(netdev, cipher, addr, tk_buf,
+						crypto_cipher_key_len(cipher),
+						hs->active_tk_index);
+	nhs->pairwise_new_key_cmd_id =
+		l_genl_family_send(nl80211, msg, netdev_new_rx_pairwise_key_cb,
+						nhs, NULL);
+
+	if (!nhs->pairwise_new_key_cmd_id)
+		goto io_error;
+
+	/*
+	 * Without control port we cannot guarantee the order that messages go
+	 * out and must wait for NEW_KEY to call back before sending message 4
+	 */
+	if (!wiphy_control_port_enabled(netdev->wiphy)) {
+		netdev->ext_key_info = l_malloc(
+					sizeof(struct netdev_ext_key_info) +
+					frame_size);
+		memcpy(netdev->ext_key_info->frame, step4, frame_size);
+		netdev->ext_key_info->proto = proto;
+		netdev->ext_key_info->noencrypt = noencrypt;
+		return;
+	}
+
+	/*
+	 * Otherwise, order of messages will be guaranteed. Therefore we can
+	 * send send message 4, and set the TK to TX (below) without waiting for
+	 * any callbacks
+	 */
+	err = netdev_control_port_frame(netdev->index, netdev->handshake->aa,
+					proto, step4, noencrypt, NULL);
+	if (err < 0)
+		goto error;
+
+	/* Then toggle to RX + TX */
+	err = netdev_set_key_tx(netdev);
+	if (err < 0)
+		goto error;
+
+	return;
+
+io_error:
+	err = -EIO;
+	l_genl_msg_unref(msg);
+
+error:
+	netdev_setting_keys_failed(nhs, err);
+}
+
 static void netdev_set_pmk_cb(struct l_genl_msg *msg, void *user_data)
 {
 	struct netdev_handshake_state *nhs = user_data;
@@ -5122,107 +5415,6 @@ static void netdev_control_port_frame_event(struct l_genl_msg *msg,
 						frame, frame_len, unencrypted);
 }
 
-static struct l_genl_msg *netdev_build_control_port_frame(struct netdev *netdev,
-							const uint8_t *to,
-							uint16_t proto,
-							bool unencrypted,
-							const void *body,
-							size_t body_len)
-{
-	struct l_genl_msg *msg;
-
-	msg = l_genl_msg_new_sized(NL80211_CMD_CONTROL_PORT_FRAME,
-							128 + body_len);
-
-	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_FRAME, body_len, body);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, 2,
-				&proto);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, to);
-
-	if (unencrypted)
-		l_genl_msg_append_attr(msg,
-				NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT, 0, NULL);
-
-	return msg;
-}
-
-static void netdev_control_port_frame_cb(struct l_genl_msg *msg,
-							void *user_data)
-{
-	int err = l_genl_msg_get_error(msg);
-	const char *ext_error;
-
-	if (err >= 0)
-		return;
-
-	ext_error = l_genl_msg_get_extended_error(msg);
-	l_error("CMD_CONTROL_PORT failed: %s",
-			ext_error ? ext_error : strerror(-err));
-}
-
-static int netdev_control_port_write_pae(struct netdev *netdev,
-						const uint8_t *dest,
-						uint16_t proto,
-						const struct eapol_frame *ef,
-						bool noencrypt)
-{
-	int fd = l_io_get_fd(netdev->pae_io);
-	struct sockaddr_ll sll;
-	size_t frame_size = sizeof(struct eapol_header) +
-					L_BE16_TO_CPU(ef->header.packet_len);
-	ssize_t r;
-
-	memset(&sll, 0, sizeof(sll));
-	sll.sll_family = AF_PACKET;
-	sll.sll_ifindex = netdev->index;
-	sll.sll_protocol = htons(proto);
-	sll.sll_halen = ETH_ALEN;
-	memcpy(sll.sll_addr, dest, ETH_ALEN);
-
-	r = sendto(fd, ef, frame_size, 0,
-			(struct sockaddr *) &sll, sizeof(sll));
-	if (r < 0)
-		l_error("EAPoL write socket: %s", strerror(errno));
-
-	return r;
-}
-
-static int netdev_control_port_frame(uint32_t ifindex,
-					const uint8_t *dest, uint16_t proto,
-					const struct eapol_frame *ef,
-					bool noencrypt,
-					void *user_data)
-{
-	struct l_genl_msg *msg;
-	struct netdev *netdev;
-	size_t frame_size;
-
-	netdev = netdev_find(ifindex);
-	if (!netdev)
-		return -ENOENT;
-
-	frame_size = sizeof(struct eapol_header) +
-			L_BE16_TO_CPU(ef->header.packet_len);
-
-	if (!netdev->pae_over_nl80211)
-		return netdev_control_port_write_pae(netdev, dest, proto,
-							ef, noencrypt);
-
-	msg = netdev_build_control_port_frame(netdev, dest, proto, noencrypt,
-						ef, frame_size);
-	if (!msg)
-		return -ENOMEM;
-
-	if (!l_genl_family_send(nl80211, msg, netdev_control_port_frame_cb,
-				netdev, NULL)) {
-		l_genl_msg_unref(msg);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static void netdev_unicast_notify(struct l_genl_msg *msg, void *user_data)
 {
 	struct netdev *netdev = NULL;
@@ -6243,6 +6435,7 @@ static int netdev_init(void)
 	__handshake_set_install_tk_func(netdev_set_tk);
 	__handshake_set_install_gtk_func(netdev_set_gtk);
 	__handshake_set_install_igtk_func(netdev_set_igtk);
+	__handshake_set_install_ext_tk_func(netdev_set_ext_tk);
 
 	__eapol_set_rekey_offload_func(netdev_set_rekey_offload);
 	__eapol_set_tx_packet_func(netdev_control_port_frame);
Signature · 1 line
2.31.1
#10 lore raw

Re: [PATCH v3 05/13] netdev: support extended key IDs

Hi James,

Quoted 18 lines · James Prestwood

This implements the new handshake callback for setting a TK with an extended key ID. The procedure is different from legacy zero index TKs.

First the new TK is set as RX only. Then message 4 should be sent out (so it uses the existing TK). This poses a slight issue with PAE sockets since message order is not guaranteed. In this case the 4th message is stored and sent after the new TK is installed. Then the new TK is modified using SET_KEY to both send and receive.

In the case of control port over NL80211 the above can be avoided and we can simply install the new key, send message 4, and modify the TK as TX + RX all in sequence, without waiting for any callbacks.

---
  src/netdev.c | 401 ++++++++++++++++++++++++++++++++++++++-------------
  1 file changed, 297 insertions(+), 104 deletions(-)

<snip>

src/netdev.c static void netdev_set_tk(struct handshake_state *hs, · line 2051

Quoted 7 lines
src/netdev.c +2 -1
@@ -1823,7 +2047,8 @@ static void netdev_set_tk(struct handshake_state *hs,
  		goto invalid_key;
 
  	msg = netdev_build_cmd_new_key_pairwise(netdev, cipher, addr, tk_buf,
-						crypto_cipher_key_len(cipher));
+						crypto_cipher_key_len(cipher),
+						hs->active_tk_index);

This seems inconsistent? You pass the key_idx in the ext_tk callback, but not here. Bit of a pain to change the signature, but it may be nicer to just pass the desired index into this callback.

Quoted 31 lines
src/netdev.c +24 -0
  	nhs->pairwise_new_key_cmd_id =
  		l_genl_family_send(nl80211, msg, netdev_new_pairwise_key_cb,
  						nhs, NULL);
@@ -1836,6 +2061,74 @@ invalid_key:
  	netdev_setting_keys_failed(nhs, err);
  }
 
+static void netdev_set_ext_tk(struct handshake_state *hs, uint8_t key_idx,
+				const uint8_t *tk, uint32_t cipher,
+				const struct eapol_frame *step4, uint16_t proto,
+				bool noencrypt)
+{
+	struct netdev_handshake_state *nhs =
+		l_container_of(hs, struct netdev_handshake_state, super);
+	uint8_t tk_buf[32];
+	struct netdev *netdev = nhs->netdev;
+	struct l_genl_msg *msg;
+	const uint8_t *addr = netdev_choose_key_address(nhs);
+	int err;
+	size_t frame_size = sizeof(struct eapol_header) +
+				L_BE16_TO_CPU(step4->header.packet_len);
+
+	err = -ENOENT;
+	if (!netdev_copy_tk(tk_buf, tk, cipher, false))
+		goto error;
+
+	msg = netdev_build_cmd_new_rx_key_pairwise(netdev, cipher, addr, tk_buf,
+						crypto_cipher_key_len(cipher),
+						hs->active_tk_index);
+	nhs->pairwise_new_key_cmd_id =
+		l_genl_family_send(nl80211, msg, netdev_new_rx_pairwise_key_cb,

src/netdev.c invalid_key: · line 2097

Quoted 10 lines
src/netdev.c +10 -0
+						nhs, NULL);
+
+	if (!nhs->pairwise_new_key_cmd_id)
+		goto io_error;
+
+	/*
+	 * Without control port we cannot guarantee the order that messages go
+	 * out and must wait for NEW_KEY to call back before sending message 4
+	 */
+	if (!wiphy_control_port_enabled(netdev->wiphy)) {

nit: lets just use netdev->pae_over_nl80211 for consistency.

Quoted 27 lines
src/netdev.c +27 -0
+		netdev->ext_key_info = l_malloc(
+					sizeof(struct netdev_ext_key_info) +
+					frame_size);
+		memcpy(netdev->ext_key_info->frame, step4, frame_size);
+		netdev->ext_key_info->proto = proto;
+		netdev->ext_key_info->noencrypt = noencrypt;
+		return;
+	}
+
+	/*
+	 * Otherwise, order of messages will be guaranteed. Therefore we can
+	 * send send message 4, and set the TK to TX (below) without waiting for
+	 * any callbacks
+	 */
+	err = netdev_control_port_frame(netdev->index, netdev->handshake->aa,
+					proto, step4, noencrypt, NULL);
+	if (err < 0)
+		goto error;
+
+	/* Then toggle to RX + TX */
+	err = netdev_set_key_tx(netdev);
+	if (err < 0)
+		goto error;
+
+	return;
+
+io_error:

src/netdev.c invalid_key: · line 2134

Quoted 10 lines
src/netdev.c +7 -0
+	err = -EIO;
+	l_genl_msg_unref(msg);
+
+error:
+	netdev_setting_keys_failed(nhs, err);
+}
+
  static void netdev_set_pmk_cb(struct l_genl_msg *msg, void *user_data)
  {
  	struct netdev_handshake_state *nhs = user_data;

<snip>

Regards,
-Denis

author
#11 lore raw

PATCH v3 6/13 station: set extended key capability

In reply to James Prestwood

If wiphy and the AP suppor it, set the Extended Key ID capability bit in the RSN info.

---
 src/station.c | 4 ++++
 1 file changed, 4 insertions(+)
src/station.c +4 -0
index f12cdde5..30335170 100644
@@ -1087,6 +1087,10 @@ build_ie:
 
 	info.ocvc = !disable_ocv;
 
+	/* Extended Key IDs can only be used if supported by both AP and STA */
+	if (wiphy_supports_ext_key_id(wiphy) && bss_info.extended_key_id)
+		info.extended_key_id = true;
+
 	/* RSN takes priority */
 	if (bss->rsne) {
 		ap_ie = bss->rsne;
Signature · 1 line
2.31.1
author
#12 lore raw

PATCH v3 7/13 handshake: set extended key ID capable

In reply to James Prestwood
---
 src/handshake.c | 1 +
 1 file changed, 1 insertion(+)
src/handshake.c +1 -0
index 58326dcd..ea1c5e4b 100644
@@ -240,6 +240,7 @@ valid_ie:
 	s->group_management_cipher = info.group_management_cipher;
 	s->akm_suite = info.akm_suites;
 	s->supplicant_ocvc = info.ocvc;
+	s->ext_key_id_capable = info.extended_key_id;
 
 	/*
 	 * Don't set MFP for OSEN otherwise EAPoL will attempt to negotiate a
Signature · 1 line
2.31.1
#13 lore raw

Re: [PATCH v3 07/13] handshake: set extended key ID capable

Hi James,

Quoted 4 lines · James Prestwood
---
  src/handshake.c | 1 +
  1 file changed, 1 insertion(+)

Applied after merging with patch 02.

Regards,
-Denis

author
#14 lore raw

PATCH v3 8/13 auto-t: iwd.py: make wait() a static method

In reply to James Prestwood

This allows it to be used without initializing an IWD class:

IWD.wait(1)

---
 autotests/util/iwd.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
autotests/util/iwd.py +2 -1
index 63b526fd..d6a7fe06 100755
@@ -1133,7 +1133,8 @@ class IWD(AsyncOpAbstract):
                                        ' condition was not met in '\
                                        + str(max_wait) + ' sec'))
 
-    def wait(self, time):
+    @staticmethod
+    def wait(time):
         ctx.non_block_wait(lambda : False, time, exception=False)
 
     @staticmethod
Signature · 1 line
2.31.1
#15 lore raw

Re: [PATCH v3 08/13] auto-t: iwd.py: make wait() a static method

Hi James,

Quoted 7 lines · James Prestwood

This allows it to be used without initializing an IWD class:

IWD.wait(1)

---
  autotests/util/iwd.py | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

Patches 8-11, 13 applied, thanks.

Regards,
-Denis

author
#16 lore raw

PATCH v3 9/13 nl80211util: set multicast on new group keys

In reply to James Prestwood

This may not be required but setting the group key mode explicitly to multicast makes things consistent, even if only for the benefit of reading iwmon logs easier.

---
 src/nl80211util.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
src/nl80211util.c +5 -9
index d9d4819d..d663c6dc 100644
@@ -247,6 +247,7 @@ struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher
 					size_t ctr_len, const uint8_t *addr)
 {
 	struct l_genl_msg *msg;
+	uint32_t type = NL80211_KEYTYPE_GROUP;
 
 	msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
 
@@ -263,16 +264,11 @@ struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher
 	if (ctr)
 		l_genl_msg_append_attr(msg, NL80211_KEY_SEQ, ctr_len, ctr);
 
-	if (addr) {
-		uint32_t type = NL80211_KEYTYPE_GROUP;
-
-		l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &type);
-		l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES);
-		l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST,
+	l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &type);
+	l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES);
+	l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST,
 					0, NULL);
-		l_genl_msg_leave_nested(msg);
-	}
-
+	l_genl_msg_leave_nested(msg);
 	l_genl_msg_leave_nested(msg);
 
 	return msg;
Signature · 1 line
2.31.1
author
#17 lore raw

PATCH v3 10/13 auto-t: hostapd.py: separate GTK and PTK rekeys

In reply to James Prestwood

REKEY_GTK kicks off the GTK only handshake where REKEY_PTK does both (via the 4-way). The way this utility was written was causing hostapd some major issues since both REKEY_GTK and REKEY_PTK was used.

Instead if address is set only do REKEY_PTK. This will also rekey the GTK via the 4-way handshake.

If no address is set do REKEY_GTK which will only rekey the GTK.

---
 autotests/util/hostapd.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
autotests/util/hostapd.py +7 -3
index 9f2dc745..22802be6 100644
@@ -202,11 +202,15 @@ class HostapdCLI(object):
         cmd = self.cmdline + ['req_beacon', addr, request]
         ctx.start_process(cmd).wait()
 
-    def rekey(self, address):
+    def rekey(self, address=None):
+        if address:
+            cmd = 'REKEY_PTK %s' % address
+            self.ctrl_sock.sendall(cmd.encode('utf-8'))
+            self.wait_for_event('EAPOL-4WAY-HS-COMPLETED')
+            return
+
         cmd = 'REKEY_GTK'
         self.ctrl_sock.sendall(cmd.encode('utf-8'))
-        cmd = 'REKEY_PTK %s' % address
-        self.ctrl_sock.sendall(cmd.encode('utf-8'))
 
     @property
     def bssid(self):
Signature · 1 line
2.31.1
author
#18 lore raw

PATCH v3 11/13 auto-t: hostapd.py: add resend_m3

In reply to James Prestwood

This forces hostapd to resend message 3 of the 4-way handshake

---
 autotests/util/hostapd.py | 4 ++++
 1 file changed, 4 insertions(+)
autotests/util/hostapd.py +4 -0
index 22802be6..5d17da6b 100644
@@ -212,6 +212,10 @@ class HostapdCLI(object):
         cmd = 'REKEY_GTK'
         self.ctrl_sock.sendall(cmd.encode('utf-8'))
 
+    def resend_m3(self, address):
+        cmd = 'RESEND_M3 %s' % address
+        self.ctrl_sock.sendall(cmd.encode('utf-8'))
+
     @property
     def bssid(self):
         cmd = self.cmdline + ['status']
Signature · 1 line
2.31.1
author
#19 lore raw

PATCH v3 12/13 auto-t: Add test for extended key IDs

In reply to James Prestwood
---
 .../testWPA2-ext-key-id/connection_test.py    | 112 ++++++++++++++++++
 autotests/testWPA2-ext-key-id/hw.conf         |   6 +
 autotests/testWPA2-ext-key-id/main_pae.conf   |   2 +
 autotests/testWPA2-ext-key-id/ssidCCMP.conf   |  11 ++
 4 files changed, 131 insertions(+)
 create mode 100644 autotests/testWPA2-ext-key-id/connection_test.py
 create mode 100644 autotests/testWPA2-ext-key-id/hw.conf
 create mode 100644 autotests/testWPA2-ext-key-id/main_pae.conf
 create mode 100644 autotests/testWPA2-ext-key-id/ssidCCMP.conf
autotests/testWPA2-ext-key-id/connection_test.py new file +112 -0
new file mode 100644
index 00000000..afd48149
@@ -0,0 +1,112 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+import os
+
+sys.path.append('../util')
+from iwd import IWD_CONFIG_DIR
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hwsim import Hwsim
+from hostapd import HostapdCLI
+import testutil
+
+class Test(unittest.TestCase):
+    def validate(self, wd, resend_m3=False):
+        hapd = HostapdCLI('ssidCCMP.conf')
+
+        psk_agent = PSKAgent("secret123")
+        wd.register_psk_agent(psk_agent)
+
+        devices = wd.list_devices(1)
+        device = devices[0]
+
+        ordered_network = device.get_ordered_network('ssidCCMP')
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(device, condition)
+
+        testutil.test_iface_operstate()
+        testutil.test_ifaces_connected()
+
+
+        # Rekey 5 times just to make sure the key ID can be toggled back and
+        # forth without causing problems.
+        for i in range(5):
+            hapd.rekey(device.address)
+
+            if resend_m3:
+                hapd.resend_m3(device.address)
+
+            testutil.test_iface_operstate()
+            testutil.test_ifaces_connected()
+
+        device.disconnect()
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        wd.unregister_psk_agent(psk_agent)
+
+    def test_ext_key_control_port(self):
+        self.hapd.set_value('extended_key_id', '1')
+        self.hapd.reload()
+
+        self.wd = IWD(True)
+
+        self.validate(self.wd)
+
+    def test_ext_key_control_port_retransmit(self):
+        self.hapd.set_value('extended_key_id', '1')
+        self.hapd.reload()
+
+        self.wd = IWD(True)
+
+        self.validate(self.wd, resend_m3=True)
+
+    def test_ext_key_index_1(self):
+        self.hapd.set_value('extended_key_id', '2')
+        self.hapd.reload()
+
+        self.wd = IWD(True)
+
+        self.validate(self.wd)
+
+    def test_ext_key_pae(self):
+        self.hapd.set_value('extended_key_id', '1')
+        self.hapd.reload()
+
+        IWD.copy_to_storage('main_pae.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
+
+        self.wd = IWD(True)
+
+        self.validate(self.wd)
+
+    def tearDown(self):
+        try:
+            os.system('rm -rf %s/main.conf' % IWD_CONFIG_DIR)
+        except:
+            pass
+
+        self.wd = None
+
+    @classmethod
+    def setUpClass(cls):
+        cls.hapd = HostapdCLI()
+
+    @classmethod
+    def tearDownClass(cls):
+        IWD.clear_storage()
+        cls.hapd = None
+
+if __name__ == '__main__':
+    unittest.main(exit=True)
autotests/testWPA2-ext-key-id/hw.conf new file +6 -0
new file mode 100644
index 00000000..de81e1e2
@@ -0,0 +1,6 @@
+[SETUP]
+num_radios=2
+start_iwd=0
+
+[HOSTAPD]
+rad0=ssidCCMP.conf
autotests/testWPA2-ext-key-id/main_pae.conf new file +2 -0
new file mode 100644
index 00000000..8bcedda5
@@ -0,0 +1,2 @@
+[General]
+ControlPortOverNL80211=false
autotests/testWPA2-ext-key-id/ssidCCMP.conf new file +11 -0
new file mode 100644
index 00000000..b52bfb7c
@@ -0,0 +1,11 @@
+hw_mode=g
+channel=1
+ssid=ssidCCMP
+
+wpa=2
+wpa_pairwise=CCMP
+wpa_passphrase=secret123
+
+ieee80211w=2
+wpa_key_mgmt=WPA-PSK-SHA256
+extended_key_id=1
Signature · 1 line
2.31.1
author
#20 lore raw

PATCH v3 13/13 auto-t: update rekey() use to not wait for event

In reply to James Prestwood

The hostapd event wait was moved into rekey() itself.

---
 autotests/testFILS/fils_256_test.py       | 1 -
 autotests/testFILS/fils_384_test.py       | 1 -
 autotests/testFT-FILS/connection_test.py  | 1 -
 autotests/testPSK-roam/connection_test.py | 1 -
 4 files changed, 4 deletions(-)
autotests/testFILS/fils_256_test.py +0 -1
index 02fad28e..a4e58715 100644
@@ -56,7 +56,6 @@ class Test(unittest.TestCase):
         testutil.test_ifaces_connected(device.name, hapd.ifname)
 
         hapd.rekey(device.address)
-        hapd.wait_for_event('EAPOL-4WAY-HS-COMPLETED')
 
         device.disconnect()
 
autotests/testFILS/fils_384_test.py +0 -1
index 8ecd2fec..e6550a17 100644
@@ -56,7 +56,6 @@ class Test(unittest.TestCase):
         testutil.test_ifaces_connected(device.name, hapd.ifname)
 
         hapd.rekey(device.address)
-        hapd.wait_for_event('EAPOL-4WAY-HS-COMPLETED')
 
         device.disconnect()
 
autotests/testFT-FILS/connection_test.py +0 -1
index d1389cea..14025a3b 100644
@@ -96,7 +96,6 @@ class Test(unittest.TestCase):
                           (self.bss_hostapd[0].ifname, device.name, True, True))
 
         self.bss_hostapd[1].rekey(device.address)
-        self.bss_hostapd[1].wait_for_event('EAPOL-4WAY-HS-COMPLETED')
 
     def test_fils_ft_roam_sha256(self):
         wd = IWD(True)
autotests/testPSK-roam/connection_test.py +0 -1
index d1beb010..ee50e4a7 100644
@@ -81,7 +81,6 @@ class Test(unittest.TestCase):
                           (self.bss_hostapd[0].ifname, device.name, True, True))
 
         self.bss_hostapd[1].rekey(device.address)
-        self.bss_hostapd[1].wait_for_event('EAPOL-4WAY-HS-COMPLETED')
 
         device.roam(self.bss_hostapd[0].bssid)
 
Signature · 1 line
2.31.1
Applied
#21 lore raw
In reply to James Prestwood

Hi James,

Quoted 11 lines · James Prestwood

Move the reading of ControlPortOverNL80211 into wiphy itself and renamed wiphy_control_port_capable to wiphy_control_port_enabled. This makes things easier for any modules interested in control port support since they will only have to check this one API rather than read the settings and check capability.

---
  src/netdev.c |  7 +------
  src/wiphy.c  | 16 +++++++++++++---
  src/wiphy.h  |  2 +-
  3 files changed, 15 insertions(+), 10 deletions(-)

Applied, thanks.

Regards,
-Denis