From 99cdb860c031acce2e212834d5ba3258a7c628a6 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 21 May 2015 21:10:21 -0500 Subject: [PATCH] eapol: Simplify install_tk callback --- src/eapol.c | 10 ++++++++-- src/eapol.h | 2 +- src/wiphy.c | 29 +++++------------------------ 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/eapol.c b/src/eapol.c index a1e4baac..864a821c 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -1003,6 +1003,7 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex, const uint8_t *rsne; const uint8_t *optional_rsne = NULL; uint8_t gtk_key_index; + enum ie_rsn_cipher_suite pairwise = sm->pairwise_cipher; if (!eapol_verify_ptk_3_of_4(ek, sm->wpa_ie)) { handshake_failed(ifindex, sm, MPDU_REASON_CODE_UNSPECIFIED); @@ -1100,6 +1101,8 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex, MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); return; } + + pairwise = override; } /* @@ -1141,8 +1144,11 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex, sm->ptk_complete = true; - if (install_tk) - install_tk(sm->ifindex, sm->aa, ptk->tk, rsne, sm->user_data); + if (install_tk) { + uint32_t cipher = ie_rsn_cipher_suite_to_cipher(pairwise); + + install_tk(sm->ifindex, sm->aa, ptk->tk, cipher, sm->user_data); + } if (gtk && install_gtk) { uint32_t cipher = diff --git a/src/eapol.h b/src/eapol.h index 6d71a7de..d96b4855 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -100,7 +100,7 @@ typedef int (*eapol_tx_packet_func_t)(uint32_t ifindex, const uint8_t *aa, void *user_data); typedef bool (*eapol_get_nonce_func_t)(uint8_t nonce[]); typedef void (*eapol_install_tk_func_t)(uint32_t ifindex, const uint8_t *aa, - const uint8_t *tk, const uint8_t *rsn, + const uint8_t *tk, uint32_t cipher, void *user_data); typedef void (*eapol_install_gtk_func_t)(uint32_t ifindex, uint8_t key_index, const uint8_t *gtk, uint8_t gtk_len, diff --git a/src/wiphy.c b/src/wiphy.c index f53f876e..011f8f2f 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -965,39 +965,20 @@ static unsigned int mlme_new_pairwise_key(struct netdev *netdev, } static void wiphy_set_tk(uint32_t ifindex, const uint8_t *aa, - const uint8_t *tk, const uint8_t *rsn, + const uint8_t *tk, uint32_t cipher, void *user_data) { struct netdev *netdev = user_data; struct network *network = netdev->connected_network; - struct wiphy *wiphy = netdev->wiphy; - struct ie_rsn_info info; - enum crypto_cipher cipher; - int result; uint8_t tk_buf[32]; l_debug(""); - if (rsn[0] == IE_TYPE_RSN) - result = ie_parse_rsne_from_data(rsn, rsn[1] + 2, &info); - else if (rsn[0] == IE_TYPE_VENDOR_SPECIFIC) - result = ie_parse_wpa_from_data(rsn, rsn[1] + 2, &info); - else - result = -1; - - if (result) { - l_error("Can't parse the RSN"); - setting_keys_failed(netdev, MPDU_REASON_CODE_INVALID_IE); - return; - } - - switch (wiphy_select_cipher(wiphy, info.pairwise_ciphers)) { - case IE_RSN_CIPHER_SUITE_CCMP: - cipher = CRYPTO_CIPHER_CCMP; + switch (cipher) { + case CRYPTO_CIPHER_CCMP: memcpy(tk_buf, tk, 16); break; - case IE_RSN_CIPHER_SUITE_TKIP: - cipher = CRYPTO_CIPHER_TKIP; + case CRYPTO_CIPHER_TKIP: /* * Swap the TX and RX MIC key portions for supplicant. * WPA_80211_v3_1_090922 doc's 3.3.4: @@ -1014,7 +995,7 @@ static void wiphy_set_tk(uint32_t ifindex, const uint8_t *aa, memcpy(tk_buf + 24, tk + 16, 8); break; default: - l_error("Unexpected cipher suite: %d", info.pairwise_ciphers); + l_error("Unexpected cipher: %x", cipher); setting_keys_failed(netdev, MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); return;