knownnetworks: make frequencies/UUID forgettable

Since the UUID was being generated purely on the file path, it
would never change for a given network (unless the SSID/name changed).
In the future we would like to use this unique UUID to generate a
MAC per-SSID, and if that network is forgotten we also want the UUID
to change next time the network is connected to.

Rather than only using the file path, the mtime can also be fed into
the UUID generation. Since the mtime would be changed after forgetting
and re-adding a known network we will get a new UUID.

Now, whenever a known network is removed, we lookup the UUID we have
in network_info and remove that entry in the settings file and
sync the frequency file.
This commit is contained in:
James Prestwood 2019-09-13 10:27:27 -07:00 committed by Denis Kenzior
parent f57b73898b
commit 66346712e6
1 changed files with 18 additions and 1 deletions

View File

@ -234,6 +234,7 @@ const struct iovec *network_info_get_extra_ies(const struct network_info *info,
const uint8_t *network_info_get_uuid(struct network_info *info)
{
char *file_path;
char *to_hash;
/*
* 16 bytes of randomness. Since we only care about a unique value there
* is no need to use any special pre-defined namespace.
@ -248,7 +249,15 @@ const uint8_t *network_info_get_uuid(struct network_info *info)
file_path = info->ops->get_file_path(info);
l_uuid_v5(nsid, file_path, strlen(file_path), info->uuid);
/*
* This will generate a UUID based on file path and mtime. This
* is done so we can get a different UUID if the network has
* been forgotten.
*/
to_hash = l_strdup_printf("%s_%" PRIu64, file_path,
info->connected_time);
l_uuid_v5(nsid, to_hash, strlen(to_hash), info->uuid);
l_free(to_hash);
info->has_uuid = true;
@ -600,6 +609,14 @@ void known_networks_remove(struct network_info *network)
known_networks_watch_func_t,
KNOWN_NETWORKS_EVENT_REMOVED, network);
if (known_freqs && network->has_uuid) {
char uuid[37];
l_uuid_to_string(network->uuid, uuid, sizeof(uuid));
l_settings_remove_group(known_freqs, uuid);
storage_known_frequencies_sync(known_freqs);
}
network_info_free(network);
}