lkundrak / rpms / hostapd

Forked from rpms/hostapd 4 years ago
Clone
41817b0
From 12fac09b437a1dc8a0f253e265934a8aaf4d2f8b Mon Sep 17 00:00:00 2001
41817b0
From: Jouni Malinen <j@w1.fi>
41817b0
Date: Sun, 1 Oct 2017 12:32:57 +0300
41817b0
Subject: [PATCH 5/8] Fix PTK rekeying to generate a new ANonce
41817b0
41817b0
The Authenticator state machine path for PTK rekeying ended up bypassing
41817b0
the AUTHENTICATION2 state where a new ANonce is generated when going
41817b0
directly to the PTKSTART state since there is no need to try to
41817b0
determine the PMK again in such a case. This is far from ideal since the
41817b0
new PTK would depend on a new nonce only from the supplicant.
41817b0
41817b0
Fix this by generating a new ANonce when moving to the PTKSTART state
41817b0
for the purpose of starting new 4-way handshake to rekey PTK.
41817b0
41817b0
Signed-off-by: Jouni Malinen <j@w1.fi>
41817b0
---
41817b0
 src/ap/wpa_auth.c | 24 +++++++++++++++++++++---
41817b0
 1 file changed, 21 insertions(+), 3 deletions(-)
41817b0
41817b0
diff --git a/src/ap/wpa_auth.c b/src/ap/wpa_auth.c
41817b0
index 707971d..bf10cc1 100644
41817b0
--- a/src/ap/wpa_auth.c
41817b0
+++ b/src/ap/wpa_auth.c
41817b0
@@ -1901,6 +1901,21 @@ SM_STATE(WPA_PTK, AUTHENTICATION2)
41817b0
 }
41817b0
 
41817b0
 
41817b0
+static int wpa_auth_sm_ptk_update(struct wpa_state_machine *sm)
41817b0
+{
41817b0
+	if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
41817b0
+		wpa_printf(MSG_ERROR,
41817b0
+			   "WPA: Failed to get random data for ANonce");
41817b0
+		sm->Disconnect = TRUE;
41817b0
+		return -1;
41817b0
+	}
41817b0
+	wpa_hexdump(MSG_DEBUG, "WPA: Assign new ANonce", sm->ANonce,
41817b0
+		    WPA_NONCE_LEN);
41817b0
+	sm->TimeoutCtr = 0;
41817b0
+	return 0;
41817b0
+}
41817b0
+
41817b0
+
41817b0
 SM_STATE(WPA_PTK, INITPMK)
41817b0
 {
41817b0
 	u8 msk[2 * PMK_LEN];
41817b0
@@ -2458,9 +2473,12 @@ SM_STEP(WPA_PTK)
41817b0
 		SM_ENTER(WPA_PTK, AUTHENTICATION);
41817b0
 	else if (sm->ReAuthenticationRequest)
41817b0
 		SM_ENTER(WPA_PTK, AUTHENTICATION2);
41817b0
-	else if (sm->PTKRequest)
41817b0
-		SM_ENTER(WPA_PTK, PTKSTART);
41817b0
-	else switch (sm->wpa_ptk_state) {
41817b0
+	else if (sm->PTKRequest) {
41817b0
+		if (wpa_auth_sm_ptk_update(sm) < 0)
41817b0
+			SM_ENTER(WPA_PTK, DISCONNECTED);
41817b0
+		else
41817b0
+			SM_ENTER(WPA_PTK, PTKSTART);
41817b0
+	} else switch (sm->wpa_ptk_state) {
41817b0
 	case WPA_PTK_INITIALIZE:
41817b0
 		break;
41817b0
 	case WPA_PTK_DISCONNECT:
41817b0
-- 
41817b0
2.7.4
41817b0