Skip to contentSkip to conversation

dpp: use frame data directly in unwrap for config response

PATCH In review James Prestwood 2 participants 10 messages Dec 20, 2021 Kbuild

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/9 dpp: use frame data directly in unwrap for config response

Rather than hard coding ad0, use the actual frame data. There really isn't a reason this would differ (only status attribute) but just in case its better to use the frame data directly.

---
 src/dpp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
src/dpp.c +1 -2
index 5e125265..69dbeb1e 100644
@@ -391,7 +391,6 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	size_t wrapped_len = 0;
 	_auto_(l_free) uint8_t *unwrapped = NULL;
 	struct dpp_configuration *config;
-	uint8_t ad0[] = { 0x00, 0x10, 0x01, 0x00, 0x05 };
 
 	if (dpp->state != DPP_STATE_CONFIGURING)
 		return;
@@ -474,7 +473,7 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 		return;
 	}
 
-	unwrapped = dpp_unwrap_attr(ad0, sizeof(ad0), NULL, 0, dpp->ke,
+	unwrapped = dpp_unwrap_attr(ptr, wrapped - ptr - 4, NULL, 0, dpp->ke,
 					dpp->key_len, wrapped, wrapped_len,
 					&wrapped_len);
 	if (!unwrapped) {
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 2/9 dpp-util: pass actual ad_size, not hard coded '2'.

---
 src/dpp-util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/dpp-util.c +1 -1
index 5e8ab2a7..1db38cfb 100644
@@ -280,7 +280,7 @@ uint8_t *dpp_unwrap_attr(const void *ad0, size_t ad0_len, const void *ad1,
 
 	unwrapped = l_malloc(wrapped_len - 16);
 
-	if (!aes_siv_decrypt(key, key_len, wrapped, wrapped_len, ad, 2,
+	if (!aes_siv_decrypt(key, key_len, wrapped, wrapped_len, ad, ad_size,
 				unwrapped)) {
 		l_free(unwrapped);
 		return NULL;
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 3/9 dpp-util: add dpp_configuration_new/dpp_configuration_to_json

In reply to James Prestwood

Allows creating a new configuration object based on settings, ssid, and akm suite (for configurator role) as well as converting a configuration object to JSON.

---
 src/dpp-util.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/dpp-util.h |  6 ++++
 2 files changed, 87 insertions(+)
src/dpp-util.c +81 -0
index 1db38cfb..55d6f3f1 100644
@@ -193,6 +193,87 @@ free_contents:
 	return NULL;
 }
 
+/*
+ * The DPP spec does not specify a difference between FT AKMs and their normal
+ * counterpart. Because of this any FT AKM will just result in the standard
+ * 'psk' or 'sae' AKM.
+ */
+static const char *dpp_akm_to_string(enum ie_rsn_akm_suite akm_suite)
+{
+	switch (akm_suite) {
+	case IE_RSN_AKM_SUITE_PSK:
+	case IE_RSN_AKM_SUITE_FT_USING_PSK:
+	case IE_RSN_AKM_SUITE_PSK_SHA256:
+		return "psk";
+	case IE_RSN_AKM_SUITE_SAE_SHA256:
+	case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
+		return "sae";
+	default:
+		return NULL;
+	}
+}
+
+char *dpp_configuration_to_json(struct dpp_configuration *config)
+{
+	_auto_(l_free) char *pass_or_psk;
+	_auto_(l_free) char *ssid;
+
+	ssid = l_malloc(config->ssid_len + 1);
+	memcpy(ssid, config->ssid, config->ssid_len);
+	ssid[config->ssid_len] = '\0';
+
+	if (config->passphrase)
+		pass_or_psk = l_strdup_printf("\"pass\":\"%s\"",
+						config->passphrase);
+	else
+		pass_or_psk = l_strdup_printf("\"psk\":\"%s\"",
+						config->psk);
+
+	return l_strdup_printf("{\"wi-fi_tech\":\"infra\","
+				"\"discovery\":{\"ssid\":\"%s\"},"
+				"\"cred\":{\"akm\":\"%s\",%s}}",
+				ssid, dpp_akm_to_string(config->akm_suites),
+				pass_or_psk);
+}
+
+struct dpp_configuration *dpp_configuration_new(
+					const struct l_settings *settings,
+					const char *ssid,
+					enum ie_rsn_akm_suite akm_suite)
+{
+	struct dpp_configuration *config;
+	_auto_(l_free) char *passphrase = NULL;
+	_auto_(l_free) char *psk = NULL;
+	size_t ssid_len = strlen(ssid);
+
+	if (!l_settings_has_group(settings, "Security"))
+		return NULL;
+
+	passphrase = l_settings_get_string(settings, "Security", "Passphrase");
+	if (!passphrase) {
+		psk = l_settings_get_string(settings, "Security",
+						"PreSharedKey");
+		if (!psk)
+			return NULL;
+	}
+
+	config = l_new(struct dpp_configuration, 1);
+
+	memcpy(config->ssid, ssid, ssid_len);
+	config->ssid[ssid_len] = '\0';
+	config->ssid_len = ssid_len;
+
+	if (passphrase)
+		config->passphrase = l_steal_ptr(passphrase);
+	else
+		config->psk = l_steal_ptr(psk);
+
+
+	config->akm_suites = akm_suite;
+
+	return config;
+}
+
 void dpp_configuration_free(struct dpp_configuration *config)
 {
 	if (config->passphrase)
src/dpp-util.h +6 -0
index 543cf9f8..84d33656 100644
@@ -21,6 +21,7 @@
  */
 struct l_ecc_point;
 struct l_ecc_scalar;
+enum ie_rsn_akm_suite;
 
 enum dpp_frame_type {
 	DPP_FRAME_AUTHENTICATION_REQUEST	= 0,
@@ -110,6 +111,11 @@ struct dpp_configuration {
 
 struct dpp_configuration *dpp_parse_configuration_object(const char *json,
 							size_t json_len);
+struct dpp_configuration *dpp_configuration_new(
+					const struct l_settings *settings,
+					const char *ssid,
+					enum ie_rsn_akm_suite akm_suite);
+char *dpp_configuration_to_json(struct dpp_configuration *config);
 void dpp_configuration_free(struct dpp_configuration *conf);
 
 struct dpp_attr_iter {
Signature · 1 line
2.31.1
author
#3 lore raw

PATCH 4/9 dpp: add timeout for auth/config protocols

In reply to James Prestwood

This also allows the card to re-issue ROC if it ends in the middle of authenticating or configuring as well as add a maximum timeout for auth/config protocols.

IO errors were also handled as these sometimes can happen with certain drivers but are not fatal.

---
 src/dpp.c | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)
src/dpp.c +33 -10
index 69dbeb1e..c98ba021 100644
@@ -98,6 +98,9 @@ struct dpp_sm {
 	struct l_ecc_point *i_proto_public;
 
 	uint8_t diag_token;
+
+	/* Timeout of either auth/config protocol */
+	struct l_timeout *timeout;
 };
 
 static void dpp_free_auth_data(struct dpp_sm *dpp)
@@ -239,6 +242,24 @@ static size_t dpp_build_config_header(const uint8_t *src, const uint8_t *dest,
 	return ptr - buf;
 }
 
+static void dpp_protocol_timeout(struct l_timeout *timeout, void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+
+	l_debug("DPP timed out");
+
+	dpp_reset(dpp);
+}
+
+static void dpp_reset_protocol_timer(struct dpp_sm *dpp)
+{
+	if (dpp->timeout)
+		l_timeout_modify(dpp->timeout, 10);
+	else
+		dpp->timeout = l_timeout_create(10, dpp_protocol_timeout,
+						dpp, NULL);
+}
+
 /*
  * The configuration protocols use of AD components is somewhat confusing
  * since the request/response frames are of a different format than the rest.
@@ -733,6 +754,7 @@ static void authenticate_confirm(struct dpp_sm *dpp, const uint8_t *from,
 
 	l_debug("Authentication successful");
 
+	dpp_reset_protocol_timer(dpp);
 	dpp_configuration_start(dpp, from);
 
 	return;
@@ -941,6 +963,7 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,
 	memcpy(dpp->auth_addr, from, 6);
 
 	dpp->state = DPP_STATE_AUTHENTICATING;
+	dpp_reset_protocol_timer(dpp);
 
 	send_authenticate_response(dpp, r_auth);
 
@@ -1013,6 +1036,12 @@ static void dpp_roc_started(void *user_data)
 {
 	struct dpp_sm *dpp = user_data;
 
+	/*
+	 * If not in presence procedure, just stay on channel.
+	 */
+	if (dpp->state != DPP_STATE_PRESENCE)
+		return;
+
 	dpp_presence_announce(dpp);
 }
 
@@ -1082,6 +1111,8 @@ static void dpp_presence_timeout(int error, void *user_data)
 	 */
 	if (error == -ECANCELED)
 		return;
+	else if (error == -EIO)
+		goto next_roc;
 	else if (error < 0)
 		goto protocol_failed;
 
@@ -1093,16 +1124,7 @@ static void dpp_presence_timeout(int error, void *user_data)
 		return;
 	case DPP_STATE_AUTHENTICATING:
 	case DPP_STATE_CONFIGURING:
-		/*
-		 * TODO: If either the auth or config protocol is running we
-		 * need to stay on channel until the specified timeouts.
-		 * Unfortunately the kernel makes this very inconvenient since
-		 * there is no way to stay on channel indefinitely or any way
-		 * of knowing what duration the kernel/card actually chooses.
-		 *
-		 * For now just treat this as a failure.
-		 */
-		goto protocol_failed;
+		goto next_roc;
 	}
 
 	dpp->freqs_idx++;
@@ -1117,6 +1139,7 @@ static void dpp_presence_timeout(int error, void *user_data)
 	l_debug("Presence timeout, moving to next frequency %u, duration %u",
 			dpp->current_freq, dpp->dwell);
 
+next_roc:
 	dpp->offchannel_id = offchannel_start(netdev_get_wdev_id(dpp->netdev),
 			dpp->current_freq, dpp->dwell, dpp_roc_started,
 			dpp, dpp_presence_timeout);
Signature · 1 line
2.31.1
author
#4 lore raw

PATCH 5/9 dpp: add role definitions

In reply to James Prestwood

Added both enrollee and configurator roles, as well as the needed logic inside the authentication protocol to verify role compatibility. The dpp_sm's role will now be used when setting capability bits making the auth protocol agnostic to enrollees or configurators.

---
 src/dpp.c | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)
src/dpp.c +32 -9
index c98ba021..29cec5cd 100644
@@ -58,9 +58,15 @@ enum dpp_state {
 	DPP_STATE_CONFIGURING,
 };
 
+enum dpp_capability {
+	DPP_CAPABILITY_ENROLLEE = 0x01,
+	DPP_CAPABILITY_CONFIGURATOR = 0x02,
+};
+
 struct dpp_sm {
 	struct netdev *netdev;
 	char *uri;
+	uint8_t role;
 
 	uint64_t wdev_id;
 
@@ -583,7 +589,6 @@ static void send_authenticate_response(struct dpp_sm *dpp, void *r_auth)
 	uint8_t status = DPP_STATUS_OK;
 	uint64_t r_proto_key[L_ECC_MAX_DIGITS * 2];
 	uint8_t version = 2;
-	uint8_t r_capabilities = 0x01;
 	struct iovec iov[3];
 	uint8_t wrapped2_plaintext[dpp->key_len + 4];
 	uint8_t wrapped2[dpp->key_len + 16 + 8];
@@ -623,7 +628,7 @@ static void send_authenticate_response(struct dpp_sm *dpp, void *r_auth)
 			ptr, sizeof(attrs), dpp->k2, dpp->key_len, 4,
 			DPP_ATTR_RESPONDER_NONCE, dpp->nonce_len, dpp->r_nonce,
 			DPP_ATTR_INITIATOR_NONCE, dpp->nonce_len, dpp->i_nonce,
-			DPP_ATTR_RESPONDER_CAPABILITIES, 1, &r_capabilities,
+			DPP_ATTR_RESPONDER_CAPABILITIES, 1, &dpp->role,
 			DPP_ATTR_WRAPPED_DATA, wrapped2_len, wrapped2);
 
 	iov[1].iov_base = attrs;
@@ -755,7 +760,9 @@ static void authenticate_confirm(struct dpp_sm *dpp, const uint8_t *from,
 	l_debug("Authentication successful");
 
 	dpp_reset_protocol_timer(dpp);
-	dpp_configuration_start(dpp, from);
+
+	if (dpp->role == DPP_CAPABILITY_ENROLLEE)
+		dpp_configuration_start(dpp, from);
 
 	return;
 
@@ -772,7 +779,6 @@ static void dpp_auth_request_failed(struct dpp_sm *dpp,
 	uint8_t attrs[128];
 	uint8_t *ptr = attrs;
 	uint8_t version = 2;
-	uint8_t r_capabilities = 0x01;
 	uint8_t s = status;
 	struct iovec iov[2];
 
@@ -790,7 +796,7 @@ static void dpp_auth_request_failed(struct dpp_sm *dpp,
 	ptr += dpp_append_wrapped_data(hdr + 26, 6, attrs, ptr - attrs,
 			ptr, sizeof(attrs) - (ptr - attrs), k1, dpp->key_len, 2,
 			DPP_ATTR_INITIATOR_NONCE, dpp->nonce_len, dpp->i_nonce,
-			DPP_ATTR_RESPONDER_CAPABILITIES, 1, &r_capabilities);
+			DPP_ATTR_RESPONDER_CAPABILITIES, 1, &dpp->role);
 
 	iov[1].iov_base = attrs;
 	iov[1].iov_len = ptr - attrs;
@@ -799,6 +805,18 @@ static void dpp_auth_request_failed(struct dpp_sm *dpp,
 				dpp->current_freq);
 }
 
+static bool dpp_check_roles(struct dpp_sm *dpp, uint8_t peer_capa)
+{
+	if (dpp->role == DPP_CAPABILITY_ENROLLEE &&
+			!(peer_capa & DPP_CAPABILITY_CONFIGURATOR))
+		return false;
+	else if (dpp->role == DPP_CAPABILITY_CONFIGURATOR &&
+			!(peer_capa & DPP_CAPABILITY_ENROLLEE))
+		return false;
+
+	return true;
+}
+
 static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,
 					const uint8_t *body, size_t body_len)
 {
@@ -811,6 +829,7 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,
 	const uint8_t *i_proto = NULL;
 	const void *wrapped = NULL;
 	const uint8_t *i_nonce = NULL;
+	uint8_t i_capa = 0;
 	size_t r_boot_len = 0, i_proto_len = 0, wrapped_len = 0;
 	size_t i_nonce_len = 0;
 	_auto_(l_free) uint8_t *unwrapped = NULL;
@@ -920,9 +939,10 @@ static void authenticate_request(struct dpp_sm *dpp, const uint8_t *from,
 			 * failure by adding the DPP Status field set to
 			 * STATUS_NOT_COMPATIBLE"
 			 */
-			if (!(l_get_u8(data) & 0x2)) {
-				l_debug("Initiator is not configurator");
+			i_capa = l_get_u8(data);
 
+			if (!dpp_check_roles(dpp, i_capa)) {
+				l_debug("Peer does not support required role");
 				dpp_auth_request_failed(dpp,
 						DPP_STATUS_NOT_COMPATIBLE, k1);
 				goto auth_request_failed;
@@ -1037,9 +1057,11 @@ static void dpp_roc_started(void *user_data)
 	struct dpp_sm *dpp = user_data;
 
 	/*
-	 * If not in presence procedure, just stay on channel.
+	 * If not in presence procedure or in a configurator role, just stay
+	 * on channel.
 	 */
-	if (dpp->state != DPP_STATE_PRESENCE)
+	if (dpp->state != DPP_STATE_PRESENCE ||
+			dpp->role == DPP_CAPABILITY_CONFIGURATOR)
 		return;
 
 	dpp_presence_announce(dpp);
@@ -1230,6 +1252,7 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 					1, NULL, NULL);
 
 	dpp->state = DPP_STATE_PRESENCE;
+	dpp->role = DPP_CAPABILITY_ENROLLEE;
 
 	l_debug("DPP Start Enrollee: %s", dpp->uri);
 
Signature · 1 line
2.31.1
author
#5 lore raw

PATCH 6/9 dpp: implement configurator role

In reply to James Prestwood

This implements a configurator in the responder role. Currently configuring an enrollee is limited to only the connected network. This is to avoid the need to go offchannel for any reason. But because of this a roam, channel switch, or disconnect will cause the configuration to fail as none of the frames are being sent offchannel.

---
 src/dpp.c | 338 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 336 insertions(+), 2 deletions(-)
src/dpp.c +336 -2
index 29cec5cd..4ddd93cf 100644
@@ -45,7 +45,12 @@
 #include "src/mpdu.h"
 #include "ell/useful.h"
 #include "src/common.h"
+#include "src/json.h"
 #include "src/storage.h"
+#include "src/station.h"
+#include "src/scan.h"
+#include "src/network.h"
+#include "src/handshake.h"
 
 static uint32_t netdev_watch;
 static struct l_genl_family *nl80211;
@@ -107,6 +112,8 @@ struct dpp_sm {
 
 	/* Timeout of either auth/config protocol */
 	struct l_timeout *timeout;
+
+	struct dpp_configuration *config;
 };
 
 static void dpp_free_auth_data(struct dpp_sm *dpp)
@@ -144,6 +151,16 @@ static void dpp_reset(struct dpp_sm *dpp)
 		dpp->offchannel_id = 0;
 	}
 
+	if (dpp->timeout) {
+		l_timeout_remove(dpp->timeout);
+		dpp->timeout = NULL;
+	}
+
+	if (dpp->config) {
+		dpp_configuration_free(dpp->config);
+		dpp->config = NULL;
+	}
+
 	dpp->state = DPP_STATE_NOTHING;
 
 	dpp_free_auth_data(dpp);
@@ -556,6 +573,258 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	send_config_result(dpp, dpp->auth_addr);
 }
 
+static void dpp_send_config_response(struct dpp_sm *dpp)
+{
+	_auto_(l_free) char *json;
+	struct iovec iov[3];
+	uint8_t hdr[41];
+	uint8_t attrs[512];
+	size_t json_len;
+	uint8_t zero = 0;
+	uint8_t *ptr = hdr + 24;
+
+	l_put_le16(0x00d0, hdr);
+	memcpy(hdr + 4, dpp->auth_addr, 6);
+	memcpy(hdr + 10, netdev_get_address(dpp->netdev), 6);
+	memcpy(hdr + 16, broadcast, 6);
+
+	*ptr++ = 0x04;
+	*ptr++ = 0x0b;
+	*ptr++ = dpp->diag_token;
+	l_put_le16(0, ptr); /* status */
+	ptr += 2;
+	l_put_le16(0, ptr); /* fragmented (no) */
+	ptr += 2;
+	*ptr++ = IE_TYPE_ADVERTISEMENT_PROTOCOL;
+	*ptr++ = 0x08;
+	*ptr++ = 0x7f;
+	*ptr++ = IE_TYPE_VENDOR_SPECIFIC;
+	*ptr++ = 5;
+	memcpy(ptr, wifi_alliance_oui, sizeof(wifi_alliance_oui));
+	ptr += sizeof(wifi_alliance_oui);
+	*ptr++ = 0x1a;
+	*ptr++ = 1;
+
+	json = dpp_configuration_to_json(dpp->config);
+	json_len = strlen(json);
+
+	iov[0].iov_base = hdr;
+	iov[0].iov_len = ptr - hdr;
+
+	ptr = attrs;
+
+	ptr += 2; /* length */
+
+	ptr += dpp_append_attr(ptr, DPP_ATTR_STATUS, &zero, 1);
+
+	ptr += dpp_append_wrapped_data(attrs + 2, ptr - attrs - 2, NULL, 0, ptr,
+			sizeof(attrs), dpp->ke, dpp->key_len, 2,
+			DPP_ATTR_ENROLLEE_NONCE, dpp->nonce_len, dpp->e_nonce,
+			DPP_ATTR_CONFIGURATION_OBJECT, json_len, json);
+
+	l_put_le16(ptr - attrs - 2, attrs);
+
+	iov[1].iov_base = attrs;
+	iov[1].iov_len = ptr - attrs;
+
+	dpp_send_frame(dpp->wdev_id, iov, 2, dpp->current_freq);
+}
+
+static void dpp_handle_config_request_frame(const struct mmpdu_header *frame,
+				const void *body, size_t body_len,
+				int rssi, void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+	const uint8_t *ptr = body;
+	struct dpp_attr_iter iter;
+	enum dpp_attribute_type type;
+	size_t len;
+	const uint8_t *data;
+	const char *json = NULL;
+	size_t json_len = 0;
+	struct json_contents *c;
+	const uint8_t *wrapped = NULL;
+	const uint8_t *e_nonce = NULL;
+	size_t wrapped_len = 0;
+	_auto_(l_free) uint8_t *unwrapped = NULL;
+	uint8_t hdr_check[] = { IE_TYPE_ADVERTISEMENT_PROTOCOL, 0x08, 0x7f,
+				IE_TYPE_VENDOR_SPECIFIC, 5 };
+
+	if (dpp->state != DPP_STATE_AUTHENTICATING) {
+		l_debug("Configuration request in wrong state");
+		return;
+	}
+
+	if (memcmp(dpp->auth_addr, frame->address_2, 6)) {
+		l_debug("Configuration request not from authenticated peer");
+		return;
+	}
+
+	if (body_len < 15) {
+		l_debug("Configuration request data not long enough");
+		return;
+	}
+
+	ptr += 2;
+
+	dpp->diag_token = *ptr++;
+
+	if (memcmp(ptr, hdr_check, sizeof(hdr_check)))
+		return;
+
+	ptr += sizeof(hdr_check);
+
+	if (memcmp(ptr, wifi_alliance_oui, sizeof(wifi_alliance_oui)))
+		return;
+
+	ptr += sizeof(wifi_alliance_oui);
+
+	if (*ptr != 0x1a && *(ptr + 1) != 1)
+		return;
+
+	ptr += 2;
+
+	len = l_get_le16(ptr);
+	ptr += 2;
+
+	if (len > body_len - 15)
+		return;
+
+	dpp_attr_iter_init(&iter, ptr, len);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_WRAPPED_DATA:
+			wrapped = data;
+			wrapped_len = len;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!wrapped) {
+		l_debug("Wrapped data missing");
+		return;
+	}
+
+	unwrapped = dpp_unwrap_attr(NULL, 0, NULL, 0, dpp->ke,
+					dpp->key_len, wrapped, wrapped_len,
+					&wrapped_len);
+	if (!unwrapped) {
+		l_debug("Failed to unwrap");
+		return;
+	}
+
+	dpp_attr_iter_init(&iter, unwrapped, wrapped_len);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_ENROLLEE_NONCE:
+			if (len != dpp->nonce_len)
+				break;
+
+			e_nonce = data;
+			break;
+		case DPP_ATTR_CONFIGURATION_REQUEST:
+			json = (const char *)data;
+			json_len = len;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!json || !e_nonce) {
+		l_debug("No configuration object in response");
+		return;
+	}
+
+	/*
+	 * TODO: Full JSON type support (arrays/numbers) is not yet implemented.
+	 * Just verify the JSON is valid for now. There really isn't much need
+	 * to parse this anyhow since IWD only supports configuring stations.
+	 * If this request is for anything else it will fail regardless.
+	 */
+	c = json_contents_new(json, json_len);
+	if (!c) {
+		json_contents_free(c);
+		return;
+	}
+
+	json_contents_free(c);
+
+	memcpy(dpp->e_nonce, e_nonce, dpp->nonce_len);
+
+	dpp->state = DPP_STATE_CONFIGURING;
+
+	dpp_send_config_response(dpp);
+}
+
+static void dpp_handle_config_result_frame(struct dpp_sm *dpp,
+					const uint8_t *from, const void *body,
+					size_t body_len)
+{
+	struct dpp_attr_iter iter;
+	enum dpp_attribute_type type;
+	size_t len;
+	const uint8_t *data;
+	int status = -1;
+	const void *e_nonce = NULL;
+	const void *wrapped = NULL;
+	size_t wrapped_len;
+	_auto_(l_free) void *unwrapped;
+
+	if (dpp->state != DPP_STATE_CONFIGURING)
+		return;
+
+	dpp_attr_iter_init(&iter, body + 8, body_len - 8);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_WRAPPED_DATA:
+			wrapped = data;
+			wrapped_len = len;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!wrapped)
+		return;
+
+	unwrapped = dpp_unwrap_attr(body + 2, wrapped - body - 6, wrapped, 0,
+					dpp->ke, dpp->key_len, wrapped,
+					wrapped_len, &wrapped_len);
+	if (!unwrapped) {
+		l_debug("Failed to unwrap DPP configuration result");
+		return;
+	}
+
+	dpp_attr_iter_init(&iter, unwrapped, wrapped_len);
+
+	while (dpp_attr_iter_next(&iter, &type, &len, &data)) {
+		switch (type) {
+		case DPP_ATTR_STATUS:
+			status = l_get_u8(data);
+			break;
+		case DPP_ATTR_ENROLLEE_NONCE:
+			e_nonce = data;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (status != DPP_STATUS_OK || !e_nonce)
+		l_debug("Enrollee signaled a failed configuration");
+	else
+		l_debug("Configuration success");
+
+	dpp_reset(dpp);
+}
+
 /*
  * The Authentication protocol has a consistent use of AD components, and this
  * use is defined in 6.3.1.4:
@@ -994,7 +1263,7 @@ auth_request_failed:
 	dpp_free_auth_data(dpp);
 }
 
-static void dpp_handle_auth_frame(const struct mmpdu_header *frame,
+static void dpp_handle_frame(const struct mmpdu_header *frame,
 				const void *body, size_t body_len,
 				int rssi, void *user_data)
 {
@@ -1018,6 +1287,10 @@ static void dpp_handle_auth_frame(const struct mmpdu_header *frame,
 	case DPP_FRAME_AUTHENTICATION_CONFIRM:
 		authenticate_confirm(dpp, frame->address_2, body, body_len);
 		break;
+	case DPP_FRAME_CONFIGURATION_RESULT:
+		dpp_handle_config_result_frame(dpp, frame->address_2,
+						body, body_len);
+		break;
 	default:
 		l_debug("Unhandled DPP frame %u", *ptr);
 		break;
@@ -1073,6 +1346,7 @@ static void dpp_create(struct netdev *netdev)
 	struct dpp_sm *dpp = l_new(struct dpp_sm, 1);
 	uint8_t dpp_prefix[] = { 0x04, 0x09, 0x50, 0x6f, 0x9a, 0x1a, 0x01 };
 	uint8_t dpp_conf_response_prefix[] = { 0x04, 0x0b };
+	uint8_t dpp_conf_request_prefix[] = { 0x04, 0x0a };
 
 	dpp->netdev = netdev;
 	dpp->state = DPP_STATE_NOTHING;
@@ -1093,12 +1367,16 @@ static void dpp_create(struct netdev *netdev)
 					IWD_DPP_INTERFACE, dpp);
 
 	frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0, dpp_prefix,
-				sizeof(dpp_prefix), dpp_handle_auth_frame,
+				sizeof(dpp_prefix), dpp_handle_frame,
 				dpp, NULL);
 	frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0,
 				dpp_conf_response_prefix,
 				sizeof(dpp_conf_response_prefix),
 				dpp_handle_config_response_frame, dpp, NULL);
+	frame_watch_add(netdev_get_wdev_id(netdev), 0, 0x00d0,
+				dpp_conf_request_prefix,
+				sizeof(dpp_conf_request_prefix),
+				dpp_handle_config_request_frame, dpp, NULL);
 }
 
 static void dpp_netdev_watch(struct netdev *netdev,
@@ -1270,6 +1548,60 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 	return reply;
 }
 
+static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+	struct l_dbus_message *reply;
+	struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
+	struct scan_bss *bss;
+	struct network *network;
+	struct l_settings *settings;
+	struct handshake_state *hs = netdev_get_handshake(dpp->netdev);
+
+	/*
+	 * For now limit the configurator to only configuring enrollees to the
+	 * currently connected network.
+	 */
+	if (!station)
+		return dbus_error_not_available(message);
+
+	bss = station_get_connected_bss(station);
+	network = station_get_connected_network(station);
+	if (!bss || !network)
+		return dbus_error_not_connected(message);
+
+	settings = network_get_settings(network);
+	if (!settings)
+		return dbus_error_not_configured(message);
+
+	if (network_get_security(network) != SECURITY_PSK)
+		return dbus_error_not_supported(message);
+
+	if (dpp->state != DPP_STATE_NOTHING)
+		return dbus_error_busy(message);
+
+	dpp->uri = dpp_generate_uri(dpp->pub_asn1, dpp->pub_asn1_len, 2,
+					netdev_get_address(dpp->netdev),
+					&bss->frequency, 1, NULL, NULL);
+
+	dpp->state = DPP_STATE_PRESENCE;
+	dpp->role = DPP_CAPABILITY_CONFIGURATOR;
+	dpp->current_freq = bss->frequency;
+	dpp->config = dpp_configuration_new(settings,
+						network_get_ssid(network),
+						hs->akm_suite);
+
+	l_debug("DPP Start Configurator: %s", dpp->uri);
+
+	reply = l_dbus_message_new_method_return(message);
+
+	l_dbus_message_set_arguments(reply, "s", dpp->uri);
+
+	return reply;
+}
+
 static struct l_dbus_message *dpp_dbus_stop(struct l_dbus *dbus,
 						struct l_dbus_message *message,
 						void *user_data)
@@ -1285,6 +1617,8 @@ static void dpp_setup_interface(struct l_dbus_interface *interface)
 {
 	l_dbus_interface_method(interface, "StartEnrollee", 0,
 				dpp_dbus_start_enrollee, "s", "", "uri");
+	l_dbus_interface_method(interface, "StartConfigurator", 0,
+				dpp_dbus_start_configurator, "s", "", "uri");
 	l_dbus_interface_method(interface, "Stop", 0,
 				dpp_dbus_stop, "", "");
 }
Signature · 1 line
2.31.1
author
#6 lore raw

PATCH 7/9 doc: document StartConfigurator

In reply to James Prestwood
---
 doc/device-provisioning.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
doc/device-provisioning.txt +14 -0
index 3ac2d934..bf54c5fe 100644
@@ -23,3 +23,17 @@ Methods		string StartEnrollee()
 			Possible errors:	net.connman.iwd.Busy
 						net.connman.iwd.Failed
 						net.connman.iwd.InvalidArguments
+
+		string StartConfigurator()
+
+			Start a DPP configurator. Currently only connected
+			station devices are supported, and will only configure
+			the enrollee to the currently connected network.
+
+			Returns the configurator URI
+
+			Possible errors:	net.connman.iwd.NotAvailable
+						net.connman.iwd.NotConnected
+						net.connman.iwd.NotConfigured
+						net.connman.iwd.NotSupported
+						net.connman.iwd.Busy
Signature · 1 line
2.31.1
author
#7 lore raw

PATCH 8/9 client: add DPP interface

In reply to James Prestwood
---
 client/dbus-proxy.h | 1 +
 1 file changed, 1 insertion(+)
client/dbus-proxy.h +1 -0
index 2a366d1b..1d6af5de 100644
@@ -36,6 +36,7 @@ struct proxy_interface;
 #define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"
 #define IWD_AP_DIAGNOSTIC_INTERFACE      "net.connman.iwd.AccessPointDiagnostic"
 #define IWD_DAEMON_INTERFACE             "net.connman.iwd.Daemon"
+#define IWD_DPP_INTERFACE                "net.connman.iwd.DeviceProvisioning"
 
 typedef bool (*proxy_property_match_func_t) (const void *a, const void *b);
 
Signature · 1 line
2.31.1
author
#8 lore raw

PATCH 9/9 client: add DPP client commands

In reply to James Prestwood

Two commands were added:

dpp <iface> start-enrollee
dpp <iface> start-configurator
dpp <iface> stop

In addition there is support for using the qrencode utility for displaying the QR code after DPP is started (enrollee or configurator. If qrencode is found on the system the QR code will be displayed. Otherwise only the URI will be printed to the console.

---
 Makefile.am  |   3 +-
 client/dpp.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 235 insertions(+), 1 deletion(-)
 create mode 100644 client/dpp.c
Makefile.am +2 -1
index d079ba89..fe307587 100644
@@ -299,7 +299,8 @@ client_iwctl_SOURCES = client/main.c \
 			client/properties.h client/properties.c \
 			client/wsc.c client/station.c \
 			client/diagnostic.c client/diagnostic.h \
-			client/daemon.c client/daemon.h
+			client/daemon.c client/daemon.h \
+			client/dpp.c
 
 client_iwctl_LDADD = $(ell_ldadd) $(READLINE_LIBS)
 
client/dpp.c new file +233 -0

233 lines not on this page · raw message

Signature · 1 line
2.31.1
#9 lore raw
In reply to James Prestwood

Hi James,

Quoted 7 lines · James Prestwood

Rather than hard coding ad0, use the actual frame data. There really isn't a reason this would differ (only status attribute) but just in case its better to use the frame data directly.

---
  src/dpp.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

Patches 1-3 applied, thanks.

Regards,
-Denis