From: Peddolla Harshavardhan Reddy Date: Sat, 26 Apr 2025 19:14:49 +0000 (+0530) Subject: PR: Fetch Device Identity Key from configuration file X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd971fbc1b96bca2b646f6d9705d0c336a10c19a;p=thirdparty%2Fhostap.git PR: Fetch Device Identity Key from configuration file Get Device Identity Key from wpa_supplicant configuration file. Generate a new DIK if it is not present in the configuration file. Signed-off-by: Peddolla Harshavardhan Reddy --- diff --git a/src/common/proximity_ranging.h b/src/common/proximity_ranging.h index 830ac5f8b..45ae998fc 100644 --- a/src/common/proximity_ranging.h +++ b/src/common/proximity_ranging.h @@ -12,6 +12,8 @@ #include "utils/list.h" #include "wps/wps_defs.h" +#define DEVICE_IDENTITY_KEY_LEN 16 + /** * PR_MAX_OP_CLASSES - Maximum number of operating classes */ @@ -285,6 +287,18 @@ struct pr_config { bool support_6ghz; + /* Cipher version type */ + int dik_cipher; + + /* Buffer to hold the DevIK */ + u8 dik_data[DEVICE_IDENTITY_KEY_LEN]; + + /* Length of DevIK in octets */ + size_t dik_len; + + /* DevIK expiration */ + int expiration; + /** * cb_ctx - Context to use with callback functions */ diff --git a/wpa_supplicant/pr_supplicant.c b/wpa_supplicant/pr_supplicant.c index f32d9a45e..961d5711e 100644 --- a/wpa_supplicant/pr_supplicant.c +++ b/wpa_supplicant/pr_supplicant.c @@ -10,6 +10,7 @@ #include "utils/common.h" #include "common/proximity_ranging.h" +#include "p2p/p2p.h" #include "wpa_supplicant_i.h" #include "config.h" #include "pr_supplicant.h" @@ -312,6 +313,35 @@ int wpas_pr_init(struct wpa_global *global, struct wpa_supplicant *wpa_s, os_memcpy(pr.country, "XX\x04", 3); } + if (wpa_s->conf->dik && + wpabuf_len(wpa_s->conf->dik) <= DEVICE_IDENTITY_KEY_LEN) { + pr.dik_cipher = wpa_s->conf->dik_cipher; + pr.dik_len = wpabuf_len(wpa_s->conf->dik); + os_memcpy(pr.dik_data, wpabuf_head(wpa_s->conf->dik), + pr.dik_len); + pr.expiration = 24; /* hours */ + } else { + pr.dik_cipher = DIRA_CIPHER_VERSION_128; + pr.dik_len = DEVICE_IDENTITY_KEY_LEN; + pr.expiration = 24; /* hours */ + if (os_get_random(pr.dik_data, pr.dik_len) < 0) + return -1; + + wpa_s->conf->dik = + wpabuf_alloc_copy(pr.dik_data, pr.dik_len); + if (!wpa_s->conf->dik) + return -1; + + wpa_s->conf->dik_cipher = pr.dik_cipher; + + wpa_printf(MSG_DEBUG, "PR: PR init new DIRA set"); + + if (wpa_s->conf->update_config && + wpa_config_write(wpa_s->confname, wpa_s->conf)) + wpa_printf(MSG_DEBUG, + "PR: Failed to update configuration"); + } + global->pr = pr_init(&pr); if (!global->pr) { wpa_printf(MSG_DEBUG, "PR: Failed to init PR");