public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj at gmail.com>
To: iwd at lists.01.org
Subject: [PATCH v3 04/11] dpp: generate URI on StartEnrollee
Date: Wed, 15 Dec 2021 09:58:07 -0800	[thread overview]
Message-ID: <20211215175814.2467124-4-prestwoj@gmail.com> (raw)
In-Reply-To: 20211215175814.2467124-1-prestwoj@gmail.com

[-- 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

                 reply	other threads:[~2021-12-15 17:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211215175814.2467124-4-prestwoj@gmail.com \
    --to=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox