public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 1/4] dpp-util: add support for 3rd party JSON fields
@ 2023-11-17 14:12 James Prestwood
  2023-11-17 14:12 ` [PATCH 2/4] dpp: include 3rd party settings in network profile James Prestwood
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: James Prestwood @ 2023-11-17 14:12 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

The DPP spec allows 3rd party fields in the DPP configuration
object (section 4.5.2). IWD can take advantage of this (when
configuring another IWD supplicant) to communicate additional
profile options that may be required for the network.

The new configuration member will be called "/net/connman/iwd"
and will be an object containing settings specific to IWD.
More settings could be added here if needed but for now only
the following are defined:

{
  send_hostname: true/false,
  hidden: true/false
}

These correspond to the following network profile settings:

[IPv4].SendHostname
[Settings].Hidden
---
 src/dpp-util.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---
 src/dpp-util.h |  4 +++
 2 files changed, 70 insertions(+), 3 deletions(-)

RFC->v1:
 * Decided to make this not configurable with an option. Any
   supplicant should support 3rd party fields existing (even
   if they don't parse them) and the two settings here will
   only improve the experience. 

diff --git a/src/dpp-util.c b/src/dpp-util.c
index cadc6437..c805b14a 100644
--- a/src/dpp-util.c
+++ b/src/dpp-util.c
@@ -144,6 +144,40 @@ static uint32_t dpp_parse_akm(char *akms)
 	return akm_out;
 }
 
+static bool dpp_parse_extra_options(struct dpp_configuration *config,
+					struct json_iter *extra)
+{
+	struct json_iter host_val;
+	struct json_iter hidden_val;
+	bool hostname = false;
+	bool hidden = false;
+
+	if (!json_iter_parse(extra,
+			JSON_OPTIONAL("send_hostname", JSON_PRIMITIVE,
+					&host_val),
+			JSON_OPTIONAL("hidden", JSON_PRIMITIVE, &hidden_val),
+			JSON_UNDEFINED))
+		return false;
+
+	/*
+	 * The values are optional in order to support backwards compatibility
+	 * if more are added, but if the key does exist require the type
+	 * matches and fail otherwise.
+	 */
+	if (json_iter_is_valid(&host_val) &&
+			!json_iter_get_boolean(&host_val, &hostname))
+		return false;
+
+	if (json_iter_is_valid(&hidden_val) &&
+			!json_iter_get_boolean(&hidden_val, &hidden))
+		return false;
+
+	config->send_hostname = hostname;
+	config->hidden = hidden;
+
+	return true;
+}
+
 /*
  * TODO: This handles the most basic configuration. i.e. a configuration object
  * with ssid/passphrase/akm.
@@ -156,6 +190,7 @@ struct dpp_configuration *dpp_parse_configuration_object(const char *json,
 	struct json_iter iter;
 	struct json_iter discovery;
 	struct json_iter cred;
+	struct json_iter extra;
 	_auto_(l_free) char *tech = NULL;
 	_auto_(l_free) char *ssid = NULL;
 	_auto_(l_free) char *akm = NULL;
@@ -172,6 +207,7 @@ struct dpp_configuration *dpp_parse_configuration_object(const char *json,
 			JSON_MANDATORY("wi-fi_tech", JSON_STRING, &tech),
 			JSON_MANDATORY("discovery", JSON_OBJECT, &discovery),
 			JSON_MANDATORY("cred", JSON_OBJECT, &cred),
+			JSON_OPTIONAL("/net/connman/iwd", JSON_OBJECT, &extra),
 			JSON_UNDEFINED))
 		goto free_contents;
 
@@ -210,6 +246,11 @@ struct dpp_configuration *dpp_parse_configuration_object(const char *json,
 	if (!config->akm_suites)
 		goto free_config;
 
+	if (json_iter_is_valid(&extra)) {
+		if (!dpp_parse_extra_options(config, &extra))
+			l_warn("Extra settings failed to parse!");
+	}
+
 	json_contents_free(c);
 
 	return config;
@@ -258,10 +299,20 @@ char *dpp_configuration_to_json(struct dpp_configuration *config)
 						config->psk);
 
 	return l_strdup_printf("{\"wi-fi_tech\":\"infra\","
-				"\"discovery\":{\"ssid\":\"%s\"},"
-				"\"cred\":{\"akm\":\"%s\",%s}}",
+				"\"discovery\":{"
+					"\"ssid\":\"%s\""
+				"},"
+				"\"cred\":{"
+					"\"akm\":\"%s\",%s"
+				"},"
+				"\"/net/connman/iwd\":{"
+					"\"send_hostname\":%s,"
+					"\"hidden\":%s}"
+				"}",
 				ssid, dpp_akm_to_string(config->akm_suites),
-				pass_or_psk);
+				pass_or_psk,
+				config->send_hostname ? "true" : "false",
+				config->hidden ? "true" : "false");
 }
 
 struct dpp_configuration *dpp_configuration_new(
@@ -273,6 +324,8 @@ struct dpp_configuration *dpp_configuration_new(
 	_auto_(l_free) char *passphrase = NULL;
 	_auto_(l_free) char *psk = NULL;
 	size_t ssid_len = strlen(ssid);
+	bool send_hostname;
+	bool hidden;
 
 	if (!l_settings_has_group(settings, "Security"))
 		return NULL;
@@ -299,6 +352,16 @@ struct dpp_configuration *dpp_configuration_new(
 
 	config->akm_suites = akm_suite;
 
+	if (!l_settings_get_bool(settings, "IPv4", "SendHostname",
+					&send_hostname))
+		send_hostname = false;
+
+	if (!l_settings_get_bool(settings, "Settings", "Hidden", &hidden))
+		hidden = false;
+
+	config->send_hostname = send_hostname;
+	config->hidden = hidden;
+
 	return config;
 }
 
diff --git a/src/dpp-util.h b/src/dpp-util.h
index 0724ee44..dc8a894b 100644
--- a/src/dpp-util.h
+++ b/src/dpp-util.h
@@ -117,6 +117,10 @@ struct dpp_configuration {
 	uint32_t akm_suites;
 	char *passphrase;
 	char *psk;		/* hex string */
+
+	/* "3rd party extensions" only applicable for two IWD peers */
+	bool send_hostname : 1;
+	bool hidden : 1;
 };
 
 struct dpp_configuration *dpp_parse_configuration_object(const char *json,
-- 
2.34.1


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

* [PATCH 2/4] dpp: include 3rd party settings in network profile
  2023-11-17 14:12 [PATCH 1/4] dpp-util: add support for 3rd party JSON fields James Prestwood
@ 2023-11-17 14:12 ` James Prestwood
  2023-11-17 14:12 ` [PATCH 3/4] auto-t: add checks for DPP 3rd party settings James Prestwood
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2023-11-17 14:12 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

If the configuration object contained IWD's 3rd party settings set
those into the network profile.
---
 src/dpp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/dpp.c b/src/dpp.c
index f8d76805..0064187b 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -837,6 +837,12 @@ static void dpp_write_config(struct dpp_configuration *config,
 			network_set_psk(network, psk);
 	}
 
+	if (config->send_hostname)
+		l_settings_set_bool(settings, "IPv4", "SendHostname", true);
+
+	if (config->hidden)
+		l_settings_set_bool(settings, "Settings", "Hidden", true);
+
 	l_debug("Storing credential for '%s(%s)'", config->ssid,
 						security_to_str(SECURITY_PSK));
 	storage_network_sync(SECURITY_PSK, config->ssid, settings);
-- 
2.34.1


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

* [PATCH 3/4] auto-t: add checks for DPP 3rd party settings
  2023-11-17 14:12 [PATCH 1/4] dpp-util: add support for 3rd party JSON fields James Prestwood
  2023-11-17 14:12 ` [PATCH 2/4] dpp: include 3rd party settings in network profile James Prestwood
@ 2023-11-17 14:12 ` James Prestwood
  2023-11-17 14:12 ` [PATCH 4/4] json: fix comment typo, "json_object_is_valid" James Prestwood
  2023-11-17 15:49 ` [PATCH 1/4] dpp-util: add support for 3rd party JSON fields Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2023-11-17 14:12 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

Ensure the newly configured profile contains the additional
SendHostname setting that the configurator sends.
---
 autotests/testDPP/pkex_test.py | 6 ++++++
 autotests/testDPP/ssidCCMP.psk | 9 ---------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py
index 6c5cf054..9e0b5dd8 100644
--- a/autotests/testDPP/pkex_test.py
+++ b/autotests/testDPP/pkex_test.py
@@ -168,6 +168,12 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         self.wd.wait_for_object_condition(self.device[1], condition)
 
+        # Check additional settings were carried over
+        with open('/tmp/ns0/ssidCCMP.psk', 'r') as f:
+            settings = f.read()
+
+        self.assertIn("SendHostname=true", settings)
+
     def test_pkex_configurator_with_agent(self):
         self.start_iwd_pkex_configurator(self.device[0], agent=True)
 
diff --git a/autotests/testDPP/ssidCCMP.psk b/autotests/testDPP/ssidCCMP.psk
index d428fd34..a82324c8 100644
--- a/autotests/testDPP/ssidCCMP.psk
+++ b/autotests/testDPP/ssidCCMP.psk
@@ -1,14 +1,5 @@
 [Security]
 Passphrase=secret123
 
-[DeviceProvisioning]
-SharedCode=secret123
-SharedCodeIdentifier=test
-ExactConfig=true
-
 [IPv4]
 SendHostname=true
-
-[Settings]
-AutoConnect=true
-Hidden=false
-- 
2.34.1


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

* [PATCH 4/4] json: fix comment typo, "json_object_is_valid"
  2023-11-17 14:12 [PATCH 1/4] dpp-util: add support for 3rd party JSON fields James Prestwood
  2023-11-17 14:12 ` [PATCH 2/4] dpp: include 3rd party settings in network profile James Prestwood
  2023-11-17 14:12 ` [PATCH 3/4] auto-t: add checks for DPP 3rd party settings James Prestwood
@ 2023-11-17 14:12 ` James Prestwood
  2023-11-17 15:49 ` [PATCH 1/4] dpp-util: add support for 3rd party JSON fields Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2023-11-17 14:12 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

This should be json_iter_is_valid.
---
 src/json.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/json.h b/src/json.h
index 713ab56f..feb85d67 100644
--- a/src/json.h
+++ b/src/json.h
@@ -85,7 +85,7 @@ void json_iter_init(struct json_iter *iter, struct json_contents *c);
  * other types are encountered.
  *
  * JSON_OPTIONAL string values will point to NULL if not found
- * JSON_OPTIONAL objects/primitives can be checked with json_object_is_valid.
+ * JSON_OPTIONAL objects/primitives can be checked with json_iter_is_valid.
  */
 bool json_iter_parse(struct json_iter *iter, enum json_type type, ...);
 
-- 
2.34.1


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

* Re: [PATCH 1/4] dpp-util: add support for 3rd party JSON fields
  2023-11-17 14:12 [PATCH 1/4] dpp-util: add support for 3rd party JSON fields James Prestwood
                   ` (2 preceding siblings ...)
  2023-11-17 14:12 ` [PATCH 4/4] json: fix comment typo, "json_object_is_valid" James Prestwood
@ 2023-11-17 15:49 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2023-11-17 15:49 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 11/17/23 08:12, James Prestwood wrote:
> The DPP spec allows 3rd party fields in the DPP configuration
> object (section 4.5.2). IWD can take advantage of this (when
> configuring another IWD supplicant) to communicate additional
> profile options that may be required for the network.
> 
> The new configuration member will be called "/net/connman/iwd"
> and will be an object containing settings specific to IWD.
> More settings could be added here if needed but for now only
> the following are defined:
> 
> {
>    send_hostname: true/false,
>    hidden: true/false
> }
> 
> These correspond to the following network profile settings:
> 
> [IPv4].SendHostname
> [Settings].Hidden
> ---
>   src/dpp-util.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---
>   src/dpp-util.h |  4 +++
>   2 files changed, 70 insertions(+), 3 deletions(-)
> 

All applied, thanks.

Regards,
-Denis


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

end of thread, other threads:[~2023-11-17 15:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 14:12 [PATCH 1/4] dpp-util: add support for 3rd party JSON fields James Prestwood
2023-11-17 14:12 ` [PATCH 2/4] dpp: include 3rd party settings in network profile James Prestwood
2023-11-17 14:12 ` [PATCH 3/4] auto-t: add checks for DPP 3rd party settings James Prestwood
2023-11-17 14:12 ` [PATCH 4/4] json: fix comment typo, "json_object_is_valid" James Prestwood
2023-11-17 15:49 ` [PATCH 1/4] dpp-util: add support for 3rd party JSON fields Denis Kenzior

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