009-Fix-PTK-rekeying-to-generate-a-new-ANonce.patch 1.6 KB

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