From 66346712e67d9fcc5e4f2a00ae2984946a847354 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Fri, 13 Sep 2019 10:27:27 -0700 Subject: [PATCH] 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. --- src/knownnetworks.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index e19b344c..f380fb63 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -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); }