* [PATCH v2 03/10] dpp: generate URI on StartEnrollee
@ 2021-12-14 18:12 James Prestwood
0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2021-12-14 18:12 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 4629 bytes --]
Generates the required keys, hashes, and sets the Uri property
---
src/dpp.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 118 insertions(+), 2 deletions(-)
v2;
* Removed Frequency option and just choose a default
* Use 19 as the default group
diff --git a/src/dpp.c b/src/dpp.c
index d727e639..10d8f542 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)
@@ -47,8 +61,33 @@ static void dpp_create(struct netdev *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);
}
@@ -72,23 +111,100 @@ static void dpp_netdev_watch(struct netdev *netdev,
}
}
+static bool dpp_parse_enrollee_params(struct l_dbus_message *message,
+ const char **info_out,
+ const char **host_out)
+{
+ struct l_dbus_message_iter iter;
+ struct l_dbus_message_iter variant;
+ const char *key;
+ char *info = NULL, *host = NULL;
+
+ if (!l_dbus_message_get_arguments(message, "a{sv}", &iter)) {
+ l_error("Failed to parse StartEnrollee parameters");
+ return false;
+ }
+
+ while (l_dbus_message_iter_next_entry(&iter, &key, &variant)) {
+ if (!strcmp(key, "Information")) {
+ if (!l_dbus_message_iter_get_variant(&variant, "s",
+ &info))
+ return false;
+ } else if (!strcmp(key, "Host")) {
+ if (!l_dbus_message_iter_get_variant(&variant, "s",
+ &host))
+ return false;
+ }
+ /*
+ * TODO:
+ * - Allow a MAC to be specififed, this would require changing
+ * the device MAC prior to starting.
+ * - Allow a custom key pair to be supplied, or some way of
+ * deterministically generating one based on some seed.
+ */
+ }
+
+ if (info_out && info)
+ *info_out = info;
+ else if (!info_out && info)
+ l_free(info);
+
+ if (host_out && host)
+ *host_out = host;
+ else if (!host_out && host)
+ l_free(host);
+
+ return true;
+}
+
static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data)
{
struct dpp_sm *dpp = user_data;
+ const char *info = NULL, *host = NULL;
+ uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
if (!netdev_get_is_up(dpp->netdev))
return dbus_error_not_available(message);
- return dbus_error_not_supported(message);
+ if (!dpp_parse_enrollee_params(message, &info, &host))
+ return dbus_error_invalid_args(message);
+
+ 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 = l_ecc_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);
+
+ dpp->uri = dpp_generate_uri(dpp->pub_asn1, dpp->pub_asn1_len, 2,
+ netdev_get_address(dpp->netdev), &freq,
+ 1, info, host);
+
+ l_debug("DPP Start Enrollee: %s", dpp->uri);
+
+ l_dbus_property_changed(dbus_get_bus(), netdev_get_path(dpp->netdev),
+ IWD_DPP_INTERFACE, "Uri");
+
+ return l_dbus_message_new_method_return(message);
}
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] 2+ messages in thread
* Re: [PATCH v2 03/10] dpp: generate URI on StartEnrollee
@ 2021-12-14 23:28 Denis Kenzior
0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-12-14 23:28 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 3947 bytes --]
Hi James,
On 12/14/21 12:12 PM, James Prestwood wrote:
> Generates the required keys, hashes, and sets the Uri property
> ---
> src/dpp.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 118 insertions(+), 2 deletions(-)
>
> v2;
> * Removed Frequency option and just choose a default
> * Use 19 as the default group
>
<snip>
> @@ -72,23 +111,100 @@ static void dpp_netdev_watch(struct netdev *netdev,
> }
> }
>
> +static bool dpp_parse_enrollee_params(struct l_dbus_message *message,
> + const char **info_out,
> + const char **host_out)
> +{
> + struct l_dbus_message_iter iter;
> + struct l_dbus_message_iter variant;
> + const char *key;
> + char *info = NULL, *host = NULL;
> +
> + if (!l_dbus_message_get_arguments(message, "a{sv}", &iter)) {
> + l_error("Failed to parse StartEnrollee parameters");
> + return false;
> + }
> +
> + while (l_dbus_message_iter_next_entry(&iter, &key, &variant)) {
> + if (!strcmp(key, "Information")) {
> + if (!l_dbus_message_iter_get_variant(&variant, "s",
> + &info))
> + return false;
> + } else if (!strcmp(key, "Host")) {
> + if (!l_dbus_message_iter_get_variant(&variant, "s",
> + &host))
> + return false;
> + }
> + /*
> + * TODO:
> + * - Allow a MAC to be specififed, this would require changing
> + * the device MAC prior to starting.
> + * - Allow a custom key pair to be supplied, or some way of
> + * deterministically generating one based on some seed.
> + */
> + }
> +
Note that Information & Hostname have some limitations as to what characters are
allowed. DBus strings are valid UTF8 strings, but it seems EasyConnect spec
wants these to be ASCII sans ';' characters. Given the lack of utility of these
parameters, perhaps we should just drop them entirely.
> + if (info_out && info)
> + *info_out = info;
> + else if (!info_out && info)
> + l_free(info);
> +
> + if (host_out && host)
> + *host_out = host;
> + else if (!host_out && host)
> + l_free(host);
> +
> + return true;
> +}
> +
> static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
> struct l_dbus_message *message,
> void *user_data)
> {
> struct dpp_sm *dpp = user_data;
> + const char *info = NULL, *host = NULL;
> + uint32_t freq = band_channel_to_freq(6, BAND_FREQ_2_4_GHZ);
>
> if (!netdev_get_is_up(dpp->netdev))
> return dbus_error_not_available(message);
>
> - return dbus_error_not_supported(message);
> + if (!dpp_parse_enrollee_params(message, &info, &host))
> + return dbus_error_invalid_args(message);
> +
> + 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);
> +
Since the curve is most likely always going to be the same, it might make sense
to initialize these parts when creating the dpp_sm object.
> + l_ecdh_generate_key_pair(dpp->curve, &dpp->boot_private,
> + &dpp->boot_public);
Similarly, maybe the boot key should be created only once or when the dpp_sm
object is created?
> +
> + dpp->pub_asn1 = l_ecc_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);
> +
> + dpp->uri = dpp_generate_uri(dpp->pub_asn1, dpp->pub_asn1_len, 2,
> + netdev_get_address(dpp->netdev), &freq,
> + 1, info, host);
> +
> + l_debug("DPP Start Enrollee: %s", dpp->uri);
> +
> + l_dbus_property_changed(dbus_get_bus(), netdev_get_path(dpp->netdev),
> + IWD_DPP_INTERFACE, "Uri");
There is no such property now. And you should return the uri string as part of
the method return.
> +
> + return l_dbus_message_new_method_return(message);
> }
>
<snip>
Regards,
-Denis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-14 23:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 18:12 [PATCH v2 03/10] dpp: generate URI on StartEnrollee James Prestwood
2021-12-14 23:28 Denis Kenzior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.