hostapd: fix up ubus support
[oweals/openwrt.git] / package / network / services / hostapd / patches / 004-Fix-PTK-rekeying-to-generate-a-new-ANonce.patch
1 From: Jouni Malinen <j@w1.fi>
2 Date: Sun, 1 Oct 2017 12:32:57 +0300
3 Subject: [PATCH] Fix PTK rekeying to generate a new ANonce
4
5 The Authenticator state machine path for PTK rekeying ended up bypassing
6 the AUTHENTICATION2 state where a new ANonce is generated when going
7 directly to the PTKSTART state since there is no need to try to
8 determine the PMK again in such a case. This is far from ideal since the
9 new PTK would depend on a new nonce only from the supplicant.
10
11 Fix this by generating a new ANonce when moving to the PTKSTART state
12 for the purpose of starting new 4-way handshake to rekey PTK.
13
14 Signed-off-by: Jouni Malinen <j@w1.fi>
15 ---
16
17 --- a/src/ap/wpa_auth.c
18 +++ b/src/ap/wpa_auth.c
19 @@ -1951,6 +1951,21 @@ SM_STATE(WPA_PTK, AUTHENTICATION2)
20  }
21  
22  
23 +static int wpa_auth_sm_ptk_update(struct wpa_state_machine *sm)
24 +{
25 +       if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
26 +               wpa_printf(MSG_ERROR,
27 +                          "WPA: Failed to get random data for ANonce");
28 +               sm->Disconnect = TRUE;
29 +               return -1;
30 +       }
31 +       wpa_hexdump(MSG_DEBUG, "WPA: Assign new ANonce", sm->ANonce,
32 +                   WPA_NONCE_LEN);
33 +       sm->TimeoutCtr = 0;
34 +       return 0;
35 +}
36 +
37 +
38  SM_STATE(WPA_PTK, INITPMK)
39  {
40         u8 msk[2 * PMK_LEN];
41 @@ -3116,9 +3131,12 @@ SM_STEP(WPA_PTK)
42                 SM_ENTER(WPA_PTK, AUTHENTICATION);
43         else if (sm->ReAuthenticationRequest)
44                 SM_ENTER(WPA_PTK, AUTHENTICATION2);
45 -       else if (sm->PTKRequest)
46 -               SM_ENTER(WPA_PTK, PTKSTART);
47 -       else switch (sm->wpa_ptk_state) {
48 +       else if (sm->PTKRequest) {
49 +               if (wpa_auth_sm_ptk_update(sm) < 0)
50 +                       SM_ENTER(WPA_PTK, DISCONNECTED);
51 +               else
52 +                       SM_ENTER(WPA_PTK, PTKSTART);
53 +       } else switch (sm->wpa_ptk_state) {
54         case WPA_PTK_INITIALIZE:
55                 break;
56         case WPA_PTK_DISCONNECT: