diff mbox series

[03/17] ap: add profile settings PairwiseCiphers/GroupCipher

Message ID 20221101201747.143379-3-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [01/17] wiphy: add wiphy_get_supported_ciphers | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint
prestwoj/iwd-alpine-ci-incremental_build fail Make FAIL (patch 2): In file included from ./ell/ell.h:3, from src/ap.c:33: src/ap.c: In function 'ap_start': ./ell/strv.h:41:21: error: 'ciphers_str' may be used uninitialized [-Werror=maybe-uninitialized] 41 | DEFINE_CLEANUP_FUNC(l_strv_free); | ^~~~~~~~~~~ src/ap.c:3163:36: note: 'ciphers_str' was declared here 3163 | _auto_(l_strv_free) char **ciphers_str; | ^~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [Makefile:2409: src/ap.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:1588: all] Error 2
prestwoj/iwd-ci-incremental_build fail Make FAIL (patch 2): In file included from ./ell/ell.h:3, from src/ap.c:33: src/ap.c: In function ‘ap_start’: ./ell/strv.h:41:21: error: ‘ciphers_str’ may be used uninitialized [-Werror=maybe-uninitialized] 41 | DEFINE_CLEANUP_FUNC(l_strv_free); | ^~~~~~~~~~~ src/ap.c:3163:36: note: ‘ciphers_str’ was declared here 3163 | _auto_(l_strv_free) char **ciphers_str; | ^~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [Makefile:2408: src/ap.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:1587: all] Error 2

Commit Message

James Prestwood Nov. 1, 2022, 8:17 p.m. UTC
These can now be optionally provided in an AP profile and provide a
way to limit what ciphers can be chosen. This still is dependent on
what the hardware supports.
---
 src/ap.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/ap.c b/src/ap.c
index 2939a9c1..834fa089 100644
--- a/src/ap.c
+++ b/src/ap.c
@@ -3132,12 +3132,38 @@  static bool ap_load_psk(struct ap_state *ap, const struct l_settings *config)
 	return true;
 }
 
+/*
+ * Note: only PTK/GTK ciphers are supported here since this is all these are
+ *       used for.
+ */
+static enum ie_rsn_cipher_suite ap_string_to_cipher(const char *str)
+{
+	if (!strcmp(str, "UseGroupCipher"))
+		return IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER;
+	else if (!strcmp(str, "TKIP"))
+		return IE_RSN_CIPHER_SUITE_TKIP;
+	else if (!strcmp(str, "CCMP-128") || !strcmp(str, "CCMP"))
+		return IE_RSN_CIPHER_SUITE_CCMP;
+	else if (!strcmp(str, "GCMP-128") || !strcmp(str, "GCMP"))
+		return IE_RSN_CIPHER_SUITE_GCMP;
+	else if (!strcmp(str, "GCMP-256"))
+		return IE_RSN_CIPHER_SUITE_GCMP_256;
+	else if (!strcmp(str, "CCMP-256"))
+		return IE_RSN_CIPHER_SUITE_CCMP_256;
+	else
+		return 0;
+}
+
 static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
 				bool *out_cck_rates)
 {
+	struct wiphy *wiphy = netdev_get_wiphy(ap->netdev);
 	size_t len;
 	L_AUTO_FREE_VAR(char *, strval) = NULL;
+	_auto_(l_strv_free) char **ciphers_str;
+	uint16_t cipher_mask;
 	int err;
+	int i;
 
 	strval = l_settings_get_string(config, "General", "SSID");
 	if (L_WARN_ON(!strval))
@@ -3212,6 +3238,8 @@  static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
 			l_error("AP [WSC].PrimaryDeviceType format unknown");
 			return -EINVAL;
 		}
+
+		l_free(l_steal_ptr(strval));
 	} else {
 		/* Make ourselves a WFA standard PC by default */
 		ap->wsc_primary_device_type.category = 1;
@@ -3260,6 +3288,47 @@  static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
 	} else
 		*out_cck_rates = true;
 
+	cipher_mask = wiphy_get_supported_ciphers(wiphy, IE_PAIRWISE_CIPHERS);
+	ciphers_str = l_settings_get_string_list(config, "Security",
+						"PairwiseCiphers", ',');
+	for (i = 0; ciphers_str && ciphers_str[i]; i++) {
+		enum ie_rsn_cipher_suite cipher =
+					ap_string_to_cipher(ciphers_str[i]);
+
+		/*
+		 * Constrain list to only values in both supported ciphers and
+		 * the cipher list provided.
+		 */
+		if (!cipher || !(cipher & cipher_mask)) {
+			l_error("Unsupported or unknown cipher %s",
+					ciphers_str[i]);
+			return -ENOTSUP;
+		}
+
+		ap->ciphers |= cipher;
+	}
+
+	/* No list provided, just set to all supported ciphers */
+	if (!ap->ciphers)
+		ap->ciphers = cipher_mask;
+
+	cipher_mask = wiphy_get_supported_ciphers(wiphy, IE_GROUP_CIPHERS);
+
+	strval = l_settings_get_string(config, "Security", "GroupCipher");
+	if (strval) {
+		enum ie_rsn_cipher_suite cipher = ap_string_to_cipher(strval);
+
+		if (!cipher || !(cipher & cipher_mask)) {
+			l_error("Unsupported or unknown cipher %s", strval);
+			return -ENOTSUP;
+		}
+
+		ap->group_cipher = cipher;
+
+		l_free(l_steal_ptr(strval));
+	} else
+		ap->group_cipher = wiphy_select_cipher(wiphy, cipher_mask);
+
 	return 0;
 }
 
@@ -3302,12 +3371,6 @@  struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,
 
 	err = -EINVAL;
 
-	/* TODO: Add all ciphers supported by wiphy */
-	ap->ciphers = wiphy_select_cipher(wiphy, IE_RSN_CIPHER_SUITE_TKIP |
-						IE_RSN_CIPHER_SUITE_CCMP);
-	ap->group_cipher = wiphy_select_cipher(wiphy,
-						IE_RSN_CIPHER_SUITE_TKIP |
-						IE_RSN_CIPHER_SUITE_CCMP);
 	ap->beacon_interval = 100;
 	ap->networks = l_queue_new();