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 <j@w1.fi>
This commit is contained in:
parent
771e2f7b33
commit
986de33d5c
15 changed files with 29 additions and 25 deletions
|
@ -1470,7 +1470,6 @@ static int hostapd_config_fill(struct hostapd_config *conf,
|
||||||
} else {
|
} else {
|
||||||
os_memcpy(bss->ssid.ssid, pos,
|
os_memcpy(bss->ssid.ssid, pos,
|
||||||
bss->ssid.ssid_len);
|
bss->ssid.ssid_len);
|
||||||
bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
|
|
||||||
bss->ssid.ssid_set = 1;
|
bss->ssid.ssid_set = 1;
|
||||||
}
|
}
|
||||||
} else if (os_strcmp(buf, "macaddr_acl") == 0) {
|
} else if (os_strcmp(buf, "macaddr_acl") == 0) {
|
||||||
|
|
|
@ -523,7 +523,8 @@ static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
|
||||||
ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
|
ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
|
||||||
"ssid=%s\n",
|
"ssid=%s\n",
|
||||||
MAC2STR(hapd->own_addr),
|
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)
|
if (ret < 0 || ret >= end - pos)
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
pos += ret;
|
pos += ret;
|
||||||
|
|
|
@ -248,7 +248,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface)
|
||||||
}
|
}
|
||||||
params.bssid = b;
|
params.bssid = b;
|
||||||
params.ifname = hapd->conf->iface;
|
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.ssid_len = hapd->conf->ssid.ssid_len;
|
||||||
params.test_socket = hapd->conf->test_socket;
|
params.test_socket = hapd->conf->test_socket;
|
||||||
params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
|
params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
|
||||||
|
|
|
@ -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",
|
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,
|
if (!hostapd_config_get_radius_attr(hapd->conf->radius_acct_req_attr,
|
||||||
RADIUS_ATTR_CALLED_STATION_ID) &&
|
RADIUS_ATTR_CALLED_STATION_ID) &&
|
||||||
!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
|
!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
|
||||||
|
|
|
@ -48,7 +48,7 @@ typedef enum hostap_security_policy {
|
||||||
} secpolicy;
|
} secpolicy;
|
||||||
|
|
||||||
struct hostapd_ssid {
|
struct hostapd_ssid {
|
||||||
char ssid[HOSTAPD_MAX_SSID_LEN + 1];
|
u8 ssid[HOSTAPD_MAX_SSID_LEN];
|
||||||
size_t ssid_len;
|
size_t ssid_len;
|
||||||
int ssid_set;
|
int ssid_set;
|
||||||
|
|
||||||
|
|
|
@ -653,7 +653,7 @@ void ieee802_11_set_beacon(struct hostapd_data *hapd)
|
||||||
params.dtim_period = hapd->conf->dtim_period;
|
params.dtim_period = hapd->conf->dtim_period;
|
||||||
params.beacon_int = hapd->iconf->beacon_int;
|
params.beacon_int = hapd->iconf->beacon_int;
|
||||||
params.basic_rates = hapd->iconf->basic_rates;
|
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.ssid_len = hapd->conf->ssid.ssid_len;
|
||||||
params.pairwise_ciphers = hapd->conf->rsn_pairwise ?
|
params.pairwise_ciphers = hapd->conf->rsn_pairwise ?
|
||||||
hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
|
hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
|
||||||
|
|
|
@ -98,7 +98,7 @@ static void hostapd_reload_bss(struct hostapd_data *hapd)
|
||||||
hostapd_update_wps(hapd);
|
hostapd_update_wps(hapd);
|
||||||
|
|
||||||
if (hapd->conf->ssid.ssid_set &&
|
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)) {
|
hapd->conf->ssid.ssid_len)) {
|
||||||
wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
|
wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
|
||||||
/* try to continue */
|
/* try to continue */
|
||||||
|
@ -679,14 +679,14 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
|
||||||
set_ssid = 0;
|
set_ssid = 0;
|
||||||
conf->ssid.ssid_len = ssid_len;
|
conf->ssid.ssid_len = ssid_len;
|
||||||
os_memcpy(conf->ssid.ssid, ssid, conf->ssid.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)) {
|
if (!hostapd_drv_none(hapd)) {
|
||||||
wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
|
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->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)) {
|
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
|
/* Set SSID for the kernel driver (to be used in beacon and probe
|
||||||
* response frames) */
|
* 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)) {
|
conf->ssid.ssid_len)) {
|
||||||
wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
|
wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -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",
|
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,
|
if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
|
||||||
(u8 *) buf, os_strlen(buf))) {
|
(u8 *) buf, os_strlen(buf))) {
|
||||||
wpa_printf(MSG_DEBUG, "Could not add Called-Station-Id");
|
wpa_printf(MSG_DEBUG, "Could not add Called-Station-Id");
|
||||||
|
|
|
@ -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",
|
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';
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
|
if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
|
||||||
RADIUS_ATTR_CALLED_STATION_ID) &&
|
RADIUS_ATTR_CALLED_STATION_ID) &&
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "sha1.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,
|
size_t ssid_len, int iterations, unsigned int count,
|
||||||
u8 *digest)
|
u8 *digest)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ static int pbkdf2_sha1_f(const char *passphrase, const char *ssid,
|
||||||
size_t len[2];
|
size_t len[2];
|
||||||
size_t passphrase_len = os_strlen(passphrase);
|
size_t passphrase_len = os_strlen(passphrase);
|
||||||
|
|
||||||
addr[0] = (u8 *) ssid;
|
addr[0] = ssid;
|
||||||
len[0] = ssid_len;
|
len[0] = ssid_len;
|
||||||
addr[1] = count_buf;
|
addr[1] = count_buf;
|
||||||
len[1] = 4;
|
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
|
* 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.
|
* 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)
|
int iterations, u8 *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
|
|
|
@ -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,
|
int __must_check tls_prf_sha1_md5(const u8 *secret, size_t secret_len,
|
||||||
const char *label, const u8 *seed,
|
const char *label, const u8 *seed,
|
||||||
size_t seed_len, u8 *out, size_t outlen);
|
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);
|
int iterations, u8 *buf, size_t buflen);
|
||||||
#endif /* SHA1_H */
|
#endif /* SHA1_H */
|
||||||
|
|
|
@ -150,7 +150,6 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
|
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_len = ssid->ssid_len;
|
||||||
bss->ssid.ssid_set = 1;
|
bss->ssid.ssid_set = 1;
|
||||||
|
|
||||||
|
|
|
@ -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)
|
void wpa_config_update_psk(struct wpa_ssid *ssid)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_NO_PBKDF2
|
#ifndef CONFIG_NO_PBKDF2
|
||||||
pbkdf2_sha1(ssid->passphrase,
|
pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
|
||||||
(char *) ssid->ssid, ssid->ssid_len, 4096,
|
|
||||||
ssid->psk, PMK_LEN);
|
ssid->psk, PMK_LEN);
|
||||||
wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
|
wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
|
||||||
ssid->psk, PMK_LEN);
|
ssid->psk, PMK_LEN);
|
||||||
|
|
|
@ -52,7 +52,7 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
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("network={\n");
|
||||||
printf("\tssid=\"%s\"\n", ssid);
|
printf("\tssid=\"%s\"\n", ssid);
|
||||||
|
|
|
@ -1097,8 +1097,8 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
|
||||||
if (bss && ssid->bssid_set && ssid->ssid_len == 0 &&
|
if (bss && ssid->bssid_set && ssid->ssid_len == 0 &&
|
||||||
ssid->passphrase) {
|
ssid->passphrase) {
|
||||||
u8 psk[PMK_LEN];
|
u8 psk[PMK_LEN];
|
||||||
pbkdf2_sha1(ssid->passphrase, (char *) bss->ssid,
|
pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len,
|
||||||
bss->ssid_len, 4096, psk, PMK_LEN);
|
4096, psk, PMK_LEN);
|
||||||
wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
|
wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
|
||||||
psk, PMK_LEN);
|
psk, PMK_LEN);
|
||||||
wpa_sm_set_pmk(wpa_s->wpa, 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
|
#ifndef CONFIG_NO_PBKDF2
|
||||||
if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss)
|
if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss)
|
||||||
{
|
{
|
||||||
pbkdf2_sha1(pw_str, (char *) bss->ssid,
|
pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len,
|
||||||
bss->ssid_len, 4096, psk, PMK_LEN);
|
4096, psk, PMK_LEN);
|
||||||
os_memset(pw_str, 0, sizeof(pw_str));
|
os_memset(pw_str, 0, sizeof(pw_str));
|
||||||
wpa_hexdump_key(MSG_MSGDUMP, "PSK (from "
|
wpa_hexdump_key(MSG_MSGDUMP, "PSK (from "
|
||||||
"external passphrase)",
|
"external passphrase)",
|
||||||
|
|
Loading…
Reference in a new issue