From 5e5caedb90f3f1f91d17991e12a6bee54058a0e7 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Mon, 8 Oct 2018 13:44:11 -0700 Subject: [PATCH] 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. --- src/ap.c | 41 ++++------------------------------------- src/nl80211_util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/nl80211_util.h | 2 ++ 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/ap.c b/src/ap.c index cb0d1a54..8a05f19d 100644 --- a/src/ap.c +++ b/src/ap.c @@ -453,48 +453,15 @@ error: static void ap_gtk_query_cb(struct l_genl_msg *msg, void *user_data) { struct sta_state *sta = user_data; - struct l_genl_attr attr, nested; - uint16_t type, len; - const void *data; + const void *gtk_rsc; sta->gtk_query_cmd_id = 0; - 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)); + gtk_rsc = nl80211_parse_get_key_seq(msg); + if (!gtk_rsc) goto error; - } - 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"); - 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); + ap_start_rsna(sta, gtk_rsc); return; error: diff --git a/src/nl80211_util.c b/src/nl80211_util.c index ef2ac53f..534a8cd9 100644 --- a/src/nl80211_util.c +++ b/src/nl80211_util.c @@ -133,3 +133,47 @@ struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index) 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; +} diff --git a/src/nl80211_util.h b/src/nl80211_util.h index 63e0b3ed..abffc66d 100644 --- a/src/nl80211_util.h +++ b/src/nl80211_util.h @@ -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_get_key(uint32_t ifindex, uint8_t key_index); + +const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg);