Fix RADIUS Called-Station-Id to not escape SSID
authorJouni Malinen <j@w1.fi>
Thu, 24 Dec 2015 10:15:36 +0000 (12:15 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 24 Dec 2015 10:15:36 +0000 (12:15 +0200)
Commit 986de33d5c3e11dd08a26ed65eacede8b75aa339 ('Convert remaining SSID
routines from char* to u8*') started using wpa_ssid_txt() to print out
the SSID for the Called-Station-Id attribute in RADIUS messages. This
was further modified by commit 6bc1f95613cc2bedd8849564d30419bff82ed074
('Use printf escaping in SSID-to-printable-string conversion') to use
printf escaping (though, even without this, wpa_ssid_txt() would have
masked characters).

This is not desired for Called-Station-Id attribute. While it is defined
as a "String", RFC 2865 indicates that "a robust implementation SHOULD
support the field as undistinguished octets.".

Copy the SSID as an array of arbitrary octets into Called-Station-Id to
avoid any kind of masking or escaping behavior. This goes a step further
from the initial implementation by allowing even the possible (but
unlikely in practical use cases) 0x00 octet in the middle of an SSID.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/ap/ieee802_1x.c

index f566603..e3b3d94 100644 (file)
@@ -475,6 +475,7 @@ int add_common_radius_attr(struct hostapd_data *hapd,
 {
        char buf[128];
        struct hostapd_radius_attr *attr;
+       int len;
 
        if (!hostapd_config_get_radius_attr(req_attr,
                                            RADIUS_ATTR_NAS_IP_ADDRESS) &&
@@ -506,15 +507,15 @@ int add_common_radius_attr(struct hostapd_data *hapd,
                return -1;
        }
 
-       os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
-                   MAC2STR(hapd->own_addr),
-                   wpa_ssid_txt(hapd->conf->ssid.ssid,
-                                hapd->conf->ssid.ssid_len));
-       buf[sizeof(buf) - 1] = '\0';
+       len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":",
+                         MAC2STR(hapd->own_addr));
+       os_memcpy(&buf[len], hapd->conf->ssid.ssid,
+                 hapd->conf->ssid.ssid_len);
+       len += hapd->conf->ssid.ssid_len;
        if (!hostapd_config_get_radius_attr(req_attr,
                                            RADIUS_ATTR_CALLED_STATION_ID) &&
            !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
-                                (u8 *) buf, os_strlen(buf))) {
+                                (u8 *) buf, len)) {
                wpa_printf(MSG_ERROR, "Could not add Called-Station-Id");
                return -1;
        }