public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v3 04/11] dpp: generate URI on StartEnrollee
@ 2021-12-15 17:58 James Prestwood
  0 siblings, 0 replies; only message in thread
From: James Prestwood @ 2021-12-15 17:58 UTC (permalink / raw)
  To: iwd 

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

Generates the required keys, hashes, and sets the Uri property
---
 src/dpp.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 70 insertions(+), 2 deletions(-)

v3:
 * Move curve/key init into dpp_create
 * Removed StartEnrollee argument entirely
 * Removed Uri property change

diff --git a/src/dpp.c b/src/dpp.c
index e70a2357..dbab71c1 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -29,11 +29,25 @@
 #include "src/dbus.h"
 #include "src/netdev.h"
 #include "src/module.h"
+#include "src/dpp-util.h"
+#include "src/band.h"
 
 static uint32_t netdev_watch;
 
 struct dpp_sm {
 	struct netdev *netdev;
+	char *uri;
+
+	uint64_t wdev_id;
+
+	uint8_t *pub_asn1;
+	size_t pub_asn1_len;
+	uint8_t pub_boot_hash[32];
+	const struct l_ecc_curve *curve;
+	size_t key_len;
+	size_t nonce_len;
+	struct l_ecc_scalar *boot_private;
+	struct l_ecc_point *boot_public;
 };
 
 static void dpp_create(struct netdev *netdev)
@@ -42,13 +56,49 @@ static void dpp_create(struct netdev *netdev)
 	struct dpp_sm *dpp = l_new(struct dpp_sm, 1);
 
 	dpp->netdev = netdev;
+	dpp->curve = l_ecc_curve_from_ike_group(19);
+	dpp->key_len = l_ecc_curve_get_scalar_bytes(dpp->curve);
+	dpp->nonce_len = dpp_nonce_len_from_key_len(dpp->key_len);
+
+	l_ecdh_generate_key_pair(dpp->curve, &dpp->boot_private,
+					&dpp->boot_public);
+
+	dpp->pub_asn1 = dpp_point_to_asn1(dpp->boot_public, &dpp->pub_asn1_len);
+
+	dpp_hash(L_CHECKSUM_SHA256, dpp->pub_boot_hash, 1,
+			dpp->pub_asn1, dpp->pub_asn1_len);
 
 	l_dbus_object_add_interface(dbus, netdev_get_path(netdev),
 					IWD_DPP_INTERFACE, dpp);
 }
 
+static void dpp_reset(struct dpp_sm *dpp)
+{
+	if (dpp->uri) {
+		l_free(dpp->uri);
+		dpp->uri = NULL;
+	}
+
+	if (dpp->pub_asn1) {
+		l_free(dpp->pub_asn1);
+		dpp->pub_asn1 = NULL;
+	}
+
+	if (dpp->boot_public) {
+		l_ecc_point_free(dpp->boot_public);
+		dpp->boot_public = NULL;
+	}
+
+	if (dpp->boot_private) {
+		l_ecc_scalar_free(dpp->boot_private);
+		dpp->boot_private = NULL;
+	}
+}
+
 static void dpp_free(struct dpp_sm *dpp)
 {
+	dpp_reset(dpp);
+
 	l_free(dpp);
 }
 
@@ -78,14 +128,32 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
 						struct l_dbus_message *message,
 						void *user_data)
 {
-	return dbus_error_not_supported(message);
+	struct dpp_sm *dpp = user_data;
+	uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
+	struct l_dbus_message *reply;
+
+	dpp->uri = dpp_generate_uri(dpp->pub_asn1, dpp->pub_asn1_len, 2,
+					netdev_get_address(dpp->netdev), &freq,
+					1, NULL, NULL);
+
+	l_debug("DPP Start Enrollee: %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)
 {
-	return dbus_error_not_supported(message);
+	struct dpp_sm *dpp = user_data;
+
+	dpp_reset(dpp);
+
+	return l_dbus_message_new_method_return(message);
 }
 
 static void dpp_setup_interface(struct l_dbus_interface *interface)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-15 17:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-15 17:58 [PATCH v3 04/11] dpp: generate URI on StartEnrollee James Prestwood

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