aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/pmksa_cache.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2005-12-13 02:35:30 (GMT)
committerJouni Malinen <j@w1.fi>2005-12-13 02:35:30 (GMT)
commit6c45f2e5c7f47d86c4b0f31863892cd4a6886750 (patch)
tree2a9211d16c7d4f988959de81e107f47cf6ff2e2c /hostapd/pmksa_cache.c
parentb297cf77df8d4e72e5c0a74c4209c2771c3e61d9 (diff)
downloadhostap-history-6c45f2e5c7f47d86c4b0f31863892cd4a6886750.zip
hostap-history-6c45f2e5c7f47d86c4b0f31863892cd4a6886750.tar.gz
hostap-history-6c45f2e5c7f47d86c4b0f31863892cd4a6886750.tar.bz2
Changed PMKSA cache implementation to be closer to wpa_supplicant
version.
Diffstat (limited to 'hostapd/pmksa_cache.c')
-rw-r--r--hostapd/pmksa_cache.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/hostapd/pmksa_cache.c b/hostapd/pmksa_cache.c
index 506898a..12a19c0 100644
--- a/hostapd/pmksa_cache.c
+++ b/hostapd/pmksa_cache.c
@@ -40,6 +40,15 @@ struct rsn_pmksa_cache {
};
+/**
+ * rsn_pmkid - Calculate PMK identifier
+ * @pmk: Pairwise master key
+ * @aa: Authenticator address
+ * @spa: Supplicant address
+ *
+ * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
+ * PMKID = HMAC-SHA1-128(PMK, "PMK Name" || AA || SPA)
+ */
static void rsn_pmkid(const u8 *pmk, const u8 *aa, const u8 *spa, u8 *pmkid)
{
char *title = "PMK Name";
@@ -112,10 +121,10 @@ static void pmksa_cache_free_entry(struct rsn_pmksa_cache *pmksa,
static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx)
{
struct rsn_pmksa_cache *pmksa = eloop_ctx;
- time_t now;
+ struct os_time now;
- time(&now);
- while (pmksa->pmksa && pmksa->pmksa->expiration <= now) {
+ os_get_time(&now);
+ while (pmksa->pmksa && pmksa->pmksa->expiration <= now.sec) {
struct rsn_pmksa_cache_entry *entry = pmksa->pmksa;
pmksa->pmksa = entry->next;
wpa_printf(MSG_DEBUG, "RSN: expired PMKSA cache entry for "
@@ -188,21 +197,37 @@ void pmksa_cache_to_eapol_data(struct rsn_pmksa_cache_entry *entry,
}
-int pmksa_cache_add(struct rsn_pmksa_cache *pmksa, struct sta_info *sta,
- const u8 *pmk, int session_timeout)
+/**
+ * pmksa_cache_add - Add a PMKSA cache entry
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ * @sta: Pointer to the station data
+ * @pmk: The new pairwise master key
+ * @session_timeout: Session timeout
+ * 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 *
+pmksa_cache_add(struct rsn_pmksa_cache *pmksa, struct sta_info *sta,
+ const u8 *pmk, int session_timeout)
{
struct rsn_pmksa_cache_entry *entry, *pos, *prev;
+ struct os_time now;
if (sta->wpa != WPA_VERSION_WPA2)
- return -1;
+ return NULL;
entry = malloc(sizeof(*entry));
if (entry == NULL)
- return -1;
+ return NULL;
memset(entry, 0, sizeof(*entry));
memcpy(entry->pmk, pmk, PMK_LEN);
rsn_pmkid(pmk, pmksa->own_addr, sta->addr, entry->pmkid);
- time(&entry->expiration);
+ os_get_time(&now);
+ entry->expiration = now.sec;
if (session_timeout > 0)
entry->expiration += session_timeout;
else
@@ -245,12 +270,18 @@ int pmksa_cache_add(struct rsn_pmksa_cache *pmksa, struct sta_info *sta,
pmksa->pmkid[PMKID_HASH(entry->pmkid)] = entry;
pmksa->pmksa_count++;
+ 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);
- return 0;
+ return entry;
}
+/**
+ * pmksa_cache_deinit - Free all entries in PMKSA cache
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ */
void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
{
struct rsn_pmksa_cache_entry *entry, *prev;
@@ -268,9 +299,17 @@ void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL);
for (i = 0; i < PMKID_HASH_SIZE; i++)
pmksa->pmkid[i] = NULL;
+ free(pmksa);
}
+/**
+ * pmksa_cache_get - Fetch a PMKSA cache entry
+ * @pmksa: Pointer to PMKSA cache data from pmksa_cache_init()
+ * @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
+ */
struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
const u8 *spa, const u8 *pmkid)
{
@@ -291,6 +330,13 @@ struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
}
+/**
+ * pmksa_cache_init - Initialize PMKSA cache
+ * @free_cb: Callback function to be called when a PMKSA cache entry is freed
+ * @ctx: Context pointer for free_cb function
+ * @own_addr: Own MAC address
+ * Returns: Pointer to PMKSA cache data or %NULL on failure
+ */
struct rsn_pmksa_cache *
pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),