From 986de33d5c3e11dd08a26ed65eacede8b75aa339 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 7 Aug 2012 16:07:25 +0300 Subject: [PATCH] Convert remaining SSID routines from char* to u8* This makes it more explicit that the SSID is not a null terminated C string. Signed-hostap: Jouni Malinen --- hostapd/config_file.c | 1 - hostapd/ctrl_iface.c | 3 ++- hostapd/main.c | 2 +- src/ap/accounting.c | 4 +++- src/ap/ap_config.h | 2 +- src/ap/beacon.c | 2 +- src/ap/hostapd.c | 10 +++++----- src/ap/ieee802_11_auth.c | 4 +++- src/ap/ieee802_1x.c | 4 +++- src/crypto/sha1-pbkdf2.c | 6 +++--- src/crypto/sha1.h | 2 +- wpa_supplicant/ap.c | 1 - wpa_supplicant/config.c | 3 +-- wpa_supplicant/wpa_passphrase.c | 2 +- wpa_supplicant/wpa_supplicant.c | 8 ++++---- 15 files changed, 29 insertions(+), 25 deletions(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index 42c1ccbcf..1f898dbb2 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -1470,7 +1470,6 @@ static int hostapd_config_fill(struct hostapd_config *conf, } else { os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len); - bss->ssid.ssid[bss->ssid.ssid_len] = '\0'; bss->ssid.ssid_set = 1; } } else if (os_strcmp(buf, "macaddr_acl") == 0) { diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 7587e0328..77146e3e5 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -523,7 +523,8 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd, ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n" "ssid=%s\n", MAC2STR(hapd->own_addr), - hapd->conf->ssid.ssid); + wpa_ssid_txt(hapd->conf->ssid.ssid, + hapd->conf->ssid.ssid_len)); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; diff --git a/hostapd/main.c b/hostapd/main.c index d8c27765c..3826ccf83 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -248,7 +248,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface) } params.bssid = b; params.ifname = hapd->conf->iface; - params.ssid = (const u8 *) hapd->conf->ssid.ssid; + params.ssid = hapd->conf->ssid.ssid; params.ssid_len = hapd->conf->ssid.ssid_len; params.test_socket = hapd->conf->test_socket; params.use_pae_group_addr = hapd->conf->use_pae_group_addr; diff --git a/src/ap/accounting.c b/src/ap/accounting.c index 0b838a4cb..e027d5386 100644 --- a/src/ap/accounting.c +++ b/src/ap/accounting.c @@ -136,7 +136,9 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd, } os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s", - MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid); + MAC2STR(hapd->own_addr), + wpa_ssid_txt(hapd->conf->ssid.ssid, + hapd->conf->ssid.ssid_len)); if (!hostapd_config_get_radius_attr(hapd->conf->radius_acct_req_attr, RADIUS_ATTR_CALLED_STATION_ID) && !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID, diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h index 98c6f9539..bfb2d8af2 100644 --- a/src/ap/ap_config.h +++ b/src/ap/ap_config.h @@ -48,7 +48,7 @@ typedef enum hostap_security_policy { } secpolicy; struct hostapd_ssid { - char ssid[HOSTAPD_MAX_SSID_LEN + 1]; + u8 ssid[HOSTAPD_MAX_SSID_LEN]; size_t ssid_len; int ssid_set; diff --git a/src/ap/beacon.c b/src/ap/beacon.c index ef97c6e7d..ca3f054bc 100644 --- a/src/ap/beacon.c +++ b/src/ap/beacon.c @@ -653,7 +653,7 @@ void ieee802_11_set_beacon(struct hostapd_data *hapd) params.dtim_period = hapd->conf->dtim_period; params.beacon_int = hapd->iconf->beacon_int; params.basic_rates = hapd->iconf->basic_rates; - params.ssid = (u8 *) hapd->conf->ssid.ssid; + params.ssid = hapd->conf->ssid.ssid; params.ssid_len = hapd->conf->ssid.ssid_len; params.pairwise_ciphers = hapd->conf->rsn_pairwise ? hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise; diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 22c5e654a..ba8d83243 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -98,7 +98,7 @@ static void hostapd_reload_bss(struct hostapd_data *hapd) hostapd_update_wps(hapd); if (hapd->conf->ssid.ssid_set && - hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid, + hostapd_set_ssid(hapd, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len)) { wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); /* try to continue */ @@ -679,14 +679,14 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) set_ssid = 0; conf->ssid.ssid_len = ssid_len; os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len); - conf->ssid.ssid[conf->ssid.ssid_len] = '\0'; } if (!hostapd_drv_none(hapd)) { wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR - " and ssid '%s'", + " and ssid \"%s\"", hapd->conf->iface, MAC2STR(hapd->own_addr), - hapd->conf->ssid.ssid); + wpa_ssid_txt(hapd->conf->ssid.ssid, + hapd->conf->ssid.ssid_len)); } if (hostapd_setup_wpa_psk(conf)) { @@ -696,7 +696,7 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) /* Set SSID for the kernel driver (to be used in beacon and probe * response frames) */ - if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid, + if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid, conf->ssid.ssid_len)) { wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); return -1; diff --git a/src/ap/ieee802_11_auth.c b/src/ap/ieee802_11_auth.c index 0c4c5f327..e30d85aba 100644 --- a/src/ap/ieee802_11_auth.c +++ b/src/ap/ieee802_11_auth.c @@ -165,7 +165,9 @@ static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr, } os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s", - MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid); + MAC2STR(hapd->own_addr), + wpa_ssid_txt(hapd->conf->ssid.ssid, + hapd->conf->ssid.ssid_len)); if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID, (u8 *) buf, os_strlen(buf))) { wpa_printf(MSG_DEBUG, "Could not add Called-Station-Id"); diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c index dd0df1d38..25b5065cb 100644 --- a/src/ap/ieee802_1x.c +++ b/src/ap/ieee802_1x.c @@ -481,7 +481,9 @@ static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd, } os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s", - MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid); + MAC2STR(hapd->own_addr), + wpa_ssid_txt(hapd->conf->ssid.ssid, + hapd->conf->ssid.ssid_len)); buf[sizeof(buf) - 1] = '\0'; if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr, RADIUS_ATTR_CALLED_STATION_ID) && diff --git a/src/crypto/sha1-pbkdf2.c b/src/crypto/sha1-pbkdf2.c index 450c2a036..8effe2fe0 100644 --- a/src/crypto/sha1-pbkdf2.c +++ b/src/crypto/sha1-pbkdf2.c @@ -11,7 +11,7 @@ #include "common.h" #include "sha1.h" -static int pbkdf2_sha1_f(const char *passphrase, const char *ssid, +static int pbkdf2_sha1_f(const char *passphrase, const u8 *ssid, size_t ssid_len, int iterations, unsigned int count, u8 *digest) { @@ -22,7 +22,7 @@ static int pbkdf2_sha1_f(const char *passphrase, const char *ssid, size_t len[2]; size_t passphrase_len = os_strlen(passphrase); - addr[0] = (u8 *) ssid; + addr[0] = ssid; len[0] = ssid_len; addr[1] = count_buf; len[1] = 4; @@ -69,7 +69,7 @@ static int pbkdf2_sha1_f(const char *passphrase, const char *ssid, * iterations is set to 4096 and buflen to 32. This function is described in * IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0. */ -int pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len, +int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len, int iterations, u8 *buf, size_t buflen) { unsigned int count = 0; diff --git a/src/crypto/sha1.h b/src/crypto/sha1.h index 08e5a59de..933cd81b9 100644 --- a/src/crypto/sha1.h +++ b/src/crypto/sha1.h @@ -22,6 +22,6 @@ int sha1_t_prf(const u8 *key, size_t key_len, const char *label, int __must_check tls_prf_sha1_md5(const u8 *secret, size_t secret_len, const char *label, const u8 *seed, size_t seed_len, u8 *out, size_t outlen); -int pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len, +int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len, int iterations, u8 *buf, size_t buflen); #endif /* SHA1_H */ diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index f9e004570..80c1783cc 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -150,7 +150,6 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s, return -1; } os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len); - bss->ssid.ssid[ssid->ssid_len] = '\0'; bss->ssid.ssid_len = ssid->ssid_len; bss->ssid.ssid_set = 1; diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 94052c5fa..c09f3104e 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -2308,8 +2308,7 @@ char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var) void wpa_config_update_psk(struct wpa_ssid *ssid) { #ifndef CONFIG_NO_PBKDF2 - pbkdf2_sha1(ssid->passphrase, - (char *) ssid->ssid, ssid->ssid_len, 4096, + pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096, ssid->psk, PMK_LEN); wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)", ssid->psk, PMK_LEN); diff --git a/wpa_supplicant/wpa_passphrase.c b/wpa_supplicant/wpa_passphrase.c index a9ec23618..9b568f0f7 100644 --- a/wpa_supplicant/wpa_passphrase.c +++ b/wpa_supplicant/wpa_passphrase.c @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) return 1; } - pbkdf2_sha1(passphrase, ssid, os_strlen(ssid), 4096, psk, 32); + pbkdf2_sha1(passphrase, (u8 *) ssid, os_strlen(ssid), 4096, psk, 32); printf("network={\n"); printf("\tssid=\"%s\"\n", ssid); diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 61fbec99c..9a4257050 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -1097,8 +1097,8 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, if (bss && ssid->bssid_set && ssid->ssid_len == 0 && ssid->passphrase) { u8 psk[PMK_LEN]; - pbkdf2_sha1(ssid->passphrase, (char *) bss->ssid, - bss->ssid_len, 4096, psk, PMK_LEN); + pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len, + 4096, psk, PMK_LEN); wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)", psk, PMK_LEN); wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN); @@ -1131,8 +1131,8 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, #ifndef CONFIG_NO_PBKDF2 if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss) { - pbkdf2_sha1(pw_str, (char *) bss->ssid, - bss->ssid_len, 4096, psk, PMK_LEN); + pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len, + 4096, psk, PMK_LEN); os_memset(pw_str, 0, sizeof(pw_str)); wpa_hexdump_key(MSG_MSGDUMP, "PSK (from " "external passphrase)",