From 221519dea30870c35d7a67cfd9eb7fbce5daa681 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 21 Nov 2010 13:19:43 +0200 Subject: [PATCH] wlantest: Derive PMK to existing BSSes when a new passphrase is added --- wlantest/bss.c | 41 +++++++++++++++++++++++++---------------- wlantest/ctrl.c | 10 +++++++++- wlantest/wlantest.h | 2 ++ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/wlantest/bss.c b/wlantest/bss.c index b3a744153..88064a5e5 100644 --- a/wlantest/bss.c +++ b/wlantest/bss.c @@ -78,10 +78,33 @@ void bss_deinit(struct wlantest_bss *bss) } +int bss_add_pmk_from_passphrase(struct wlantest_bss *bss, + const char *passphrase) +{ + struct wlantest_pmk *pmk; + + pmk = os_zalloc(sizeof(*pmk)); + if (pmk == NULL) + return -1; + if (pbkdf2_sha1(passphrase, (char *) bss->ssid, bss->ssid_len, 4096, + pmk->pmk, sizeof(pmk->pmk)) < 0) { + os_free(pmk); + return -1; + } + + wpa_printf(MSG_INFO, "Add possible PMK for BSSID " MACSTR + " based on passphrase '%s'", + MAC2STR(bss->bssid), passphrase); + wpa_hexdump(MSG_DEBUG, "Possible PMK", pmk->pmk, sizeof(pmk->pmk)); + dl_list_add(&bss->pmk, &pmk->list); + + return 0; +} + + static void bss_add_pmk(struct wlantest *wt, struct wlantest_bss *bss) { struct wlantest_passphrase *p; - struct wlantest_pmk *pmk; dl_list_for_each(p, &wt->passphrase, struct wlantest_passphrase, list) { @@ -93,22 +116,8 @@ static void bss_add_pmk(struct wlantest *wt, struct wlantest_bss *bss) os_memcmp(p->ssid, bss->ssid, p->ssid_len) != 0)) continue; - pmk = os_zalloc(sizeof(*pmk)); - if (pmk == NULL) + if (bss_add_pmk_from_passphrase(bss, p->passphrase) < 0) break; - if (pbkdf2_sha1(p->passphrase, (char *) bss->ssid, - bss->ssid_len, 4096, - pmk->pmk, sizeof(pmk->pmk)) < 0) { - os_free(pmk); - continue; - } - - wpa_printf(MSG_INFO, "Add possible PMK for BSSID " MACSTR - " based on passphrase '%s'", - MAC2STR(bss->bssid), p->passphrase); - wpa_hexdump(MSG_DEBUG, "Possible PMK", - pmk->pmk, sizeof(pmk->pmk)); - dl_list_add(&bss->pmk, &pmk->list); } } diff --git a/wlantest/ctrl.c b/wlantest/ctrl.c index ac6efe911..76dd40847 100644 --- a/wlantest/ctrl.c +++ b/wlantest/ctrl.c @@ -726,8 +726,16 @@ static void ctrl_add_passphrase(struct wlantest *wt, int sock, u8 *cmd, } } - if (p) + if (p) { + struct wlantest_bss *bss; dl_list_add(&wt->passphrase, &p->list); + dl_list_for_each(bss, &wt->bss, struct wlantest_bss, list) { + if (bssid && + os_memcmp(p->bssid, bss->bssid, ETH_ALEN) != 0) + continue; + bss_add_pmk_from_passphrase(bss, p->passphrase); + } + } ctrl_send_simple(wt, sock, WLANTEST_CTRL_SUCCESS); } diff --git a/wlantest/wlantest.h b/wlantest/wlantest.h index 444855836..4899659c0 100644 --- a/wlantest/wlantest.h +++ b/wlantest/wlantest.h @@ -169,6 +169,8 @@ void bss_deinit(struct wlantest_bss *bss); void bss_update(struct wlantest *wt, struct wlantest_bss *bss, struct ieee802_11_elems *elems); void bss_flush(struct wlantest *wt); +int bss_add_pmk_from_passphrase(struct wlantest_bss *bss, + const char *passphrase); void pmk_deinit(struct wlantest_pmk *pmk); struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr);