WPS 2.0: Modify empty-string workaround to meet 2.0 rules
authorJouni Malinen <jouni.malinen@atheros.com>
Wed, 26 May 2010 06:46:48 +0000 (09:46 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 9 Sep 2010 13:07:47 +0000 (06:07 -0700)
Instead of using 0x00 as the extra character, use space (' ') to
avoid failing tests that verify that the variable length string
attributes are not null terminated. In addition, this workaround
can now be disabled by defining CONFIG_WPS_STRICT for the build.
This can be done by adding following line to .config:
CFLAGS += -DCONFIG_WPS_STRICT

However, it should be noted that such a build may not interoperate
with some deployed WPS 1.0 -based implementations and as such, is
mainly designed for testing.

src/wps/wps_dev_attr.c

index 6ae84f2..823c7ef 100644 (file)
@@ -25,18 +25,20 @@ int wps_build_manufacturer(struct wps_device_data *dev, struct wpabuf *msg)
        wpa_printf(MSG_DEBUG, "WPS:  * Manufacturer");
        wpabuf_put_be16(msg, ATTR_MANUFACTURER);
        len = dev->manufacturer ? os_strlen(dev->manufacturer) : 0;
+#ifndef CONFIG_WPS_STRICT
        if (len == 0) {
                /*
                 * Some deployed WPS implementations fail to parse zero-length
-                * attributes. As a workaround, send a null character if the
+                * attributes. As a workaround, send a space character if the
                 * device attribute string is empty.
                 */
                wpabuf_put_be16(msg, 1);
-               wpabuf_put_u8(msg, '\0');
-       } else {
-               wpabuf_put_be16(msg, len);
-               wpabuf_put_data(msg, dev->manufacturer, len);
+               wpabuf_put_u8(msg, ' ');
+               return 0;
        }
+#endif /* CONFIG_WPS_STRICT */
+       wpabuf_put_be16(msg, len);
+       wpabuf_put_data(msg, dev->manufacturer, len);
        return 0;
 }
 
@@ -47,18 +49,20 @@ int wps_build_model_name(struct wps_device_data *dev, struct wpabuf *msg)
        wpa_printf(MSG_DEBUG, "WPS:  * Model Name");
        wpabuf_put_be16(msg, ATTR_MODEL_NAME);
        len = dev->model_name ? os_strlen(dev->model_name) : 0;
+#ifndef CONFIG_WPS_STRICT
        if (len == 0) {
                /*
                 * Some deployed WPS implementations fail to parse zero-length
-                * attributes. As a workaround, send a null character if the
+                * attributes. As a workaround, send a space character if the
                 * device attribute string is empty.
                 */
                wpabuf_put_be16(msg, 1);
-               wpabuf_put_u8(msg, '\0');
-       } else {
-               wpabuf_put_be16(msg, len);
-               wpabuf_put_data(msg, dev->model_name, len);
+               wpabuf_put_u8(msg, ' ');
+               return 0;
        }
+#endif /* CONFIG_WPS_STRICT */
+       wpabuf_put_be16(msg, len);
+       wpabuf_put_data(msg, dev->model_name, len);
        return 0;
 }
 
@@ -69,18 +73,20 @@ int wps_build_model_number(struct wps_device_data *dev, struct wpabuf *msg)
        wpa_printf(MSG_DEBUG, "WPS:  * Model Number");
        wpabuf_put_be16(msg, ATTR_MODEL_NUMBER);
        len = dev->model_number ? os_strlen(dev->model_number) : 0;
+#ifndef CONFIG_WPS_STRICT
        if (len == 0) {
                /*
                 * Some deployed WPS implementations fail to parse zero-length
-                * attributes. As a workaround, send a null character if the
+                * attributes. As a workaround, send a space character if the
                 * device attribute string is empty.
                 */
                wpabuf_put_be16(msg, 1);
-               wpabuf_put_u8(msg, '\0');
-       } else {
-               wpabuf_put_be16(msg, len);
-               wpabuf_put_data(msg, dev->model_number, len);
+               wpabuf_put_u8(msg, ' ');
+               return 0;
        }
+#endif /* CONFIG_WPS_STRICT */
+       wpabuf_put_be16(msg, len);
+       wpabuf_put_data(msg, dev->model_number, len);
        return 0;
 }
 
@@ -92,18 +98,20 @@ static int wps_build_serial_number(struct wps_device_data *dev,
        wpa_printf(MSG_DEBUG, "WPS:  * Serial Number");
        wpabuf_put_be16(msg, ATTR_SERIAL_NUMBER);
        len = dev->serial_number ? os_strlen(dev->serial_number) : 0;
+#ifndef CONFIG_WPS_STRICT
        if (len == 0) {
                /*
                 * Some deployed WPS implementations fail to parse zero-length
-                * attributes. As a workaround, send a null character if the
+                * attributes. As a workaround, send a space character if the
                 * device attribute string is empty.
                 */
                wpabuf_put_be16(msg, 1);
-               wpabuf_put_u8(msg, '\0');
-       } else {
-               wpabuf_put_be16(msg, len);
-               wpabuf_put_data(msg, dev->serial_number, len);
+               wpabuf_put_u8(msg, ' ');
+               return 0;
        }
+#endif /* CONFIG_WPS_STRICT */
+       wpabuf_put_be16(msg, len);
+       wpabuf_put_data(msg, dev->serial_number, len);
        return 0;
 }
 
@@ -124,18 +132,20 @@ int wps_build_dev_name(struct wps_device_data *dev, struct wpabuf *msg)
        wpa_printf(MSG_DEBUG, "WPS:  * Device Name");
        wpabuf_put_be16(msg, ATTR_DEV_NAME);
        len = dev->device_name ? os_strlen(dev->device_name) : 0;
+#ifndef CONFIG_WPS_STRICT
        if (len == 0) {
                /*
                 * Some deployed WPS implementations fail to parse zero-length
-                * attributes. As a workaround, send a null character if the
+                * attributes. As a workaround, send a space character if the
                 * device attribute string is empty.
                 */
                wpabuf_put_be16(msg, 1);
-               wpabuf_put_u8(msg, '\0');
-       } else {
-               wpabuf_put_be16(msg, len);
-               wpabuf_put_data(msg, dev->device_name, len);
+               wpabuf_put_u8(msg, ' ');
+               return 0;
        }
+#endif /* CONFIG_WPS_STRICT */
+       wpabuf_put_be16(msg, len);
+       wpabuf_put_data(msg, dev->device_name, len);
        return 0;
 }