Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH v2 1/4] station: support full MAC randomization and override
@ 2020-03-19 22:02 James Prestwood
  2020-03-19 22:02 ` [PATCH v2 2/4] netdev: honor handshake->spa if set James Prestwood
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: James Prestwood @ 2020-03-19 22:02 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2680 bytes --]

This patch adds two new options to a network provisioning file:

AlwaysRandomizeAddress={true,false}

If true, IWD will randomize the MAC address on each connection to this
network. The address does not persists between connections, any new
connection will result in a different MAC.

AddressOverride=<MAC>

If set, the MAC address will be set to <MAC> assuming its a valid MAC
address.

These two options should not be used together, and will only take effect
if [General].AddressRandomization is set to 'network' in the IWD
config file.

If neither of these options are set, and [General].AddressRandomization
is set to 'network', the default behavior remains the same; the MAC
will be generated deterministically on a per-network basis.
---
 src/station.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

v2:
 * Removed check for AddressRandomization=network. This is checked in
   netdev.

diff --git a/src/station.c b/src/station.c
index 36b41f64..47af726e 100644
--- a/src/station.c
+++ b/src/station.c
@@ -875,6 +875,10 @@ static struct handshake_state *station_handshake_setup(struct station *station,
 	struct handshake_state *hs;
 	const char *ssid;
 	uint32_t eapol_proto_version;
+	const char *value;
+	bool full_random;
+	bool override = false;
+	uint8_t new_addr[ETH_ALEN];
 
 	hs = netdev_handshake_state_new(station->netdev);
 
@@ -934,6 +938,40 @@ static struct handshake_state *station_handshake_setup(struct station *station,
 				IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384))
 		hs->erp_cache = erp_cache_get(network_get_ssid(network));
 
+	/*
+	 * We have three possible options here:
+	 * 1. per-network MAC generation (default, no option in network config)
+	 * 2. per-network full MAC randomization
+	 * 3. per-network MAC override
+	 */
+
+	if (!l_settings_get_bool(settings, "Settings",
+					"AlwaysRandomizeAddress",
+					&full_random))
+		full_random = false;
+
+	value = l_settings_get_value(settings, "Settings",
+					"AddressOverride");
+	if (value)
+		override = true;
+
+	if (override && full_random) {
+		l_warn("Cannot use both AlwaysRandomizeAddress and "
+			"AddressOverride concurrently, defaulting to override");
+		full_random = false;
+	}
+
+	if (override) {
+		if (util_string_to_address(value, new_addr))
+			handshake_state_set_supplicant_address(hs, new_addr);
+		else
+			l_warn("[Network].AddressOverride is not a valid "
+				"MAC address");
+	} else if (full_random) {
+		wiphy_generate_random_address(wiphy, new_addr);
+		handshake_state_set_supplicant_address(hs, new_addr);
+	}
+
 	return hs;
 
 no_psk:
-- 
2.21.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-19 22:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-19 22:02 [PATCH v2 1/4] station: support full MAC randomization and override James Prestwood
2020-03-19 22:02 ` [PATCH v2 2/4] netdev: honor handshake->spa if set James Prestwood
2020-03-19 22:02 ` [PATCH v2 3/4] doc: document AlwaysRandomizeAddress and AddressOverride James Prestwood
2020-03-19 22:02 ` [PATCH v2 4/4] auto-t: add test for AddressRandomization option James Prestwood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox