Add a callback to notify added PMKSA cache entry details

Add a callback handler to notify details of a PMKSA cache entry when it
is added to the PMKSA cache. This can be used to provide external
components more convenient access to the PMKSA cache contents.

Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
This commit is contained in:
Vinay Gannevaram 2022-11-20 19:27:51 +05:30 committed by Jouni Malinen
parent e174ec7a07
commit 46e6b72b7b
8 changed files with 55 additions and 1 deletions

View file

@ -28,6 +28,7 @@ struct rsn_pmksa_cache {
enum pmksa_free_reason reason);
bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx);
void (*notify_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx);
void *ctx;
};
@ -360,6 +361,9 @@ pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
if (!pmksa->sm)
return entry;
if (pmksa->notify_cb)
pmksa->notify_cb(entry, pmksa->ctx);
wpa_sm_add_pmkid(pmksa->sm, entry->network_ctx, entry->aa, entry->pmkid,
entry->fils_cache_id_set ? entry->fils_cache_id : NULL,
entry->pmk, entry->pmk_len,
@ -754,6 +758,8 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx, enum pmksa_free_reason reason),
bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),
void (*notify_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),
void *ctx, struct wpa_sm *sm)
{
struct rsn_pmksa_cache *pmksa;
@ -762,6 +768,7 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
if (pmksa) {
pmksa->free_cb = free_cb;
pmksa->is_current_cb = is_current_cb;
pmksa->notify_cb = notify_cb;
pmksa->ctx = ctx;
pmksa->sm = sm;
}

View file

@ -62,6 +62,8 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx, enum pmksa_free_reason reason),
bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),
void (*notify_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),
void *ctx, struct wpa_sm *sm);
void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
@ -101,6 +103,8 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx, enum pmksa_free_reason reason),
bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),
void (*notify_cb)(struct rsn_pmksa_cache_entry *entry,
void *ctx),
void *ctx, struct wpa_sm *sm)
{
return (void *) -1;

View file

@ -3969,6 +3969,15 @@ static bool wpa_sm_pmksa_is_current_cb(struct rsn_pmksa_cache_entry *entry,
}
static void wpa_sm_pmksa_notify_cb(struct rsn_pmksa_cache_entry *entry,
void *ctx)
{
struct wpa_sm *sm = ctx;
wpa_sm_notify_pmksa_cache_entry(sm, entry);
}
/**
* wpa_sm_init - Initialize WPA state machine
* @ctx: Context pointer for callbacks; this needs to be an allocated buffer
@ -3993,7 +4002,8 @@ struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
sm->dot11RSNAConfigSATimeout = 60;
sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb,
wpa_sm_pmksa_is_current_cb, sm, sm);
wpa_sm_pmksa_is_current_cb,
wpa_sm_pmksa_notify_cb, sm, sm);
if (sm->pmksa == NULL) {
wpa_msg(sm->ctx->msg_ctx, MSG_ERROR,
"RSN: PMKSA cache initialization failed");

View file

@ -19,6 +19,7 @@ struct eapol_sm;
struct wpa_config_blob;
struct hostapd_freq_params;
struct wpa_channel_info;
struct rsn_pmksa_cache_entry;
enum frame_encryption;
struct wpa_sm_ctx {
@ -98,6 +99,8 @@ struct wpa_sm_ctx {
const u8 *peer_addr, size_t ltf_keyseed_len,
const u8 *ltf_keyseed);
#endif /* CONFIG_PASN */
void (*notify_pmksa_cache_entry)(void *ctx,
struct rsn_pmksa_cache_entry *entry);
};

View file

@ -497,6 +497,14 @@ static inline int wpa_sm_set_ltf_keyseed(struct wpa_sm *sm, const u8 *own_addr,
}
#endif /* CONFIG_PASN */
static inline void
wpa_sm_notify_pmksa_cache_entry(struct wpa_sm *sm,
struct rsn_pmksa_cache_entry *entry)
{
if (sm->ctx->notify_pmksa_cache_entry)
sm->ctx->notify_pmksa_cache_entry(sm->ctx->ctx, entry);
}
int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk,
int ver, const u8 *dest, u16 proto,
u8 *msg, size_t msg_len, u8 *key_mic);

View file

@ -17,6 +17,7 @@
#include "dbus/dbus_common.h"
#include "dbus/dbus_new.h"
#include "rsn_supp/wpa.h"
#include "rsn_supp/pmksa_cache.h"
#include "fst/fst.h"
#include "crypto/tls.h"
#include "bss.h"
@ -976,3 +977,10 @@ void wpas_notify_interworking_select_done(struct wpa_supplicant *wpa_s)
}
#endif /* CONFIG_INTERWORKING */
void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s,
struct rsn_pmksa_cache_entry *entry)
{
/* TODO: Notify external entities of the added PMKSA cache entry */
}

View file

@ -16,6 +16,7 @@ struct wps_event_m2d;
struct wps_event_fail;
struct tls_cert_data;
struct wpa_cred;
struct rsn_pmksa_cache_entry;
int wpas_notify_supplicant_initialized(struct wpa_global *global);
void wpas_notify_supplicant_deinitialized(struct wpa_global *global);
@ -163,5 +164,7 @@ void wpas_notify_interworking_ap_added(struct wpa_supplicant *wpa_s,
const char *type, int bh, int bss_load,
int conn_capab);
void wpas_notify_interworking_select_done(struct wpa_supplicant *wpa_s);
void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s,
struct rsn_pmksa_cache_entry *entry);
#endif /* NOTIFY_H */

View file

@ -1381,6 +1381,16 @@ static int wpa_supplicant_set_ltf_keyseed(void *_wpa_s, const u8 *own_addr,
#endif /* CONFIG_PASN */
static void
wpa_supplicant_notify_pmksa_cache_entry(void *_wpa_s,
struct rsn_pmksa_cache_entry *entry)
{
struct wpa_supplicant *wpa_s = _wpa_s;
wpas_notify_pmk_cache_added(wpa_s, entry);
}
int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
{
#ifndef CONFIG_NO_WPA
@ -1446,6 +1456,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
#ifdef CONFIG_PASN
ctx->set_ltf_keyseed = wpa_supplicant_set_ltf_keyseed;
#endif /* CONFIG_PASN */
ctx->notify_pmksa_cache_entry = wpa_supplicant_notify_pmksa_cache_entry;
wpa_s->wpa = wpa_sm_init(ctx);
if (wpa_s->wpa == NULL) {