WPS: Fix strict validation of encrypted data for WSC 2.0-only case
[libeap.git] / src / wps / wps_validate.c
index 755f1d4..c3071a0 100644 (file)
@@ -1122,7 +1122,8 @@ int wps_validate_beacon(const struct wpabuf *wps_ie)
 }
 
 
-int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe)
+int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe,
+                                  const u8 *addr)
 {
        struct wps_parse_attr attr;
        int wps2, sel_reg;
@@ -1166,15 +1167,21 @@ int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe)
            wps_validate_authorized_macs(attr.authorized_macs,
                                         attr.authorized_macs_len, 0)) {
                wpa_printf(MSG_INFO, "WPS-STRICT: Invalid %sProbe Response "
-                          "frame", probe ? "" : "Beacon/");
+                          "frame from " MACSTR, probe ? "" : "Beacon/",
+                          MAC2STR(addr));
+#ifdef WPS_STRICT_WPS2
+               if (wps2)
+                       return -1;
+#else /* WPS_STRICT_WPS2 */
                return -1;
+#endif /* WPS_STRICT_WPS2 */
        }
 
        return 0;
 }
 
 
-int wps_validate_probe_req(const struct wpabuf *wps_ie)
+int wps_validate_probe_req(const struct wpabuf *wps_ie, const u8 *addr)
 {
        struct wps_parse_attr attr;
        int wps2;
@@ -1213,7 +1220,7 @@ int wps_validate_probe_req(const struct wpabuf *wps_ie)
            wps_validate_req_dev_type(attr.req_dev_type, attr.num_req_dev_type,
                                      0)) {
                wpa_printf(MSG_INFO, "WPS-STRICT: Invalid Probe Request "
-                          "frame");
+                          "frame from " MACSTR, MAC2STR(addr));
                return -1;
        }
 
@@ -1268,7 +1275,7 @@ int wps_validate_assoc_resp(const struct wpabuf *wps_ie)
 
        wps2 = attr.version2 != NULL;
        if (wps_validate_version(attr.version, 1) ||
-           wps_validate_request_type(attr.request_type, 1) ||
+           wps_validate_response_type(attr.response_type, 1) ||
            wps_validate_version2(attr.version2, wps2)) {
                wpa_printf(MSG_INFO, "WPS-STRICT: Invalid (Re)Association "
                           "Response frame");
@@ -1516,10 +1523,9 @@ int wps_validate_m4(const struct wpabuf *tlvs)
 }
 
 
-int wps_validate_m4_encr(const struct wpabuf *tlvs)
+int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2)
 {
        struct wps_parse_attr attr;
-       int wps2;
 
        if (tlvs == NULL) {
                wpa_printf(MSG_INFO, "WPS-STRICT: No TLVs in M4 encrypted "
@@ -1532,7 +1538,6 @@ int wps_validate_m4_encr(const struct wpabuf *tlvs)
                return -1;
        }
 
-       wps2 = attr.version2 != NULL;
        if (wps_validate_r_snonce1(attr.r_snonce1, 1) ||
            wps_validate_key_wrap_auth(attr.key_wrap_auth, 1)) {
                wpa_printf(MSG_INFO, "WPS-STRICT: Invalid M4 encrypted "
@@ -1585,10 +1590,9 @@ int wps_validate_m5(const struct wpabuf *tlvs)
 }
 
 
-int wps_validate_m5_encr(const struct wpabuf *tlvs)
+int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2)
 {
        struct wps_parse_attr attr;
-       int wps2;
 
        if (tlvs == NULL) {
                wpa_printf(MSG_INFO, "WPS-STRICT: No TLVs in M5 encrypted "
@@ -1601,7 +1605,6 @@ int wps_validate_m5_encr(const struct wpabuf *tlvs)
                return -1;
        }
 
-       wps2 = attr.version2 != NULL;
        if (wps_validate_e_snonce1(attr.e_snonce1, 1) ||
            wps_validate_key_wrap_auth(attr.key_wrap_auth, 1)) {
                wpa_printf(MSG_INFO, "WPS-STRICT: Invalid M5 encrypted "
@@ -1654,10 +1657,9 @@ int wps_validate_m6(const struct wpabuf *tlvs)
 }
 
 
-int wps_validate_m6_encr(const struct wpabuf *tlvs)
+int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2)
 {
        struct wps_parse_attr attr;
-       int wps2;
 
        if (tlvs == NULL) {
                wpa_printf(MSG_INFO, "WPS-STRICT: No TLVs in M6 encrypted "
@@ -1670,7 +1672,6 @@ int wps_validate_m6_encr(const struct wpabuf *tlvs)
                return -1;
        }
 
-       wps2 = attr.version2 != NULL;
        if (wps_validate_r_snonce2(attr.r_snonce2, 1) ||
            wps_validate_key_wrap_auth(attr.key_wrap_auth, 1)) {
                wpa_printf(MSG_INFO, "WPS-STRICT: Invalid M6 encrypted "
@@ -1724,10 +1725,9 @@ int wps_validate_m7(const struct wpabuf *tlvs)
 }
 
 
-int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap)
+int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap, int wps2)
 {
        struct wps_parse_attr attr;
-       int wps2;
 
        if (tlvs == NULL) {
                wpa_printf(MSG_INFO, "WPS-STRICT: No TLVs in M7 encrypted "
@@ -1740,7 +1740,6 @@ int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap)
                return -1;
        }
 
-       wps2 = attr.version2 != NULL;
        if (wps_validate_e_snonce2(attr.e_snonce2, 1) ||
            wps_validate_ssid(attr.ssid, attr.ssid_len, !ap) ||
            wps_validate_mac_addr(attr.mac_addr, !ap) ||
@@ -1800,10 +1799,9 @@ int wps_validate_m8(const struct wpabuf *tlvs)
 }
 
 
-int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap)
+int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap, int wps2)
 {
        struct wps_parse_attr attr;
-       int wps2;
 
        if (tlvs == NULL) {
                wpa_printf(MSG_INFO, "WPS-STRICT: No TLVs in M8 encrypted "
@@ -1816,7 +1814,6 @@ int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap)
                return -1;
        }
 
-       wps2 = attr.version2 != NULL;
        if (wps_validate_ssid(attr.ssid, attr.ssid_len, ap) ||
            wps_validate_auth_type(attr.auth_type, ap) ||
            wps_validate_encr_type(attr.encr_type, ap) ||