station, eapol: Set up eap-tls-common for session caching

Use eap_set_peer_id() to set a string identifying the TLS server,
currently the hex-encoded SSID of the network, to be used as group name
and primary key in the session cache l_settings object.  Provide pointers
to storage_eap_tls_cache_{load,sync} to eap-tls-common.c using
eap_tls_set_session_cache_ops().  Listen to Known Network removed
signals and call eap_tls_forget_peer() to have any session related to
the network also dropped from the cache.
This commit is contained in:
Andrew Zaborowski 2022-11-17 14:56:10 +01:00 committed by Denis Kenzior
parent ef81917e8d
commit a793a41662
2 changed files with 34 additions and 0 deletions

View File

@ -2770,6 +2770,8 @@ void eapol_register(struct eapol_sm *sm)
bool eapol_start(struct eapol_sm *sm)
{
if (sm->handshake->settings_8021x) {
_auto_(l_free) char *network_id = NULL;
sm->eap = eap_new(eapol_eap_msg_cb, eapol_eap_complete_cb, sm);
if (!sm->eap)
@ -2785,6 +2787,10 @@ bool eapol_start(struct eapol_sm *sm)
eap_set_key_material_func(sm->eap, eapol_eap_results_cb);
eap_set_event_func(sm->eap, eapol_eap_event_cb);
network_id = l_util_hexstring(sm->handshake->ssid,
sm->handshake->ssid_len);
eap_set_peer_id(sm->eap, network_id);
}
sm->started = true;

View File

@ -60,6 +60,9 @@
#include "src/sysfs.h"
#include "src/band.h"
#include "src/ft.h"
#include "src/eap.h"
#include "src/eap-tls-common.h"
#include "src/storage.h"
static struct l_queue *station_list;
static uint32_t netdev_watch;
@ -69,6 +72,7 @@ static bool anqp_disabled;
static bool supports_arp_evict_nocarrier;
static bool supports_ndisc_evict_nocarrier;
static struct watchlist event_watches;
static uint32_t known_networks_watch;
struct station {
enum station_state state;
@ -5087,6 +5091,22 @@ static void station_netdev_watch(struct netdev *netdev,
}
}
static void station_known_networks_changed(enum known_networks_event event,
const struct network_info *info,
void *user_data)
{
_auto_(l_free) char *network_id = NULL;
if (event != KNOWN_NETWORKS_EVENT_REMOVED)
return;
if (info->type != SECURITY_8021X)
return;
network_id = l_util_hexstring(info->ssid, strlen(info->ssid));
eap_tls_forget_peer(network_id);
}
static int station_init(void)
{
station_list = l_queue_new();
@ -5139,6 +5159,12 @@ static int station_init(void)
watchlist_init(&event_watches, NULL);
eap_tls_set_session_cache_ops(storage_eap_tls_cache_load,
storage_eap_tls_cache_sync);
known_networks_watch = known_networks_watch_add(
station_known_networks_changed,
NULL, NULL);
return 0;
}
@ -5154,6 +5180,8 @@ static void station_exit(void)
l_queue_destroy(station_list, NULL);
station_list = NULL;
watchlist_destroy(&event_watches);
known_networks_watch_remove(known_networks_watch);
known_networks_watch = 0;
}
IWD_MODULE(station, station_init, station_exit)