eapol: Simplify install_tk callback

This commit is contained in:
Denis Kenzior 2015-05-21 21:10:21 -05:00
parent e93dd44607
commit 99cdb860c0
3 changed files with 14 additions and 27 deletions

View File

@ -1003,6 +1003,7 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex,
const uint8_t *rsne; const uint8_t *rsne;
const uint8_t *optional_rsne = NULL; const uint8_t *optional_rsne = NULL;
uint8_t gtk_key_index; 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)) { if (!eapol_verify_ptk_3_of_4(ek, sm->wpa_ie)) {
handshake_failed(ifindex, sm, MPDU_REASON_CODE_UNSPECIFIED); 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); MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER);
return; return;
} }
pairwise = override;
} }
/* /*
@ -1141,8 +1144,11 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex,
sm->ptk_complete = true; sm->ptk_complete = true;
if (install_tk) if (install_tk) {
install_tk(sm->ifindex, sm->aa, ptk->tk, rsne, sm->user_data); 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) { if (gtk && install_gtk) {
uint32_t cipher = uint32_t cipher =

View File

@ -100,7 +100,7 @@ typedef int (*eapol_tx_packet_func_t)(uint32_t ifindex, const uint8_t *aa,
void *user_data); void *user_data);
typedef bool (*eapol_get_nonce_func_t)(uint8_t nonce[]); typedef bool (*eapol_get_nonce_func_t)(uint8_t nonce[]);
typedef void (*eapol_install_tk_func_t)(uint32_t ifindex, const uint8_t *aa, 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); void *user_data);
typedef void (*eapol_install_gtk_func_t)(uint32_t ifindex, uint8_t key_index, typedef void (*eapol_install_gtk_func_t)(uint32_t ifindex, uint8_t key_index,
const uint8_t *gtk, uint8_t gtk_len, const uint8_t *gtk, uint8_t gtk_len,

View File

@ -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, 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) void *user_data)
{ {
struct netdev *netdev = user_data; struct netdev *netdev = user_data;
struct network *network = netdev->connected_network; 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]; uint8_t tk_buf[32];
l_debug(""); l_debug("");
if (rsn[0] == IE_TYPE_RSN) switch (cipher) {
result = ie_parse_rsne_from_data(rsn, rsn[1] + 2, &info); case CRYPTO_CIPHER_CCMP:
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;
memcpy(tk_buf, tk, 16); memcpy(tk_buf, tk, 16);
break; break;
case IE_RSN_CIPHER_SUITE_TKIP: case CRYPTO_CIPHER_TKIP:
cipher = CRYPTO_CIPHER_TKIP;
/* /*
* Swap the TX and RX MIC key portions for supplicant. * Swap the TX and RX MIC key portions for supplicant.
* WPA_80211_v3_1_090922 doc's 3.3.4: * 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); memcpy(tk_buf + 24, tk + 16, 8);
break; break;
default: default:
l_error("Unexpected cipher suite: %d", info.pairwise_ciphers); l_error("Unexpected cipher: %x", cipher);
setting_keys_failed(netdev, setting_keys_failed(netdev,
MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER); MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER);
return; return;