3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-23 06:02:37 +01:00

nl80211: added verifier/parser for GET_KEY

AdHoc will also need the same functionality to verify and parse the
key sequence from GET_KEY. This block of code was moved from AP's
GET_KEY callback into nl80211_parse_get_key_seq.
This commit is contained in:
James Prestwood 2018-10-08 13:44:11 -07:00 committed by Denis Kenzior
parent 60aba7114e
commit 5e5caedb90
3 changed files with 50 additions and 37 deletions

View File

@ -453,48 +453,15 @@ error:
static void ap_gtk_query_cb(struct l_genl_msg *msg, void *user_data) static void ap_gtk_query_cb(struct l_genl_msg *msg, void *user_data)
{ {
struct sta_state *sta = user_data; struct sta_state *sta = user_data;
struct l_genl_attr attr, nested; const void *gtk_rsc;
uint16_t type, len;
const void *data;
sta->gtk_query_cmd_id = 0; sta->gtk_query_cmd_id = 0;
if (l_genl_msg_get_error(msg) < 0 || !l_genl_attr_init(&attr, msg)) { gtk_rsc = nl80211_parse_get_key_seq(msg);
l_error("GET_KEY failed for the GTK: %i", if (!gtk_rsc)
l_genl_msg_get_error(msg));
goto error; goto error;
}
while (l_genl_attr_next(&attr, &type, &len, &data)) { ap_start_rsna(sta, gtk_rsc);
if (type != NL80211_ATTR_KEY)
continue;
break;
}
if (type != NL80211_ATTR_KEY || !l_genl_attr_recurse(&attr, &nested)) {
l_error("Can't recurse into ATTR_KEY in GET_KEY reply");
goto error;
}
while (l_genl_attr_next(&nested, &type, &len, &data)) {
if (type != NL80211_KEY_SEQ)
continue;
break;
}
if (type != NL80211_KEY_SEQ) {
l_error("KEY_SEQ not returned in GET_KEY reply");
goto error;
}
if (len != 6) {
l_error("KEY_SEQ length != 6 in GET_KEY reply");
goto error;
}
ap_start_rsna(sta, data);
return; return;
error: error:

View File

@ -133,3 +133,47 @@ struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index)
return msg; return msg;
} }
const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg)
{
struct l_genl_attr attr, nested;
uint16_t type, len;
const void *data;
if (l_genl_msg_get_error(msg) < 0 || !l_genl_attr_init(&attr, msg)) {
l_error("GET_KEY failed for the GTK: %i",
l_genl_msg_get_error(msg));
return NULL;
}
while (l_genl_attr_next(&attr, &type, &len, &data)) {
if (type != NL80211_ATTR_KEY)
continue;
break;
}
if (type != NL80211_ATTR_KEY || !l_genl_attr_recurse(&attr, &nested)) {
l_error("Can't recurse into ATTR_KEY in GET_KEY reply");
return NULL;
}
while (l_genl_attr_next(&nested, &type, &len, &data)) {
if (type != NL80211_KEY_SEQ)
continue;
break;
}
if (type != NL80211_KEY_SEQ) {
l_error("KEY_SEQ not returned in GET_KEY reply");
return NULL;
}
if (len != 6) {
l_error("KEY_SEQ length != 6 in GET_KEY reply");
return NULL;
}
return data;
}

View File

@ -39,3 +39,5 @@ struct l_genl_msg *nl80211_build_set_station_unauthorized(uint32_t ifindex,
struct l_genl_msg *nl80211_build_set_key(uint32_t ifindex, uint8_t key_index); struct l_genl_msg *nl80211_build_set_key(uint32_t ifindex, uint8_t key_index);
struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index); struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index);
const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg);