Compare commits

..

3 Commits

Author SHA1 Message Date
jeltz 9fa8a0c991
Replace some vlan_id with vlan_description
Signed-off-by: Tom Barthe <jeltz+hostap@auro.re>
3 years ago
jeltz c34c234aec
Add a per-PSK vlan_description
Signed-off-by: Tom Barthe <jeltz+hostap@auro.re>
3 years ago
jeltz b82877d603
Support for RADIUS attributes filtering by tag
Signed-off-by: Tom Barthe <jeltz+hostap@auro.re>
3 years ago

@ -1094,28 +1094,16 @@ const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
}
static struct vlan_description vlan_desc_from_id(int vlan_id)
{
struct vlan_description vlan_desc;
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
vlan_desc.notempty = 1;
vlan_desc.untagged = vlan_id;
return vlan_desc;
}
const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
const u8 *addr, const u8 *p2p_dev_addr,
const u8 *prev_psk, struct vlan_description *vlan_desc)
const u8 *prev_psk,
struct vlan_description *vlan_desc)
{
struct hostapd_wpa_psk *psk;
int next_ok = prev_psk == NULL;
if (vlan_desc)
vlan_desc->notempty = 0;
os_memset(vlan_desc, 0, sizeof(*vlan_desc));
if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR

@ -2321,11 +2321,25 @@ ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta,
{
u32 session_timeout = info->session_timeout;
u32 acct_interim_interval = info->acct_interim_interval;
struct vlan_description *vlan_id = &info->vlan_id;
struct hostapd_sta_wpa_psk_short *psk = info->psk;
char *identity = info->identity;
char *radius_cui = info->radius_cui;
sta->default_radius_vlan = info->vlan_id;
if (vlan_id->notempty &&
!hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_INFO,
"Invalid VLAN %d%s received from RADIUS server",
vlan_id->untagged,
vlan_id->tagged[0] ? "+" : "");
return -1;
}
if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0)
return -1;
if (sta->vlan_id)
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
hostapd_free_psk_list(sta->psk);
if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED)

@ -458,7 +458,7 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
struct radius_sta *info;
struct radius_hdr *hdr = radius_msg_get_hdr(msg);
struct hostapd_sta_wpa_psk_short *psk;
int vlan_psk_notempty = 1;
int vlan_psk_empty = 1;
query = hapd->acl_queries;
prev = NULL;
@ -523,12 +523,12 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED) {
/*
* Fill in the "default" VLAN (in case there is no
* Tunnel* attribute associated with the PSK)
* tagged Tunnel* attribute associated with the PSK)
*/
info->vlan_id.notempty = !!radius_msg_get_vlanid(
msg, &info->vlan_id.untagged,
MAX_NUM_TAGGED_VLAN, info->vlan_id.tagged, 0);
/* Fill in per PSK VLAN descriptions */
/* Fill in per-PSK VLAN descriptions */
for (psk = info->psk; psk; psk = psk->next) {
psk->vlan.notempty = !!radius_msg_get_vlanid(
msg, &psk->vlan.untagged,
@ -576,12 +576,12 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
psk->vlan.tagged[0] ? "+" : "");
os_memset(&psk->vlan, 0, sizeof(psk->vlan));
}
vlan_psk_notempty &= psk->vlan.notempty;
vlan_psk_empty &= !psk->vlan.notempty;
}
if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED &&
!info->vlan_id.notempty && !vlan_psk_notempty)
!info->vlan_id.notempty && vlan_psk_empty) {
cache->accepted = HOSTAPD_ACL_REJECT;
}
} else
cache->accepted = HOSTAPD_ACL_REJECT;
cache->next = hapd->acl_cache;

@ -200,9 +200,8 @@ struct sta_info {
int vlan_id; /* 0: none, >0: VID */
struct vlan_description *vlan_desc;
int vlan_id_bound; /* updated by ap_sta_bind_vlan() */
/* PSKs from RADIUS authentication server */
/* PSKs from RADIUS authentication server */
struct hostapd_sta_wpa_psk_short *psk;
struct vlan_description default_radius_vlan;
char *identity; /* User-Name from RADIUS */
char *radius_cui; /* Chargeable-User-Identity from RADIUS */

@ -32,3 +32,16 @@ int vlan_compare(struct vlan_description *a, struct vlan_description *b)
}
return 0;
}
struct vlan_description
vlan_desc_from_id(int vlan_id)
{
struct vlan_description vlan_desc;
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
vlan_desc.notempty = 1;
vlan_desc.untagged = vlan_id;
return vlan_desc;
}

@ -19,12 +19,23 @@ struct vlan_description {
#ifndef CONFIG_NO_VLAN
int vlan_compare(struct vlan_description *a, struct vlan_description *b);
struct vlan_description vlan_desc_from_id(int vlan_id);
#else /* CONFIG_NO_VLAN */
static inline int
vlan_compare(struct vlan_description *a, struct vlan_description *b)
{
return 0;
}
static inline struct vlan_description
vlan_desc_from_id(int vlan_id)
{
struct vlan_description vlan_desc;
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
return vlan_desc;
}
#endif /* CONFIG_NO_VLAN */
#endif /* VLAN_H */

@ -940,8 +940,8 @@ static int wpa_try_alt_snonce(struct wpa_state_machine *sm, u8 *data,
size_t pmk_len;
struct vlan_description vlan_desc;
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
os_memset(&PTK, 0, sizeof(PTK));
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
for (;;) {
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
!wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
@ -990,7 +990,8 @@ static int wpa_try_alt_snonce(struct wpa_state_machine *sm, u8 *data,
"WPA: Earlier SNonce resulted in matching MIC");
sm->alt_snonce_valid = 0;
if (vlan_desc.notempty && wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
if (vlan_desc.notempty && vlan_desc.untagged
&& wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
wpa_auth_update_vlan(sm->wpa_auth, sm->addr, &vlan_desc) < 0)
return -1;
@ -2943,13 +2944,13 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
struct vlan_description vlan_desc;
int owe_ptk_workaround = !!wpa_auth->conf.owe_ptk_workaround;
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING, wpa_ptk);
sm->EAPOLKeyReceived = false;
sm->update_snonce = false;
os_memset(&PTK, 0, sizeof(PTK));
os_memset(&vlan_desc, 0, sizeof(vlan_desc));
mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
/* WPA with IEEE 802.1X: use the derived PMK from EAP
@ -3090,7 +3091,6 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
WLAN_REASON_PREV_AUTH_NOT_VALID);
return;
}
#ifdef CONFIG_OCV
if (wpa_auth_uses_ocv(sm)) {
struct wpa_channel_info ci;
@ -3194,7 +3194,8 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
}
#endif /* CONFIG_IEEE80211R_AP */
if (vlan_desc.notempty && wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
if (vlan_desc.notempty && vlan_desc.untagged &&
wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
wpa_auth_update_vlan(wpa_auth, sm->addr, &vlan_desc) < 0) {
wpa_sta_disconnect(wpa_auth, sm->addr,
WLAN_REASON_PREV_AUTH_NOT_VALID);

@ -296,7 +296,7 @@ struct wpa_auth_callbacks {
int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
const u8 *prev_psk, size_t *psk_len,
struct vlan_description *vlan);
struct vlan_description *vlan_desc);
int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
const u8 *addr, int idx, u8 *key, size_t key_len,
@ -314,7 +314,7 @@ struct wpa_auth_callbacks {
size_t data_len);
int (*channel_info)(void *ctx, struct wpa_channel_info *ci);
int (*update_vlan)(void *ctx, const u8 *addr,
struct vlan_description *vlan);
struct vlan_description *vlan_desc);
int (*get_sta_tx_params)(void *ctx, const u8 *addr,
int ap_max_chanwidth, int ap_seg1_idx,
int *bandwidth, int *seg1_idx);

@ -337,6 +337,8 @@ static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
struct vlan_description *vlan = NULL;
const u8 *psk;
if (vlan_desc)
os_memset(vlan_desc, 0, sizeof(*vlan_desc));
if (psk_len)
*psk_len = PMK_LEN;
@ -383,7 +385,7 @@ static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
struct hostapd_sta_wpa_psk_short *pos;
if (vlan_desc)
vlan_desc->notempty = 0;
os_memset(vlan_desc, 0, sizeof(*vlan_desc));
psk = sta->psk->psk;
vlan = &sta->psk->vlan;
for (pos = sta->psk; pos; pos = pos->next) {
@ -401,13 +403,8 @@ static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
}
}
}
if (vlan && vlan_desc) {
if (vlan && vlan->notempty)
*vlan_desc = *vlan;
else if (sta->default_radius_vlan.notempty)
*vlan_desc = sta->default_radius_vlan;
}
if (vlan_desc && vlan)
*vlan_desc = *vlan;
return psk;
}
@ -948,39 +945,39 @@ static void hostapd_clear_ptksa(void *ctx, const u8 *addr, int cipher)
static int hostapd_wpa_auth_update_vlan(void *ctx, const u8 *addr,
struct vlan_description *vlan_desc)
struct vlan_description *vlan_desc)
{
#ifndef CONFIG_NO_VLAN
struct hostapd_data *hapd = ctx;
struct sta_info *sta;
int vlan_id = 0;
if (vlan_desc)
vlan_id = vlan_desc->untagged;
if (!hostapd_vlan_valid(hapd->conf->vlan, vlan_desc)) {
wpa_printf(MSG_INFO,
"Invalid VLAN ID %d",
vlan_desc->untagged);
return -1;
}
sta = ap_get_sta(hapd, addr);
if (!sta)
return -1;
if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
if (!hostapd_vlan_valid(hapd->conf->vlan, vlan_desc)) {
wpa_printf(MSG_INFO, "Invalid VLAN ID %d", vlan_id);
return -1;
}
if (ap_sta_set_vlan(hapd, sta, vlan_desc) < 0) {
wpa_printf(MSG_INFO,
"Failed to assign VLAN ID %d to " MACSTR,
vlan_id, MAC2STR(sta->addr));
"Failed to assign VLAN ID %d to "
MACSTR, vlan_desc->untagged,
MAC2STR(sta->addr));
return -1;
}
} else {
sta->vlan_id = vlan_id;
/* TODO: tagged? */
sta->vlan_id = vlan_desc->untagged;
}
wpa_printf(MSG_INFO,
"Assigned VLAN ID %d from to " MACSTR,
vlan_id, MAC2STR(sta->addr));
"Assigned VLAN ID %d to " MACSTR,
vlan_desc->untagged, MAC2STR(sta->addr));
if ((sta->flags & WLAN_STA_ASSOC) &&
ap_sta_bind_vlan(hapd, sta) < 0)
return -1;

@ -1483,7 +1483,7 @@ int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
dlen = attr->length - sizeof(*attr);
if (attr->length < 3)
continue;
if (tag_is_valid(tag) && data[0] != tag)
if (data[0] != tag)
continue;
switch (attr->type) {
@ -1556,7 +1556,8 @@ int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
*/
char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen,
const u8 *secret, size_t secret_len,
struct radius_msg *sent_msg, size_t n, u8 *tag)
struct radius_msg *sent_msg, size_t n,
u8 *tag)
{
u8 *buf = NULL;
size_t buflen;
@ -1594,7 +1595,7 @@ char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen,
if (j <= n)
continue;
if (tag_is_valid(data[0]))
if (tag && tag_is_valid(data[0]))
*tag = data[0];
fdata = data;

@ -11,6 +11,7 @@
#include "utils/common.h"
#include "utils/eloop.h"
#include "ap/wpa_auth.h"
#include "ap/vlan.h"
#include "../fuzzer-common.h"
@ -148,7 +149,7 @@ static const u8 * auth_get_psk(void *ctx, const u8 *addr,
wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
__func__, MAC2STR(addr), prev_psk);
if (vlan_desc)
vlan_desc->notempty = 0;
os_memset(vlan_desc, 0, sizeof(*vlan_desc));
if (psk_len)
*psk_len = PMK_LEN;
if (prev_psk)

@ -18,6 +18,7 @@
#include "wpa_supplicant_i.h"
#include "driver_i.h"
#include "common/ieee802_11_defs.h"
#include "ap/vlan.h"
#include "ibss_rsn.h"
@ -274,14 +275,15 @@ static void auth_logger(void *ctx, const u8 *addr, logger_level level,
static const u8 * auth_get_psk(void *ctx, const u8 *addr,
const u8 *p2p_dev_addr, const u8 *prev_psk,
size_t *psk_len, int *vlan_id)
size_t *psk_len,
struct vlan_description *vlan_desc)
{
struct ibss_rsn *ibss_rsn = ctx;
if (psk_len)
*psk_len = PMK_LEN;
if (vlan_id)
*vlan_id = 0;
if (vlan_desc)
os_memset(vlan_desc, 0, sizeof(*vlan_desc));
wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
__func__, MAC2STR(addr), prev_psk);
if (prev_psk)

@ -76,7 +76,8 @@ static void auth_logger(void *ctx, const u8 *addr, logger_level level,
static const u8 *auth_get_psk(void *ctx, const u8 *addr,
const u8 *p2p_dev_addr, const u8 *prev_psk,
size_t *psk_len, int *vlan_id)
size_t *psk_len,
struct vlan_description *vlan_desc)
{
struct mesh_rsn *mesh_rsn = ctx;
struct hostapd_data *hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
@ -84,8 +85,8 @@ static const u8 *auth_get_psk(void *ctx, const u8 *addr,
if (psk_len)
*psk_len = PMK_LEN;
if (vlan_id)
*vlan_id = 0;
if (vlan_desc)
os_memset(vlan_desc, 0, sizeof(*vlan_desc));
wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
__func__, MAC2STR(addr), prev_psk);

Loading…
Cancel
Save