Updated to hostap_2_6
[mech_eap.git] / libeap / src / wps / wps_attr_build.c
index b689357..770f5e9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Wi-Fi Protected Setup - attribute building
- * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2008-2016, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
 
 int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg)
 {
-       struct wpabuf *pubkey;
+       struct wpabuf *pubkey = NULL;
 
        wpa_printf(MSG_DEBUG, "WPS:  * Public Key");
-       wpabuf_free(wps->dh_privkey);
+       wpabuf_clear_free(wps->dh_privkey);
        wps->dh_privkey = NULL;
        if (wps->dev_pw_id != DEV_PW_DEFAULT && wps->wps->dh_privkey &&
            wps->wps->dh_ctx) {
@@ -298,7 +298,16 @@ int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg)
        auth_types &= ~WPS_AUTH_WPA;
        auth_types &= ~WPS_AUTH_WPA2;
        auth_types &= ~WPS_AUTH_SHARED;
-       wpa_printf(MSG_DEBUG, "WPS:  * Authentication Type Flags");
+#ifdef CONFIG_WPS_TESTING
+       if (wps_force_auth_types_in_use) {
+               wpa_printf(MSG_DEBUG,
+                          "WPS: Testing - replace auth type 0x%x with 0x%x",
+                          auth_types, wps_force_auth_types);
+               auth_types = wps_force_auth_types;
+       }
+#endif /* CONFIG_WPS_TESTING */
+       wpa_printf(MSG_DEBUG, "WPS:  * Authentication Type Flags (0x%x)",
+                  auth_types);
        wpabuf_put_be16(msg, ATTR_AUTH_TYPE_FLAGS);
        wpabuf_put_be16(msg, 2);
        wpabuf_put_be16(msg, auth_types);
@@ -310,7 +319,16 @@ int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg)
 {
        u16 encr_types = WPS_ENCR_TYPES;
        encr_types &= ~WPS_ENCR_WEP;
-       wpa_printf(MSG_DEBUG, "WPS:  * Encryption Type Flags");
+#ifdef CONFIG_WPS_TESTING
+       if (wps_force_encr_types_in_use) {
+               wpa_printf(MSG_DEBUG,
+                          "WPS: Testing - replace encr type 0x%x with 0x%x",
+                          encr_types, wps_force_encr_types);
+               encr_types = wps_force_encr_types;
+       }
+#endif /* CONFIG_WPS_TESTING */
+       wpa_printf(MSG_DEBUG, "WPS:  * Encryption Type Flags (0x%x)",
+                  encr_types);
        wpabuf_put_be16(msg, ATTR_ENCR_TYPE_FLAGS);
        wpabuf_put_be16(msg, 2);
        wpabuf_put_be16(msg, encr_types);
@@ -395,7 +413,8 @@ int wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id,
                   dev_pw_id);
        addr[0] = wpabuf_head(pubkey);
        hash_len = wpabuf_len(pubkey);
-       sha256_vector(1, addr, &hash_len, pubkey_hash);
+       if (sha256_vector(1, addr, &hash_len, pubkey_hash) < 0)
+               return -1;
 #ifdef CONFIG_WPS_TESTING
        if (wps_corrupt_pkhash) {
                wpa_hexdump(MSG_DEBUG, "WPS: Real Public Key Hash",