mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-26 02:19:26 +01:00
storage: Refactor storage_tls_session_{load,sync}
Minor changes to these two methods resulting from two rewrites of them. Actual changes are: * storage_tls_session_sync parameter is const, * more specific naming, * storage_tls_session_load will return an empty l_settings instead of NULL so eap-tls-common.c doesn't have to handle this. storage.c makes no assumptions about the group names in the l_settings object and keeps no reference to that object, eap-tls-common.c is going to maintain the memory copy of the cache since this cache and the disk copy of it are reserved for EAP methods only.
This commit is contained in:
parent
b4406cce82
commit
e63c5bf4f8
@ -53,7 +53,7 @@
|
|||||||
#define STORAGE_FILE_MODE (S_IRUSR | S_IWUSR)
|
#define STORAGE_FILE_MODE (S_IRUSR | S_IWUSR)
|
||||||
|
|
||||||
#define KNOWN_FREQ_FILENAME ".known_network.freq"
|
#define KNOWN_FREQ_FILENAME ".known_network.freq"
|
||||||
#define TLS_CACHE_FILENAME ".tls-session-cache"
|
#define EAP_TLS_CACHE_FILENAME ".eap-tls-session-cache"
|
||||||
|
|
||||||
static char *storage_path = NULL;
|
static char *storage_path = NULL;
|
||||||
static char *storage_hotspot_path = NULL;
|
static char *storage_hotspot_path = NULL;
|
||||||
@ -702,29 +702,35 @@ void storage_known_frequencies_sync(struct l_settings *known_freqs)
|
|||||||
l_free(known_freq_file_path);
|
l_free(known_freq_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct l_settings *storage_tls_session_cache_load(void)
|
struct l_settings *storage_eap_tls_cache_load(void)
|
||||||
{
|
{
|
||||||
_auto_(l_settings_free) struct l_settings *cache = l_settings_new();
|
_auto_(l_free) char *path =
|
||||||
_auto_(l_free) char *tls_cache_file_path =
|
storage_get_path("%s", EAP_TLS_CACHE_FILENAME);
|
||||||
storage_get_path("%s", TLS_CACHE_FILENAME);
|
struct l_settings *cache = l_settings_new();
|
||||||
|
|
||||||
if (unlikely(!l_settings_load_from_file(cache, tls_cache_file_path)))
|
if (!l_settings_load_from_file(cache, path))
|
||||||
return NULL;
|
l_debug("No session cache loaded from %s, starting with an "
|
||||||
|
"empty cache", path);
|
||||||
|
|
||||||
return l_steal_ptr(cache);
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void storage_tls_session_cache_sync(struct l_settings *cache)
|
void storage_eap_tls_cache_sync(const struct l_settings *cache)
|
||||||
{
|
{
|
||||||
_auto_(l_free) char *tls_cache_file_path = NULL;
|
_auto_(l_free) char *path =
|
||||||
|
storage_get_path("%s", EAP_TLS_CACHE_FILENAME);
|
||||||
|
_auto_(l_free) char *settings_data = NULL;
|
||||||
_auto_(l_free) char *data = NULL;
|
_auto_(l_free) char *data = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
static const char comment[] =
|
||||||
|
"# External changes to this file are not tracked by IWD "
|
||||||
|
"and will be overwritten.\n\n";
|
||||||
|
static const size_t comment_len = L_ARRAY_SIZE(comment) - 1;
|
||||||
|
|
||||||
if (!cache)
|
settings_data = l_settings_to_data(cache, &len);
|
||||||
return;
|
data = l_malloc(comment_len + len);
|
||||||
|
memcpy(data, comment, comment_len);
|
||||||
tls_cache_file_path = storage_get_path("%s", TLS_CACHE_FILENAME);
|
memcpy(data + comment_len, settings_data, len);
|
||||||
data = l_settings_to_data(cache, &len);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note this data contains cryptographic secrets. write_file()
|
* Note this data contains cryptographic secrets. write_file()
|
||||||
@ -732,7 +738,8 @@ void storage_tls_session_cache_sync(struct l_settings *cache)
|
|||||||
*
|
*
|
||||||
* TODO: consider encrypting with system_key.
|
* TODO: consider encrypting with system_key.
|
||||||
*/
|
*/
|
||||||
write_file(data, len, false, "%s", tls_cache_file_path);
|
write_file(data, comment_len + len, false, "%s", path);
|
||||||
|
explicit_bzero(settings_data, len);
|
||||||
explicit_bzero(data, len);
|
explicit_bzero(data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ int storage_network_remove(enum security type, const char *ssid);
|
|||||||
struct l_settings *storage_known_frequencies_load(void);
|
struct l_settings *storage_known_frequencies_load(void);
|
||||||
void storage_known_frequencies_sync(struct l_settings *known_freqs);
|
void storage_known_frequencies_sync(struct l_settings *known_freqs);
|
||||||
|
|
||||||
struct l_settings *storage_tls_session_cache_load(void);
|
struct l_settings *storage_eap_tls_cache_load(void);
|
||||||
void storage_tls_session_cache_sync(struct l_settings *cache);
|
void storage_eap_tls_cache_sync(const struct l_settings *cache);
|
||||||
|
|
||||||
int __storage_decrypt(struct l_settings *settings, const char *ssid,
|
int __storage_decrypt(struct l_settings *settings, const char *ssid,
|
||||||
bool *changed);
|
bool *changed);
|
||||||
|
Loading…
Reference in New Issue
Block a user