WPS UFD: Build OOB functionality only if UFD is enabled
[wpasupplicant] / src / wps / wps_attr_build.c
index 0466d13..f35881a 100644 (file)
@@ -15,6 +15,7 @@
 #include "includes.h"
 
 #include "common.h"
+#include "dh_groups.h"
 #include "crypto.h"
 #include "sha256.h"
 #include "aes_wrap.h"
@@ -27,8 +28,17 @@ int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg)
 
        wpa_printf(MSG_DEBUG, "WPS:  * Public Key");
        wpabuf_free(wps->dh_privkey);
-       wps->dh_privkey = wpabuf_dup(wps->wps->dh_privkey);
-       pubkey = wpabuf_dup(wps->wps->dh_pubkey);
+       if (wps->dev_pw_id != DEV_PW_DEFAULT && wps->wps->dh_privkey) {
+               wpa_printf(MSG_DEBUG, "WPS: Using pre-configured DH keys");
+               wps->dh_privkey = wpabuf_dup(wps->wps->dh_privkey);
+               pubkey = wpabuf_dup(wps->wps->dh_pubkey);
+       } else {
+               wpa_printf(MSG_DEBUG, "WPS: Generate new DH keys");
+               wps->dh_privkey = NULL;
+               pubkey = dh_init(dh_groups_get(WPS_DH_GROUP),
+                                &wps->dh_privkey);
+               pubkey = wpabuf_zeropad(pubkey, 192);
+       }
        if (wps->dh_privkey == NULL || pubkey == NULL) {
                wpa_printf(MSG_DEBUG, "WPS: Failed to initialize "
                           "Diffie-Hellman handshake");
@@ -256,6 +266,7 @@ int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
 }
 
 
+#ifdef CONFIG_WPS_OOB
 int wps_build_oob_dev_password(struct wpabuf *msg, struct wps_context *wps)
 {
        size_t hash_len;
@@ -296,3 +307,4 @@ int wps_build_oob_dev_password(struct wpabuf *msg, struct wps_context *wps)
 
        return 0;
 }
+#endif /* CONFIG_WPS_OOB */