Skip to contentSkip to conversation

handshake: add force_sha1 flag to handshake_state_get_pmkid()

PATCH In review James Prestwood 2 participants 8 messages Jun 19, 2023 – Jun 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 handshake: add force_sha1 flag to handshake_state_get_pmkid()

To prepare adding FT_OVER_8021X to the SHA256 list for PMKID derivation, add a flag to force SHA1 to be used with preauthentication. The spec dictates that preauth must use SHA1 but this isn't consistent with PMKID derivation in all other cases for the FT_OVER_8021X AKM.

---
 src/eapol.c     | 2 +-
 src/handshake.c | 7 ++++---
 src/handshake.h | 3 ++-
 src/station.c   | 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)
src/eapol.c +1 -1
index 37f5eaaa..354b8fe7 100644
@@ -1236,7 +1236,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
 	} else if (pmkid) {
 		uint8_t own_pmkid[16];
 
-		if (!handshake_state_get_pmkid(sm->handshake, own_pmkid))
+		if (!handshake_state_get_pmkid(sm->handshake, own_pmkid, false))
 			goto error_unspecified;
 
 		if (l_secure_memcmp(pmkid, own_pmkid, 16)) {
src/handshake.c +4 -3
index cd9b3082..7f749632 100644
@@ -734,7 +734,8 @@ void handshake_state_set_pmkid(struct handshake_state *s, const uint8_t *pmkid)
 	s->have_pmkid = true;
 }
 
-bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid)
+bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid,
+				bool force_sha1)
 {
 	bool use_sha256;
 
@@ -755,8 +756,8 @@ bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid)
 	 * calculation."
 	 */
 
-	if (s->akm_suite & (IE_RSN_AKM_SUITE_8021X_SHA256 |
-			IE_RSN_AKM_SUITE_PSK_SHA256))
+	if (!force_sha1 && (s->akm_suite & (IE_RSN_AKM_SUITE_8021X_SHA256 |
+			IE_RSN_AKM_SUITE_PSK_SHA256)))
 		use_sha256 = true;
 	else
 		use_sha256 = false;
src/handshake.h +2 -1
index 863ffac7..d9505593 100644
@@ -269,7 +269,8 @@ void handshake_state_install_igtk(struct handshake_state *s,
 void handshake_state_override_pairwise_cipher(struct handshake_state *s,
 					enum ie_rsn_cipher_suite pairwise);
 
-bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid);
+bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid,
+				bool force_sha1);
 
 bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,
 				size_t key_len, uint8_t *key_out);
src/station.c +1 -1
index f830ab7a..2e819460 100644
@@ -2236,7 +2236,7 @@ static void station_preauthenticate_cb(struct netdev *netdev,
 					new_hs->supplicant_ie[1] + 2,
 					&rsn_info);
 
-		handshake_state_get_pmkid(new_hs, pmkid);
+		handshake_state_get_pmkid(new_hs, pmkid, true);
 
 		rsn_info.num_pmkids = 1;
 		rsn_info.pmkids = pmkid;
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/6 handshake: add FT_OVER_8021X AKM for SHA256 PMKID derivation

Hostapd commit b6d3fd05e3 changed the PMKID derivation in accordance with 802.11-2020 which then breaks PMKID validation in IWD. This breaks the FT-8021x AKM in IWD if the AP uses this hostapd version since the PMKID doesn't validate during EAPoL.

This updates the PMKID derivation to use the correct SHA hash for this AKM, and following patches will address backwards compatibility with older hostapd versions.

---
 src/handshake.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/handshake.c +2 -1
index 7f749632..bbab5ab6 100644
@@ -757,7 +757,8 @@ bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid,
 	 */
 
 	if (!force_sha1 && (s->akm_suite & (IE_RSN_AKM_SUITE_8021X_SHA256 |
-			IE_RSN_AKM_SUITE_PSK_SHA256)))
+			IE_RSN_AKM_SUITE_PSK_SHA256 |
+			IE_RSN_AKM_SUITE_FT_OVER_8021X)))
 		use_sha256 = true;
 	else
 		use_sha256 = false;
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/6 handshake: add handshake_state_pmkid_matches

In reply to James Prestwood

This will check if the given PMKID matches the derived PMKID. This has been exposed as its own API in order to handle the case of the PMKID being derived using the 'legacy' spec derivation, specifically with the FT-8021X AKM. The spec was updated to be more clear on what hash algorithm to use but older hostapd version use the old derivation. This handles both and will allow EAPoL to accept the PMKID in either case.

---
 src/handshake.c | 26 ++++++++++++++++++++++++++
 src/handshake.h |  3 ++-
 2 files changed, 28 insertions(+), 1 deletion(-)
src/handshake.c +26 -0
index bbab5ab6..7438c85a 100644
@@ -767,6 +767,32 @@ bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid,
 					use_sha256);
 }
 
+bool handshake_state_pmkid_matches(struct handshake_state *s,
+					const uint8_t *check)
+{
+	uint8_t own_pmkid[16];
+
+	if (!handshake_state_get_pmkid(s, own_pmkid, false))
+		return false;
+
+	if (l_secure_memcmp(own_pmkid, check, 16)) {
+		if (s->akm_suite != IE_RSN_AKM_SUITE_FT_OVER_8021X)
+			return false;
+		/*
+		 * Recent hostapd versions (commit b6d3fd05e3) changed the PMKID
+		 * derivation for the FT-8021x AKM to use SHA256. This may be
+		 * the issue here so try the SHA1 derivation before giving up.
+		 */
+
+		if (!handshake_state_get_pmkid(s, own_pmkid, true))
+			return false;
+
+		return l_secure_memcmp(own_pmkid, check, 16) == 0;
+	}
+
+	return true;
+}
+
 void handshake_state_set_gtk(struct handshake_state *s, const uint8_t *key,
 				unsigned int key_index, const uint8_t *rsc)
 {
src/handshake.h +2 -1
index d9505593..3e3841bf 100644
@@ -271,7 +271,8 @@ void handshake_state_override_pairwise_cipher(struct handshake_state *s,
 
 bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid,
 				bool force_sha1);
-
+bool handshake_state_pmkid_matches(struct handshake_state *s,
+					const uint8_t *check);
 bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,
 				size_t key_len, uint8_t *key_out);
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/6 eapol: use handshake_state_pmkid_matches

In reply to James Prestwood

This allows compatibility with older hostapd versions using the SHA1 derivation for the FT-8021X AKM.

---
 src/eapol.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
src/eapol.c +1 -6
index 354b8fe7..7db6148e 100644
@@ -1234,12 +1234,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
 		if (!found)
 			goto error_unspecified;
 	} else if (pmkid) {
-		uint8_t own_pmkid[16];
-
-		if (!handshake_state_get_pmkid(sm->handshake, own_pmkid, false))
-			goto error_unspecified;
-
-		if (l_secure_memcmp(pmkid, own_pmkid, 16)) {
+		if (!handshake_state_pmkid_matches(sm->handshake, pmkid)) {
 			l_debug("Authenticator sent a PMKID that didn't match");
 
 			/*
Signature · 1 line
2.25.1
#4 lore raw

PATCH 5/6 auto-t: add comment about FILS rekeys

In reply to James Prestwood

FILS rekeys were fixed in hostapd somewhat recently but older versions will fail this test. Document that so we don't get confused when running tests against older hostapd versions.

---
 autotests/testFILS/fils_256_test.py | 4 ++++
 autotests/testFILS/fils_384_test.py | 4 ++++
 2 files changed, 8 insertions(+)
autotests/testFILS/fils_256_test.py +4 -0
index 7018f0f2..ca20f683 100644
@@ -55,6 +55,10 @@ class Test(unittest.TestCase):
         testutil.test_iface_operstate()
         testutil.test_ifaces_connected(device.name, hapd.ifname)
 
+        #
+        # TODO: If this is failing its likely due to an older hostapd version
+        #       not containing commit 7ee814201b72
+        #
         hapd.rekey(device.address)
 
         device.disconnect()
autotests/testFILS/fils_384_test.py +4 -0
index ce8904df..5ff6ec36 100644
@@ -55,6 +55,10 @@ class Test(unittest.TestCase):
         testutil.test_iface_operstate()
         testutil.test_ifaces_connected(device.name, hapd.ifname)
 
+        #
+        # TODO: If this is failing its likely due to an older hostapd version
+        #       not containing commit 7ee814201b72
+        #
         hapd.rekey(device.address)
 
         device.disconnect()
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH 5/6] auto-t: add comment about FILS rekeys

Hi James,

Quoted 8 lines · James Prestwood

FILS rekeys were fixed in hostapd somewhat recently but older versions will fail this test. Document that so we don't get confused when running tests against older hostapd versions.

---
  autotests/testFILS/fils_256_test.py | 4 ++++
  autotests/testFILS/fils_384_test.py | 4 ++++
  2 files changed, 8 insertions(+)

Patch 5 & 6 applied, thanks.

Regards,
-Denis

#6 lore raw

PATCH 6/6 auto-t: fix testNetconfig lease parsing

In reply to James Prestwood

The parsing code was breaking out of the loop on the first comment which is incorrect and causes only part of the file to be parsed. Its odd this hasn't popped up until now but its likely due to differing dhcpd versions, some which add comments and others that do not.

---
 autotests/testNetconfig/connection_test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
autotests/testNetconfig/connection_test.py +1 -1
index cf90993a..aed35bee 100644
@@ -276,7 +276,7 @@ class Test(unittest.TestCase):
                 elif quote or ch not in ' \t\r\n;{}#':
                     token += ch
                 if ch == '#':
-                    break
+                    continue
                 elif ch == '{':
                     stack.append([])
                 elif ch == '}':
Signature · 1 line
2.25.1
#7 lore raw
In reply to James Prestwood

Hi James,

Quoted 5 lines · James Prestwood

To prepare adding FT_OVER_8021X to the SHA256 list for PMKID derivation, add a flag to force SHA1 to be used with preauthentication. The spec dictates that preauth must use SHA1 but this isn't consistent with PMKID derivation in all other cases for the FT_OVER_8021X AKM.

Can we port some of the long-form explanations from discussion we had during the previous iteration of this patchset. I think some pointers to relevant sections in the specification would be nice here.

Quoted 7 lines
---
  src/eapol.c     | 2 +-
  src/handshake.c | 7 ++++---
  src/handshake.h | 3 ++-
  src/station.c   | 2 +-
  4 files changed, 8 insertions(+), 6 deletions(-)

<snip>

src/handshake.c void handshake_state_set_pmkid(struct handshake_state *s, const uint8_t *pmkid) · line 738

Quoted 7 lines
src/handshake.c +2 -1
@@ -734,7 +734,8 @@ void handshake_state_set_pmkid(struct handshake_state *s, const uint8_t *pmkid)
  	s->have_pmkid = true;
  }
 
-bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid)
+bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid,
+				bool force_sha1)

I think it would look much better if we pass in the checksum type here instead. That way eapol can simply hard-code the value to SHA1, and other callers can invoke a helper to convert the AKM into a checksum type.

Could also simplify crypto_derive_pmkid as well.

Regards.
-Denis