12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039 |
- /*
- * hostapd / IEEE 802.1X-2004 Authenticator
- * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
- #include "includes.h"
- #include "hostapd.h"
- #include "ieee802_1x.h"
- #include "accounting.h"
- #include "radius/radius.h"
- #include "radius/radius_client.h"
- #include "eapol_sm.h"
- #include "md5.h"
- #include "rc4.h"
- #include "eloop.h"
- #include "sta_info.h"
- #include "wpa.h"
- #include "preauth.h"
- #include "pmksa_cache.h"
- #include "driver.h"
- #include "hw_features.h"
- #include "eap_server/eap.h"
- #include "ieee802_11_defs.h"
- static void ieee802_1x_finished(struct hostapd_data *hapd,
- struct sta_info *sta, int success);
- static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
- u8 type, const u8 *data, size_t datalen)
- {
- u8 *buf;
- struct ieee802_1x_hdr *xhdr;
- size_t len;
- int encrypt = 0;
- len = sizeof(*xhdr) + datalen;
- buf = os_zalloc(len);
- if (buf == NULL) {
- wpa_printf(MSG_ERROR, "malloc() failed for "
- "ieee802_1x_send(len=%lu)",
- (unsigned long) len);
- return;
- }
- xhdr = (struct ieee802_1x_hdr *) buf;
- xhdr->version = hapd->conf->eapol_version;
- xhdr->type = type;
- xhdr->length = host_to_be16(datalen);
- if (datalen > 0 && data != NULL)
- os_memcpy(xhdr + 1, data, datalen);
- if (wpa_auth_pairwise_set(sta->wpa_sm))
- encrypt = 1;
- if (sta->flags & WLAN_STA_PREAUTH) {
- rsn_preauth_send(hapd, sta, buf, len);
- } else {
- hostapd_send_eapol(hapd, sta->addr, buf, len, encrypt);
- }
- os_free(buf);
- }
- void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
- struct sta_info *sta, int authorized)
- {
- int res;
- if (sta->flags & WLAN_STA_PREAUTH)
- return;
- if (authorized) {
- sta->flags |= WLAN_STA_AUTHORIZED;
- res = hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- WLAN_STA_AUTHORIZED, ~0);
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "authorizing port");
- } else {
- sta->flags &= ~WLAN_STA_AUTHORIZED;
- res = hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- 0, ~WLAN_STA_AUTHORIZED);
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
- }
- if (res && errno != ENOENT) {
- printf("Could not set station " MACSTR " flags for kernel "
- "driver (errno=%d).\n", MAC2STR(sta->addr), errno);
- }
- if (authorized)
- accounting_sta_start(hapd, sta);
- }
- static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
- struct sta_info *sta,
- int idx, int broadcast,
- u8 *key_data, size_t key_len)
- {
- u8 *buf, *ekey;
- struct ieee802_1x_hdr *hdr;
- struct ieee802_1x_eapol_key *key;
- size_t len, ekey_len;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- len = sizeof(*key) + key_len;
- buf = os_zalloc(sizeof(*hdr) + len);
- if (buf == NULL)
- return;
- hdr = (struct ieee802_1x_hdr *) buf;
- key = (struct ieee802_1x_eapol_key *) (hdr + 1);
- key->type = EAPOL_KEY_TYPE_RC4;
- key->key_length = htons(key_len);
- wpa_get_ntp_timestamp(key->replay_counter);
- if (os_get_random(key->key_iv, sizeof(key->key_iv))) {
- wpa_printf(MSG_ERROR, "Could not get random numbers");
- os_free(buf);
- return;
- }
- key->key_index = idx | (broadcast ? 0 : BIT(7));
- if (hapd->conf->eapol_key_index_workaround) {
- /* According to some information, WinXP Supplicant seems to
- * interpret bit7 as an indication whether the key is to be
- * activated, so make it possible to enable workaround that
- * sets this bit for all keys. */
- key->key_index |= BIT(7);
- }
- /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
- * MSK[32..63] is used to sign the message. */
- if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
- wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
- "and signing EAPOL-Key");
- os_free(buf);
- return;
- }
- os_memcpy((u8 *) (key + 1), key_data, key_len);
- ekey_len = sizeof(key->key_iv) + 32;
- ekey = os_malloc(ekey_len);
- if (ekey == NULL) {
- wpa_printf(MSG_ERROR, "Could not encrypt key");
- os_free(buf);
- return;
- }
- os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
- os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
- rc4((u8 *) (key + 1), key_len, ekey, ekey_len);
- os_free(ekey);
- /* This header is needed here for HMAC-MD5, but it will be regenerated
- * in ieee802_1x_send() */
- hdr->version = hapd->conf->eapol_version;
- hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
- hdr->length = host_to_be16(len);
- hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
- key->key_signature);
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
- " (%s index=%d)", MAC2STR(sm->addr),
- broadcast ? "broadcast" : "unicast", idx);
- ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
- if (sta->eapol_sm)
- sta->eapol_sm->dot1xAuthEapolFramesTx++;
- os_free(buf);
- }
- static struct hostapd_wep_keys *
- ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
- {
- struct hostapd_wep_keys *key;
- key = os_zalloc(sizeof(*key));
- if (key == NULL)
- return NULL;
- key->default_len = hapd->conf->default_wep_key_len;
- if (key->idx >= hapd->conf->broadcast_key_idx_max ||
- key->idx < hapd->conf->broadcast_key_idx_min)
- key->idx = hapd->conf->broadcast_key_idx_min;
- else
- key->idx++;
- if (!key->key[key->idx])
- key->key[key->idx] = os_malloc(key->default_len);
- if (key->key[key->idx] == NULL ||
- os_get_random(key->key[key->idx], key->default_len)) {
- printf("Could not generate random WEP key (dynamic VLAN).\n");
- os_free(key->key[key->idx]);
- key->key[key->idx] = NULL;
- os_free(key);
- return NULL;
- }
- key->len[key->idx] = key->default_len;
- wpa_printf(MSG_DEBUG, "%s: Default WEP idx %d for dynamic VLAN\n",
- ifname, key->idx);
- wpa_hexdump_key(MSG_DEBUG, "Default WEP key (dynamic VLAN)",
- key->key[key->idx], key->len[key->idx]);
- if (hostapd_set_encryption(ifname, hapd, "WEP", NULL, key->idx,
- key->key[key->idx], key->len[key->idx], 1))
- printf("Could not set dynamic VLAN WEP encryption key.\n");
- hostapd_set_ieee8021x(ifname, hapd, 1);
- return key;
- }
- static struct hostapd_wep_keys *
- ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
- size_t vlan_id)
- {
- const char *ifname;
- if (vlan_id == 0)
- return &ssid->wep;
- if (vlan_id <= ssid->max_dyn_vlan_keys && ssid->dyn_vlan_keys &&
- ssid->dyn_vlan_keys[vlan_id])
- return ssid->dyn_vlan_keys[vlan_id];
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: Creating new group "
- "state machine for VLAN ID %lu",
- (unsigned long) vlan_id);
- ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
- if (ifname == NULL) {
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: Unknown VLAN ID %lu - "
- "cannot create group key state machine",
- (unsigned long) vlan_id);
- return NULL;
- }
- if (ssid->dyn_vlan_keys == NULL) {
- int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
- ssid->dyn_vlan_keys = os_zalloc(size);
- if (ssid->dyn_vlan_keys == NULL)
- return NULL;
- ssid->max_dyn_vlan_keys = vlan_id;
- }
- if (ssid->max_dyn_vlan_keys < vlan_id) {
- struct hostapd_wep_keys **na;
- int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
- na = os_realloc(ssid->dyn_vlan_keys, size);
- if (na == NULL)
- return NULL;
- ssid->dyn_vlan_keys = na;
- os_memset(&ssid->dyn_vlan_keys[ssid->max_dyn_vlan_keys + 1], 0,
- (vlan_id - ssid->max_dyn_vlan_keys) *
- sizeof(ssid->dyn_vlan_keys[0]));
- ssid->max_dyn_vlan_keys = vlan_id;
- }
- ssid->dyn_vlan_keys[vlan_id] = ieee802_1x_group_alloc(hapd, ifname);
- return ssid->dyn_vlan_keys[vlan_id];
- }
- void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
- {
- struct hostapd_wep_keys *key = NULL;
- struct eapol_state_machine *sm = sta->eapol_sm;
- int vlan_id;
- if (sm == NULL || !sm->eap_if->eapKeyData)
- return;
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
- MAC2STR(sta->addr));
- vlan_id = sta->vlan_id;
- if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
- vlan_id = 0;
- if (vlan_id) {
- key = ieee802_1x_get_group(hapd, sta->ssid, vlan_id);
- if (key && key->key[key->idx])
- ieee802_1x_tx_key_one(hapd, sta, key->idx, 1,
- key->key[key->idx],
- key->len[key->idx]);
- } else if (hapd->default_wep_key) {
- ieee802_1x_tx_key_one(hapd, sta, hapd->default_wep_key_idx, 1,
- hapd->default_wep_key,
- hapd->conf->default_wep_key_len);
- }
- if (hapd->conf->individual_wep_key_len > 0) {
- u8 *ikey;
- ikey = os_malloc(hapd->conf->individual_wep_key_len);
- if (ikey == NULL ||
- os_get_random(ikey, hapd->conf->individual_wep_key_len)) {
- wpa_printf(MSG_ERROR, "Could not generate random "
- "individual WEP key.");
- os_free(ikey);
- return;
- }
- wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
- ikey, hapd->conf->individual_wep_key_len);
- ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
- hapd->conf->individual_wep_key_len);
- /* TODO: set encryption in TX callback, i.e., only after STA
- * has ACKed EAPOL-Key frame */
- if (hostapd_set_encryption(hapd->conf->iface, hapd, "WEP",
- sta->addr, 0, ikey,
- hapd->conf->individual_wep_key_len,
- 1)) {
- wpa_printf(MSG_ERROR, "Could not set individual WEP "
- "encryption.");
- }
- os_free(ikey);
- }
- }
- const char *radius_mode_txt(struct hostapd_data *hapd)
- {
- if (hapd->iface->current_mode == NULL)
- return "802.11";
- switch (hapd->iface->current_mode->mode) {
- case HOSTAPD_MODE_IEEE80211A:
- return "802.11a";
- case HOSTAPD_MODE_IEEE80211G:
- return "802.11g";
- case HOSTAPD_MODE_IEEE80211B:
- default:
- return "802.11b";
- }
- }
- int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
- {
- int i;
- u8 rate = 0;
- for (i = 0; i < sta->supported_rates_len; i++)
- if ((sta->supported_rates[i] & 0x7f) > rate)
- rate = sta->supported_rates[i] & 0x7f;
- return rate;
- }
- static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
- struct eapol_state_machine *sm,
- const u8 *eap, size_t len)
- {
- const u8 *identity;
- size_t identity_len;
- if (len <= sizeof(struct eap_hdr) ||
- eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY)
- return;
- identity = eap_get_identity(sm->eap, &identity_len);
- if (identity == NULL)
- return;
- /* Save station identity for future RADIUS packets */
- os_free(sm->identity);
- sm->identity = os_malloc(identity_len + 1);
- if (sm->identity == NULL) {
- sm->identity_len = 0;
- return;
- }
- os_memcpy(sm->identity, identity, identity_len);
- sm->identity_len = identity_len;
- sm->identity[identity_len] = '\0';
- hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
- sm->dot1xAuthEapolRespIdFramesRx++;
- }
- static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
- struct sta_info *sta,
- const u8 *eap, size_t len)
- {
- struct radius_msg *msg;
- char buf[128];
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- ieee802_1x_learn_identity(hapd, sm, eap, len);
- wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
- "packet");
- sm->radius_identifier = radius_client_get_id(hapd->radius);
- msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
- sm->radius_identifier);
- if (msg == NULL) {
- printf("Could not create net RADIUS packet\n");
- return;
- }
- radius_msg_make_authenticator(msg, (u8 *) sta, sizeof(*sta));
- if (sm->identity &&
- !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
- sm->identity, sm->identity_len)) {
- printf("Could not add User-Name\n");
- goto fail;
- }
- if (hapd->conf->own_ip_addr.af == AF_INET &&
- !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
- (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
- printf("Could not add NAS-IP-Address\n");
- goto fail;
- }
- #ifdef CONFIG_IPV6
- if (hapd->conf->own_ip_addr.af == AF_INET6 &&
- !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
- (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
- printf("Could not add NAS-IPv6-Address\n");
- goto fail;
- }
- #endif /* CONFIG_IPV6 */
- if (hapd->conf->nas_identifier &&
- !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
- (u8 *) hapd->conf->nas_identifier,
- os_strlen(hapd->conf->nas_identifier))) {
- printf("Could not add NAS-Identifier\n");
- goto fail;
- }
- if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
- printf("Could not add NAS-Port\n");
- goto fail;
- }
- os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
- MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
- buf[sizeof(buf) - 1] = '\0';
- if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
- (u8 *) buf, os_strlen(buf))) {
- printf("Could not add Called-Station-Id\n");
- goto fail;
- }
- os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
- MAC2STR(sta->addr));
- buf[sizeof(buf) - 1] = '\0';
- if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
- (u8 *) buf, os_strlen(buf))) {
- printf("Could not add Calling-Station-Id\n");
- goto fail;
- }
- /* TODO: should probably check MTU from driver config; 2304 is max for
- * IEEE 802.11, but use 1400 to avoid problems with too large packets
- */
- if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
- printf("Could not add Framed-MTU\n");
- goto fail;
- }
- if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
- RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
- printf("Could not add NAS-Port-Type\n");
- goto fail;
- }
- if (sta->flags & WLAN_STA_PREAUTH) {
- os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
- sizeof(buf));
- } else {
- os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
- radius_sta_rate(hapd, sta) / 2,
- (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
- radius_mode_txt(hapd));
- buf[sizeof(buf) - 1] = '\0';
- }
- if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
- (u8 *) buf, os_strlen(buf))) {
- printf("Could not add Connect-Info\n");
- goto fail;
- }
- if (eap && !radius_msg_add_eap(msg, eap, len)) {
- printf("Could not add EAP-Message\n");
- goto fail;
- }
- /* State attribute must be copied if and only if this packet is
- * Access-Request reply to the previous Access-Challenge */
- if (sm->last_recv_radius && sm->last_recv_radius->hdr->code ==
- RADIUS_CODE_ACCESS_CHALLENGE) {
- int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
- RADIUS_ATTR_STATE);
- if (res < 0) {
- printf("Could not copy State attribute from previous "
- "Access-Challenge\n");
- goto fail;
- }
- if (res > 0) {
- wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
- }
- }
- radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr);
- return;
- fail:
- radius_msg_free(msg);
- os_free(msg);
- }
- char *eap_type_text(u8 type)
- {
- switch (type) {
- case EAP_TYPE_IDENTITY: return "Identity";
- case EAP_TYPE_NOTIFICATION: return "Notification";
- case EAP_TYPE_NAK: return "Nak";
- case EAP_TYPE_MD5: return "MD5-Challenge";
- case EAP_TYPE_OTP: return "One-Time Password";
- case EAP_TYPE_GTC: return "Generic Token Card";
- case EAP_TYPE_TLS: return "TLS";
- case EAP_TYPE_TTLS: return "TTLS";
- case EAP_TYPE_PEAP: return "PEAP";
- case EAP_TYPE_SIM: return "SIM";
- case EAP_TYPE_FAST: return "FAST";
- case EAP_TYPE_SAKE: return "SAKE";
- case EAP_TYPE_PSK: return "PSK";
- case EAP_TYPE_PAX: return "PAX";
- default: return "Unknown";
- }
- }
- static void handle_eap_response(struct hostapd_data *hapd,
- struct sta_info *sta, struct eap_hdr *eap,
- size_t len)
- {
- u8 type, *data;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- data = (u8 *) (eap + 1);
- if (len < sizeof(*eap) + 1) {
- printf("handle_eap_response: too short response data\n");
- return;
- }
- sm->eap_type_supp = type = data[0];
- hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
- "id=%d len=%d) from STA: EAP Response-%s (%d)",
- eap->code, eap->identifier, be_to_host16(eap->length),
- eap_type_text(type), type);
- sm->dot1xAuthEapolRespFramesRx++;
- wpabuf_free(sm->eap_if->eapRespData);
- sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
- sm->eapolEap = TRUE;
- }
- /* Process incoming EAP packet from Supplicant */
- static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
- u8 *buf, size_t len)
- {
- struct eap_hdr *eap;
- u16 eap_len;
- if (len < sizeof(*eap)) {
- printf(" too short EAP packet\n");
- return;
- }
- eap = (struct eap_hdr *) buf;
- eap_len = be_to_host16(eap->length);
- wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
- eap->code, eap->identifier, eap_len);
- if (eap_len < sizeof(*eap)) {
- wpa_printf(MSG_DEBUG, " Invalid EAP length");
- return;
- } else if (eap_len > len) {
- wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
- "packet");
- return;
- } else if (eap_len < len) {
- wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
- "packet", (unsigned long) len - eap_len);
- }
- switch (eap->code) {
- case EAP_CODE_REQUEST:
- wpa_printf(MSG_DEBUG, " (request)");
- return;
- case EAP_CODE_RESPONSE:
- wpa_printf(MSG_DEBUG, " (response)");
- handle_eap_response(hapd, sta, eap, eap_len);
- break;
- case EAP_CODE_SUCCESS:
- wpa_printf(MSG_DEBUG, " (success)");
- return;
- case EAP_CODE_FAILURE:
- wpa_printf(MSG_DEBUG, " (failure)");
- return;
- default:
- wpa_printf(MSG_DEBUG, " (unknown code)");
- return;
- }
- }
- /**
- * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
- * @hapd: hostapd BSS data
- * @sa: Source address (sender of the EAPOL frame)
- * @buf: EAPOL frame
- * @len: Length of buf in octets
- *
- * This function is called for each incoming EAPOL frame from the interface
- */
- void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
- size_t len)
- {
- struct sta_info *sta;
- struct ieee802_1x_hdr *hdr;
- struct ieee802_1x_eapol_key *key;
- u16 datalen;
- struct rsn_pmksa_cache_entry *pmksa;
- if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
- !hapd->conf->wps_state)
- return;
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
- (unsigned long) len, MAC2STR(sa));
- sta = ap_get_sta(hapd, sa);
- if (!sta) {
- printf(" no station information available\n");
- return;
- }
- if (len < sizeof(*hdr)) {
- printf(" too short IEEE 802.1X packet\n");
- return;
- }
- hdr = (struct ieee802_1x_hdr *) buf;
- datalen = be_to_host16(hdr->length);
- wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
- hdr->version, hdr->type, datalen);
- if (len - sizeof(*hdr) < datalen) {
- printf(" frame too short for this IEEE 802.1X packet\n");
- if (sta->eapol_sm)
- sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
- return;
- }
- if (len - sizeof(*hdr) > datalen) {
- wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
- "IEEE 802.1X packet",
- (unsigned long) len - sizeof(*hdr) - datalen);
- }
- if (sta->eapol_sm) {
- sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
- sta->eapol_sm->dot1xAuthEapolFramesRx++;
- }
- key = (struct ieee802_1x_eapol_key *) (hdr + 1);
- if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
- hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
- (key->type == EAPOL_KEY_TYPE_WPA ||
- key->type == EAPOL_KEY_TYPE_RSN)) {
- wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
- sizeof(*hdr) + datalen);
- return;
- }
- if ((!hapd->conf->ieee802_1x &&
- !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) ||
- wpa_key_mgmt_wpa_psk(wpa_auth_sta_key_mgmt(sta->wpa_sm)))
- return;
- if (!sta->eapol_sm) {
- sta->eapol_sm = eapol_auth_alloc(hapd->eapol_auth, sta->addr,
- sta->flags & WLAN_STA_PREAUTH,
- sta);
- if (!sta->eapol_sm)
- return;
- #ifdef CONFIG_WPS
- if (!hapd->conf->ieee802_1x &&
- ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
- WLAN_STA_MAYBE_WPS)) {
- /*
- * Delay EAPOL frame transmission until a possible WPS
- * STA initiates the handshake with EAPOL-Start.
- */
- sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
- }
- #endif /* CONFIG_WPS */
- }
- /* since we support version 1, we can ignore version field and proceed
- * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
- /* TODO: actually, we are not version 1 anymore.. However, Version 2
- * does not change frame contents, so should be ok to process frames
- * more or less identically. Some changes might be needed for
- * verification of fields. */
- switch (hdr->type) {
- case IEEE802_1X_TYPE_EAP_PACKET:
- handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
- break;
- case IEEE802_1X_TYPE_EAPOL_START:
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
- "from STA");
- sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
- pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
- if (pmksa) {
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
- HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
- "available - ignore it since "
- "STA sent EAPOL-Start");
- wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
- }
- sta->eapol_sm->eapolStart = TRUE;
- sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
- wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
- break;
- case IEEE802_1X_TYPE_EAPOL_LOGOFF:
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
- "from STA");
- sta->acct_terminate_cause =
- RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
- accounting_sta_stop(hapd, sta);
- sta->eapol_sm->eapolLogoff = TRUE;
- sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
- break;
- case IEEE802_1X_TYPE_EAPOL_KEY:
- wpa_printf(MSG_DEBUG, " EAPOL-Key");
- if (!(sta->flags & WLAN_STA_AUTHORIZED)) {
- wpa_printf(MSG_DEBUG, " Dropped key data from "
- "unauthorized Supplicant");
- break;
- }
- break;
- case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
- wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
- /* TODO: implement support for this; show data */
- break;
- default:
- wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
- sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
- break;
- }
- eapol_auth_step(sta->eapol_sm);
- }
- /**
- * ieee802_1x_new_station - Start IEEE 802.1X authentication
- * @hapd: hostapd BSS data
- * @sta: The station
- *
- * This function is called to start IEEE 802.1X authentication when a new
- * station completes IEEE 802.11 association.
- */
- void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
- {
- struct rsn_pmksa_cache_entry *pmksa;
- int reassoc = 1;
- int force_1x = 0;
- #ifdef CONFIG_WPS
- if (hapd->conf->wps_state &&
- (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
- /*
- * Need to enable IEEE 802.1X/EAPOL state machines for possible
- * WPS handshake even if IEEE 802.1X/EAPOL is not used for
- * authentication in this BSS.
- */
- force_1x = 1;
- }
- #endif /* CONFIG_WPS */
- if ((!force_1x && !hapd->conf->ieee802_1x) ||
- wpa_key_mgmt_wpa_psk(wpa_auth_sta_key_mgmt(sta->wpa_sm)))
- return;
- if (sta->eapol_sm == NULL) {
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "start authentication");
- sta->eapol_sm = eapol_auth_alloc(hapd->eapol_auth, sta->addr,
- sta->flags & WLAN_STA_PREAUTH,
- sta);
- if (sta->eapol_sm == NULL) {
- hostapd_logger(hapd, sta->addr,
- HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_INFO,
- "failed to allocate state machine");
- return;
- }
- reassoc = 0;
- }
- #ifdef CONFIG_WPS
- sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
- if (!hapd->conf->ieee802_1x && !(sta->flags & WLAN_STA_WPS)) {
- /*
- * Delay EAPOL frame transmission until a possible WPS
- * initiates the handshake with EAPOL-Start.
- */
- sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
- }
- #endif /* CONFIG_WPS */
- sta->eapol_sm->eap_if->portEnabled = TRUE;
- pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
- if (pmksa) {
- int old_vlanid;
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG,
- "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
- /* Setup EAPOL state machines to already authenticated state
- * because of existing PMKSA information in the cache. */
- sta->eapol_sm->keyRun = TRUE;
- sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
- sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
- sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
- sta->eapol_sm->authSuccess = TRUE;
- if (sta->eapol_sm->eap)
- eap_sm_notify_cached(sta->eapol_sm->eap);
- old_vlanid = sta->vlan_id;
- pmksa_cache_to_eapol_data(pmksa, sta->eapol_sm);
- if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
- sta->vlan_id = 0;
- ap_sta_bind_vlan(hapd, sta, old_vlanid);
- } else {
- if (reassoc) {
- /*
- * Force EAPOL state machines to start
- * re-authentication without having to wait for the
- * Supplicant to send EAPOL-Start.
- */
- sta->eapol_sm->reAuthenticate = TRUE;
- }
- eapol_auth_step(sta->eapol_sm);
- }
- }
- void ieee802_1x_free_radius_class(struct radius_class_data *class)
- {
- size_t i;
- if (class == NULL)
- return;
- for (i = 0; i < class->count; i++)
- os_free(class->attr[i].data);
- os_free(class->attr);
- class->attr = NULL;
- class->count = 0;
- }
- int ieee802_1x_copy_radius_class(struct radius_class_data *dst,
- const struct radius_class_data *src)
- {
- size_t i;
- if (src->attr == NULL)
- return 0;
- dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
- if (dst->attr == NULL)
- return -1;
- dst->count = 0;
- for (i = 0; i < src->count; i++) {
- dst->attr[i].data = os_malloc(src->attr[i].len);
- if (dst->attr[i].data == NULL)
- break;
- dst->count++;
- os_memcpy(dst->attr[i].data, src->attr[i].data,
- src->attr[i].len);
- dst->attr[i].len = src->attr[i].len;
- }
- return 0;
- }
- void ieee802_1x_free_station(struct sta_info *sta)
- {
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- sta->eapol_sm = NULL;
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- }
- os_free(sm->identity);
- ieee802_1x_free_radius_class(&sm->radius_class);
- eapol_auth_free(sm);
- }
- static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
- struct sta_info *sta)
- {
- u8 *eap;
- size_t len;
- struct eap_hdr *hdr;
- int eap_type = -1;
- char buf[64];
- struct radius_msg *msg;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL || sm->last_recv_radius == NULL) {
- if (sm)
- sm->eap_if->aaaEapNoReq = TRUE;
- return;
- }
- msg = sm->last_recv_radius;
- eap = radius_msg_get_eap(msg, &len);
- if (eap == NULL) {
- /* RFC 3579, Chap. 2.6.3:
- * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
- * attribute */
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_WARNING, "could not extract "
- "EAP-Message from RADIUS message");
- sm->eap_if->aaaEapNoReq = TRUE;
- return;
- }
- if (len < sizeof(*hdr)) {
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_WARNING, "too short EAP packet "
- "received from authentication server");
- os_free(eap);
- sm->eap_if->aaaEapNoReq = TRUE;
- return;
- }
- if (len > sizeof(*hdr))
- eap_type = eap[sizeof(*hdr)];
- hdr = (struct eap_hdr *) eap;
- switch (hdr->code) {
- case EAP_CODE_REQUEST:
- if (eap_type >= 0)
- sm->eap_type_authsrv = eap_type;
- os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
- eap_type >= 0 ? eap_type_text(eap_type) : "??",
- eap_type);
- break;
- case EAP_CODE_RESPONSE:
- os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
- eap_type >= 0 ? eap_type_text(eap_type) : "??",
- eap_type);
- break;
- case EAP_CODE_SUCCESS:
- os_strlcpy(buf, "EAP Success", sizeof(buf));
- break;
- case EAP_CODE_FAILURE:
- os_strlcpy(buf, "EAP Failure", sizeof(buf));
- break;
- default:
- os_strlcpy(buf, "unknown EAP code", sizeof(buf));
- break;
- }
- buf[sizeof(buf) - 1] = '\0';
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
- "id=%d len=%d) from RADIUS server: %s",
- hdr->code, hdr->identifier, be_to_host16(hdr->length),
- buf);
- sm->eap_if->aaaEapReq = TRUE;
- wpabuf_free(sm->eap_if->aaaEapReqData);
- sm->eap_if->aaaEapReqData = wpabuf_alloc_ext_data(eap, len);
- }
- static void ieee802_1x_get_keys(struct hostapd_data *hapd,
- struct sta_info *sta, struct radius_msg *msg,
- struct radius_msg *req,
- u8 *shared_secret, size_t shared_secret_len)
- {
- struct radius_ms_mppe_keys *keys;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- keys = radius_msg_get_ms_keys(msg, req, shared_secret,
- shared_secret_len);
- if (keys && keys->send && keys->recv) {
- size_t len = keys->send_len + keys->recv_len;
- wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
- keys->send, keys->send_len);
- wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
- keys->recv, keys->recv_len);
- os_free(sm->eap_if->aaaEapKeyData);
- sm->eap_if->aaaEapKeyData = os_malloc(len);
- if (sm->eap_if->aaaEapKeyData) {
- os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
- keys->recv_len);
- os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
- keys->send, keys->send_len);
- sm->eap_if->aaaEapKeyDataLen = len;
- sm->eap_if->aaaEapKeyAvailable = TRUE;
- }
- }
- if (keys) {
- os_free(keys->send);
- os_free(keys->recv);
- os_free(keys);
- }
- }
- static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
- struct sta_info *sta,
- struct radius_msg *msg)
- {
- u8 *class;
- size_t class_len;
- struct eapol_state_machine *sm = sta->eapol_sm;
- int count, i;
- struct radius_attr_data *nclass;
- size_t nclass_count;
- if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
- sm == NULL)
- return;
- ieee802_1x_free_radius_class(&sm->radius_class);
- count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
- if (count <= 0)
- return;
- nclass = os_zalloc(count * sizeof(struct radius_attr_data));
- if (nclass == NULL)
- return;
- nclass_count = 0;
- class = NULL;
- for (i = 0; i < count; i++) {
- do {
- if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
- &class, &class_len,
- class) < 0) {
- i = count;
- break;
- }
- } while (class_len < 1);
- nclass[nclass_count].data = os_malloc(class_len);
- if (nclass[nclass_count].data == NULL)
- break;
- os_memcpy(nclass[nclass_count].data, class, class_len);
- nclass[nclass_count].len = class_len;
- nclass_count++;
- }
- sm->radius_class.attr = nclass;
- sm->radius_class.count = nclass_count;
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
- "attributes for " MACSTR,
- (unsigned long) sm->radius_class.count,
- MAC2STR(sta->addr));
- }
- /* Update sta->identity based on User-Name attribute in Access-Accept */
- static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
- struct sta_info *sta,
- struct radius_msg *msg)
- {
- u8 *buf, *identity;
- size_t len;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
- NULL) < 0)
- return;
- identity = os_malloc(len + 1);
- if (identity == NULL)
- return;
- os_memcpy(identity, buf, len);
- identity[len] = '\0';
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
- "User-Name from Access-Accept '%s'",
- sm->identity ? (char *) sm->identity : "N/A",
- (char *) identity);
- os_free(sm->identity);
- sm->identity = identity;
- sm->identity_len = len;
- }
- struct sta_id_search {
- u8 identifier;
- struct eapol_state_machine *sm;
- };
- static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
- struct sta_info *sta,
- void *ctx)
- {
- struct sta_id_search *id_search = ctx;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm && sm->radius_identifier >= 0 &&
- sm->radius_identifier == id_search->identifier) {
- id_search->sm = sm;
- return 1;
- }
- return 0;
- }
- static struct eapol_state_machine *
- ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
- {
- struct sta_id_search id_search;
- id_search.identifier = identifier;
- id_search.sm = NULL;
- ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
- return id_search.sm;
- }
- /**
- * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
- * @msg: RADIUS response message
- * @req: RADIUS request message
- * @shared_secret: RADIUS shared secret
- * @shared_secret_len: Length of shared_secret in octets
- * @data: Context data (struct hostapd_data *)
- * Returns: Processing status
- */
- static RadiusRxResult
- ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
- u8 *shared_secret, size_t shared_secret_len,
- void *data)
- {
- struct hostapd_data *hapd = data;
- struct sta_info *sta;
- u32 session_timeout = 0, termination_action, acct_interim_interval;
- int session_timeout_set, old_vlanid = 0;
- struct eapol_state_machine *sm;
- int override_eapReq = 0;
- sm = ieee802_1x_search_radius_identifier(hapd, msg->hdr->identifier);
- if (sm == NULL) {
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
- "station for this RADIUS message");
- return RADIUS_RX_UNKNOWN;
- }
- sta = sm->sta;
- /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
- * present when packet contains an EAP-Message attribute */
- if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
- radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
- 0) < 0 &&
- radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
- wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
- "Message-Authenticator since it does not include "
- "EAP-Message");
- } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
- req, 1)) {
- printf("Incoming RADIUS packet did not have correct "
- "Message-Authenticator - dropped\n");
- return RADIUS_RX_INVALID_AUTHENTICATOR;
- }
- if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
- msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
- printf("Unknown RADIUS message code\n");
- return RADIUS_RX_UNKNOWN;
- }
- sm->radius_identifier = -1;
- wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
- MAC2STR(sta->addr));
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- }
- sm->last_recv_radius = msg;
- session_timeout_set =
- !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
- &session_timeout);
- if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
- &termination_action))
- termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
- if (hapd->conf->radius->acct_interim_interval == 0 &&
- msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
- radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
- &acct_interim_interval) == 0) {
- if (acct_interim_interval < 60) {
- hostapd_logger(hapd, sta->addr,
- HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_INFO,
- "ignored too small "
- "Acct-Interim-Interval %d",
- acct_interim_interval);
- } else
- sta->acct_interim_interval = acct_interim_interval;
- }
- switch (msg->hdr->code) {
- case RADIUS_CODE_ACCESS_ACCEPT:
- if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
- sta->vlan_id = 0;
- else {
- old_vlanid = sta->vlan_id;
- sta->vlan_id = radius_msg_get_vlanid(msg);
- }
- if (sta->vlan_id > 0 &&
- hostapd_get_vlan_id_ifname(hapd->conf->vlan,
- sta->vlan_id)) {
- hostapd_logger(hapd, sta->addr,
- HOSTAPD_MODULE_RADIUS,
- HOSTAPD_LEVEL_INFO,
- "VLAN ID %d", sta->vlan_id);
- } else if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_REQUIRED) {
- sta->eapol_sm->authFail = TRUE;
- hostapd_logger(hapd, sta->addr,
- HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_INFO, "authentication "
- "server did not include required VLAN "
- "ID in Access-Accept");
- break;
- }
- ap_sta_bind_vlan(hapd, sta, old_vlanid);
- /* RFC 3580, Ch. 3.17 */
- if (session_timeout_set && termination_action ==
- RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) {
- sm->reAuthPeriod = session_timeout;
- } else if (session_timeout_set)
- ap_sta_session_timeout(hapd, sta, session_timeout);
- sm->eap_if->aaaSuccess = TRUE;
- override_eapReq = 1;
- ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
- shared_secret_len);
- ieee802_1x_store_radius_class(hapd, sta, msg);
- ieee802_1x_update_sta_identity(hapd, sta, msg);
- if (sm->eap_if->eapKeyAvailable &&
- wpa_auth_pmksa_add(sta->wpa_sm, sm->eapol_key_crypt,
- session_timeout_set ?
- (int) session_timeout : -1, sm) == 0) {
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
- HOSTAPD_LEVEL_DEBUG,
- "Added PMKSA cache entry");
- }
- break;
- case RADIUS_CODE_ACCESS_REJECT:
- sm->eap_if->aaaFail = TRUE;
- override_eapReq = 1;
- break;
- case RADIUS_CODE_ACCESS_CHALLENGE:
- sm->eap_if->aaaEapReq = TRUE;
- if (session_timeout_set) {
- /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
- sm->eap_if->aaaMethodTimeout = session_timeout;
- hostapd_logger(hapd, sm->addr,
- HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG,
- "using EAP timeout of %d seconds (from "
- "RADIUS)",
- sm->eap_if->aaaMethodTimeout);
- } else {
- /*
- * Use dynamic retransmission behavior per EAP
- * specification.
- */
- sm->eap_if->aaaMethodTimeout = 0;
- }
- break;
- }
- ieee802_1x_decapsulate_radius(hapd, sta);
- if (override_eapReq)
- sm->eap_if->aaaEapReq = FALSE;
- eapol_auth_step(sm);
- return RADIUS_RX_QUEUED;
- }
- void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
- {
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "aborting authentication");
- if (sm->last_recv_radius) {
- radius_msg_free(sm->last_recv_radius);
- os_free(sm->last_recv_radius);
- sm->last_recv_radius = NULL;
- }
- if (sm->eap_if->eapTimeout) {
- /*
- * Disconnect the STA since it did not reply to the last EAP
- * request and we cannot continue EAP processing (EAP-Failure
- * could only be sent if the EAP peer actually replied).
- */
- sm->eap_if->portEnabled = FALSE;
- hostapd_sta_deauth(hapd, sta->addr,
- WLAN_REASON_PREV_AUTH_NOT_VALID);
- sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
- WLAN_STA_AUTHORIZED);
- eloop_cancel_timeout(ap_handle_timer, hapd, sta);
- eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta);
- sta->timeout_next = STA_REMOVE;
- }
- }
- #ifdef HOSTAPD_DUMP_STATE
- static void fprint_char(FILE *f, char c)
- {
- if (c >= 32 && c < 127)
- fprintf(f, "%c", c);
- else
- fprintf(f, "<%02x>", c);
- }
- void ieee802_1x_dump_state(FILE *f, const char *prefix, struct sta_info *sta)
- {
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return;
- fprintf(f, "%sIEEE 802.1X:\n", prefix);
- if (sm->identity) {
- size_t i;
- fprintf(f, "%sidentity=", prefix);
- for (i = 0; i < sm->identity_len; i++)
- fprint_char(f, sm->identity[i]);
- fprintf(f, "\n");
- }
- fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
- "Supplicant: %d (%s)\n", prefix,
- sm->eap_type_authsrv, eap_type_text(sm->eap_type_authsrv),
- sm->eap_type_supp, eap_type_text(sm->eap_type_supp));
- fprintf(f, "%scached_packets=%s\n", prefix,
- sm->last_recv_radius ? "[RX RADIUS]" : "");
- eapol_auth_dump_state(f, prefix, sm);
- }
- #endif /* HOSTAPD_DUMP_STATE */
- static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
- {
- if (hapd->conf->default_wep_key_len < 1)
- return 0;
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
- if (hapd->default_wep_key == NULL ||
- os_get_random(hapd->default_wep_key,
- hapd->conf->default_wep_key_len)) {
- printf("Could not generate random WEP key.\n");
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
- return -1;
- }
- wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
- hapd->default_wep_key,
- hapd->conf->default_wep_key_len);
- return 0;
- }
- static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
- struct sta_info *sta, void *ctx)
- {
- if (sta->eapol_sm) {
- sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
- eapol_auth_step(sta->eapol_sm);
- }
- return 0;
- }
- static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
- {
- struct hostapd_data *hapd = eloop_ctx;
- if (hapd->default_wep_key_idx >= 3)
- hapd->default_wep_key_idx =
- hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
- else
- hapd->default_wep_key_idx++;
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
- hapd->default_wep_key_idx);
-
- if (ieee802_1x_rekey_broadcast(hapd)) {
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_WARNING, "failed to generate a "
- "new broadcast key");
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
- return;
- }
- /* TODO: Could setup key for RX here, but change default TX keyid only
- * after new broadcast key has been sent to all stations. */
- if (hostapd_set_encryption(hapd->conf->iface, hapd, "WEP", NULL,
- hapd->default_wep_key_idx,
- hapd->default_wep_key,
- hapd->conf->default_wep_key_len, 1)) {
- hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_WARNING, "failed to configure a "
- "new broadcast key");
- os_free(hapd->default_wep_key);
- hapd->default_wep_key = NULL;
- return;
- }
- ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
- if (hapd->conf->wep_rekeying_period > 0) {
- eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
- ieee802_1x_rekey, hapd, NULL);
- }
- }
- static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
- const u8 *data, size_t datalen)
- {
- ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
- }
- static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
- const u8 *data, size_t datalen)
- {
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = sta_ctx;
- ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
- }
- static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
- int preauth)
- {
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = sta_ctx;
- if (preauth)
- rsn_preauth_finished(hapd, sta, success);
- else
- ieee802_1x_finished(hapd, sta, success);
- }
- static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
- size_t identity_len, int phase2,
- struct eap_user *user)
- {
- struct hostapd_data *hapd = ctx;
- const struct hostapd_eap_user *eap_user;
- int i, count;
- eap_user = hostapd_get_eap_user(hapd->conf, identity,
- identity_len, phase2);
- if (eap_user == NULL)
- return -1;
- os_memset(user, 0, sizeof(*user));
- user->phase2 = phase2;
- count = EAP_USER_MAX_METHODS;
- if (count > EAP_MAX_METHODS)
- count = EAP_MAX_METHODS;
- for (i = 0; i < count; i++) {
- user->methods[i].vendor = eap_user->methods[i].vendor;
- user->methods[i].method = eap_user->methods[i].method;
- }
- if (eap_user->password) {
- user->password = os_malloc(eap_user->password_len);
- if (user->password == NULL)
- return -1;
- os_memcpy(user->password, eap_user->password,
- eap_user->password_len);
- user->password_len = eap_user->password_len;
- }
- user->force_version = eap_user->force_version;
- user->ttls_auth = eap_user->ttls_auth;
- return 0;
- }
- static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
- {
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta;
- sta = ap_get_sta(hapd, addr);
- if (sta == NULL || sta->eapol_sm == NULL)
- return 0;
- return 1;
- }
- static void ieee802_1x_logger(void *ctx, const u8 *addr,
- eapol_logger_level level, const char *txt)
- {
- struct hostapd_data *hapd = ctx;
- int hlevel;
- switch (level) {
- case EAPOL_LOGGER_WARNING:
- hlevel = HOSTAPD_LEVEL_WARNING;
- break;
- case EAPOL_LOGGER_INFO:
- hlevel = HOSTAPD_LEVEL_INFO;
- break;
- case EAPOL_LOGGER_DEBUG:
- default:
- hlevel = HOSTAPD_LEVEL_DEBUG;
- break;
- }
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
- txt);
- }
- static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
- int authorized)
- {
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = sta_ctx;
- ieee802_1x_set_sta_authorized(hapd, sta, authorized);
- }
- static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
- {
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = sta_ctx;
- ieee802_1x_abort_auth(hapd, sta);
- }
- static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
- {
- struct hostapd_data *hapd = ctx;
- struct sta_info *sta = sta_ctx;
- ieee802_1x_tx_key(hapd, sta);
- }
- int ieee802_1x_init(struct hostapd_data *hapd)
- {
- int i;
- struct eapol_auth_config conf;
- struct eapol_auth_cb cb;
- os_memset(&conf, 0, sizeof(conf));
- conf.hapd = hapd;
- conf.eap_reauth_period = hapd->conf->eap_reauth_period;
- conf.wpa = hapd->conf->wpa;
- conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
- conf.eap_server = hapd->conf->eap_server;
- conf.ssl_ctx = hapd->ssl_ctx;
- conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
- conf.eap_req_id_text = hapd->conf->eap_req_id_text;
- conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
- conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
- conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
- conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
- conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
- conf.eap_fast_prov = hapd->conf->eap_fast_prov;
- conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
- conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
- conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
- conf.tnc = hapd->conf->tnc;
- conf.wps = hapd->wps;
- os_memset(&cb, 0, sizeof(cb));
- cb.eapol_send = ieee802_1x_eapol_send;
- cb.aaa_send = ieee802_1x_aaa_send;
- cb.finished = _ieee802_1x_finished;
- cb.get_eap_user = ieee802_1x_get_eap_user;
- cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
- cb.logger = ieee802_1x_logger;
- cb.set_port_authorized = ieee802_1x_set_port_authorized;
- cb.abort_auth = _ieee802_1x_abort_auth;
- cb.tx_key = _ieee802_1x_tx_key;
- hapd->eapol_auth = eapol_auth_init(&conf, &cb);
- if (hapd->eapol_auth == NULL)
- return -1;
- if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
- hostapd_set_ieee8021x(hapd->conf->iface, hapd, 1))
- return -1;
- if (radius_client_register(hapd->radius, RADIUS_AUTH,
- ieee802_1x_receive_auth, hapd))
- return -1;
- if (hapd->conf->default_wep_key_len) {
- hostapd_set_privacy(hapd, 1);
- for (i = 0; i < 4; i++)
- hostapd_set_encryption(hapd->conf->iface, hapd,
- "none", NULL, i, NULL, 0, 0);
- ieee802_1x_rekey(hapd, NULL);
- if (hapd->default_wep_key == NULL)
- return -1;
- }
- return 0;
- }
- void ieee802_1x_deinit(struct hostapd_data *hapd)
- {
- eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
- if (hapd->driver != NULL &&
- (hapd->conf->ieee802_1x || hapd->conf->wpa))
- hostapd_set_ieee8021x(hapd->conf->iface, hapd, 0);
- eapol_auth_deinit(hapd->eapol_auth);
- hapd->eapol_auth = NULL;
- }
- int ieee802_1x_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf,
- struct hostapd_bss_config *oldbss)
- {
- ieee802_1x_deinit(hapd);
- return ieee802_1x_init(hapd);
- }
- int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
- u8 *buf, size_t len, int ack)
- {
- struct ieee80211_hdr *hdr;
- struct ieee802_1x_hdr *xhdr;
- struct ieee802_1x_eapol_key *key;
- u8 *pos;
- const unsigned char rfc1042_hdr[ETH_ALEN] =
- { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
- if (sta == NULL)
- return -1;
- if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2 + sizeof(*xhdr))
- return 0;
- hdr = (struct ieee80211_hdr *) buf;
- pos = (u8 *) (hdr + 1);
- if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
- return 0;
- pos += sizeof(rfc1042_hdr);
- if (WPA_GET_BE16(pos) != ETH_P_PAE)
- return 0;
- pos += 2;
- xhdr = (struct ieee802_1x_hdr *) pos;
- pos += sizeof(*xhdr);
- wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
- "type=%d length=%d - ack=%d",
- MAC2STR(sta->addr), xhdr->version, xhdr->type,
- be_to_host16(xhdr->length), ack);
- /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
- * or Authenticator state machines, but EAPOL-Key packets are not
- * retransmitted in case of failure. Try to re-sent failed EAPOL-Key
- * packets couple of times because otherwise STA keys become
- * unsynchronized with AP. */
- if (xhdr->type == IEEE802_1X_TYPE_EAPOL_KEY && !ack &&
- pos + sizeof(*key) <= buf + len) {
- key = (struct ieee802_1x_eapol_key *) pos;
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
- HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
- "frame (%scast index=%d)",
- key->key_index & BIT(7) ? "uni" : "broad",
- key->key_index & ~BIT(7));
- /* TODO: re-send EAPOL-Key couple of times (with short delay
- * between them?). If all attempt fail, report error and
- * deauthenticate STA so that it will get new keys when
- * authenticating again (e.g., after returning in range).
- * Separate limit/transmit state needed both for unicast and
- * broadcast keys(?) */
- }
- /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
- * to here and change the key only if the EAPOL-Key packet was Acked.
- */
- return 1;
- }
- u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
- {
- if (sm == NULL || sm->identity == NULL)
- return NULL;
- *len = sm->identity_len;
- return sm->identity;
- }
- u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
- int idx)
- {
- if (sm == NULL || sm->radius_class.attr == NULL ||
- idx >= (int) sm->radius_class.count)
- return NULL;
- *len = sm->radius_class.attr[idx].len;
- return sm->radius_class.attr[idx].data;
- }
- const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
- {
- if (sm == NULL)
- return NULL;
- *len = sm->eap_if->eapKeyDataLen;
- return sm->eap_if->eapKeyData;
- }
- void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
- int enabled)
- {
- if (sm == NULL)
- return;
- sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
- eapol_auth_step(sm);
- }
- void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
- int valid)
- {
- if (sm == NULL)
- return;
- sm->portValid = valid ? TRUE : FALSE;
- eapol_auth_step(sm);
- }
- void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
- {
- if (sm == NULL)
- return;
- if (pre_auth)
- sm->flags |= EAPOL_SM_PREAUTH;
- else
- sm->flags &= ~EAPOL_SM_PREAUTH;
- }
- static const char * bool_txt(Boolean bool)
- {
- return bool ? "TRUE" : "FALSE";
- }
- int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
- {
- /* TODO */
- return 0;
- }
- int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
- char *buf, size_t buflen)
- {
- int len = 0, ret;
- struct eapol_state_machine *sm = sta->eapol_sm;
- if (sm == NULL)
- return 0;
- ret = os_snprintf(buf + len, buflen - len,
- "dot1xPaePortNumber=%d\n"
- "dot1xPaePortProtocolVersion=%d\n"
- "dot1xPaePortCapabilities=1\n"
- "dot1xPaePortInitialize=%d\n"
- "dot1xPaePortReauthenticate=FALSE\n",
- sta->aid,
- EAPOL_VERSION,
- sm->initialize);
- if (ret < 0 || (size_t) ret >= buflen - len)
- return len;
- len += ret;
- /* dot1xAuthConfigTable */
- ret = os_snprintf(buf + len, buflen - len,
- "dot1xAuthPaeState=%d\n"
- "dot1xAuthBackendAuthState=%d\n"
- "dot1xAuthAdminControlledDirections=%d\n"
- "dot1xAuthOperControlledDirections=%d\n"
- "dot1xAuthAuthControlledPortStatus=%d\n"
- "dot1xAuthAuthControlledPortControl=%d\n"
- "dot1xAuthQuietPeriod=%u\n"
- "dot1xAuthServerTimeout=%u\n"
- "dot1xAuthReAuthPeriod=%u\n"
- "dot1xAuthReAuthEnabled=%s\n"
- "dot1xAuthKeyTxEnabled=%s\n",
- sm->auth_pae_state + 1,
- sm->be_auth_state + 1,
- sm->adminControlledDirections,
- sm->operControlledDirections,
- sm->authPortStatus,
- sm->portControl,
- sm->quietPeriod,
- sm->serverTimeout,
- sm->reAuthPeriod,
- bool_txt(sm->reAuthEnabled),
- bool_txt(sm->keyTxEnabled));
- if (ret < 0 || (size_t) ret >= buflen - len)
- return len;
- len += ret;
- /* dot1xAuthStatsTable */
- ret = os_snprintf(buf + len, buflen - len,
- "dot1xAuthEapolFramesRx=%u\n"
- "dot1xAuthEapolFramesTx=%u\n"
- "dot1xAuthEapolStartFramesRx=%u\n"
- "dot1xAuthEapolLogoffFramesRx=%u\n"
- "dot1xAuthEapolRespIdFramesRx=%u\n"
- "dot1xAuthEapolRespFramesRx=%u\n"
- "dot1xAuthEapolReqIdFramesTx=%u\n"
- "dot1xAuthEapolReqFramesTx=%u\n"
- "dot1xAuthInvalidEapolFramesRx=%u\n"
- "dot1xAuthEapLengthErrorFramesRx=%u\n"
- "dot1xAuthLastEapolFrameVersion=%u\n"
- "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
- sm->dot1xAuthEapolFramesRx,
- sm->dot1xAuthEapolFramesTx,
- sm->dot1xAuthEapolStartFramesRx,
- sm->dot1xAuthEapolLogoffFramesRx,
- sm->dot1xAuthEapolRespIdFramesRx,
- sm->dot1xAuthEapolRespFramesRx,
- sm->dot1xAuthEapolReqIdFramesTx,
- sm->dot1xAuthEapolReqFramesTx,
- sm->dot1xAuthInvalidEapolFramesRx,
- sm->dot1xAuthEapLengthErrorFramesRx,
- sm->dot1xAuthLastEapolFrameVersion,
- MAC2STR(sm->addr));
- if (ret < 0 || (size_t) ret >= buflen - len)
- return len;
- len += ret;
- /* dot1xAuthDiagTable */
- ret = os_snprintf(buf + len, buflen - len,
- "dot1xAuthEntersConnecting=%u\n"
- "dot1xAuthEapLogoffsWhileConnecting=%u\n"
- "dot1xAuthEntersAuthenticating=%u\n"
- "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
- "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
- "dot1xAuthAuthFailWhileAuthenticating=%u\n"
- "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
- "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
- "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
- "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
- "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
- "dot1xAuthBackendResponses=%u\n"
- "dot1xAuthBackendAccessChallenges=%u\n"
- "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
- "dot1xAuthBackendAuthSuccesses=%u\n"
- "dot1xAuthBackendAuthFails=%u\n",
- sm->authEntersConnecting,
- sm->authEapLogoffsWhileConnecting,
- sm->authEntersAuthenticating,
- sm->authAuthSuccessesWhileAuthenticating,
- sm->authAuthTimeoutsWhileAuthenticating,
- sm->authAuthFailWhileAuthenticating,
- sm->authAuthEapStartsWhileAuthenticating,
- sm->authAuthEapLogoffWhileAuthenticating,
- sm->authAuthReauthsWhileAuthenticated,
- sm->authAuthEapStartsWhileAuthenticated,
- sm->authAuthEapLogoffWhileAuthenticated,
- sm->backendResponses,
- sm->backendAccessChallenges,
- sm->backendOtherRequestsToSupplicant,
- sm->backendAuthSuccesses,
- sm->backendAuthFails);
- if (ret < 0 || (size_t) ret >= buflen - len)
- return len;
- len += ret;
- /* dot1xAuthSessionStatsTable */
- ret = os_snprintf(buf + len, buflen - len,
- /* TODO: dot1xAuthSessionOctetsRx */
- /* TODO: dot1xAuthSessionOctetsTx */
- /* TODO: dot1xAuthSessionFramesRx */
- /* TODO: dot1xAuthSessionFramesTx */
- "dot1xAuthSessionId=%08X-%08X\n"
- "dot1xAuthSessionAuthenticMethod=%d\n"
- "dot1xAuthSessionTime=%u\n"
- "dot1xAuthSessionTerminateCause=999\n"
- "dot1xAuthSessionUserName=%s\n",
- sta->acct_session_id_hi, sta->acct_session_id_lo,
- (wpa_key_mgmt_wpa_ieee8021x(
- wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
- 1 : 2,
- (unsigned int) (time(NULL) -
- sta->acct_session_start),
- sm->identity);
- if (ret < 0 || (size_t) ret >= buflen - len)
- return len;
- len += ret;
- return len;
- }
- static void ieee802_1x_finished(struct hostapd_data *hapd,
- struct sta_info *sta, int success)
- {
- const u8 *key;
- size_t len;
- /* TODO: get PMKLifetime from WPA parameters */
- static const int dot11RSNAConfigPMKLifetime = 43200;
- key = ieee802_1x_get_key(sta->eapol_sm, &len);
- if (success && key && len >= PMK_LEN &&
- wpa_auth_pmksa_add(sta->wpa_sm, key, dot11RSNAConfigPMKLifetime,
- sta->eapol_sm) == 0) {
- hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
- HOSTAPD_LEVEL_DEBUG,
- "Added PMKSA cache entry (IEEE 802.1X)");
- }
- }
|