]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P2: Handle identity ID consistently within files
authorBenjamin Berg <benjamin.berg@intel.com>
Thu, 30 Oct 2025 08:24:46 +0000 (09:24 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 13 Dec 2025 20:20:11 +0000 (22:20 +0200)
Using an ID to reference a specific identity= block within the same file
for the DIK has the problem that it requires the IDs to be stable.
However, we also use a static int for the ID enumeration in case
multiple files are read.

Overall, it seems like it could be better to use the DIK as an
identifier. However, we do not, so the numbering needs to be restored
consistently within the file. The straight forward way to achieve this
is to store the base of the counter as a static variable and adding it
to both the go_dik_id and the id of the identity= blocks.

For all of this to work, we also need to make sure that we write out the
values with file-local indices. As such, we need to use the position in
the internal list rather than the assigned ID when writing the values.

Fixes: 417c67468b8d ("P2P2: Add device identity block to wpa_supplicant configuration")
Fixes: ec4569174750 ("P2P2: Store ID of Device Identity block in network block")
CC: Shivani Baranwal <quic_shivbara@quicinc.com>
CC: Vinay Gannevaram <quic_vganneva@quicinc.com>
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
wpa_supplicant/config_file.c

index c8be83a878d3c37076d48e580843ed8ffbc8b3f3..ca27e62e9dee98c921f061436e2c3c5187e73871 100644 (file)
@@ -367,7 +367,8 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
        struct wpa_config *config;
        static int id = 0;
        static int cred_id = 0;
-       static int identity_id = 1;
+       static int base_identity_id = 0;
+       int identity_id = base_identity_id;
 
        if (name == NULL)
                return NULL;
@@ -416,6 +417,7 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
                                errors++;
                                continue;
                        }
+                       ssid->go_dik_id += base_identity_id;
                        ssid->ro = ro;
                        if (head == NULL) {
                                head = tail = ssid;
@@ -456,7 +458,7 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
 #endif /* CONFIG_NO_CONFIG_BLOBS */
                } else if (os_strcmp(pos, "identity={") == 0) {
                        identity = wpa_config_read_identity(f, &line,
-                                                           identity_id++);
+                                                           ++identity_id);
                        if (!identity) {
                                wpa_printf(MSG_ERROR,
                                           "Line %d: failed to parse identity block.",
@@ -488,6 +490,8 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
        config->cred = cred_head;
        config->identity = identity_head;
 
+       base_identity_id = identity_id;
+
 #ifndef WPA_IGNORE_CONFIG_ERRORS
        if (errors) {
                if (config != cfgp)
@@ -768,7 +772,8 @@ static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid)
 #endif /* CONFIG_MACSEC */
 
 
-static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
+static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid,
+                                    struct wpa_config *config)
 {
 #define STR(t) write_str(f, #t, ssid)
 #define INT(t) write_int(f, #t, ssid->t, 0)
@@ -910,7 +915,20 @@ static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
        write_p2p_client_list(f, ssid);
        write_p2p2_client_list(f, ssid);
        write_psk_list(f, ssid);
-       INT(go_dik_id);
+       {
+               struct wpa_dev_ik *dev_ik;
+               int i = 1, go_dik_id = 0;
+
+               for (dev_ik = config->identity;
+                    dev_ik;
+                    dev_ik = dev_ik->next, i++) {
+                       if (dev_ik->id == ssid->go_dik_id) {
+                               go_dik_id = i;
+                               break;
+                       }
+               }
+               write_int(f, "go_dik_id", go_dik_id, 0);
+       }
 #endif /* CONFIG_P2P */
        INT(ap_max_inactivity);
        INT(dtim_period);
@@ -1860,7 +1878,7 @@ int wpa_config_write(const char *name, struct wpa_config *config)
                    !ssid->pmk_valid)
                        continue; /* do not save invalid network */
                fprintf(f, "\nnetwork={\n");
-               wpa_config_write_network(f, ssid);
+               wpa_config_write_network(f, ssid, config);
                fprintf(f, "}\n");
        }