]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P2: Allow PASN-PTK to be fetched for testing purposes
authorShivani Baranwal <quic_shivbara@quicinc.com>
Thu, 11 Jul 2024 18:55:01 +0000 (00:25 +0530)
committerJouni Malinen <j@w1.fi>
Tue, 19 Nov 2024 22:28:00 +0000 (00:28 +0200)
Add support to fetch a recent PASN-PTK that is derived during P2P2
connection. It is required for testing purposes.

Signed-off-by: Shivani Baranwal <quic_shivbara@quicinc.com>
src/common/wpa_common.c
src/common/wpa_common.h
src/p2p/p2p.c
src/p2p/p2p.h
src/p2p/p2p_i.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/p2p_supplicant.h

index a8c7c416d10de7d60fd959f75cce0e8c30e8464c..9c96269d5856542d637b418269f938f856b72b1e 100644 (file)
@@ -582,6 +582,7 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
        ptk->kek2_len = 0;
        ptk->kck2_len = 0;
 
+       ptk->ptk_len = ptk_len;
        os_memset(tmp, 0, sizeof(tmp));
        os_memset(data, 0, data_len);
        return 0;
@@ -1560,6 +1561,7 @@ int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
                                ptk->kdk, ptk->kdk_len);
        }
 
+       ptk->ptk_len = ptk_len;
        forced_memzero(tmp, sizeof(tmp));
        ret = 0;
 err:
index e608d3cbed3e4e0c4b5316933d3095845dd07b45..9f1a539bf597b445d6a9f737dab60fbe357cfdca 100644 (file)
@@ -268,6 +268,7 @@ struct wpa_ptk {
        size_t kck2_len;
        size_t kek2_len;
        size_t kdk_len;
+       size_t ptk_len;
        size_t ltf_keyseed_len;
        int installed; /* 1 if key has already been installed to driver */
 };
index 9159bf4a5016c3944433d8d098461ecb145534e8..bd5d7b8a60f49b18367c786f6762de461e1d86a5 100644 (file)
@@ -7006,6 +7006,9 @@ static int p2p_handle_pasn_auth(struct p2p_data *p2p, struct p2p_device *dev,
                                "PASN Responder: Handle Auth 3 failed");
                        return -1;
                }
+#ifdef CONFIG_TESTING_OPTIONS
+               p2p_pasn_store_ptk(p2p, &pasn->ptk);
+#endif /* CONFIG_TESTING_OPTIONS */
                if (p2p_pasn_handle_action_wrapper(p2p, dev, mgmt, len, freq,
                                                   auth_transaction)) {
                        p2p_dbg(p2p,
@@ -7062,12 +7065,14 @@ int p2p_pasn_auth_rx(struct p2p_data *p2p, const struct ieee80211_mgmt *mgmt,
                }
                ret = wpa_pasn_auth_rx(pasn, (const u8 *) mgmt, len,
                                       &pasn_data);
-               forced_memzero(pasn_get_ptk(pasn), sizeof(pasn->ptk));
-
                if (ret < 0) {
                        p2p_dbg(p2p, "PASN: wpa_pasn_auth_rx() failed");
                        dev->role = P2P_ROLE_IDLE;
                }
+#ifdef CONFIG_TESTING_OPTIONS
+               p2p_pasn_store_ptk(p2p, &pasn->ptk);
+#endif /* CONFIG_TESTING_OPTIONS */
+               forced_memzero(pasn_get_ptk(pasn), sizeof(pasn->ptk));
        } else {
                ret = p2p_handle_pasn_auth(p2p, dev, mgmt, len, freq);
        }
@@ -7084,4 +7089,49 @@ void p2p_pasn_pmksa_set_pmk(struct p2p_data *p2p, const u8 *src, const u8 *dst,
                                       pmk_len, pmkid);
 }
 
+
+#ifdef CONFIG_TESTING_OPTIONS
+
+void p2p_pasn_store_ptk(struct p2p_data *p2p, struct wpa_ptk *ptk)
+{
+       u8 *pos;
+
+       if (ptk->ptk_len > sizeof(p2p->pasn_ptk)) {
+               p2p_dbg(p2p, "P2P PASN PTK exceeds: (len=%ld)", ptk->ptk_len);
+               return;
+       }
+
+       pos = p2p->pasn_ptk;
+       p2p->pasn_ptk_len = ptk->ptk_len;
+       if (ptk->kck_len) {
+               os_memcpy(pos, ptk->kck, ptk->kck_len);
+               pos += ptk->kck_len;
+       }
+       if (ptk->kek_len) {
+               os_memcpy(pos, ptk->kek, ptk->kek_len);
+               pos += ptk->kek_len;
+       }
+       if (ptk->tk_len) {
+               os_memcpy(pos, ptk->tk, ptk->tk_len);
+               pos += ptk->tk_len;
+       }
+       if (ptk->kdk_len) {
+               os_memcpy(pos, ptk->kdk, ptk->kdk_len);
+               pos += ptk->kdk_len;
+       }
+}
+
+
+int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len)
+{
+       if (!p2p || !p2p->pasn_ptk_len)
+               return -1;
+
+       *buf_len = p2p->pasn_ptk_len;
+       *buf = p2p->pasn_ptk;
+       return 0;
+}
+
+#endif /* CONFIG_TESTING_OPTIONS */
+
 #endif /* CONFIG_PASN */
index 96fd85bd0f4832d5ea631b1bbd42e46e2cf6357c..acc99d1450a21067a8e4676ff46b62a8813e4229 100644 (file)
@@ -2733,5 +2733,8 @@ int p2p_pasn_auth_tx_status(struct p2p_data *p2p, const u8 *data,
 int p2p_config_sae_password(struct p2p_data *p2p, const char *pw);
 void p2p_pasn_pmksa_set_pmk(struct p2p_data *p2p, const u8 *src, const u8 *dst,
                            const u8 *pmk, size_t pmk_len, const u8 *pmkid);
+void p2p_set_store_pasn_ptk(struct p2p_data *p2p, u8 val);
+void p2p_pasn_store_ptk(struct p2p_data *p2p, struct wpa_ptk *ptk);
+int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len);
 
 #endif /* P2P_H */
index 135920b3820dd6982c6c6fed446192b6adac5ef3..6fde4f5b71526e5cc116b447bb4ebe456bc9512e 100644 (file)
@@ -678,6 +678,18 @@ struct p2p_data {
         * configuration is done, this variable is reset to false.
         */
        bool go_role;
+
+#ifdef CONFIG_TESTING_OPTIONS
+       /**
+        * PASN PTK of recent auth
+        */
+       u8 pasn_ptk[128];
+
+       /**
+        * PASN PTK length
+        */
+       size_t pasn_ptk_len;
+#endif /* CONFIG_TESTING_OPTIONS */
 };
 
 /**
index 0a8246c5e6a1bd1b89992a840a1deaadf59009ee..87da9636f8f8e5bd90f83a83172fc5013483cdbf 100644 (file)
@@ -10954,6 +10954,24 @@ static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
 #endif /* CONFIG_AP */
 }
 
+#ifdef CONFIG_P2P
+#ifdef CONFIG_PASN
+
+#ifdef CONFIG_TESTING_OPTIONS
+static int p2p_ctrl_get_pasn_ptk(struct wpa_supplicant *wpa_s, char *buf,
+                                size_t buflen)
+{
+       const u8 *ptk;
+       size_t ptk_len;
+
+       if (wpas_p2p_get_pasn_ptk(wpa_s, &ptk, &ptk_len))
+               return -1;
+       return wpa_snprintf_hex(buf, buflen, ptk, ptk_len);
+}
+#endif /* CONFIG_TESTING_OPTIONS */
+
+#endif /* CONFIG_PASN */
+#endif /* CONFIG_P2P */
 
 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
 
@@ -12968,6 +12986,12 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        reply_len = -1;
        } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
                reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
+#ifdef CONFIG_PASN
+#ifdef CONFIG_TESTING_OPTIONS
+       } else if (os_strcmp(buf, "P2P_GET_PASNPTK") == 0) {
+               reply_len = p2p_ctrl_get_pasn_ptk(wpa_s, reply, reply_size);
+#endif /* CONFIG_TESTING_OPTIONS */
+#endif /* CONFIG_PASN */
        } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
                reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
                                                   reply_size);
index 191d4bf6906954a0b414250b66ce12d5f54acb15..7f89cdb7516364913f1dc822a72ab4c901ca2693 100644 (file)
@@ -11246,6 +11246,19 @@ int wpas_p2p_pasn_auth_tx_status(struct wpa_supplicant *wpa_s, const u8 *data,
                                       awork->verify);
 }
 
+
+#ifdef CONFIG_TESTING_OPTIONS
+int wpas_p2p_get_pasn_ptk(struct wpa_supplicant *wpa_s, const u8 **ptk,
+                         size_t *ptk_len)
+{
+       struct p2p_data *p2p = wpa_s->global->p2p;
+
+       if (wpa_s->global->p2p_disabled || !p2p)
+               return -2;
+       return p2p_pasn_get_ptk(p2p, ptk, ptk_len);
+}
+#endif /* CONFIG_TESTING_OPTIONS */
+
 #endif /* CONFIG_PASN */
 
 
index 4337e25088e6f63cdbccb5cb8a4b8c3cd29468e4..1a0d11fe9abef456e3096f91401f317c2cc6aad8 100644 (file)
@@ -241,6 +241,8 @@ void wpas_p2p_update_dev_addr(struct wpa_supplicant *wpa_s);
 int wpas_p2p_pasn_auth_rx(struct wpa_supplicant *wpa_s,
                          const struct ieee80211_mgmt *mgmt, size_t len,
                          int freq);
+int wpas_p2p_get_pasn_ptk(struct wpa_supplicant *wpa_s, const u8 **ptk,
+                         size_t *ptk_len);
 
 #else /* CONFIG_P2P */
 
@@ -376,6 +378,14 @@ static inline void wpas_p2p_update_dev_addr(struct wpa_supplicant *wpa_s)
 {
 }
 
+#ifdef CONFIG_TESTING_OPTIONS
+static inline int wpas_p2p_get_pasn_ptk(struct wpa_supplicant *wpa_s,
+                                       const u8 **ptk, size_t *ptk_len)
+{
+       return 0;
+}
+#endif /* CONFIG_TESTING_OPTIONS */
+
 #endif /* CONFIG_P2P */
 
 #endif /* P2P_SUPPLICANT_H */