2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* hostapd - PMKSA cache for IEEE 802.11i RSN
|
2012-06-17 18:51:57 +02:00
|
|
|
* Copyright (c) 2004-2008, 2012, Jouni Malinen <j@w1.fi>
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "utils/includes.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
2009-11-29 19:03:28 +01:00
|
|
|
#include "eapol_auth/eapol_auth_sm.h"
|
2009-11-29 22:16:04 +01:00
|
|
|
#include "eapol_auth/eapol_auth_sm_i.h"
|
2015-01-16 14:55:39 +01:00
|
|
|
#include "radius/radius_das.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "sta_info.h"
|
|
|
|
#include "ap_config.h"
|
|
|
|
#include "pmksa_cache_auth.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
static const int pmksa_cache_max_entries = 1024;
|
|
|
|
static const int dot11RSNAConfigPMKLifetime = 43200;
|
|
|
|
|
|
|
|
struct rsn_pmksa_cache {
|
|
|
|
#define PMKID_HASH_SIZE 128
|
|
|
|
#define PMKID_HASH(pmkid) (unsigned int) ((pmkid)[0] & 0x7f)
|
|
|
|
struct rsn_pmksa_cache_entry *pmkid[PMKID_HASH_SIZE];
|
|
|
|
struct rsn_pmksa_cache_entry *pmksa;
|
|
|
|
int pmksa_count;
|
|
|
|
|
|
|
|
void (*free_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx);
|
|
|
|
void *ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa);
|
|
|
|
|
|
|
|
|
|
|
|
static void _pmksa_cache_free_entry(struct rsn_pmksa_cache_entry *entry)
|
|
|
|
{
|
|
|
|
os_free(entry->identity);
|
2012-06-17 18:51:57 +02:00
|
|
|
wpabuf_free(entry->cui);
|
2009-12-06 16:53:59 +01:00
|
|
|
#ifndef CONFIG_NO_RADIUS
|
2009-01-13 19:01:29 +01:00
|
|
|
radius_free_class(&entry->radius_class);
|
2009-12-06 16:53:59 +01:00
|
|
|
#endif /* CONFIG_NO_RADIUS */
|
2014-10-04 20:43:32 +02:00
|
|
|
bin_clear_free(entry, sizeof(*entry));
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-05 17:55:32 +02:00
|
|
|
void pmksa_cache_free_entry(struct rsn_pmksa_cache *pmksa,
|
|
|
|
struct rsn_pmksa_cache_entry *entry)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *pos, *prev;
|
2014-10-04 21:08:17 +02:00
|
|
|
unsigned int hash;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
pmksa->pmksa_count--;
|
|
|
|
pmksa->free_cb(entry, pmksa->ctx);
|
2014-10-04 21:08:17 +02:00
|
|
|
|
|
|
|
/* unlink from hash list */
|
|
|
|
hash = PMKID_HASH(entry->pmkid);
|
|
|
|
pos = pmksa->pmkid[hash];
|
2008-02-28 02:34:43 +01:00
|
|
|
prev = NULL;
|
|
|
|
while (pos) {
|
|
|
|
if (pos == entry) {
|
2014-10-04 21:08:17 +02:00
|
|
|
if (prev != NULL)
|
|
|
|
prev->hnext = entry->hnext;
|
|
|
|
else
|
|
|
|
pmksa->pmkid[hash] = entry->hnext;
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = pos;
|
|
|
|
pos = pos->hnext;
|
|
|
|
}
|
|
|
|
|
2014-10-04 21:08:17 +02:00
|
|
|
/* unlink from entry list */
|
2008-02-28 02:34:43 +01:00
|
|
|
pos = pmksa->pmksa;
|
|
|
|
prev = NULL;
|
|
|
|
while (pos) {
|
|
|
|
if (pos == entry) {
|
|
|
|
if (prev != NULL)
|
2014-10-04 21:08:17 +02:00
|
|
|
prev->next = entry->next;
|
2008-02-28 02:34:43 +01:00
|
|
|
else
|
2014-10-04 21:08:17 +02:00
|
|
|
pmksa->pmksa = entry->next;
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = pos;
|
|
|
|
pos = pos->next;
|
|
|
|
}
|
2014-10-04 21:08:17 +02:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
_pmksa_cache_free_entry(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache *pmksa = eloop_ctx;
|
2013-12-16 21:08:23 +01:00
|
|
|
struct os_reltime now;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2013-12-16 21:08:23 +01:00
|
|
|
os_get_reltime(&now);
|
2008-02-28 02:34:43 +01:00
|
|
|
while (pmksa->pmksa && pmksa->pmksa->expiration <= now.sec) {
|
|
|
|
wpa_printf(MSG_DEBUG, "RSN: expired PMKSA cache entry for "
|
2012-11-25 18:45:54 +01:00
|
|
|
MACSTR, MAC2STR(pmksa->pmksa->spa));
|
|
|
|
pmksa_cache_free_entry(pmksa, pmksa->pmksa);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pmksa_cache_set_expiration(pmksa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa)
|
|
|
|
{
|
|
|
|
int sec;
|
2013-12-16 21:08:23 +01:00
|
|
|
struct os_reltime now;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL);
|
|
|
|
if (pmksa->pmksa == NULL)
|
|
|
|
return;
|
2013-12-16 21:08:23 +01:00
|
|
|
os_get_reltime(&now);
|
2008-02-28 02:34:43 +01:00
|
|
|
sec = pmksa->pmksa->expiration - now.sec;
|
|
|
|
if (sec < 0)
|
|
|
|
sec = 0;
|
|
|
|
eloop_register_timeout(sec + 1, 0, pmksa_cache_expire, pmksa, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pmksa_cache_from_eapol_data(struct rsn_pmksa_cache_entry *entry,
|
|
|
|
struct eapol_state_machine *eapol)
|
|
|
|
{
|
|
|
|
if (eapol == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (eapol->identity) {
|
|
|
|
entry->identity = os_malloc(eapol->identity_len);
|
|
|
|
if (entry->identity) {
|
|
|
|
entry->identity_len = eapol->identity_len;
|
|
|
|
os_memcpy(entry->identity, eapol->identity,
|
|
|
|
eapol->identity_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 18:51:57 +02:00
|
|
|
if (eapol->radius_cui)
|
|
|
|
entry->cui = wpabuf_dup(eapol->radius_cui);
|
|
|
|
|
2009-12-06 16:53:59 +01:00
|
|
|
#ifndef CONFIG_NO_RADIUS
|
2009-01-13 19:01:29 +01:00
|
|
|
radius_copy_class(&entry->radius_class, &eapol->radius_class);
|
2009-12-06 16:53:59 +01:00
|
|
|
#endif /* CONFIG_NO_RADIUS */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
entry->eap_type_authsrv = eapol->eap_type_authsrv;
|
2009-11-29 18:40:47 +01:00
|
|
|
entry->vlan_id = ((struct sta_info *) eapol->sta)->vlan_id;
|
2014-10-18 09:20:24 +02:00
|
|
|
|
|
|
|
entry->acct_multi_session_id_hi = eapol->acct_multi_session_id_hi;
|
|
|
|
entry->acct_multi_session_id_lo = eapol->acct_multi_session_id_lo;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void pmksa_cache_to_eapol_data(struct rsn_pmksa_cache_entry *entry,
|
|
|
|
struct eapol_state_machine *eapol)
|
|
|
|
{
|
|
|
|
if (entry == NULL || eapol == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (entry->identity) {
|
|
|
|
os_free(eapol->identity);
|
|
|
|
eapol->identity = os_malloc(entry->identity_len);
|
|
|
|
if (eapol->identity) {
|
|
|
|
eapol->identity_len = entry->identity_len;
|
|
|
|
os_memcpy(eapol->identity, entry->identity,
|
|
|
|
entry->identity_len);
|
|
|
|
}
|
|
|
|
wpa_hexdump_ascii(MSG_DEBUG, "STA identity from PMKSA",
|
|
|
|
eapol->identity, eapol->identity_len);
|
|
|
|
}
|
|
|
|
|
2012-06-17 18:51:57 +02:00
|
|
|
if (entry->cui) {
|
|
|
|
wpabuf_free(eapol->radius_cui);
|
|
|
|
eapol->radius_cui = wpabuf_dup(entry->cui);
|
|
|
|
}
|
|
|
|
|
2009-12-06 16:53:59 +01:00
|
|
|
#ifndef CONFIG_NO_RADIUS
|
2009-01-13 19:01:29 +01:00
|
|
|
radius_free_class(&eapol->radius_class);
|
|
|
|
radius_copy_class(&eapol->radius_class, &entry->radius_class);
|
2009-12-06 16:53:59 +01:00
|
|
|
#endif /* CONFIG_NO_RADIUS */
|
2008-02-28 02:34:43 +01:00
|
|
|
if (eapol->radius_class.attr) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Copied %lu Class attribute(s) from "
|
|
|
|
"PMKSA", (unsigned long) eapol->radius_class.count);
|
|
|
|
}
|
|
|
|
|
|
|
|
eapol->eap_type_authsrv = entry->eap_type_authsrv;
|
2009-11-29 18:40:47 +01:00
|
|
|
((struct sta_info *) eapol->sta)->vlan_id = entry->vlan_id;
|
2014-10-18 09:20:24 +02:00
|
|
|
|
|
|
|
eapol->acct_multi_session_id_hi = entry->acct_multi_session_id_hi;
|
|
|
|
eapol->acct_multi_session_id_lo = entry->acct_multi_session_id_lo;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-03 19:17:58 +02:00
|
|
|
static void pmksa_cache_link_entry(struct rsn_pmksa_cache *pmksa,
|
|
|
|
struct rsn_pmksa_cache_entry *entry)
|
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *pos, *prev;
|
2014-10-04 21:08:17 +02:00
|
|
|
int hash;
|
2008-08-03 19:17:58 +02:00
|
|
|
|
|
|
|
/* Add the new entry; order by expiration time */
|
|
|
|
pos = pmksa->pmksa;
|
|
|
|
prev = NULL;
|
|
|
|
while (pos) {
|
|
|
|
if (pos->expiration > entry->expiration)
|
|
|
|
break;
|
|
|
|
prev = pos;
|
|
|
|
pos = pos->next;
|
|
|
|
}
|
|
|
|
if (prev == NULL) {
|
|
|
|
entry->next = pmksa->pmksa;
|
|
|
|
pmksa->pmksa = entry;
|
|
|
|
} else {
|
|
|
|
entry->next = prev->next;
|
|
|
|
prev->next = entry;
|
|
|
|
}
|
2014-10-04 21:08:17 +02:00
|
|
|
|
|
|
|
hash = PMKID_HASH(entry->pmkid);
|
|
|
|
entry->hnext = pmksa->pmkid[hash];
|
|
|
|
pmksa->pmkid[hash] = entry;
|
2008-08-03 19:17:58 +02:00
|
|
|
|
|
|
|
pmksa->pmksa_count++;
|
2013-01-12 16:21:50 +01:00
|
|
|
if (prev == NULL)
|
|
|
|
pmksa_cache_set_expiration(pmksa);
|
2008-08-03 19:17:58 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "RSN: added PMKSA cache entry for " MACSTR,
|
|
|
|
MAC2STR(entry->spa));
|
|
|
|
wpa_hexdump(MSG_DEBUG, "RSN: added PMKID", entry->pmkid, PMKID_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/**
|
2009-01-14 21:01:26 +01:00
|
|
|
* pmksa_cache_auth_add - Add a PMKSA cache entry
|
|
|
|
* @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
|
2008-02-28 02:34:43 +01:00
|
|
|
* @pmk: The new pairwise master key
|
|
|
|
* @pmk_len: PMK length in bytes, usually PMK_LEN (32)
|
2014-11-16 12:22:46 +01:00
|
|
|
* @kck: Key confirmation key or %NULL if not yet derived
|
|
|
|
* @kck_len: KCK length in bytes
|
2008-02-28 02:34:43 +01:00
|
|
|
* @aa: Authenticator address
|
|
|
|
* @spa: Supplicant address
|
|
|
|
* @session_timeout: Session timeout
|
|
|
|
* @eapol: Pointer to EAPOL state machine data
|
2008-08-31 21:57:28 +02:00
|
|
|
* @akmp: WPA_KEY_MGMT_* used in key derivation
|
2008-02-28 02:34:43 +01:00
|
|
|
* Returns: Pointer to the added PMKSA cache entry or %NULL on error
|
|
|
|
*
|
|
|
|
* This function create a PMKSA entry for a new PMK and adds it to the PMKSA
|
|
|
|
* cache. If an old entry is already in the cache for the same Supplicant,
|
|
|
|
* this entry will be replaced with the new entry. PMKID will be calculated
|
|
|
|
* based on the PMK.
|
|
|
|
*/
|
|
|
|
struct rsn_pmksa_cache_entry *
|
2009-01-14 21:01:26 +01:00
|
|
|
pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa,
|
|
|
|
const u8 *pmk, size_t pmk_len,
|
2014-11-16 12:22:46 +01:00
|
|
|
const u8 *kck, size_t kck_len,
|
|
|
|
const u8 *aa, const u8 *spa, int session_timeout,
|
|
|
|
struct eapol_state_machine *eapol, int akmp)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2008-08-03 19:17:58 +02:00
|
|
|
struct rsn_pmksa_cache_entry *entry, *pos;
|
2013-12-16 21:08:23 +01:00
|
|
|
struct os_reltime now;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (pmk_len > PMK_LEN)
|
|
|
|
return NULL;
|
|
|
|
|
2014-11-16 12:22:46 +01:00
|
|
|
if (wpa_key_mgmt_suite_b(akmp) && !kck)
|
|
|
|
return NULL;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
entry = os_zalloc(sizeof(*entry));
|
|
|
|
if (entry == NULL)
|
|
|
|
return NULL;
|
|
|
|
os_memcpy(entry->pmk, pmk, pmk_len);
|
|
|
|
entry->pmk_len = pmk_len;
|
2014-11-16 12:22:46 +01:00
|
|
|
if (wpa_key_mgmt_suite_b(akmp))
|
|
|
|
rsn_pmkid_suite_b(kck, kck_len, aa, spa, entry->pmkid);
|
|
|
|
else
|
|
|
|
rsn_pmkid(pmk, pmk_len, aa, spa, entry->pmkid,
|
|
|
|
wpa_key_mgmt_sha256(akmp));
|
2013-12-16 21:08:23 +01:00
|
|
|
os_get_reltime(&now);
|
2008-02-28 02:34:43 +01:00
|
|
|
entry->expiration = now.sec;
|
|
|
|
if (session_timeout > 0)
|
|
|
|
entry->expiration += session_timeout;
|
|
|
|
else
|
|
|
|
entry->expiration += dot11RSNAConfigPMKLifetime;
|
2008-08-31 21:57:28 +02:00
|
|
|
entry->akmp = akmp;
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memcpy(entry->spa, spa, ETH_ALEN);
|
|
|
|
pmksa_cache_from_eapol_data(entry, eapol);
|
|
|
|
|
|
|
|
/* Replace an old entry for the same STA (if found) with the new entry
|
|
|
|
*/
|
2009-01-14 21:01:26 +01:00
|
|
|
pos = pmksa_cache_auth_get(pmksa, spa, NULL);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (pos)
|
|
|
|
pmksa_cache_free_entry(pmksa, pos);
|
|
|
|
|
|
|
|
if (pmksa->pmksa_count >= pmksa_cache_max_entries && pmksa->pmksa) {
|
|
|
|
/* Remove the oldest entry to make room for the new entry */
|
|
|
|
wpa_printf(MSG_DEBUG, "RSN: removed the oldest PMKSA cache "
|
|
|
|
"entry (for " MACSTR ") to make room for new one",
|
|
|
|
MAC2STR(pmksa->pmksa->spa));
|
|
|
|
pmksa_cache_free_entry(pmksa, pmksa->pmksa);
|
|
|
|
}
|
|
|
|
|
2008-08-03 19:17:58 +02:00
|
|
|
pmksa_cache_link_entry(pmksa, entry);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct rsn_pmksa_cache_entry *
|
|
|
|
pmksa_cache_add_okc(struct rsn_pmksa_cache *pmksa,
|
|
|
|
const struct rsn_pmksa_cache_entry *old_entry,
|
|
|
|
const u8 *aa, const u8 *pmkid)
|
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *entry;
|
|
|
|
|
|
|
|
entry = os_zalloc(sizeof(*entry));
|
|
|
|
if (entry == NULL)
|
|
|
|
return NULL;
|
|
|
|
os_memcpy(entry->pmkid, pmkid, PMKID_LEN);
|
|
|
|
os_memcpy(entry->pmk, old_entry->pmk, old_entry->pmk_len);
|
|
|
|
entry->pmk_len = old_entry->pmk_len;
|
|
|
|
entry->expiration = old_entry->expiration;
|
|
|
|
entry->akmp = old_entry->akmp;
|
|
|
|
os_memcpy(entry->spa, old_entry->spa, ETH_ALEN);
|
|
|
|
entry->opportunistic = 1;
|
|
|
|
if (old_entry->identity) {
|
|
|
|
entry->identity = os_malloc(old_entry->identity_len);
|
|
|
|
if (entry->identity) {
|
|
|
|
entry->identity_len = old_entry->identity_len;
|
|
|
|
os_memcpy(entry->identity, old_entry->identity,
|
|
|
|
old_entry->identity_len);
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2012-06-17 18:51:57 +02:00
|
|
|
if (old_entry->cui)
|
|
|
|
entry->cui = wpabuf_dup(old_entry->cui);
|
2009-12-06 16:53:59 +01:00
|
|
|
#ifndef CONFIG_NO_RADIUS
|
2009-01-13 19:01:29 +01:00
|
|
|
radius_copy_class(&entry->radius_class, &old_entry->radius_class);
|
2009-12-06 16:53:59 +01:00
|
|
|
#endif /* CONFIG_NO_RADIUS */
|
2008-08-03 19:17:58 +02:00
|
|
|
entry->eap_type_authsrv = old_entry->eap_type_authsrv;
|
|
|
|
entry->vlan_id = old_entry->vlan_id;
|
|
|
|
entry->opportunistic = 1;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2008-08-03 19:17:58 +02:00
|
|
|
pmksa_cache_link_entry(pmksa, entry);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-14 21:01:26 +01:00
|
|
|
* pmksa_cache_auth_deinit - Free all entries in PMKSA cache
|
|
|
|
* @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
2009-01-14 21:01:26 +01:00
|
|
|
void pmksa_cache_auth_deinit(struct rsn_pmksa_cache *pmksa)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *entry, *prev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pmksa == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry = pmksa->pmksa;
|
|
|
|
while (entry) {
|
|
|
|
prev = entry;
|
|
|
|
entry = entry->next;
|
|
|
|
_pmksa_cache_free_entry(prev);
|
|
|
|
}
|
|
|
|
eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL);
|
2014-10-04 21:08:17 +02:00
|
|
|
pmksa->pmksa_count = 0;
|
|
|
|
pmksa->pmksa = NULL;
|
2008-02-28 02:34:43 +01:00
|
|
|
for (i = 0; i < PMKID_HASH_SIZE; i++)
|
|
|
|
pmksa->pmkid[i] = NULL;
|
|
|
|
os_free(pmksa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-14 21:01:26 +01:00
|
|
|
* pmksa_cache_auth_get - Fetch a PMKSA cache entry
|
|
|
|
* @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
|
2008-02-28 02:34:43 +01:00
|
|
|
* @spa: Supplicant address or %NULL to match any
|
|
|
|
* @pmkid: PMKID or %NULL to match any
|
|
|
|
* Returns: Pointer to PMKSA cache entry or %NULL if no match was found
|
|
|
|
*/
|
2009-01-14 21:01:26 +01:00
|
|
|
struct rsn_pmksa_cache_entry *
|
|
|
|
pmksa_cache_auth_get(struct rsn_pmksa_cache *pmksa,
|
|
|
|
const u8 *spa, const u8 *pmkid)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *entry;
|
|
|
|
|
2014-10-04 21:08:17 +02:00
|
|
|
if (pmkid) {
|
|
|
|
for (entry = pmksa->pmkid[PMKID_HASH(pmkid)]; entry;
|
|
|
|
entry = entry->hnext) {
|
|
|
|
if ((spa == NULL ||
|
|
|
|
os_memcmp(entry->spa, spa, ETH_ALEN) == 0) &&
|
|
|
|
os_memcmp(entry->pmkid, pmkid, PMKID_LEN) == 0)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (entry = pmksa->pmksa; entry; entry = entry->next) {
|
|
|
|
if (spa == NULL ||
|
|
|
|
os_memcmp(entry->spa, spa, ETH_ALEN) == 0)
|
|
|
|
return entry;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2014-10-04 21:08:17 +02:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-03 19:17:58 +02:00
|
|
|
/**
|
|
|
|
* pmksa_cache_get_okc - Fetch a PMKSA cache entry using OKC
|
2009-01-14 21:01:26 +01:00
|
|
|
* @pmksa: Pointer to PMKSA cache data from pmksa_cache_auth_init()
|
2009-01-02 21:28:04 +01:00
|
|
|
* @aa: Authenticator address
|
2008-08-03 19:17:58 +02:00
|
|
|
* @spa: Supplicant address
|
|
|
|
* @pmkid: PMKID
|
|
|
|
* Returns: Pointer to PMKSA cache entry or %NULL if no match was found
|
|
|
|
*
|
|
|
|
* Use opportunistic key caching (OKC) to find a PMK for a supplicant.
|
|
|
|
*/
|
|
|
|
struct rsn_pmksa_cache_entry * pmksa_cache_get_okc(
|
|
|
|
struct rsn_pmksa_cache *pmksa, const u8 *aa, const u8 *spa,
|
|
|
|
const u8 *pmkid)
|
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *entry;
|
|
|
|
u8 new_pmkid[PMKID_LEN];
|
|
|
|
|
2014-10-04 21:11:00 +02:00
|
|
|
for (entry = pmksa->pmksa; entry; entry = entry->next) {
|
2008-08-03 19:17:58 +02:00
|
|
|
if (os_memcmp(entry->spa, spa, ETH_ALEN) != 0)
|
|
|
|
continue;
|
2008-08-31 21:57:28 +02:00
|
|
|
rsn_pmkid(entry->pmk, entry->pmk_len, aa, spa, new_pmkid,
|
|
|
|
wpa_key_mgmt_sha256(entry->akmp));
|
2008-08-03 19:17:58 +02:00
|
|
|
if (os_memcmp(new_pmkid, pmkid, PMKID_LEN) == 0)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/**
|
2009-01-14 21:01:26 +01:00
|
|
|
* pmksa_cache_auth_init - Initialize PMKSA cache
|
2008-02-28 02:34:43 +01:00
|
|
|
* @free_cb: Callback function to be called when a PMKSA cache entry is freed
|
|
|
|
* @ctx: Context pointer for free_cb function
|
|
|
|
* Returns: Pointer to PMKSA cache data or %NULL on failure
|
|
|
|
*/
|
|
|
|
struct rsn_pmksa_cache *
|
2009-01-14 21:01:26 +01:00
|
|
|
pmksa_cache_auth_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
|
|
|
|
void *ctx), void *ctx)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache *pmksa;
|
|
|
|
|
|
|
|
pmksa = os_zalloc(sizeof(*pmksa));
|
|
|
|
if (pmksa) {
|
|
|
|
pmksa->free_cb = free_cb;
|
|
|
|
pmksa->ctx = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pmksa;
|
|
|
|
}
|
2015-01-16 14:55:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
static int das_attr_match(struct rsn_pmksa_cache_entry *entry,
|
|
|
|
struct radius_das_attrs *attr)
|
|
|
|
{
|
|
|
|
int match = 0;
|
|
|
|
|
|
|
|
if (attr->sta_addr) {
|
|
|
|
if (os_memcmp(attr->sta_addr, entry->spa, ETH_ALEN) != 0)
|
|
|
|
return 0;
|
|
|
|
match++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr->acct_multi_session_id) {
|
|
|
|
char buf[20];
|
|
|
|
|
|
|
|
if (attr->acct_multi_session_id_len != 17)
|
|
|
|
return 0;
|
|
|
|
os_snprintf(buf, sizeof(buf), "%08X+%08X",
|
|
|
|
entry->acct_multi_session_id_hi,
|
|
|
|
entry->acct_multi_session_id_lo);
|
|
|
|
if (os_memcmp(attr->acct_multi_session_id, buf, 17) != 0)
|
|
|
|
return 0;
|
|
|
|
match++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr->cui) {
|
|
|
|
if (!entry->cui ||
|
|
|
|
attr->cui_len != wpabuf_len(entry->cui) ||
|
|
|
|
os_memcmp(attr->cui, wpabuf_head(entry->cui),
|
|
|
|
attr->cui_len) != 0)
|
|
|
|
return 0;
|
|
|
|
match++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr->user_name) {
|
|
|
|
if (!entry->identity ||
|
|
|
|
attr->user_name_len != entry->identity_len ||
|
|
|
|
os_memcmp(attr->user_name, entry->identity,
|
|
|
|
attr->user_name_len) != 0)
|
|
|
|
return 0;
|
|
|
|
match++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int pmksa_cache_auth_radius_das_disconnect(struct rsn_pmksa_cache *pmksa,
|
|
|
|
struct radius_das_attrs *attr)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
struct rsn_pmksa_cache_entry *entry, *prev;
|
|
|
|
|
|
|
|
if (attr->acct_session_id)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
entry = pmksa->pmksa;
|
|
|
|
while (entry) {
|
|
|
|
if (das_attr_match(entry, attr)) {
|
|
|
|
found++;
|
|
|
|
prev = entry;
|
|
|
|
entry = entry->next;
|
|
|
|
pmksa_cache_free_entry(pmksa, prev);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entry = entry->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found ? 0 : -1;
|
|
|
|
}
|