3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

dpp: generate URI on StartEnrollee

Generates the required keys, hashes, and sets the Uri property
This commit is contained in:
James Prestwood 2021-12-16 10:08:48 -08:00 committed by Denis Kenzior
parent acfbc34909
commit 76d9a2e702

View File

@ -29,15 +29,54 @@
#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_reset(struct dpp_sm *dpp)
{
if (dpp->uri) {
l_free(dpp->uri);
dpp->uri = NULL;
}
}
static void dpp_free(struct dpp_sm *dpp)
{
dpp_reset(dpp);
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;
}
l_free(dpp);
}
@ -47,6 +86,17 @@ 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);
@ -77,14 +127,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)