2008-02-28 02:34:43 +01:00
|
|
|
/*
|
2011-12-24 12:50:59 +01:00
|
|
|
* IEEE 802.11 RSN / WPA Authenticator
|
2019-02-23 17:54:54 +01:00
|
|
|
* Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "utils/includes.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "utils/state_machine.h"
|
2013-03-16 18:13:31 +01:00
|
|
|
#include "utils/bitfield.h"
|
2009-12-25 23:31:51 +01:00
|
|
|
#include "common/ieee802_11_defs.h"
|
2018-08-06 21:46:27 +02:00
|
|
|
#include "common/ocv.h"
|
2015-09-03 14:59:44 +02:00
|
|
|
#include "crypto/aes.h"
|
2009-11-29 22:04:43 +01:00
|
|
|
#include "crypto/aes_wrap.h"
|
2015-09-03 14:59:44 +02:00
|
|
|
#include "crypto/aes_siv.h"
|
2009-11-29 22:04:43 +01:00
|
|
|
#include "crypto/crypto.h"
|
|
|
|
#include "crypto/sha1.h"
|
|
|
|
#include "crypto/sha256.h"
|
2017-11-18 16:08:11 +01:00
|
|
|
#include "crypto/sha384.h"
|
2010-11-24 00:05:20 +01:00
|
|
|
#include "crypto/random.h"
|
2009-11-29 19:03:28 +01:00
|
|
|
#include "eapol_auth/eapol_auth_sm.h"
|
2018-08-06 21:46:27 +02:00
|
|
|
#include "drivers/driver.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "ap_config.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "ieee802_11.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "wpa_auth.h"
|
|
|
|
#include "pmksa_cache_auth.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "wpa_auth_i.h"
|
|
|
|
#include "wpa_auth_ie.h"
|
|
|
|
|
|
|
|
#define STATE_MACHINE_DATA struct wpa_state_machine
|
|
|
|
#define STATE_MACHINE_DEBUG_PREFIX "WPA"
|
|
|
|
#define STATE_MACHINE_ADDR sm->addr
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx);
|
2010-01-10 17:54:41 +01:00
|
|
|
static int wpa_sm_step(struct wpa_state_machine *sm);
|
2017-06-17 22:48:52 +02:00
|
|
|
static int wpa_verify_key_mic(int akmp, size_t pmk_len, struct wpa_ptk *PTK,
|
|
|
|
u8 *data, size_t data_len);
|
2015-09-03 17:18:53 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
static int wpa_aead_decrypt(struct wpa_state_machine *sm, struct wpa_ptk *ptk,
|
|
|
|
u8 *buf, size_t buf_len, u16 *_key_data_len);
|
2017-04-21 17:42:00 +02:00
|
|
|
static struct wpabuf * fils_prepare_plainbuf(struct wpa_state_machine *sm,
|
|
|
|
const struct wpabuf *hlp);
|
2015-09-03 17:18:53 +02:00
|
|
|
#endif /* CONFIG_FILS */
|
2008-02-28 02:34:43 +01:00
|
|
|
static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx);
|
|
|
|
static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group);
|
2008-11-06 18:57:21 +01:00
|
|
|
static void wpa_request_new_ptk(struct wpa_state_machine *sm);
|
2009-09-06 12:55:01 +02:00
|
|
|
static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group);
|
2010-11-23 23:52:46 +01:00
|
|
|
static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group);
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
|
2015-10-14 00:18:11 +02:00
|
|
|
const u8 *pmk, unsigned int pmk_len,
|
2020-01-23 19:56:51 +01:00
|
|
|
struct wpa_ptk *ptk, int force_sha256);
|
2015-04-26 14:22:55 +02:00
|
|
|
static void wpa_group_free(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group);
|
|
|
|
static void wpa_group_get(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group);
|
|
|
|
static void wpa_group_put(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group);
|
2020-02-17 22:08:05 +01:00
|
|
|
static int ieee80211w_kde_len(struct wpa_state_machine *sm);
|
2015-09-09 14:43:53 +02:00
|
|
|
static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2008-12-18 16:15:36 +01:00
|
|
|
static const u32 eapol_key_timeout_first = 100; /* ms */
|
|
|
|
static const u32 eapol_key_timeout_subseq = 1000; /* ms */
|
2011-12-24 12:50:59 +01:00
|
|
|
static const u32 eapol_key_timeout_first_group = 500; /* ms */
|
2017-10-16 17:37:43 +02:00
|
|
|
static const u32 eapol_key_timeout_no_retrans = 4000; /* ms */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
/* TODO: make these configurable */
|
|
|
|
static const int dot11RSNAConfigPMKLifetime = 43200;
|
|
|
|
static const int dot11RSNAConfigPMKReauthThreshold = 70;
|
|
|
|
static const int dot11RSNAConfigSATimeout = 60;
|
|
|
|
|
|
|
|
|
2012-11-18 12:06:03 +01:00
|
|
|
static inline int wpa_auth_mic_failure_report(
|
2008-02-28 02:34:43 +01:00
|
|
|
struct wpa_authenticator *wpa_auth, const u8 *addr)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->mic_failure_report)
|
|
|
|
return wpa_auth->cb->mic_failure_report(wpa_auth->cb_ctx, addr);
|
2012-11-18 12:06:03 +01:00
|
|
|
return 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-19 12:14:21 +01:00
|
|
|
static inline void wpa_auth_psk_failure_report(
|
|
|
|
struct wpa_authenticator *wpa_auth, const u8 *addr)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->psk_failure_report)
|
|
|
|
wpa_auth->cb->psk_failure_report(wpa_auth->cb_ctx, addr);
|
2015-03-19 12:14:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static inline void wpa_auth_set_eapol(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *addr, wpa_eapol_variable var,
|
|
|
|
int value)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->set_eapol)
|
|
|
|
wpa_auth->cb->set_eapol(wpa_auth->cb_ctx, addr, var, value);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int wpa_auth_get_eapol(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *addr, wpa_eapol_variable var)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->get_eapol == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->get_eapol(wpa_auth->cb_ctx, addr, var);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline const u8 * wpa_auth_get_psk(struct wpa_authenticator *wpa_auth,
|
2013-09-01 10:30:26 +02:00
|
|
|
const u8 *addr,
|
|
|
|
const u8 *p2p_dev_addr,
|
2019-02-14 12:34:33 +01:00
|
|
|
const u8 *prev_psk, size_t *psk_len,
|
|
|
|
int *vlan_id)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->get_psk == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return NULL;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->get_psk(wpa_auth->cb_ctx, addr, p2p_dev_addr,
|
2019-02-14 12:34:33 +01:00
|
|
|
prev_psk, psk_len, vlan_id);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int wpa_auth_get_msk(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *addr, u8 *msk, size_t *len)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->get_msk == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->get_msk(wpa_auth->cb_ctx, addr, msk, len);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
|
|
|
|
int vlan_id,
|
2009-12-26 09:35:08 +01:00
|
|
|
enum wpa_alg alg, const u8 *addr, int idx,
|
2020-01-04 23:10:04 +01:00
|
|
|
u8 *key, size_t key_len,
|
|
|
|
enum key_flag key_flag)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->set_key == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->set_key(wpa_auth->cb_ctx, vlan_id, alg, addr, idx,
|
2020-01-04 23:10:04 +01:00
|
|
|
key, key_len, key_flag);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *addr, int idx, u8 *seq)
|
|
|
|
{
|
2020-01-04 12:05:26 +01:00
|
|
|
int res;
|
|
|
|
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->get_seqnum == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
2020-01-04 12:05:26 +01:00
|
|
|
res = wpa_auth->cb->get_seqnum(wpa_auth->cb_ctx, addr, idx, seq);
|
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
if (!addr && idx < 4 && wpa_auth->conf.gtk_rsc_override_set) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"TESTING: Override GTK RSC %016llx --> %016llx",
|
|
|
|
(long long unsigned) WPA_GET_LE64(seq),
|
|
|
|
(long long unsigned)
|
|
|
|
WPA_GET_LE64(wpa_auth->conf.gtk_rsc_override));
|
|
|
|
os_memcpy(seq, wpa_auth->conf.gtk_rsc_override,
|
|
|
|
WPA_KEY_RSC_LEN);
|
|
|
|
}
|
|
|
|
if (!addr && idx >= 4 && idx <= 5 &&
|
|
|
|
wpa_auth->conf.igtk_rsc_override_set) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"TESTING: Override IGTK RSC %016llx --> %016llx",
|
|
|
|
(long long unsigned) WPA_GET_LE64(seq),
|
|
|
|
(long long unsigned)
|
|
|
|
WPA_GET_LE64(wpa_auth->conf.igtk_rsc_override));
|
|
|
|
os_memcpy(seq, wpa_auth->conf.igtk_rsc_override,
|
|
|
|
WPA_KEY_RSC_LEN);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
|
|
|
return res;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
wpa_auth_send_eapol(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
|
|
|
const u8 *data, size_t data_len, int encrypt)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->send_eapol == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->send_eapol(wpa_auth->cb_ctx, addr, data, data_len,
|
|
|
|
encrypt);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 06:23:30 +02:00
|
|
|
#ifdef CONFIG_MESH
|
|
|
|
static inline int wpa_auth_start_ampe(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *addr)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->start_ampe == NULL)
|
2014-09-01 06:23:30 +02:00
|
|
|
return -1;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->start_ampe(wpa_auth->cb_ctx, addr);
|
2014-09-01 06:23:30 +02:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_MESH */
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
|
|
|
|
int (*cb)(struct wpa_state_machine *sm, void *ctx),
|
|
|
|
void *cb_ctx)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->for_each_sta == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->for_each_sta(wpa_auth->cb_ctx, cb, cb_ctx);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-03 19:17:58 +02:00
|
|
|
int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
|
|
|
|
int (*cb)(struct wpa_authenticator *a, void *ctx),
|
|
|
|
void *cb_ctx)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->for_each_auth == NULL)
|
2008-08-03 19:17:58 +02:00
|
|
|
return 0;
|
2017-01-26 16:24:06 +01:00
|
|
|
return wpa_auth->cb->for_each_auth(wpa_auth->cb_ctx, cb, cb_ctx);
|
2008-08-03 19:17:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
|
|
|
logger_level level, const char *txt)
|
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->logger == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
2017-01-26 16:24:06 +01:00
|
|
|
wpa_auth->cb->logger(wpa_auth->cb_ctx, addr, level, txt);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
|
|
|
logger_level level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *format;
|
|
|
|
int maxlen;
|
|
|
|
va_list ap;
|
|
|
|
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->logger == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
maxlen = os_strlen(fmt) + 100;
|
|
|
|
format = os_malloc(maxlen);
|
|
|
|
if (!format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(format, maxlen, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
wpa_auth_logger(wpa_auth, addr, level, format);
|
|
|
|
|
|
|
|
os_free(format);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_sta_disconnect(struct wpa_authenticator *wpa_auth,
|
2017-06-17 22:48:52 +02:00
|
|
|
const u8 *addr, u16 reason)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2017-01-26 16:24:06 +01:00
|
|
|
if (wpa_auth->cb->disconnect == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "wpa_sta_disconnect STA " MACSTR " (reason %u)",
|
|
|
|
MAC2STR(addr), reason);
|
|
|
|
wpa_auth->cb->disconnect(wpa_auth->cb_ctx, addr, reason);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-06 21:46:27 +02:00
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
static int wpa_channel_info(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_channel_info *ci)
|
|
|
|
{
|
|
|
|
if (!wpa_auth->cb->channel_info)
|
|
|
|
return -1;
|
|
|
|
return wpa_auth->cb->channel_info(wpa_auth->cb_ctx, ci);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
|
|
|
|
|
2019-02-14 12:34:33 +01:00
|
|
|
static int wpa_auth_update_vlan(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *addr, int vlan_id)
|
|
|
|
{
|
|
|
|
if (!wpa_auth->cb->update_vlan)
|
|
|
|
return -1;
|
|
|
|
return wpa_auth->cb->update_vlan(wpa_auth->cb_ctx, addr, vlan_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static void wpa_rekey_gmk(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = eloop_ctx;
|
|
|
|
|
2010-11-24 00:05:20 +01:00
|
|
|
if (random_get_bytes(wpa_auth->group->GMK, WPA_GMK_LEN)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_ERROR, "Failed to get random data for WPA "
|
|
|
|
"initialization.");
|
|
|
|
} else {
|
|
|
|
wpa_auth_logger(wpa_auth, NULL, LOGGER_DEBUG, "GMK rekeyd");
|
2010-11-22 23:57:14 +01:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "GMK",
|
|
|
|
wpa_auth->group->GMK, WPA_GMK_LEN);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_auth->conf.wpa_gmk_rekey) {
|
|
|
|
eloop_register_timeout(wpa_auth->conf.wpa_gmk_rekey, 0,
|
|
|
|
wpa_rekey_gmk, wpa_auth, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_rekey_gtk(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = eloop_ctx;
|
2015-04-26 14:22:55 +02:00
|
|
|
struct wpa_group *group, *next;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
wpa_auth_logger(wpa_auth, NULL, LOGGER_DEBUG, "rekeying GTK");
|
2015-04-26 14:22:55 +02:00
|
|
|
group = wpa_auth->group;
|
|
|
|
while (group) {
|
|
|
|
wpa_group_get(wpa_auth, group);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
group->GTKReKey = TRUE;
|
|
|
|
do {
|
|
|
|
group->changed = FALSE;
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
|
|
|
} while (group->changed);
|
2015-04-26 14:22:55 +02:00
|
|
|
|
|
|
|
next = group->next;
|
|
|
|
wpa_group_put(wpa_auth, group);
|
|
|
|
group = next;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_auth->conf.wpa_group_rekey) {
|
|
|
|
eloop_register_timeout(wpa_auth->conf.wpa_group_rekey,
|
|
|
|
0, wpa_rekey_gtk, wpa_auth, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-06 18:57:21 +01:00
|
|
|
static void wpa_rekey_ptk(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = eloop_ctx;
|
|
|
|
struct wpa_state_machine *sm = timeout_ctx;
|
|
|
|
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "rekeying PTK");
|
|
|
|
wpa_request_new_ptk(sm);
|
|
|
|
wpa_sm_step(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-17 21:52:23 +02:00
|
|
|
void wpa_auth_set_ptk_rekey_timer(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm && sm->wpa_auth->conf.wpa_ptk_rekey) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Start PTK rekeying timer for "
|
|
|
|
MACSTR " (%d seconds)", MAC2STR(sm->addr),
|
|
|
|
sm->wpa_auth->conf.wpa_ptk_rekey);
|
|
|
|
eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
|
|
|
|
eloop_register_timeout(sm->wpa_auth->conf.wpa_ptk_rekey, 0,
|
|
|
|
wpa_rekey_ptk, sm->wpa_auth, sm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static int wpa_auth_pmksa_clear_cb(struct wpa_state_machine *sm, void *ctx)
|
|
|
|
{
|
|
|
|
if (sm->pmksa == ctx)
|
|
|
|
sm->pmksa = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_auth_pmksa_free_cb(struct rsn_pmksa_cache_entry *entry,
|
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = ctx;
|
|
|
|
wpa_auth_for_each_sta(wpa_auth, wpa_auth_pmksa_clear_cb, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-23 23:52:46 +01:00
|
|
|
static int wpa_group_init_gmk_and_counter(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
2013-01-01 19:26:20 +01:00
|
|
|
u8 buf[ETH_ALEN + 8 + sizeof(unsigned long)];
|
2010-11-23 23:52:46 +01:00
|
|
|
u8 rkey[32];
|
2013-01-01 19:26:20 +01:00
|
|
|
unsigned long ptr;
|
2010-11-23 23:52:46 +01:00
|
|
|
|
2010-11-24 00:05:20 +01:00
|
|
|
if (random_get_bytes(group->GMK, WPA_GMK_LEN) < 0)
|
2010-11-23 23:52:46 +01:00
|
|
|
return -1;
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "GMK", group->GMK, WPA_GMK_LEN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Counter = PRF-256(Random number, "Init Counter",
|
|
|
|
* Local MAC Address || Time)
|
|
|
|
*/
|
|
|
|
os_memcpy(buf, wpa_auth->addr, ETH_ALEN);
|
|
|
|
wpa_get_ntp_timestamp(buf + ETH_ALEN);
|
2013-01-01 19:26:20 +01:00
|
|
|
ptr = (unsigned long) group;
|
|
|
|
os_memcpy(buf + ETH_ALEN + 8, &ptr, sizeof(ptr));
|
2019-02-10 16:02:49 +01:00
|
|
|
#ifdef TEST_FUZZ
|
|
|
|
os_memset(buf + ETH_ALEN, 0xab, 8);
|
|
|
|
os_memset(buf + ETH_ALEN + 8, 0xcd, sizeof(ptr));
|
|
|
|
#endif /* TEST_FUZZ */
|
2010-11-24 00:05:20 +01:00
|
|
|
if (random_get_bytes(rkey, sizeof(rkey)) < 0)
|
2010-11-23 23:52:46 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (sha1_prf(rkey, sizeof(rkey), "Init Counter", buf, sizeof(buf),
|
|
|
|
group->Counter, WPA_NONCE_LEN) < 0)
|
|
|
|
return -1;
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "Key Counter",
|
|
|
|
group->Counter, WPA_NONCE_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-06 12:55:01 +02:00
|
|
|
static struct wpa_group * wpa_group_init(struct wpa_authenticator *wpa_auth,
|
2011-08-09 13:56:16 +02:00
|
|
|
int vlan_id, int delay_init)
|
2009-09-06 12:55:01 +02:00
|
|
|
{
|
|
|
|
struct wpa_group *group;
|
|
|
|
|
|
|
|
group = os_zalloc(sizeof(struct wpa_group));
|
|
|
|
if (group == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
group->GTKAuthenticator = TRUE;
|
|
|
|
group->vlan_id = vlan_id;
|
2012-08-30 10:53:54 +02:00
|
|
|
group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2010-11-24 12:08:03 +01:00
|
|
|
if (random_pool_ready() != 1) {
|
|
|
|
wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
|
|
|
|
"for secure operations - update keys later when "
|
|
|
|
"the first station connects");
|
|
|
|
}
|
|
|
|
|
2010-11-23 23:52:46 +01:00
|
|
|
/*
|
|
|
|
* Set initial GMK/Counter value here. The actual values that will be
|
|
|
|
* used in negotiations will be set once the first station tries to
|
|
|
|
* connect. This allows more time for collecting additional randomness
|
|
|
|
* on embedded devices.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
2010-11-23 23:52:46 +01:00
|
|
|
if (wpa_group_init_gmk_and_counter(wpa_auth, group) < 0) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_ERROR, "Failed to get random data for WPA "
|
|
|
|
"initialization.");
|
|
|
|
os_free(group);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
group->GInit = TRUE;
|
2011-08-09 13:56:16 +02:00
|
|
|
if (delay_init) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Delay group state machine start "
|
|
|
|
"until Beacon frames have been configured");
|
|
|
|
/* Initialization is completed in wpa_init_keys(). */
|
|
|
|
} else {
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
|
|
|
group->GInit = FALSE;
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_init - Initialize WPA authenticator
|
|
|
|
* @addr: Authenticator address
|
|
|
|
* @conf: Configuration for WPA authenticator
|
2009-01-02 21:28:04 +01:00
|
|
|
* @cb: Callback functions for WPA authenticator
|
2008-02-28 02:34:43 +01:00
|
|
|
* Returns: Pointer to WPA authenticator data or %NULL on failure
|
|
|
|
*/
|
|
|
|
struct wpa_authenticator * wpa_init(const u8 *addr,
|
|
|
|
struct wpa_auth_config *conf,
|
2017-01-26 16:24:06 +01:00
|
|
|
const struct wpa_auth_callbacks *cb,
|
|
|
|
void *cb_ctx)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth;
|
|
|
|
|
|
|
|
wpa_auth = os_zalloc(sizeof(struct wpa_authenticator));
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return NULL;
|
|
|
|
os_memcpy(wpa_auth->addr, addr, ETH_ALEN);
|
|
|
|
os_memcpy(&wpa_auth->conf, conf, sizeof(*conf));
|
2017-01-26 16:24:06 +01:00
|
|
|
wpa_auth->cb = cb;
|
|
|
|
wpa_auth->cb_ctx = cb_ctx;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (wpa_auth_gen_wpa_ie(wpa_auth)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Could not generate WPA IE.");
|
|
|
|
os_free(wpa_auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-09 13:56:16 +02:00
|
|
|
wpa_auth->group = wpa_group_init(wpa_auth, 0, 1);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (wpa_auth->group == NULL) {
|
|
|
|
os_free(wpa_auth->wpa_ie);
|
|
|
|
os_free(wpa_auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-14 21:01:26 +01:00
|
|
|
wpa_auth->pmksa = pmksa_cache_auth_init(wpa_auth_pmksa_free_cb,
|
|
|
|
wpa_auth);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (wpa_auth->pmksa == NULL) {
|
|
|
|
wpa_printf(MSG_ERROR, "PMKSA cache initialization failed.");
|
2015-01-08 01:22:03 +01:00
|
|
|
os_free(wpa_auth->group);
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(wpa_auth->wpa_ie);
|
|
|
|
os_free(wpa_auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth->ft_pmk_cache = wpa_ft_pmk_cache_init();
|
|
|
|
if (wpa_auth->ft_pmk_cache == NULL) {
|
|
|
|
wpa_printf(MSG_ERROR, "FT PMK cache initialization failed.");
|
2015-01-08 01:22:03 +01:00
|
|
|
os_free(wpa_auth->group);
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(wpa_auth->wpa_ie);
|
2009-01-14 21:01:26 +01:00
|
|
|
pmksa_cache_auth_deinit(wpa_auth->pmksa);
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(wpa_auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (wpa_auth->conf.wpa_gmk_rekey) {
|
|
|
|
eloop_register_timeout(wpa_auth->conf.wpa_gmk_rekey, 0,
|
|
|
|
wpa_rekey_gmk, wpa_auth, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_auth->conf.wpa_group_rekey) {
|
|
|
|
eloop_register_timeout(wpa_auth->conf.wpa_group_rekey, 0,
|
|
|
|
wpa_rekey_gtk, wpa_auth, NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-16 18:13:31 +01:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (WPA_GET_BE32(conf->ip_addr_start)) {
|
|
|
|
int count = WPA_GET_BE32(conf->ip_addr_end) -
|
|
|
|
WPA_GET_BE32(conf->ip_addr_start) + 1;
|
|
|
|
if (count > 1000)
|
|
|
|
count = 1000;
|
|
|
|
if (count > 0)
|
|
|
|
wpa_auth->ip_pool = bitfield_alloc(count);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return wpa_auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-09 13:56:16 +02:00
|
|
|
int wpa_init_keys(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
struct wpa_group *group = wpa_auth->group;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Start group state machine to set initial "
|
|
|
|
"keys");
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
|
|
|
group->GInit = FALSE;
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
2013-12-24 21:38:16 +01:00
|
|
|
if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
|
|
|
|
return -1;
|
2011-08-09 13:56:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/**
|
|
|
|
* wpa_deinit - Deinitialize WPA authenticator
|
|
|
|
* @wpa_auth: Pointer to WPA authenticator data from wpa_init()
|
|
|
|
*/
|
|
|
|
void wpa_deinit(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
struct wpa_group *group, *prev;
|
|
|
|
|
|
|
|
eloop_cancel_timeout(wpa_rekey_gmk, wpa_auth, NULL);
|
|
|
|
eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
|
|
|
|
|
2009-01-14 21:01:26 +01:00
|
|
|
pmksa_cache_auth_deinit(wpa_auth->pmksa);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_ft_pmk_cache_deinit(wpa_auth->ft_pmk_cache);
|
|
|
|
wpa_auth->ft_pmk_cache = NULL;
|
2017-04-02 14:52:51 +02:00
|
|
|
wpa_ft_deinit(wpa_auth);
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2013-03-16 18:13:31 +01:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
bitfield_free(wpa_auth->ip_pool);
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(wpa_auth->wpa_ie);
|
|
|
|
|
|
|
|
group = wpa_auth->group;
|
|
|
|
while (group) {
|
|
|
|
prev = group;
|
|
|
|
group = group->next;
|
|
|
|
os_free(prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
os_free(wpa_auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_reconfig - Update WPA authenticator configuration
|
|
|
|
* @wpa_auth: Pointer to WPA authenticator data from wpa_init()
|
|
|
|
* @conf: Configuration for WPA authenticator
|
|
|
|
*/
|
|
|
|
int wpa_reconfig(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_auth_config *conf)
|
|
|
|
{
|
2009-09-06 12:55:01 +02:00
|
|
|
struct wpa_group *group;
|
2008-02-28 02:34:43 +01:00
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
os_memcpy(&wpa_auth->conf, conf, sizeof(*conf));
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wpa_auth_gen_wpa_ie(wpa_auth)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Could not generate WPA IE.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-06 12:55:01 +02:00
|
|
|
/*
|
|
|
|
* Reinitialize GTK to make sure it is suitable for the new
|
|
|
|
* configuration.
|
|
|
|
*/
|
|
|
|
group = wpa_auth->group;
|
2012-08-30 10:53:54 +02:00
|
|
|
group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
|
2009-09-06 12:55:01 +02:00
|
|
|
group->GInit = TRUE;
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
|
|
|
group->GInit = FALSE;
|
|
|
|
wpa_group_sm_step(wpa_auth, group);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wpa_state_machine *
|
2013-09-01 10:05:19 +02:00
|
|
|
wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
|
|
|
const u8 *p2p_dev_addr)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct wpa_state_machine *sm;
|
|
|
|
|
2013-12-24 21:38:16 +01:00
|
|
|
if (wpa_auth->group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
|
|
|
|
return NULL;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
sm = os_zalloc(sizeof(struct wpa_state_machine));
|
|
|
|
if (sm == NULL)
|
|
|
|
return NULL;
|
|
|
|
os_memcpy(sm->addr, addr, ETH_ALEN);
|
2013-09-01 10:05:19 +02:00
|
|
|
if (p2p_dev_addr)
|
|
|
|
os_memcpy(sm->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
sm->wpa_auth = wpa_auth;
|
|
|
|
sm->group = wpa_auth->group;
|
2015-04-26 14:22:55 +02:00
|
|
|
wpa_group_get(sm->wpa_auth, sm->group);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
return sm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-10 20:45:44 +01:00
|
|
|
int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
|
2010-01-10 20:45:44 +01:00
|
|
|
return -1;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->ft_completed) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"FT authentication already completed - do not "
|
|
|
|
"start 4-way handshake");
|
2014-06-01 11:24:49 +02:00
|
|
|
/* Go to PTKINITDONE state to allow GTK rekeying */
|
|
|
|
sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
|
2017-02-05 12:28:42 +01:00
|
|
|
sm->Pair = TRUE;
|
2010-01-10 20:45:44 +01:00
|
|
|
return 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2015-09-09 17:56:57 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
if (sm->fils_completed) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"FILS authentication already completed - do not start 4-way handshake");
|
|
|
|
/* Go to PTKINITDONE state to allow GTK rekeying */
|
|
|
|
sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
|
2017-02-05 12:28:42 +01:00
|
|
|
sm->Pair = TRUE;
|
2015-09-09 17:56:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->started) {
|
2008-12-16 13:17:33 +01:00
|
|
|
os_memset(&sm->key_replay, 0, sizeof(sm->key_replay));
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->ReAuthenticationRequest = TRUE;
|
2010-01-10 20:45:44 +01:00
|
|
|
return wpa_sm_step(sm);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"start authentication");
|
|
|
|
sm->started = 1;
|
|
|
|
|
|
|
|
sm->Init = TRUE;
|
2010-01-10 17:54:41 +01:00
|
|
|
if (wpa_sm_step(sm) == 1)
|
2010-01-10 20:45:44 +01:00
|
|
|
return 1; /* should not really happen */
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->Init = FALSE;
|
|
|
|
sm->AuthenticationRequest = TRUE;
|
2010-01-10 20:45:44 +01:00
|
|
|
return wpa_sm_step(sm);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 16:22:51 +01:00
|
|
|
void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
/* WPA/RSN was not used - clear WPA state. This is needed if the STA
|
|
|
|
* reassociates back to the same AP while the previous entry for the
|
|
|
|
* STA has not yet been removed. */
|
|
|
|
if (sm == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sm->wpa_key_mgmt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static void wpa_free_sta_sm(struct wpa_state_machine *sm)
|
|
|
|
{
|
2013-03-16 18:13:31 +01:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (WPA_GET_BE32(sm->ip_addr)) {
|
|
|
|
u32 start;
|
|
|
|
wpa_printf(MSG_DEBUG, "P2P: Free assigned IP "
|
|
|
|
"address %u.%u.%u.%u from " MACSTR,
|
|
|
|
sm->ip_addr[0], sm->ip_addr[1],
|
|
|
|
sm->ip_addr[2], sm->ip_addr[3],
|
|
|
|
MAC2STR(sm->addr));
|
|
|
|
start = WPA_GET_BE32(sm->wpa_auth->conf.ip_addr_start);
|
|
|
|
bitfield_clear(sm->wpa_auth->ip_pool,
|
|
|
|
WPA_GET_BE32(sm->ip_addr) - start);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
2011-03-23 16:00:18 +01:00
|
|
|
if (sm->GUpdateStationKeys) {
|
|
|
|
sm->group->GKeyDoneStations--;
|
|
|
|
sm->GUpdateStationKeys = FALSE;
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-10 21:40:35 +02:00
|
|
|
os_free(sm->assoc_resp_ftie);
|
2014-03-23 17:13:03 +01:00
|
|
|
wpabuf_free(sm->ft_pending_req_ies);
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(sm->last_rx_eapol_key);
|
|
|
|
os_free(sm->wpa_ie);
|
2019-10-17 23:11:24 +02:00
|
|
|
os_free(sm->rsnxe);
|
2015-04-26 14:22:55 +02:00
|
|
|
wpa_group_put(sm->wpa_auth, sm->group);
|
2019-03-17 22:51:53 +01:00
|
|
|
#ifdef CONFIG_DPP2
|
|
|
|
wpabuf_clear_free(sm->dpp_z);
|
|
|
|
#endif /* CONFIG_DPP2 */
|
2019-04-18 17:17:07 +02:00
|
|
|
bin_clear_free(sm, sizeof(*sm));
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_sta_deinit(struct wpa_state_machine *sm)
|
|
|
|
{
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_authenticator *wpa_auth;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth = sm->wpa_auth;
|
|
|
|
if (wpa_auth->conf.wpa_strict_rekey && sm->has_GTK) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
2008-02-28 02:34:43 +01:00
|
|
|
"strict rekeying - force GTK rekey since STA "
|
|
|
|
"is leaving");
|
2017-10-25 10:06:10 +02:00
|
|
|
if (eloop_deplete_timeout(0, 500000, wpa_rekey_gtk,
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth, NULL) == -1)
|
|
|
|
eloop_register_timeout(0, 500000, wpa_rekey_gtk,
|
|
|
|
wpa_auth, NULL);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
|
2011-03-29 16:39:12 +02:00
|
|
|
sm->pending_1_of_4_timeout = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
eloop_cancel_timeout(wpa_sm_call_step, sm, NULL);
|
2020-03-28 18:29:12 +01:00
|
|
|
eloop_cancel_timeout(wpa_rekey_ptk, wpa_auth, sm);
|
2017-04-02 14:52:52 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
wpa_ft_sta_deinit(sm);
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->in_step_loop) {
|
|
|
|
/* Must not free state machine while wpa_sm_step() is running.
|
|
|
|
* Freeing will be completed in the end of wpa_sm_step(). */
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Registering pending STA state "
|
|
|
|
"machine deinit for " MACSTR, MAC2STR(sm->addr));
|
|
|
|
sm->pending_deinit = 1;
|
|
|
|
} else
|
|
|
|
wpa_free_sta_sm(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_request_new_ptk(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-03-20 20:04:31 +01:00
|
|
|
if (!sm->use_ext_key_id && sm->wpa_auth->conf.wpa_deny_ptk0_rekey) {
|
2020-01-10 23:19:08 +01:00
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"WPA: PTK0 rekey not allowed, disconnect " MACSTR,
|
|
|
|
MAC2STR(sm->addr));
|
|
|
|
sm->Disconnect = TRUE;
|
|
|
|
/* Try to encourage the STA to reconnect */
|
|
|
|
sm->disconnect_reason =
|
|
|
|
WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
|
|
|
|
} else {
|
2020-03-20 20:04:31 +01:00
|
|
|
if (sm->use_ext_key_id)
|
|
|
|
sm->keyidx_active ^= 1; /* flip Key ID */
|
2020-01-10 23:19:08 +01:00
|
|
|
sm->PTKRequest = TRUE;
|
|
|
|
sm->PTK_valid = 0;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-02 21:36:11 +01:00
|
|
|
static int wpa_replay_counter_valid(struct wpa_key_replay_counter *ctr,
|
2008-12-16 13:17:33 +01:00
|
|
|
const u8 *replay_counter)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
|
2012-01-02 21:36:11 +01:00
|
|
|
if (!ctr[i].valid)
|
2008-12-16 13:17:33 +01:00
|
|
|
break;
|
2012-01-02 21:36:11 +01:00
|
|
|
if (os_memcmp(replay_counter, ctr[i].counter,
|
2008-12-16 13:17:33 +01:00
|
|
|
WPA_REPLAY_COUNTER_LEN) == 0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-02 21:36:11 +01:00
|
|
|
static void wpa_replay_counter_mark_invalid(struct wpa_key_replay_counter *ctr,
|
|
|
|
const u8 *replay_counter)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
|
|
|
|
if (ctr[i].valid &&
|
|
|
|
(replay_counter == NULL ||
|
|
|
|
os_memcmp(replay_counter, ctr[i].counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN) == 0))
|
|
|
|
ctr[i].valid = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-10 21:40:35 +02:00
|
|
|
static int ft_check_msg_2_of_4(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm,
|
|
|
|
struct wpa_eapol_ie_parse *kde)
|
|
|
|
{
|
|
|
|
struct wpa_ie_data ie;
|
|
|
|
struct rsn_mdie *mdie;
|
|
|
|
|
|
|
|
if (wpa_parse_wpa_ie_rsn(kde->rsn_ie, kde->rsn_ie_len, &ie) < 0 ||
|
|
|
|
ie.num_pmkid != 1 || ie.pmkid == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: No PMKR1Name in "
|
|
|
|
"FT 4-way handshake message 2/4");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(sm->sup_pmk_r1_name, ie.pmkid, PMKID_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from Supplicant",
|
|
|
|
sm->sup_pmk_r1_name, PMKID_LEN);
|
|
|
|
|
|
|
|
if (!kde->mdie || !kde->ftie) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: No %s in FT 4-way handshake "
|
|
|
|
"message 2/4", kde->mdie ? "FTIE" : "MDIE");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdie = (struct rsn_mdie *) (kde->mdie + 2);
|
|
|
|
if (kde->mdie[1] < sizeof(struct rsn_mdie) ||
|
|
|
|
os_memcmp(wpa_auth->conf.mobility_domain, mdie->mobility_domain,
|
|
|
|
MOBILITY_DOMAIN_ID_LEN) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: MDIE mismatch");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sm->assoc_resp_ftie &&
|
|
|
|
(kde->ftie[1] != sm->assoc_resp_ftie[1] ||
|
|
|
|
os_memcmp(kde->ftie, sm->assoc_resp_ftie,
|
|
|
|
2 + sm->assoc_resp_ftie[1]) != 0)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: FTIE mismatch");
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FT: FTIE in EAPOL-Key msg 2/4",
|
|
|
|
kde->ftie, kde->ftie_len);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FT: FTIE in (Re)AssocResp",
|
|
|
|
sm->assoc_resp_ftie, 2 + sm->assoc_resp_ftie[1]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2010-04-10 21:40:35 +02:00
|
|
|
|
|
|
|
|
2012-11-18 12:06:03 +01:00
|
|
|
static int wpa_receive_error_report(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm, int group)
|
2011-10-30 11:21:08 +01:00
|
|
|
{
|
|
|
|
/* Supplicant reported a Michael MIC error */
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key Error Request "
|
|
|
|
"(STA detected Michael MIC failure (group=%d))",
|
|
|
|
group);
|
2011-10-30 11:49:26 +01:00
|
|
|
|
|
|
|
if (group && wpa_auth->conf.wpa_group != WPA_CIPHER_TKIP) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"ignore Michael MIC failure report since "
|
|
|
|
"group cipher is not TKIP");
|
|
|
|
} else if (!group && sm->pairwise != WPA_CIPHER_TKIP) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"ignore Michael MIC failure report since "
|
|
|
|
"pairwise cipher is not TKIP");
|
|
|
|
} else {
|
2012-11-18 12:06:03 +01:00
|
|
|
if (wpa_auth_mic_failure_report(wpa_auth, sm->addr) > 0)
|
|
|
|
return 1; /* STA entry was removed */
|
2011-10-30 11:49:26 +01:00
|
|
|
sm->dot11RSNAStatsTKIPRemoteMICFailures++;
|
|
|
|
wpa_auth->dot11RSNAStatsTKIPRemoteMICFailures++;
|
|
|
|
}
|
2011-10-30 11:21:08 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Error report is not a request for a new key handshake, but since
|
|
|
|
* Authenticator may do it, let's change the keys now anyway.
|
|
|
|
*/
|
|
|
|
wpa_request_new_ptk(sm);
|
2012-11-18 12:06:03 +01:00
|
|
|
return 0;
|
2011-10-30 11:21:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
static int wpa_try_alt_snonce(struct wpa_state_machine *sm, u8 *data,
|
|
|
|
size_t data_len)
|
|
|
|
{
|
|
|
|
struct wpa_ptk PTK;
|
|
|
|
int ok = 0;
|
|
|
|
const u8 *pmk = NULL;
|
2017-10-08 15:37:32 +02:00
|
|
|
size_t pmk_len;
|
2019-02-14 12:34:33 +01:00
|
|
|
int vlan_id = 0;
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
|
2015-09-03 16:24:37 +02:00
|
|
|
os_memset(&PTK, 0, sizeof(PTK));
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
for (;;) {
|
2017-09-02 00:02:15 +02:00
|
|
|
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
|
|
|
|
!wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
|
2019-02-14 12:34:33 +01:00
|
|
|
sm->p2p_dev_addr, pmk, &pmk_len,
|
|
|
|
&vlan_id);
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
if (pmk == NULL)
|
|
|
|
break;
|
2018-02-01 12:03:28 +01:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (wpa_key_mgmt_ft_psk(sm->wpa_key_mgmt)) {
|
|
|
|
os_memcpy(sm->xxkey, pmk, pmk_len);
|
|
|
|
sm->xxkey_len = pmk_len;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2015-10-14 00:18:11 +02:00
|
|
|
} else {
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
pmk = sm->PMK;
|
2015-10-14 00:18:11 +02:00
|
|
|
pmk_len = sm->pmk_len;
|
|
|
|
}
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
|
2020-01-23 19:56:51 +01:00
|
|
|
if (wpa_derive_ptk(sm, sm->alt_SNonce, pmk, pmk_len, &PTK, 0) <
|
|
|
|
0)
|
2017-02-14 10:09:30 +01:00
|
|
|
break;
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
|
2017-06-17 22:48:52 +02:00
|
|
|
if (wpa_verify_key_mic(sm->wpa_key_mgmt, pmk_len, &PTK,
|
|
|
|
data, data_len) == 0) {
|
2019-03-23 11:44:42 +01:00
|
|
|
if (sm->PMK != pmk) {
|
|
|
|
os_memcpy(sm->PMK, pmk, pmk_len);
|
|
|
|
sm->pmk_len = pmk_len;
|
|
|
|
}
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
ok = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-02 11:13:16 +01:00
|
|
|
if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
|
|
|
|
wpa_key_mgmt_sae(sm->wpa_key_mgmt))
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Earlier SNonce did not result in matching MIC");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Earlier SNonce resulted in matching MIC");
|
|
|
|
sm->alt_snonce_valid = 0;
|
2019-02-14 12:34:33 +01:00
|
|
|
|
|
|
|
if (vlan_id && wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
|
|
|
|
wpa_auth_update_vlan(sm->wpa_auth, sm->addr, vlan_id) < 0)
|
|
|
|
return -1;
|
|
|
|
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
os_memcpy(sm->SNonce, sm->alt_SNonce, WPA_NONCE_LEN);
|
|
|
|
os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(&PTK, sizeof(PTK));
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
sm->PTK_valid = TRUE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
void wpa_receive(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm,
|
|
|
|
u8 *data, size_t data_len)
|
|
|
|
{
|
|
|
|
struct ieee802_1x_hdr *hdr;
|
|
|
|
struct wpa_eapol_key *key;
|
|
|
|
u16 key_info, key_data_length;
|
2017-09-22 13:59:13 +02:00
|
|
|
enum { PAIRWISE_2, PAIRWISE_4, GROUP_2, REQUEST } msg;
|
2008-02-28 02:34:43 +01:00
|
|
|
char *msgtxt;
|
|
|
|
struct wpa_eapol_ie_parse kde;
|
2015-09-03 14:59:44 +02:00
|
|
|
const u8 *key_data;
|
|
|
|
size_t keyhdrlen, mic_len;
|
2015-09-02 21:55:03 +02:00
|
|
|
u8 *mic;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
|
|
|
|
return;
|
2015-09-02 23:18:27 +02:00
|
|
|
wpa_hexdump(MSG_MSGDUMP, "WPA: RX EAPOL data", data, data_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2017-06-17 22:48:52 +02:00
|
|
|
mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
|
2015-09-02 21:55:03 +02:00
|
|
|
keyhdrlen = sizeof(*key) + mic_len + 2;
|
2015-01-25 22:32:01 +01:00
|
|
|
|
2015-09-02 23:18:27 +02:00
|
|
|
if (data_len < sizeof(*hdr) + keyhdrlen) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Ignore too short EAPOL-Key frame");
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
2015-09-02 23:18:27 +02:00
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
hdr = (struct ieee802_1x_hdr *) data;
|
|
|
|
key = (struct wpa_eapol_key *) (hdr + 1);
|
2015-09-02 21:55:03 +02:00
|
|
|
mic = (u8 *) (key + 1);
|
2008-02-28 02:34:43 +01:00
|
|
|
key_info = WPA_GET_BE16(key->key_info);
|
2015-09-02 21:55:03 +02:00
|
|
|
key_data = mic + mic_len + 2;
|
|
|
|
key_data_length = WPA_GET_BE16(mic + mic_len);
|
2011-11-17 21:59:31 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Received EAPOL-Key from " MACSTR
|
2015-09-02 23:18:27 +02:00
|
|
|
" key_info=0x%x type=%u mic_len=%u key_data_length=%u",
|
|
|
|
MAC2STR(sm->addr), key_info, key->type,
|
|
|
|
(unsigned int) mic_len, key_data_length);
|
|
|
|
wpa_hexdump(MSG_MSGDUMP,
|
|
|
|
"WPA: EAPOL-Key header (ending before Key MIC)",
|
|
|
|
key, sizeof(*key));
|
|
|
|
wpa_hexdump(MSG_MSGDUMP, "WPA: EAPOL-Key Key MIC",
|
|
|
|
mic, mic_len);
|
2015-01-25 22:32:01 +01:00
|
|
|
if (key_data_length > data_len - sizeof(*hdr) - keyhdrlen) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_INFO, "WPA: Invalid EAPOL-Key frame - "
|
|
|
|
"key_data overflow (%d > %lu)",
|
|
|
|
key_data_length,
|
|
|
|
(unsigned long) (data_len - sizeof(*hdr) -
|
2015-01-25 22:32:01 +01:00
|
|
|
keyhdrlen));
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-27 08:52:24 +02:00
|
|
|
if (sm->wpa == WPA_VERSION_WPA2) {
|
2012-01-22 11:23:28 +01:00
|
|
|
if (key->type == EAPOL_KEY_TYPE_WPA) {
|
|
|
|
/*
|
|
|
|
* Some deployed station implementations seem to send
|
|
|
|
* msg 4/4 with incorrect type value in WPA2 mode.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "Workaround: Allow EAPOL-Key "
|
|
|
|
"with unexpected WPA type in RSN mode");
|
|
|
|
} else if (key->type != EAPOL_KEY_TYPE_RSN) {
|
2009-05-27 08:52:24 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "Ignore EAPOL-Key with "
|
|
|
|
"unexpected type %d in RSN mode",
|
|
|
|
key->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (key->type != EAPOL_KEY_TYPE_WPA) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Ignore EAPOL-Key with "
|
|
|
|
"unexpected type %d in WPA mode",
|
|
|
|
key->type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-15 15:57:08 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA: Received Key Nonce", key->key_nonce,
|
|
|
|
WPA_NONCE_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA: Received Replay Counter",
|
|
|
|
key->replay_counter, WPA_REPLAY_COUNTER_LEN);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/* FIX: verify that the EAPOL-Key frame was encrypted if pairwise keys
|
|
|
|
* are set */
|
|
|
|
|
2017-09-22 13:59:13 +02:00
|
|
|
if (key_info & WPA_KEY_INFO_SMK_MESSAGE) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Ignore SMK message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_info & WPA_KEY_INFO_REQUEST) {
|
2008-02-28 02:34:43 +01:00
|
|
|
msg = REQUEST;
|
|
|
|
msgtxt = "Request";
|
|
|
|
} else if (!(key_info & WPA_KEY_INFO_KEY_TYPE)) {
|
|
|
|
msg = GROUP_2;
|
|
|
|
msgtxt = "2/2 Group";
|
2015-09-03 14:59:44 +02:00
|
|
|
} else if (key_data_length == 0 ||
|
|
|
|
(mic_len == 0 && (key_info & WPA_KEY_INFO_ENCR_KEY_DATA) &&
|
|
|
|
key_data_length == AES_BLOCK_SIZE)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
msg = PAIRWISE_4;
|
|
|
|
msgtxt = "4/4 Pairwise";
|
|
|
|
} else {
|
|
|
|
msg = PAIRWISE_2;
|
|
|
|
msgtxt = "2/4 Pairwise";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg == REQUEST || msg == PAIRWISE_2 || msg == PAIRWISE_4 ||
|
|
|
|
msg == GROUP_2) {
|
|
|
|
u16 ver = key_info & WPA_KEY_INFO_TYPE_MASK;
|
2012-08-29 10:52:15 +02:00
|
|
|
if (sm->pairwise == WPA_CIPHER_CCMP ||
|
|
|
|
sm->pairwise == WPA_CIPHER_GCMP) {
|
2018-03-16 12:04:15 +01:00
|
|
|
if (wpa_use_cmac(sm->wpa_key_mgmt) &&
|
|
|
|
!wpa_use_akm_defined(sm->wpa_key_mgmt) &&
|
2008-02-28 02:34:43 +01:00
|
|
|
ver != WPA_KEY_INFO_TYPE_AES_128_CMAC) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr,
|
|
|
|
LOGGER_WARNING,
|
|
|
|
"advertised support for "
|
|
|
|
"AES-128-CMAC, but did not "
|
|
|
|
"use it");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-16 12:04:15 +01:00
|
|
|
if (!wpa_use_cmac(sm->wpa_key_mgmt) &&
|
|
|
|
!wpa_use_akm_defined(sm->wpa_key_mgmt) &&
|
2008-02-28 02:34:43 +01:00
|
|
|
ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr,
|
|
|
|
LOGGER_WARNING,
|
|
|
|
"did not use HMAC-SHA1-AES "
|
2012-08-29 10:52:15 +02:00
|
|
|
"with CCMP/GCMP");
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-11-16 14:40:02 +01:00
|
|
|
|
2018-03-16 12:04:15 +01:00
|
|
|
if (wpa_use_akm_defined(sm->wpa_key_mgmt) &&
|
2014-11-16 14:40:02 +01:00
|
|
|
ver != WPA_KEY_INFO_TYPE_AKM_DEFINED) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_WARNING,
|
|
|
|
"did not use EAPOL-Key descriptor version 0 as required for AKM-defined cases");
|
|
|
|
return;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key_info & WPA_KEY_INFO_REQUEST) {
|
|
|
|
if (sm->req_replay_counter_used &&
|
|
|
|
os_memcmp(key->replay_counter, sm->req_replay_counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN) <= 0) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_WARNING,
|
|
|
|
"received EAPOL-Key request with "
|
|
|
|
"replayed counter");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(key_info & WPA_KEY_INFO_REQUEST) &&
|
2012-01-02 21:36:11 +01:00
|
|
|
!wpa_replay_counter_valid(sm->key_replay, key->replay_counter)) {
|
2008-12-16 13:17:33 +01:00
|
|
|
int i;
|
2012-01-02 21:36:11 +01:00
|
|
|
|
|
|
|
if (msg == PAIRWISE_2 &&
|
|
|
|
wpa_replay_counter_valid(sm->prev_key_replay,
|
|
|
|
key->replay_counter) &&
|
|
|
|
sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
|
|
|
|
os_memcmp(sm->SNonce, key->key_nonce, WPA_NONCE_LEN) != 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Some supplicant implementations (e.g., Windows XP
|
|
|
|
* WZC) update SNonce for each EAPOL-Key 2/4. This
|
|
|
|
* breaks the workaround on accepting any of the
|
|
|
|
* pending requests, so allow the SNonce to be updated
|
|
|
|
* even if we have already sent out EAPOL-Key 3/4.
|
|
|
|
*/
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"Process SNonce update from STA "
|
|
|
|
"based on retransmitted EAPOL-Key "
|
|
|
|
"1/4");
|
|
|
|
sm->update_snonce = 1;
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
os_memcpy(sm->alt_SNonce, sm->SNonce, WPA_NONCE_LEN);
|
|
|
|
sm->alt_snonce_valid = TRUE;
|
|
|
|
os_memcpy(sm->alt_replay_counter,
|
|
|
|
sm->key_replay[0].counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN);
|
|
|
|
goto continue_processing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg == PAIRWISE_4 && sm->alt_snonce_valid &&
|
|
|
|
sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
|
|
|
|
os_memcmp(key->replay_counter, sm->alt_replay_counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN) == 0) {
|
|
|
|
/*
|
|
|
|
* Supplicant may still be using the old SNonce since
|
|
|
|
* there was two EAPOL-Key 2/4 messages and they had
|
|
|
|
* different SNonce values.
|
|
|
|
*/
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"Try to process received EAPOL-Key 4/4 based on old Replay Counter and SNonce from an earlier EAPOL-Key 1/4");
|
2012-01-02 21:36:11 +01:00
|
|
|
goto continue_processing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg == PAIRWISE_2 &&
|
|
|
|
wpa_replay_counter_valid(sm->prev_key_replay,
|
|
|
|
key->replay_counter) &&
|
|
|
|
sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING) {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"ignore retransmitted EAPOL-Key %s - "
|
|
|
|
"SNonce did not change", msgtxt);
|
|
|
|
} else {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"received EAPOL-Key %s with "
|
|
|
|
"unexpected replay counter", msgtxt);
|
|
|
|
}
|
2008-12-16 13:17:33 +01:00
|
|
|
for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
|
|
|
|
if (!sm->key_replay[i].valid)
|
|
|
|
break;
|
|
|
|
wpa_hexdump(MSG_DEBUG, "pending replay counter",
|
|
|
|
sm->key_replay[i].counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN);
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "received replay counter",
|
|
|
|
key->replay_counter, WPA_REPLAY_COUNTER_LEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-02 21:36:11 +01:00
|
|
|
continue_processing:
|
2015-09-03 14:59:44 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA2 && mic_len == 0 &&
|
|
|
|
!(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"WPA: Encr Key Data bit not set even though AEAD cipher is supposed to be used - drop frame");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
switch (msg) {
|
|
|
|
case PAIRWISE_2:
|
|
|
|
if (sm->wpa_ptk_state != WPA_PTK_PTKSTART &&
|
2012-01-02 21:36:11 +01:00
|
|
|
sm->wpa_ptk_state != WPA_PTK_PTKCALCNEGOTIATING &&
|
|
|
|
(!sm->update_snonce ||
|
|
|
|
sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key msg 2/4 in "
|
|
|
|
"invalid state (%d) - dropped",
|
|
|
|
sm->wpa_ptk_state);
|
|
|
|
return;
|
|
|
|
}
|
Maintain internal entropy pool for augmenting random number generation
By default, make hostapd and wpa_supplicant maintain an internal
entropy pool that is fed with following information:
hostapd:
- Probe Request frames (timing, RSSI)
- Association events (timing)
- SNonce from Supplicants
wpa_supplicant:
- Scan results (timing, signal/noise)
- Association events (timing)
The internal pool is used to augment the random numbers generated
with the OS mechanism (os_get_random()). While the internal
implementation is not expected to be very strong due to limited
amount of generic (non-platform specific) information to feed the
pool, this may strengthen key derivation on some devices that are
not configured to provide strong random numbers through
os_get_random() (e.g., /dev/urandom on Linux/BSD).
This new mechanism is not supposed to replace proper OS provided
random number generation mechanism. The OS mechanism needs to be
initialized properly (e.g., hw random number generator,
maintaining entropy pool over reboots, etc.) for any of the
security assumptions to hold.
If the os_get_random() is known to provide strong ramdom data (e.g., on
Linux/BSD, the board in question is known to have reliable source of
random data from /dev/urandom), the internal hostapd random pool can be
disabled. This will save some in binary size and CPU use. However, this
should only be considered for builds that are known to be used on
devices that meet the requirements described above. The internal pool
is disabled by adding CONFIG_NO_RANDOM_POOL=y to the .config file.
2010-11-24 00:29:40 +01:00
|
|
|
random_add_randomness(key->key_nonce, WPA_NONCE_LEN);
|
2010-11-24 12:08:03 +01:00
|
|
|
if (sm->group->reject_4way_hs_for_entropy) {
|
|
|
|
/*
|
|
|
|
* The system did not have enough entropy to generate
|
|
|
|
* strong random numbers. Reject the first 4-way
|
|
|
|
* handshake(s) and collect some entropy based on the
|
|
|
|
* information from it. Once enough entropy is
|
|
|
|
* available, the next atempt will trigger GMK/Key
|
|
|
|
* Counter update and the station will be allowed to
|
|
|
|
* continue.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Reject 4-way handshake to "
|
|
|
|
"collect more entropy for random number "
|
|
|
|
"generation");
|
|
|
|
random_mark_pool_ready();
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_sta_disconnect(wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
2010-11-24 12:08:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
case PAIRWISE_4:
|
|
|
|
if (sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING ||
|
|
|
|
!sm->PTK_valid) {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key msg 4/4 in "
|
|
|
|
"invalid state (%d) - dropped",
|
|
|
|
sm->wpa_ptk_state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GROUP_2:
|
|
|
|
if (sm->wpa_ptk_group_state != WPA_PTK_GROUP_REKEYNEGOTIATING
|
|
|
|
|| !sm->PTK_valid) {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key msg 2/2 in "
|
|
|
|
"invalid state (%d) - dropped",
|
|
|
|
sm->wpa_ptk_group_state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case REQUEST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"received EAPOL-Key frame (%s)", msgtxt);
|
|
|
|
|
|
|
|
if (key_info & WPA_KEY_INFO_ACK) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received invalid EAPOL-Key: Key Ack set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-02 23:48:47 +02:00
|
|
|
if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
|
|
|
|
!(key_info & WPA_KEY_INFO_MIC)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received invalid EAPOL-Key: Key MIC not set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-02 23:48:47 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
if (wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
|
|
|
|
(key_info & WPA_KEY_INFO_MIC)) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received invalid EAPOL-Key: Key MIC set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->MICVerified = FALSE;
|
2012-01-02 21:36:11 +01:00
|
|
|
if (sm->PTK_valid && !sm->update_snonce) {
|
2015-09-03 14:59:44 +02:00
|
|
|
if (mic_len &&
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_verify_key_mic(sm->wpa_key_mgmt, sm->pmk_len, &sm->PTK,
|
|
|
|
data, data_len) &&
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
(msg != PAIRWISE_4 || !sm->alt_snonce_valid ||
|
|
|
|
wpa_try_alt_snonce(sm, data, data_len))) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key with invalid MIC");
|
2019-02-10 16:02:49 +01:00
|
|
|
#ifdef TEST_FUZZ
|
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"TEST: Ignore Key MIC failure for fuzz testing");
|
|
|
|
goto continue_fuzz;
|
|
|
|
#endif /* TEST_FUZZ */
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-09-03 17:18:53 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
if (!mic_len &&
|
|
|
|
wpa_aead_decrypt(sm, &sm->PTK, data, data_len,
|
|
|
|
&key_data_length) < 0) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key with invalid MIC");
|
2019-02-10 16:02:49 +01:00
|
|
|
#ifdef TEST_FUZZ
|
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"TEST: Ignore Key MIC failure for fuzz testing");
|
|
|
|
goto continue_fuzz;
|
|
|
|
#endif /* TEST_FUZZ */
|
2015-09-03 17:18:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
2019-02-10 16:02:49 +01:00
|
|
|
#ifdef TEST_FUZZ
|
|
|
|
continue_fuzz:
|
|
|
|
#endif /* TEST_FUZZ */
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->MICVerified = TRUE;
|
|
|
|
eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
|
2011-03-29 16:39:12 +02:00
|
|
|
sm->pending_1_of_4_timeout = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key_info & WPA_KEY_INFO_REQUEST) {
|
|
|
|
if (sm->MICVerified) {
|
|
|
|
sm->req_replay_counter_used = 1;
|
|
|
|
os_memcpy(sm->req_replay_counter, key->replay_counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN);
|
|
|
|
} else {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key request with "
|
|
|
|
"invalid MIC");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: should decrypt key data field if encryption was used;
|
|
|
|
* even though MAC address KDE is not normally encrypted,
|
|
|
|
* supplicant is allowed to encrypt it.
|
|
|
|
*/
|
2017-09-22 13:59:13 +02:00
|
|
|
if (key_info & WPA_KEY_INFO_ERROR) {
|
2012-11-18 12:06:03 +01:00
|
|
|
if (wpa_receive_error_report(
|
|
|
|
wpa_auth, sm,
|
|
|
|
!(key_info & WPA_KEY_INFO_KEY_TYPE)) > 0)
|
|
|
|
return; /* STA entry was removed */
|
2008-02-28 02:34:43 +01:00
|
|
|
} else if (key_info & WPA_KEY_INFO_KEY_TYPE) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key Request for new "
|
|
|
|
"4-Way Handshake");
|
|
|
|
wpa_request_new_ptk(sm);
|
|
|
|
} else if (key_data_length > 0 &&
|
2015-01-25 22:32:01 +01:00
|
|
|
wpa_parse_kde_ies(key_data, key_data_length,
|
|
|
|
&kde) == 0 &&
|
2008-02-28 02:34:43 +01:00
|
|
|
kde.mac_addr) {
|
|
|
|
} else {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key Request for GTK "
|
|
|
|
"rekeying");
|
|
|
|
eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
|
|
|
|
wpa_rekey_gtk(wpa_auth, NULL);
|
|
|
|
}
|
|
|
|
} else {
|
2012-01-02 21:36:11 +01:00
|
|
|
/* Do not allow the same key replay counter to be reused. */
|
|
|
|
wpa_replay_counter_mark_invalid(sm->key_replay,
|
|
|
|
key->replay_counter);
|
|
|
|
|
|
|
|
if (msg == PAIRWISE_2) {
|
|
|
|
/*
|
|
|
|
* Maintain a copy of the pending EAPOL-Key frames in
|
|
|
|
* case the EAPOL-Key frame was retransmitted. This is
|
|
|
|
* needed to allow EAPOL-Key msg 2/4 reply to another
|
|
|
|
* pending msg 1/4 to update the SNonce to work around
|
|
|
|
* unexpected supplicant behavior.
|
|
|
|
*/
|
|
|
|
os_memcpy(sm->prev_key_replay, sm->key_replay,
|
|
|
|
sizeof(sm->key_replay));
|
|
|
|
} else {
|
|
|
|
os_memset(sm->prev_key_replay, 0,
|
|
|
|
sizeof(sm->prev_key_replay));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure old valid counters are not accepted anymore and
|
|
|
|
* do not get copied again.
|
|
|
|
*/
|
|
|
|
wpa_replay_counter_mark_invalid(sm->key_replay, NULL);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
os_free(sm->last_rx_eapol_key);
|
2017-03-07 10:17:23 +01:00
|
|
|
sm->last_rx_eapol_key = os_memdup(data, data_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->last_rx_eapol_key == NULL)
|
|
|
|
return;
|
|
|
|
sm->last_rx_eapol_key_len = data_len;
|
|
|
|
|
2011-11-17 21:59:31 +01:00
|
|
|
sm->rx_eapol_key_secure = !!(key_info & WPA_KEY_INFO_SECURE);
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->EAPOLKeyReceived = TRUE;
|
|
|
|
sm->EAPOLKeyPairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
|
|
|
|
sm->EAPOLKeyRequest = !!(key_info & WPA_KEY_INFO_REQUEST);
|
|
|
|
os_memcpy(sm->SNonce, key->key_nonce, WPA_NONCE_LEN);
|
|
|
|
wpa_sm_step(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-23 00:05:26 +01:00
|
|
|
static int wpa_gmk_to_gtk(const u8 *gmk, const char *label, const u8 *addr,
|
|
|
|
const u8 *gnonce, u8 *gtk, size_t gtk_len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2017-11-18 16:08:11 +01:00
|
|
|
u8 data[ETH_ALEN + WPA_NONCE_LEN + 8 + WPA_GTK_MAX_LEN];
|
2010-11-22 23:57:14 +01:00
|
|
|
u8 *pos;
|
2010-11-23 00:05:26 +01:00
|
|
|
int ret = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2010-11-22 23:57:14 +01:00
|
|
|
/* GTK = PRF-X(GMK, "Group key expansion",
|
|
|
|
* AA || GNonce || Time || random data)
|
|
|
|
* The example described in the IEEE 802.11 standard uses only AA and
|
|
|
|
* GNonce as inputs here. Add some more entropy since this derivation
|
|
|
|
* is done only at the Authenticator and as such, does not need to be
|
|
|
|
* exactly same.
|
|
|
|
*/
|
2017-11-18 16:08:11 +01:00
|
|
|
os_memset(data, 0, sizeof(data));
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memcpy(data, addr, ETH_ALEN);
|
|
|
|
os_memcpy(data + ETH_ALEN, gnonce, WPA_NONCE_LEN);
|
2010-11-22 23:57:14 +01:00
|
|
|
pos = data + ETH_ALEN + WPA_NONCE_LEN;
|
|
|
|
wpa_get_ntp_timestamp(pos);
|
2019-02-10 16:02:49 +01:00
|
|
|
#ifdef TEST_FUZZ
|
|
|
|
os_memset(pos, 0xef, 8);
|
|
|
|
#endif /* TEST_FUZZ */
|
2010-11-22 23:57:14 +01:00
|
|
|
pos += 8;
|
2017-11-18 16:08:11 +01:00
|
|
|
if (random_get_bytes(pos, gtk_len) < 0)
|
2010-11-23 00:05:26 +01:00
|
|
|
ret = -1;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2017-11-18 16:08:11 +01:00
|
|
|
#ifdef CONFIG_SHA384
|
|
|
|
if (sha384_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data),
|
|
|
|
gtk, gtk_len) < 0)
|
2010-11-23 00:05:26 +01:00
|
|
|
ret = -1;
|
2017-11-18 16:08:11 +01:00
|
|
|
#else /* CONFIG_SHA384 */
|
|
|
|
#ifdef CONFIG_SHA256
|
|
|
|
if (sha256_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data),
|
|
|
|
gtk, gtk_len) < 0)
|
|
|
|
ret = -1;
|
|
|
|
#else /* CONFIG_SHA256 */
|
|
|
|
if (sha1_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data),
|
|
|
|
gtk, gtk_len) < 0)
|
|
|
|
ret = -1;
|
|
|
|
#endif /* CONFIG_SHA256 */
|
|
|
|
#endif /* CONFIG_SHA384 */
|
2010-11-23 00:05:26 +01:00
|
|
|
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(data, sizeof(data));
|
|
|
|
|
2010-11-23 00:05:26 +01:00
|
|
|
return ret;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = eloop_ctx;
|
|
|
|
struct wpa_state_machine *sm = timeout_ctx;
|
|
|
|
|
2011-03-29 16:39:12 +02:00
|
|
|
sm->pending_1_of_4_timeout = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "EAPOL-Key timeout");
|
|
|
|
sm->TimeoutEvt = TRUE;
|
|
|
|
wpa_sm_step(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm, int key_info,
|
|
|
|
const u8 *key_rsc, const u8 *nonce,
|
|
|
|
const u8 *kde, size_t kde_len,
|
|
|
|
int keyidx, int encr, int force_version)
|
|
|
|
{
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf = &wpa_auth->conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
struct ieee802_1x_hdr *hdr;
|
|
|
|
struct wpa_eapol_key *key;
|
2015-01-25 22:32:01 +01:00
|
|
|
size_t len, mic_len, keyhdrlen;
|
2008-02-28 02:34:43 +01:00
|
|
|
int alg;
|
|
|
|
int key_data_len, pad_len = 0;
|
|
|
|
u8 *buf, *pos;
|
|
|
|
int version, pairwise;
|
2008-12-16 13:17:33 +01:00
|
|
|
int i;
|
2015-09-02 21:55:03 +02:00
|
|
|
u8 *key_mic, *key_data;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2017-06-17 22:48:52 +02:00
|
|
|
mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
|
2015-09-02 21:55:03 +02:00
|
|
|
keyhdrlen = sizeof(*key) + mic_len + 2;
|
2015-01-25 22:32:01 +01:00
|
|
|
|
|
|
|
len = sizeof(struct ieee802_1x_hdr) + keyhdrlen;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (force_version)
|
|
|
|
version = force_version;
|
2018-03-16 12:04:15 +01:00
|
|
|
else if (wpa_use_akm_defined(sm->wpa_key_mgmt))
|
2013-07-23 20:25:21 +02:00
|
|
|
version = WPA_KEY_INFO_TYPE_AKM_DEFINED;
|
2018-03-16 12:04:15 +01:00
|
|
|
else if (wpa_use_cmac(sm->wpa_key_mgmt))
|
2008-02-28 02:34:43 +01:00
|
|
|
version = WPA_KEY_INFO_TYPE_AES_128_CMAC;
|
2012-08-29 10:52:15 +02:00
|
|
|
else if (sm->pairwise != WPA_CIPHER_TKIP)
|
2008-02-28 02:34:43 +01:00
|
|
|
version = WPA_KEY_INFO_TYPE_HMAC_SHA1_AES;
|
|
|
|
else
|
|
|
|
version = WPA_KEY_INFO_TYPE_HMAC_MD5_RC4;
|
|
|
|
|
2013-05-04 10:48:57 +02:00
|
|
|
pairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Send EAPOL(version=%d secure=%d mic=%d "
|
|
|
|
"ack=%d install=%d pairwise=%d kde_len=%lu keyidx=%d "
|
|
|
|
"encr=%d)",
|
|
|
|
version,
|
|
|
|
(key_info & WPA_KEY_INFO_SECURE) ? 1 : 0,
|
|
|
|
(key_info & WPA_KEY_INFO_MIC) ? 1 : 0,
|
|
|
|
(key_info & WPA_KEY_INFO_ACK) ? 1 : 0,
|
|
|
|
(key_info & WPA_KEY_INFO_INSTALL) ? 1 : 0,
|
|
|
|
pairwise, (unsigned long) kde_len, keyidx, encr);
|
|
|
|
|
|
|
|
key_data_len = kde_len;
|
|
|
|
|
|
|
|
if ((version == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
|
2018-03-16 12:04:15 +01:00
|
|
|
wpa_use_aes_key_wrap(sm->wpa_key_mgmt) ||
|
2008-02-28 02:34:43 +01:00
|
|
|
version == WPA_KEY_INFO_TYPE_AES_128_CMAC) && encr) {
|
|
|
|
pad_len = key_data_len % 8;
|
|
|
|
if (pad_len)
|
|
|
|
pad_len = 8 - pad_len;
|
|
|
|
key_data_len += pad_len + 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
len += key_data_len;
|
2015-09-03 16:24:37 +02:00
|
|
|
if (!mic_len && encr)
|
|
|
|
len += AES_BLOCK_SIZE;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
hdr = os_zalloc(len);
|
|
|
|
if (hdr == NULL)
|
|
|
|
return;
|
2020-03-28 18:29:12 +01:00
|
|
|
hdr->version = conf->eapol_version;
|
2008-02-28 02:34:43 +01:00
|
|
|
hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
|
|
|
|
hdr->length = host_to_be16(len - sizeof(*hdr));
|
|
|
|
key = (struct wpa_eapol_key *) (hdr + 1);
|
2015-09-02 21:55:03 +02:00
|
|
|
key_mic = (u8 *) (key + 1);
|
2015-01-25 22:32:01 +01:00
|
|
|
key_data = ((u8 *) (hdr + 1)) + keyhdrlen;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
key->type = sm->wpa == WPA_VERSION_WPA2 ?
|
|
|
|
EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA;
|
|
|
|
key_info |= version;
|
|
|
|
if (encr && sm->wpa == WPA_VERSION_WPA2)
|
|
|
|
key_info |= WPA_KEY_INFO_ENCR_KEY_DATA;
|
|
|
|
if (sm->wpa != WPA_VERSION_WPA2)
|
|
|
|
key_info |= keyidx << WPA_KEY_INFO_KEY_INDEX_SHIFT;
|
|
|
|
WPA_PUT_BE16(key->key_info, key_info);
|
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
alg = pairwise ? sm->pairwise : conf->wpa_group;
|
2017-09-22 13:59:13 +02:00
|
|
|
if (sm->wpa == WPA_VERSION_WPA2 && !pairwise)
|
2008-02-28 02:34:43 +01:00
|
|
|
WPA_PUT_BE16(key->key_length, 0);
|
2017-02-05 12:52:43 +01:00
|
|
|
else
|
|
|
|
WPA_PUT_BE16(key->key_length, wpa_cipher_key_len(alg));
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2008-12-16 13:17:33 +01:00
|
|
|
for (i = RSNA_MAX_EAPOL_RETRIES - 1; i > 0; i--) {
|
|
|
|
sm->key_replay[i].valid = sm->key_replay[i - 1].valid;
|
|
|
|
os_memcpy(sm->key_replay[i].counter,
|
|
|
|
sm->key_replay[i - 1].counter,
|
|
|
|
WPA_REPLAY_COUNTER_LEN);
|
|
|
|
}
|
|
|
|
inc_byte_array(sm->key_replay[0].counter, WPA_REPLAY_COUNTER_LEN);
|
|
|
|
os_memcpy(key->replay_counter, sm->key_replay[0].counter,
|
2008-02-28 02:34:43 +01:00
|
|
|
WPA_REPLAY_COUNTER_LEN);
|
2014-11-21 14:35:19 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA: Replay Counter",
|
|
|
|
key->replay_counter, WPA_REPLAY_COUNTER_LEN);
|
2008-12-16 13:17:33 +01:00
|
|
|
sm->key_replay[0].valid = TRUE;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (nonce)
|
|
|
|
os_memcpy(key->key_nonce, nonce, WPA_NONCE_LEN);
|
|
|
|
|
|
|
|
if (key_rsc)
|
|
|
|
os_memcpy(key->key_rsc, key_rsc, WPA_KEY_RSC_LEN);
|
|
|
|
|
|
|
|
if (kde && !encr) {
|
2015-01-25 22:32:01 +01:00
|
|
|
os_memcpy(key_data, kde, kde_len);
|
2015-09-02 21:55:03 +02:00
|
|
|
WPA_PUT_BE16(key_mic + mic_len, kde_len);
|
2015-09-03 16:24:37 +02:00
|
|
|
#ifdef CONFIG_FILS
|
2018-03-02 20:10:38 +01:00
|
|
|
} else if (!mic_len && kde) {
|
2015-09-03 16:24:37 +02:00
|
|
|
const u8 *aad[1];
|
|
|
|
size_t aad_len[1];
|
|
|
|
|
|
|
|
WPA_PUT_BE16(key_mic, AES_BLOCK_SIZE + kde_len);
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "Plaintext EAPOL-Key Key Data",
|
|
|
|
kde, kde_len);
|
|
|
|
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPA: KEK",
|
|
|
|
sm->PTK.kek, sm->PTK.kek_len);
|
|
|
|
/* AES-SIV AAD from EAPOL protocol version field (inclusive) to
|
|
|
|
* to Key Data (exclusive). */
|
|
|
|
aad[0] = (u8 *) hdr;
|
|
|
|
aad_len[0] = key_mic + 2 - (u8 *) hdr;
|
|
|
|
if (aes_siv_encrypt(sm->PTK.kek, sm->PTK.kek_len, kde, kde_len,
|
|
|
|
1, aad, aad_len, key_mic + 2) < 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: AES-SIV encryption failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA: Encrypted Key Data from SIV",
|
|
|
|
key_mic + 2, AES_BLOCK_SIZE + kde_len);
|
|
|
|
#endif /* CONFIG_FILS */
|
2008-02-28 02:34:43 +01:00
|
|
|
} else if (encr && kde) {
|
|
|
|
buf = os_zalloc(key_data_len);
|
|
|
|
if (buf == NULL) {
|
|
|
|
os_free(hdr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pos = buf;
|
|
|
|
os_memcpy(pos, kde, kde_len);
|
|
|
|
pos += kde_len;
|
|
|
|
|
|
|
|
if (pad_len)
|
|
|
|
*pos++ = 0xdd;
|
|
|
|
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "Plaintext EAPOL-Key Key Data",
|
|
|
|
buf, key_data_len);
|
|
|
|
if (version == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
|
2018-03-16 12:04:15 +01:00
|
|
|
wpa_use_aes_key_wrap(sm->wpa_key_mgmt) ||
|
2008-02-28 02:34:43 +01:00
|
|
|
version == WPA_KEY_INFO_TYPE_AES_128_CMAC) {
|
2017-03-12 18:43:39 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Encrypt Key Data using AES-WRAP (KEK length %u)",
|
|
|
|
(unsigned int) sm->PTK.kek_len);
|
2015-01-25 15:49:18 +01:00
|
|
|
if (aes_wrap(sm->PTK.kek, sm->PTK.kek_len,
|
2015-01-25 22:32:01 +01:00
|
|
|
(key_data_len - 8) / 8, buf, key_data)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(hdr);
|
|
|
|
os_free(buf);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-02 21:55:03 +02:00
|
|
|
WPA_PUT_BE16(key_mic + mic_len, key_data_len);
|
2015-08-01 22:37:07 +02:00
|
|
|
#ifndef CONFIG_NO_RC4
|
2015-01-25 15:49:18 +01:00
|
|
|
} else if (sm->PTK.kek_len == 16) {
|
2008-02-28 02:34:43 +01:00
|
|
|
u8 ek[32];
|
2017-03-12 18:43:39 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Encrypt Key Data using RC4");
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memcpy(key->key_iv,
|
|
|
|
sm->group->Counter + WPA_NONCE_LEN - 16, 16);
|
|
|
|
inc_byte_array(sm->group->Counter, WPA_NONCE_LEN);
|
|
|
|
os_memcpy(ek, key->key_iv, 16);
|
2015-01-25 15:49:18 +01:00
|
|
|
os_memcpy(ek + 16, sm->PTK.kek, sm->PTK.kek_len);
|
2015-01-25 22:32:01 +01:00
|
|
|
os_memcpy(key_data, buf, key_data_len);
|
|
|
|
rc4_skip(ek, 32, 256, key_data, key_data_len);
|
2015-09-02 21:55:03 +02:00
|
|
|
WPA_PUT_BE16(key_mic + mic_len, key_data_len);
|
2015-08-01 22:37:07 +02:00
|
|
|
#endif /* CONFIG_NO_RC4 */
|
2015-01-25 15:49:18 +01:00
|
|
|
} else {
|
|
|
|
os_free(hdr);
|
|
|
|
os_free(buf);
|
|
|
|
return;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
os_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_info & WPA_KEY_INFO_MIC) {
|
2015-09-03 16:24:37 +02:00
|
|
|
if (!sm->PTK_valid || !mic_len) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"PTK not valid when sending EAPOL-Key "
|
|
|
|
"frame");
|
|
|
|
os_free(hdr);
|
|
|
|
return;
|
|
|
|
}
|
2015-01-25 22:32:01 +01:00
|
|
|
|
2017-11-24 11:13:26 +01:00
|
|
|
if (wpa_eapol_key_mic(sm->PTK.kck, sm->PTK.kck_len,
|
|
|
|
sm->wpa_key_mgmt, version,
|
|
|
|
(u8 *) hdr, len, key_mic) < 0) {
|
|
|
|
os_free(hdr);
|
|
|
|
return;
|
|
|
|
}
|
2013-05-04 10:45:03 +02:00
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
if (!pairwise &&
|
2020-03-28 18:29:12 +01:00
|
|
|
conf->corrupt_gtk_rekey_mic_probability > 0.0 &&
|
|
|
|
drand48() < conf->corrupt_gtk_rekey_mic_probability) {
|
2013-05-04 10:45:03 +02:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"Corrupting group EAPOL-Key Key MIC");
|
2015-01-25 22:32:01 +01:00
|
|
|
key_mic[0]++;
|
2013-05-04 10:45:03 +02:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_set_eapol(wpa_auth, sm->addr, WPA_EAPOL_inc_EapolFramesTx, 1);
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_send_eapol(wpa_auth, sm->addr, (u8 *) hdr, len,
|
|
|
|
sm->pairwise_set);
|
|
|
|
os_free(hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_send_eapol(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm, int key_info,
|
|
|
|
const u8 *key_rsc, const u8 *nonce,
|
|
|
|
const u8 *kde, size_t kde_len,
|
|
|
|
int keyidx, int encr)
|
|
|
|
{
|
|
|
|
int timeout_ms;
|
|
|
|
int pairwise = key_info & WPA_KEY_INFO_KEY_TYPE;
|
2017-01-05 17:00:33 +01:00
|
|
|
u32 ctr;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (sm == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
__wpa_send_eapol(wpa_auth, sm, key_info, key_rsc, nonce, kde, kde_len,
|
|
|
|
keyidx, encr, 0);
|
|
|
|
|
2008-12-18 16:15:36 +01:00
|
|
|
ctr = pairwise ? sm->TimeoutCtr : sm->GTimeoutCtr;
|
2011-03-29 16:39:12 +02:00
|
|
|
if (ctr == 1 && wpa_auth->conf.tx_status)
|
2011-12-24 12:50:59 +01:00
|
|
|
timeout_ms = pairwise ? eapol_key_timeout_first :
|
|
|
|
eapol_key_timeout_first_group;
|
2008-12-18 16:15:36 +01:00
|
|
|
else
|
|
|
|
timeout_ms = eapol_key_timeout_subseq;
|
2017-10-16 17:37:43 +02:00
|
|
|
if (wpa_auth->conf.wpa_disable_eapol_key_retries &&
|
|
|
|
(!pairwise || (key_info & WPA_KEY_INFO_MIC)))
|
|
|
|
timeout_ms = eapol_key_timeout_no_retrans;
|
2011-03-29 16:39:12 +02:00
|
|
|
if (pairwise && ctr == 1 && !(key_info & WPA_KEY_INFO_MIC))
|
|
|
|
sm->pending_1_of_4_timeout = 1;
|
2019-02-10 16:02:49 +01:00
|
|
|
#ifdef TEST_FUZZ
|
|
|
|
timeout_ms = 1;
|
|
|
|
#endif /* TEST_FUZZ */
|
2011-03-29 16:39:12 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Use EAPOL-Key timeout of %u ms (retry "
|
2017-01-05 17:00:33 +01:00
|
|
|
"counter %u)", timeout_ms, ctr);
|
2008-02-28 02:34:43 +01:00
|
|
|
eloop_register_timeout(timeout_ms / 1000, (timeout_ms % 1000) * 1000,
|
|
|
|
wpa_send_eapol_timeout, wpa_auth, sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-17 22:48:52 +02:00
|
|
|
static int wpa_verify_key_mic(int akmp, size_t pmk_len, struct wpa_ptk *PTK,
|
|
|
|
u8 *data, size_t data_len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct ieee802_1x_hdr *hdr;
|
|
|
|
struct wpa_eapol_key *key;
|
|
|
|
u16 key_info;
|
|
|
|
int ret = 0;
|
2015-09-02 21:55:03 +02:00
|
|
|
u8 mic[WPA_EAPOL_KEY_MIC_MAX_LEN], *mic_pos;
|
2017-06-17 22:48:52 +02:00
|
|
|
size_t mic_len = wpa_mic_len(akmp, pmk_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (data_len < sizeof(*hdr) + sizeof(*key))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hdr = (struct ieee802_1x_hdr *) data;
|
|
|
|
key = (struct wpa_eapol_key *) (hdr + 1);
|
2015-09-02 21:55:03 +02:00
|
|
|
mic_pos = (u8 *) (key + 1);
|
2008-02-28 02:34:43 +01:00
|
|
|
key_info = WPA_GET_BE16(key->key_info);
|
2015-09-02 21:55:03 +02:00
|
|
|
os_memcpy(mic, mic_pos, mic_len);
|
|
|
|
os_memset(mic_pos, 0, mic_len);
|
2015-01-25 15:49:18 +01:00
|
|
|
if (wpa_eapol_key_mic(PTK->kck, PTK->kck_len, akmp,
|
|
|
|
key_info & WPA_KEY_INFO_TYPE_MASK,
|
2015-09-02 21:55:03 +02:00
|
|
|
data, data_len, mic_pos) ||
|
|
|
|
os_memcmp_const(mic, mic_pos, mic_len) != 0)
|
2008-02-28 02:34:43 +01:00
|
|
|
ret = -1;
|
2015-09-02 21:55:03 +02:00
|
|
|
os_memcpy(mic_pos, mic, mic_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_remove_ptk(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
sm->PTK_valid = FALSE;
|
|
|
|
os_memset(&sm->PTK, 0, sizeof(sm->PTK));
|
2016-10-25 23:22:49 +02:00
|
|
|
if (wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 0, NULL,
|
2020-01-04 23:10:04 +01:00
|
|
|
0, KEY_FLAG_PAIRWISE))
|
2016-10-25 23:22:49 +02:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"RSN: PTK removal from the driver failed");
|
2020-03-20 20:04:31 +01:00
|
|
|
if (sm->wpa_auth->conf.extended_key_id && sm->use_ext_key_id &&
|
|
|
|
wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 1, NULL,
|
|
|
|
0, KEY_FLAG_PAIRWISE))
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"RSN: PTK Key ID 1 removal from the driver failed");
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->pairwise_set = FALSE;
|
2008-11-06 18:57:21 +01:00
|
|
|
eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-28 15:34:38 +02:00
|
|
|
int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2008-08-31 10:04:47 +02:00
|
|
|
int remove_ptk = 1;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm == NULL)
|
2010-01-10 20:45:44 +01:00
|
|
|
return -1;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"event %d notification", event);
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case WPA_AUTH:
|
2014-09-01 06:23:30 +02:00
|
|
|
#ifdef CONFIG_MESH
|
|
|
|
/* PTKs are derived through AMPE */
|
|
|
|
if (wpa_auth_start_ampe(sm->wpa_auth, sm->addr)) {
|
|
|
|
/* not mesh */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
#endif /* CONFIG_MESH */
|
2008-02-28 02:34:43 +01:00
|
|
|
case WPA_ASSOC:
|
|
|
|
break;
|
|
|
|
case WPA_DEAUTH:
|
|
|
|
case WPA_DISASSOC:
|
|
|
|
sm->DeauthenticationRequest = TRUE;
|
2019-04-18 17:17:07 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
os_memset(sm->PMK, 0, sizeof(sm->PMK));
|
|
|
|
sm->pmk_len = 0;
|
|
|
|
os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
|
|
|
|
sm->xxkey_len = 0;
|
2019-04-18 17:17:07 +02:00
|
|
|
os_memset(sm->pmk_r1, 0, sizeof(sm->pmk_r1));
|
|
|
|
sm->pmk_r1_len = 0;
|
2019-04-18 17:17:07 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
case WPA_REAUTH:
|
|
|
|
case WPA_REAUTH_EAPOL:
|
2010-04-23 15:49:50 +02:00
|
|
|
if (!sm->started) {
|
|
|
|
/*
|
|
|
|
* When using WPS, we may end up here if the STA
|
|
|
|
* manages to re-associate without the previous STA
|
|
|
|
* entry getting removed. Consequently, we need to make
|
|
|
|
* sure that the WPA state machines gets initialized
|
|
|
|
* properly at this point.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA state machine had not been "
|
|
|
|
"started - initialize now");
|
|
|
|
sm->started = 1;
|
|
|
|
sm->Init = TRUE;
|
|
|
|
if (wpa_sm_step(sm) == 1)
|
|
|
|
return 1; /* should not really happen */
|
|
|
|
sm->Init = FALSE;
|
|
|
|
sm->AuthenticationRequest = TRUE;
|
|
|
|
break;
|
2020-03-20 20:04:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sm->use_ext_key_id &&
|
|
|
|
sm->wpa_auth->conf.wpa_deny_ptk0_rekey) {
|
2020-01-10 23:19:08 +01:00
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"WPA: PTK0 rekey not allowed, disconnect "
|
|
|
|
MACSTR, MAC2STR(sm->addr));
|
|
|
|
sm->Disconnect = TRUE;
|
2020-03-20 20:04:31 +01:00
|
|
|
/* Try to encourage the STA to reconnect */
|
2020-01-10 23:19:08 +01:00
|
|
|
sm->disconnect_reason =
|
|
|
|
WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
|
|
|
|
break;
|
2010-04-23 15:49:50 +02:00
|
|
|
}
|
2020-03-20 20:04:31 +01:00
|
|
|
|
|
|
|
if (sm->use_ext_key_id)
|
|
|
|
sm->keyidx_active ^= 1; /* flip Key ID */
|
|
|
|
|
2008-10-21 12:54:54 +02:00
|
|
|
if (sm->GUpdateStationKeys) {
|
|
|
|
/*
|
|
|
|
* Reauthentication cancels the pending group key
|
|
|
|
* update for this STA.
|
|
|
|
*/
|
|
|
|
sm->group->GKeyDoneStations--;
|
|
|
|
sm->GUpdateStationKeys = FALSE;
|
|
|
|
sm->PtkGroupInit = TRUE;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->ReAuthenticationRequest = TRUE;
|
|
|
|
break;
|
|
|
|
case WPA_ASSOC_FT:
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-04 08:34:14 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "FT: Retry PTK configuration "
|
|
|
|
"after association");
|
|
|
|
wpa_ft_install_ptk(sm);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/* Using FT protocol, not WPA auth state machine */
|
|
|
|
sm->ft_completed = 1;
|
2019-04-19 00:11:41 +02:00
|
|
|
wpa_auth_set_ptk_rekey_timer(sm);
|
2010-01-10 20:45:44 +01:00
|
|
|
return 0;
|
2016-10-27 14:18:32 +02:00
|
|
|
#else /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2017-04-21 20:01:03 +02:00
|
|
|
case WPA_ASSOC_FILS:
|
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: TK configuration after association");
|
|
|
|
fils_set_tk(sm);
|
|
|
|
sm->fils_completed = 1;
|
|
|
|
return 0;
|
|
|
|
#else /* CONFIG_FILS */
|
|
|
|
break;
|
|
|
|
#endif /* CONFIG_FILS */
|
2017-07-14 15:15:35 +02:00
|
|
|
case WPA_DRV_STA_REMOVED:
|
|
|
|
sm->tk_already_set = FALSE;
|
|
|
|
return 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->ft_completed = 0;
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2008-08-31 10:04:47 +02:00
|
|
|
if (sm->mgmt_frame_prot && event == WPA_AUTH)
|
|
|
|
remove_ptk = 0;
|
2015-09-09 00:27:22 +02:00
|
|
|
#ifdef CONFIG_FILS
|
2015-09-09 18:32:44 +02:00
|
|
|
if (wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
|
|
|
|
(event == WPA_AUTH || event == WPA_ASSOC))
|
2015-09-09 00:27:22 +02:00
|
|
|
remove_ptk = 0;
|
|
|
|
#endif /* CONFIG_FILS */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2008-08-31 10:04:47 +02:00
|
|
|
if (remove_ptk) {
|
|
|
|
sm->PTK_valid = FALSE;
|
|
|
|
os_memset(&sm->PTK, 0, sizeof(sm->PTK));
|
|
|
|
|
|
|
|
if (event != WPA_REAUTH_EAPOL)
|
|
|
|
wpa_remove_ptk(sm);
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2015-08-28 15:32:14 +02:00
|
|
|
if (sm->in_step_loop) {
|
|
|
|
/*
|
|
|
|
* wpa_sm_step() is already running - avoid recursive call to
|
|
|
|
* it by making the existing loop process the new update.
|
|
|
|
*/
|
|
|
|
sm->changed = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-10 20:45:44 +01:00
|
|
|
return wpa_sm_step(sm);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, INITIALIZE)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK, INITIALIZE, wpa_ptk);
|
|
|
|
if (sm->Init) {
|
|
|
|
/* Init flag is not cleared here, so avoid busy
|
|
|
|
* loop by claiming nothing changed. */
|
|
|
|
sm->changed = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sm->keycount = 0;
|
|
|
|
if (sm->GUpdateStationKeys)
|
|
|
|
sm->group->GKeyDoneStations--;
|
|
|
|
sm->GUpdateStationKeys = FALSE;
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA)
|
|
|
|
sm->PInitAKeys = FALSE;
|
|
|
|
if (1 /* Unicast cipher supported AND (ESS OR ((IBSS or WDS) and
|
|
|
|
* Local AA > Remote AA)) */) {
|
|
|
|
sm->Pair = TRUE;
|
|
|
|
}
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 0);
|
|
|
|
wpa_remove_ptk(sm);
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid, 0);
|
|
|
|
sm->TimeoutCtr = 0;
|
2017-03-11 23:32:23 +01:00
|
|
|
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
|
2017-06-17 22:48:52 +02:00
|
|
|
sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP ||
|
2017-03-11 23:32:23 +01:00
|
|
|
sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
|
|
|
|
WPA_EAPOL_authorized, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, DISCONNECT)
|
|
|
|
{
|
2017-06-17 22:48:52 +02:00
|
|
|
u16 reason = sm->disconnect_reason;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTRY_MA(WPA_PTK, DISCONNECT, wpa_ptk);
|
|
|
|
sm->Disconnect = FALSE;
|
2017-06-17 22:48:52 +02:00
|
|
|
sm->disconnect_reason = 0;
|
|
|
|
if (!reason)
|
|
|
|
reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
|
|
|
|
wpa_sta_disconnect(sm->wpa_auth, sm->addr, reason);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, DISCONNECTED)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK, DISCONNECTED, wpa_ptk);
|
|
|
|
sm->DeauthenticationRequest = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, AUTHENTICATION)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK, AUTHENTICATION, wpa_ptk);
|
|
|
|
os_memset(&sm->PTK, 0, sizeof(sm->PTK));
|
|
|
|
sm->PTK_valid = FALSE;
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portControl_Auto,
|
|
|
|
1);
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 1);
|
|
|
|
sm->AuthenticationRequest = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-29 17:11:43 +01:00
|
|
|
static void wpa_group_ensure_init(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
2010-11-23 23:52:46 +01:00
|
|
|
{
|
2012-01-29 17:11:43 +01:00
|
|
|
if (group->first_sta_seen)
|
|
|
|
return;
|
2010-11-23 23:52:46 +01:00
|
|
|
/*
|
|
|
|
* System has run bit further than at the time hostapd was started
|
|
|
|
* potentially very early during boot up. This provides better chances
|
|
|
|
* of collecting more randomness on embedded systems. Re-initialize the
|
|
|
|
* GMK and Counter here to improve their strength if there was not
|
|
|
|
* enough entropy available immediately after system startup.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Re-initialize GMK/Counter on first "
|
|
|
|
"station");
|
2010-11-24 12:08:03 +01:00
|
|
|
if (random_pool_ready() != 1) {
|
|
|
|
wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
|
|
|
|
"to proceed - reject first 4-way handshake");
|
|
|
|
group->reject_4way_hs_for_entropy = TRUE;
|
2012-01-29 17:11:43 +01:00
|
|
|
} else {
|
|
|
|
group->first_sta_seen = TRUE;
|
|
|
|
group->reject_4way_hs_for_entropy = FALSE;
|
2010-11-24 12:08:03 +01:00
|
|
|
}
|
2012-01-29 17:11:43 +01:00
|
|
|
|
2015-06-28 20:40:37 +02:00
|
|
|
if (wpa_group_init_gmk_and_counter(wpa_auth, group) < 0 ||
|
|
|
|
wpa_gtk_update(wpa_auth, group) < 0 ||
|
|
|
|
wpa_group_config_group_keys(wpa_auth, group) < 0) {
|
|
|
|
wpa_printf(MSG_INFO, "WPA: GMK/GTK setup failed");
|
|
|
|
group->first_sta_seen = FALSE;
|
|
|
|
group->reject_4way_hs_for_entropy = TRUE;
|
|
|
|
}
|
2010-11-23 23:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_STATE(WPA_PTK, AUTHENTICATION2)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK, AUTHENTICATION2, wpa_ptk);
|
2010-11-23 23:52:46 +01:00
|
|
|
|
2012-01-29 17:11:43 +01:00
|
|
|
wpa_group_ensure_init(sm->wpa_auth, sm->group);
|
2013-03-30 18:53:22 +01:00
|
|
|
sm->ReAuthenticationRequest = FALSE;
|
2010-11-23 23:52:46 +01:00
|
|
|
|
2012-02-26 11:06:36 +01:00
|
|
|
/*
|
|
|
|
* Definition of ANonce selection in IEEE Std 802.11i-2004 is somewhat
|
|
|
|
* ambiguous. The Authenticator state machine uses a counter that is
|
|
|
|
* incremented by one for each 4-way handshake. However, the security
|
|
|
|
* analysis of 4-way handshake points out that unpredictable nonces
|
|
|
|
* help in preventing precomputation attacks. Instead of the state
|
|
|
|
* machine definition, use an unpredictable nonce value here to provide
|
|
|
|
* stronger protection against potential precomputation attacks.
|
|
|
|
*/
|
|
|
|
if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
|
|
|
|
wpa_printf(MSG_ERROR, "WPA: Failed to get random data for "
|
|
|
|
"ANonce.");
|
2013-03-30 18:53:22 +01:00
|
|
|
sm->Disconnect = TRUE;
|
2012-02-26 11:06:36 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-01-15 15:57:08 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA: Assign ANonce", sm->ANonce,
|
|
|
|
WPA_NONCE_LEN);
|
2008-02-28 02:34:43 +01:00
|
|
|
/* IEEE 802.11i does not clear TimeoutCtr here, but this is more
|
|
|
|
* logical place than INITIALIZE since AUTHENTICATION2 can be
|
|
|
|
* re-entered on ReAuthenticationRequest without going through
|
|
|
|
* INITIALIZE. */
|
|
|
|
sm->TimeoutCtr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-01 11:32:57 +02:00
|
|
|
static int wpa_auth_sm_ptk_update(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"WPA: Failed to get random data for ANonce");
|
|
|
|
sm->Disconnect = TRUE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA: Assign new ANonce", sm->ANonce,
|
|
|
|
WPA_NONCE_LEN);
|
|
|
|
sm->TimeoutCtr = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_STATE(WPA_PTK, INITPMK)
|
|
|
|
{
|
|
|
|
u8 msk[2 * PMK_LEN];
|
|
|
|
size_t len = 2 * PMK_LEN;
|
|
|
|
|
|
|
|
SM_ENTRY_MA(WPA_PTK, INITPMK, wpa_ptk);
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->xxkey_len = 0;
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->pmksa) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: PMK from PMKSA cache");
|
2015-10-14 00:18:11 +02:00
|
|
|
os_memcpy(sm->PMK, sm->pmksa->pmk, sm->pmksa->pmk_len);
|
|
|
|
sm->pmk_len = sm->pmksa->pmk_len;
|
2017-06-17 22:48:52 +02:00
|
|
|
#ifdef CONFIG_DPP
|
|
|
|
} else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"DPP: No PMKSA cache entry for STA - reject connection");
|
|
|
|
sm->Disconnect = TRUE;
|
|
|
|
sm->disconnect_reason = WLAN_REASON_INVALID_PMKID;
|
|
|
|
return;
|
|
|
|
#endif /* CONFIG_DPP */
|
2008-02-28 02:34:43 +01:00
|
|
|
} else if (wpa_auth_get_msk(sm->wpa_auth, sm->addr, msk, &len) == 0) {
|
2015-10-14 00:18:11 +02:00
|
|
|
unsigned int pmk_len;
|
|
|
|
|
2017-02-16 20:18:18 +01:00
|
|
|
if (wpa_key_mgmt_sha384(sm->wpa_key_mgmt))
|
2015-10-14 00:18:11 +02:00
|
|
|
pmk_len = PMK_LEN_SUITE_B_192;
|
|
|
|
else
|
|
|
|
pmk_len = PMK_LEN;
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPA: PMK from EAPOL state machine "
|
2015-10-14 00:18:11 +02:00
|
|
|
"(MSK len=%lu PMK len=%u)", (unsigned long) len,
|
|
|
|
pmk_len);
|
|
|
|
if (len < pmk_len) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: MSK not long enough (%u) to create PMK (%u)",
|
|
|
|
(unsigned int) len, (unsigned int) pmk_len);
|
|
|
|
sm->Disconnect = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
os_memcpy(sm->PMK, msk, pmk_len);
|
|
|
|
sm->pmk_len = pmk_len;
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
if (len >= 2 * PMK_LEN) {
|
2018-06-04 14:16:54 +02:00
|
|
|
if (wpa_key_mgmt_sha384(sm->wpa_key_mgmt)) {
|
|
|
|
os_memcpy(sm->xxkey, msk, SHA384_MAC_LEN);
|
|
|
|
sm->xxkey_len = SHA384_MAC_LEN;
|
|
|
|
} else {
|
|
|
|
os_memcpy(sm->xxkey, msk + PMK_LEN, PMK_LEN);
|
|
|
|
sm->xxkey_len = PMK_LEN;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
} else {
|
2015-01-12 23:15:45 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Could not get PMK, get_msk: %p",
|
2017-01-26 16:24:06 +01:00
|
|
|
sm->wpa_auth->cb->get_msk);
|
2015-01-29 21:31:41 +01:00
|
|
|
sm->Disconnect = TRUE;
|
|
|
|
return;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(msk, sizeof(msk));
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
sm->req_replay_counter_used = 0;
|
|
|
|
/* IEEE 802.11i does not set keyRun to FALSE, but not doing this
|
|
|
|
* will break reauthentication since EAPOL state machines may not be
|
|
|
|
* get into AUTHENTICATING state that clears keyRun before WPA state
|
|
|
|
* machine enters AUTHENTICATION2 state and goes immediately to INITPMK
|
|
|
|
* state and takes PMK from the previously used AAA Key. This will
|
|
|
|
* eventually fail in 4-Way Handshake because Supplicant uses PMK
|
|
|
|
* derived from the new AAA Key. Setting keyRun = FALSE here seems to
|
|
|
|
* be good workaround for this issue. */
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyRun, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, INITPSK)
|
|
|
|
{
|
|
|
|
const u8 *psk;
|
2017-10-08 15:37:32 +02:00
|
|
|
size_t psk_len;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTRY_MA(WPA_PTK, INITPSK, wpa_ptk);
|
2017-10-08 15:37:32 +02:00
|
|
|
psk = wpa_auth_get_psk(sm->wpa_auth, sm->addr, sm->p2p_dev_addr, NULL,
|
2019-02-14 12:34:33 +01:00
|
|
|
&psk_len, NULL);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (psk) {
|
2017-10-08 15:37:32 +02:00
|
|
|
os_memcpy(sm->PMK, psk, psk_len);
|
|
|
|
sm->pmk_len = psk_len;
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memcpy(sm->xxkey, psk, PMK_LEN);
|
|
|
|
sm->xxkey_len = PMK_LEN;
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2017-09-02 00:02:15 +02:00
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
if (wpa_auth_uses_sae(sm) && sm->pmksa) {
|
|
|
|
wpa_printf(MSG_DEBUG, "SAE: PMK from PMKSA cache");
|
|
|
|
os_memcpy(sm->PMK, sm->pmksa->pmk, sm->pmksa->pmk_len);
|
|
|
|
sm->pmk_len = sm->pmksa->pmk_len;
|
2019-03-26 15:49:02 +01:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
os_memcpy(sm->xxkey, sm->pmksa->pmk, sm->pmksa->pmk_len);
|
|
|
|
sm->xxkey_len = sm->pmksa->pmk_len;
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2017-09-02 00:02:15 +02:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_SAE */
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->req_replay_counter_used = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, PTKSTART)
|
|
|
|
{
|
|
|
|
u8 buf[2 + RSN_SELECTOR_LEN + PMKID_LEN], *pmkid = NULL;
|
|
|
|
size_t pmkid_len = 0;
|
|
|
|
|
|
|
|
SM_ENTRY_MA(WPA_PTK, PTKSTART, wpa_ptk);
|
|
|
|
sm->PTKRequest = FALSE;
|
|
|
|
sm->TimeoutEvt = FALSE;
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
sm->alt_snonce_valid = FALSE;
|
2008-12-18 16:15:36 +01:00
|
|
|
|
|
|
|
sm->TimeoutCtr++;
|
2017-01-05 17:00:33 +01:00
|
|
|
if (sm->TimeoutCtr > sm->wpa_auth->conf.wpa_pairwise_update_count) {
|
2008-12-18 16:15:36 +01:00
|
|
|
/* No point in sending the EAPOL-Key - we will disconnect
|
|
|
|
* immediately following this. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"sending 1/4 msg of 4-Way Handshake");
|
|
|
|
/*
|
2018-08-10 12:51:04 +02:00
|
|
|
* For infrastructure BSS cases, it is better for the AP not to include
|
|
|
|
* the PMKID KDE in EAPOL-Key msg 1/4 since it could be used to initiate
|
|
|
|
* offline search for the passphrase/PSK without having to be able to
|
|
|
|
* capture a 4-way handshake from a STA that has access to the network.
|
|
|
|
*
|
|
|
|
* For IBSS cases, addition of PMKID KDE could be considered even with
|
|
|
|
* WPA2-PSK cases that use multiple PSKs, but only if there is a single
|
|
|
|
* possible PSK for this STA. However, this should not be done unless
|
|
|
|
* there is support for using that information on the supplicant side.
|
|
|
|
* The concern about exposing PMKID unnecessarily in infrastructure BSS
|
|
|
|
* cases would also apply here, but at least in the IBSS case, this
|
|
|
|
* would cover a potential real use case.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA2 &&
|
2017-09-02 00:02:15 +02:00
|
|
|
(wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) ||
|
2017-10-09 11:08:12 +02:00
|
|
|
(sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && sm->pmksa) ||
|
2017-09-02 00:02:15 +02:00
|
|
|
wpa_key_mgmt_sae(sm->wpa_key_mgmt)) &&
|
2013-07-23 20:25:21 +02:00
|
|
|
sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN) {
|
2008-02-28 02:34:43 +01:00
|
|
|
pmkid = buf;
|
|
|
|
pmkid_len = 2 + RSN_SELECTOR_LEN + PMKID_LEN;
|
|
|
|
pmkid[0] = WLAN_EID_VENDOR_SPECIFIC;
|
|
|
|
pmkid[1] = RSN_SELECTOR_LEN + PMKID_LEN;
|
|
|
|
RSN_SELECTOR_PUT(&pmkid[2], RSN_KEY_DATA_PMKID);
|
2014-11-16 14:40:02 +01:00
|
|
|
if (sm->pmksa) {
|
2018-03-23 16:45:44 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"RSN: Message 1/4 PMKID from PMKSA entry",
|
|
|
|
sm->pmksa->pmkid, PMKID_LEN);
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memcpy(&pmkid[2 + RSN_SELECTOR_LEN],
|
|
|
|
sm->pmksa->pmkid, PMKID_LEN);
|
2014-11-16 14:40:02 +01:00
|
|
|
} else if (wpa_key_mgmt_suite_b(sm->wpa_key_mgmt)) {
|
|
|
|
/* No KCK available to derive PMKID */
|
2018-03-23 16:45:44 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"RSN: No KCK available to derive PMKID for message 1/4");
|
2014-11-16 14:40:02 +01:00
|
|
|
pmkid = NULL;
|
2019-04-17 21:52:23 +02:00
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
} else if (wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
|
|
|
|
if (sm->pmkid_set) {
|
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"RSN: Message 1/4 PMKID from FILS/ERP",
|
|
|
|
sm->pmkid, PMKID_LEN);
|
|
|
|
os_memcpy(&pmkid[2 + RSN_SELECTOR_LEN],
|
|
|
|
sm->pmkid, PMKID_LEN);
|
|
|
|
} else {
|
|
|
|
/* No PMKID available */
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"RSN: No FILS/ERP PMKID available for message 1/4");
|
|
|
|
pmkid = NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
2019-04-18 17:17:07 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
} else if (wpa_key_mgmt_ft(sm->wpa_key_mgmt) &&
|
|
|
|
sm->ft_completed) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FT: No PMKID in message 1/4 when using FT protocol");
|
|
|
|
pmkid = NULL;
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2018-03-23 16:45:44 +01:00
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
} else if (wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
|
|
|
|
if (sm->pmkid_set) {
|
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"RSN: Message 1/4 PMKID from SAE",
|
|
|
|
sm->pmkid, PMKID_LEN);
|
|
|
|
os_memcpy(&pmkid[2 + RSN_SELECTOR_LEN],
|
|
|
|
sm->pmkid, PMKID_LEN);
|
|
|
|
} else {
|
|
|
|
/* No PMKID available */
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"RSN: No SAE PMKID available for message 1/4");
|
|
|
|
pmkid = NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SAE */
|
2014-11-16 14:40:02 +01:00
|
|
|
} else {
|
2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* Calculate PMKID since no PMKSA cache entry was
|
|
|
|
* available with pre-calculated PMKID.
|
|
|
|
*/
|
2015-10-14 00:18:11 +02:00
|
|
|
rsn_pmkid(sm->PMK, sm->pmk_len, sm->wpa_auth->addr,
|
2008-08-31 21:57:28 +02:00
|
|
|
sm->addr, &pmkid[2 + RSN_SELECTOR_LEN],
|
2017-09-13 16:58:29 +02:00
|
|
|
sm->wpa_key_mgmt);
|
2018-03-23 16:45:44 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"RSN: Message 1/4 PMKID derived from PMK",
|
|
|
|
&pmkid[2 + RSN_SELECTOR_LEN], PMKID_LEN);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-19 10:51:05 +01:00
|
|
|
if (!pmkid)
|
|
|
|
pmkid_len = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_send_eapol(sm->wpa_auth, sm,
|
|
|
|
WPA_KEY_INFO_ACK | WPA_KEY_INFO_KEY_TYPE, NULL,
|
|
|
|
sm->ANonce, pmkid, pmkid_len, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
AP: Extend EAPOL-Key msg 1/4 retry workaround for changing SNonce
If the 4-way handshake ends up having to retransmit the EAPOL-Key
message 1/4 due to a timeout on waiting for the response, it is possible
for the Supplicant to change SNonce between the first and second
EAPOL-Key message 2/4. This is not really desirable due to extra
complexities it causes on the Authenticator side, but some deployed
stations are doing this.
This message sequence looks like this:
AP->STA: EAPOL-Key 1/4 (replay counter 1, ANonce)
AP->STA: EAPOL-Key 1/4 (replay counter 2, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 1, SNonce 1)
AP->STA: EAPOL-Key 3/4 (replay counter 3, ANonce)
STA->AP: EAPOL-Key 2/4 (replay counter 2, SNonce 2)
followed by either:
STA->AP: EAPOL-Key 4/4 (replay counter 3 using PTK from SNonce 1)
or:
AP->STA: EAPOL-Key 3/4 (replay counter 4, ANonce)
STA->AP: EAPOL-Key 4/4 (replay counter 4, using PTK from SNonce 2)
Previously, Authenticator implementation was able to handle the cases
where SNonce 1 and SNonce 2 were identifical (i.e., Supplicant did not
update SNonce which is the wpa_supplicant behavior) and where PTK
derived using SNonce 2 was used in EAPOL-Key 4/4. However, the case of
using PTK from SNonce 1 was rejected ("WPA: received EAPOL-Key 4/4
Pairwise with unexpected replay counter" since EAPOL-Key 3/4 TX and
following second EAPOL-Key 2/4 invalidated the Replay Counter that was
used previously with the first SNonce).
This commit extends the AP/Authenticator workaround to keep both SNonce
values in memory if two EAPOL-Key 2/4 messages are received with
different SNonce values. The following EAPOL-Key 4/4 message is then
accepted whether the MIC has been calculated with the latest SNonce (the
previously existing behavior) or with the earlier SNonce (the new
extension). This makes 4-way handshake more robust with stations that
update SNonce for each transmitted EAPOL-Key 2/4 message in cases where
EAPOL-Key message 1/4 needs to be retransmitted.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
2014-11-21 16:02:00 +01:00
|
|
|
static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
|
2015-10-14 00:18:11 +02:00
|
|
|
const u8 *pmk, unsigned int pmk_len,
|
2020-01-23 19:56:51 +01:00
|
|
|
struct wpa_ptk *ptk, int force_sha256)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2019-03-17 22:51:53 +01:00
|
|
|
const u8 *z = NULL;
|
|
|
|
size_t z_len = 0;
|
2020-01-23 19:56:51 +01:00
|
|
|
int akmp;
|
2019-03-17 22:51:53 +01:00
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2019-04-18 17:17:07 +02:00
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
if (sm->ft_completed) {
|
|
|
|
u8 ptk_name[WPA_PMK_NAME_LEN];
|
|
|
|
|
|
|
|
return wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->pmk_r1_len,
|
|
|
|
sm->SNonce, sm->ANonce,
|
|
|
|
sm->addr, sm->wpa_auth->addr,
|
|
|
|
sm->pmk_r1_name,
|
|
|
|
ptk, ptk_name,
|
|
|
|
sm->wpa_key_mgmt,
|
|
|
|
sm->pairwise);
|
|
|
|
}
|
2019-04-18 23:23:43 +02:00
|
|
|
return wpa_auth_derive_ptk_ft(sm, ptk);
|
2019-04-18 17:17:07 +02:00
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2019-03-17 22:51:53 +01:00
|
|
|
#ifdef CONFIG_DPP2
|
|
|
|
if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP && sm->dpp_z) {
|
|
|
|
z = wpabuf_head(sm->dpp_z);
|
|
|
|
z_len = wpabuf_len(sm->dpp_z);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DPP2 */
|
|
|
|
|
2020-01-23 19:56:51 +01:00
|
|
|
akmp = sm->wpa_key_mgmt;
|
|
|
|
if (force_sha256)
|
2020-03-05 12:20:38 +01:00
|
|
|
akmp |= WPA_KEY_MGMT_PSK_SHA256;
|
2015-10-14 00:18:11 +02:00
|
|
|
return wpa_pmk_to_ptk(pmk, pmk_len, "Pairwise key expansion",
|
2015-01-25 15:49:18 +01:00
|
|
|
sm->wpa_auth->addr, sm->addr, sm->ANonce, snonce,
|
2020-01-23 19:56:51 +01:00
|
|
|
ptk, akmp, sm->pairwise, z, z_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-03 14:59:44 +02:00
|
|
|
#ifdef CONFIG_FILS
|
2015-09-04 23:04:21 +02:00
|
|
|
|
|
|
|
int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk,
|
2017-05-07 16:04:08 +02:00
|
|
|
size_t pmk_len, const u8 *snonce, const u8 *anonce,
|
2017-09-13 20:36:05 +02:00
|
|
|
const u8 *dhss, size_t dhss_len,
|
2017-05-07 16:04:08 +02:00
|
|
|
struct wpabuf *g_sta, struct wpabuf *g_ap)
|
2015-09-04 23:04:21 +02:00
|
|
|
{
|
|
|
|
u8 ick[FILS_ICK_MAX_LEN];
|
|
|
|
size_t ick_len;
|
|
|
|
int res;
|
2017-05-07 13:32:25 +02:00
|
|
|
u8 fils_ft[FILS_FT_MAX_LEN];
|
|
|
|
size_t fils_ft_len = 0;
|
2015-09-04 23:04:21 +02:00
|
|
|
|
|
|
|
res = fils_pmk_to_ptk(pmk, pmk_len, sm->addr, sm->wpa_auth->addr,
|
2017-09-13 20:36:05 +02:00
|
|
|
snonce, anonce, dhss, dhss_len,
|
|
|
|
&sm->PTK, ick, &ick_len,
|
2017-05-07 13:32:25 +02:00
|
|
|
sm->wpa_key_mgmt, sm->pairwise,
|
|
|
|
fils_ft, &fils_ft_len);
|
2015-09-04 23:04:21 +02:00
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
sm->PTK_valid = TRUE;
|
2017-08-25 15:24:18 +02:00
|
|
|
sm->tk_already_set = FALSE;
|
2015-09-04 23:04:21 +02:00
|
|
|
|
2017-05-07 13:32:25 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (fils_ft_len) {
|
|
|
|
struct wpa_authenticator *wpa_auth = sm->wpa_auth;
|
|
|
|
struct wpa_auth_config *conf = &wpa_auth->conf;
|
2018-06-04 14:16:54 +02:00
|
|
|
u8 pmk_r0[PMK_LEN_MAX], pmk_r0_name[WPA_PMK_NAME_LEN];
|
|
|
|
int use_sha384 = wpa_key_mgmt_sha384(sm->wpa_key_mgmt);
|
|
|
|
size_t pmk_r0_len = use_sha384 ? SHA384_MAC_LEN : PMK_LEN;
|
2017-05-07 13:32:25 +02:00
|
|
|
|
|
|
|
if (wpa_derive_pmk_r0(fils_ft, fils_ft_len,
|
|
|
|
conf->ssid, conf->ssid_len,
|
|
|
|
conf->mobility_domain,
|
|
|
|
conf->r0_key_holder,
|
|
|
|
conf->r0_key_holder_len,
|
2018-06-04 14:16:54 +02:00
|
|
|
sm->addr, pmk_r0, pmk_r0_name,
|
|
|
|
use_sha384) < 0)
|
2017-05-07 13:32:25 +02:00
|
|
|
return -1;
|
|
|
|
|
2018-06-04 14:16:54 +02:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "FILS+FT: PMK-R0",
|
|
|
|
pmk_r0, pmk_r0_len);
|
2017-05-07 13:32:25 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS+FT: PMKR0Name",
|
|
|
|
pmk_r0_name, WPA_PMK_NAME_LEN);
|
2017-05-18 15:21:50 +02:00
|
|
|
wpa_ft_store_pmk_fils(sm, pmk_r0, pmk_r0_name);
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(fils_ft, sizeof(fils_ft));
|
2019-03-13 16:24:29 +01:00
|
|
|
|
|
|
|
res = wpa_derive_pmk_r1_name(pmk_r0_name, conf->r1_key_holder,
|
|
|
|
sm->addr, sm->pmk_r1_name,
|
|
|
|
use_sha384);
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(pmk_r0, PMK_LEN_MAX);
|
2019-03-13 16:24:29 +01:00
|
|
|
if (res < 0)
|
|
|
|
return -1;
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS+FT: PMKR1Name", sm->pmk_r1_name,
|
|
|
|
WPA_PMK_NAME_LEN);
|
|
|
|
sm->pmk_r1_name_valid = 1;
|
2017-05-07 13:32:25 +02:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
|
|
|
|
2015-09-04 23:04:21 +02:00
|
|
|
res = fils_key_auth_sk(ick, ick_len, snonce, anonce,
|
|
|
|
sm->addr, sm->wpa_auth->addr,
|
2017-05-07 16:04:08 +02:00
|
|
|
g_sta ? wpabuf_head(g_sta) : NULL,
|
|
|
|
g_sta ? wpabuf_len(g_sta) : 0,
|
|
|
|
g_ap ? wpabuf_head(g_ap) : NULL,
|
|
|
|
g_ap ? wpabuf_len(g_ap) : 0,
|
2015-09-04 23:04:21 +02:00
|
|
|
sm->wpa_key_mgmt, sm->fils_key_auth_sta,
|
|
|
|
sm->fils_key_auth_ap,
|
|
|
|
&sm->fils_key_auth_len);
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(ick, sizeof(ick));
|
2015-09-09 00:27:22 +02:00
|
|
|
|
|
|
|
/* Store nonces for (Re)Association Request/Response frame processing */
|
|
|
|
os_memcpy(sm->SNonce, snonce, FILS_NONCE_LEN);
|
|
|
|
os_memcpy(sm->ANonce, anonce, FILS_NONCE_LEN);
|
|
|
|
|
2015-09-04 23:04:21 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-03 14:59:44 +02:00
|
|
|
static int wpa_aead_decrypt(struct wpa_state_machine *sm, struct wpa_ptk *ptk,
|
2015-09-03 17:18:53 +02:00
|
|
|
u8 *buf, size_t buf_len, u16 *_key_data_len)
|
2015-09-03 14:59:44 +02:00
|
|
|
{
|
|
|
|
struct ieee802_1x_hdr *hdr;
|
|
|
|
struct wpa_eapol_key *key;
|
|
|
|
u8 *pos;
|
|
|
|
u16 key_data_len;
|
|
|
|
u8 *tmp;
|
|
|
|
const u8 *aad[1];
|
|
|
|
size_t aad_len[1];
|
|
|
|
|
2015-09-03 17:18:53 +02:00
|
|
|
hdr = (struct ieee802_1x_hdr *) buf;
|
2015-09-03 14:59:44 +02:00
|
|
|
key = (struct wpa_eapol_key *) (hdr + 1);
|
|
|
|
pos = (u8 *) (key + 1);
|
|
|
|
key_data_len = WPA_GET_BE16(pos);
|
|
|
|
if (key_data_len < AES_BLOCK_SIZE ||
|
|
|
|
key_data_len > buf_len - sizeof(*hdr) - sizeof(*key) - 2) {
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"No room for AES-SIV data in the frame");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pos += 2; /* Pointing at the Encrypted Key Data field */
|
|
|
|
|
|
|
|
tmp = os_malloc(key_data_len);
|
|
|
|
if (!tmp)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* AES-SIV AAD from EAPOL protocol version field (inclusive) to
|
|
|
|
* to Key Data (exclusive). */
|
2015-09-03 17:18:53 +02:00
|
|
|
aad[0] = buf;
|
|
|
|
aad_len[0] = pos - buf;
|
2015-09-03 14:59:44 +02:00
|
|
|
if (aes_siv_decrypt(ptk->kek, ptk->kek_len, pos, key_data_len,
|
|
|
|
1, aad, aad_len, tmp) < 0) {
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"Invalid AES-SIV data in the frame");
|
|
|
|
bin_clear_free(tmp, key_data_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AEAD decryption and validation completed successfully */
|
|
|
|
key_data_len -= AES_BLOCK_SIZE;
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPA: Decrypted Key Data",
|
|
|
|
tmp, key_data_len);
|
|
|
|
|
|
|
|
/* Replace Key Data field with the decrypted version */
|
|
|
|
os_memcpy(pos, tmp, key_data_len);
|
|
|
|
pos -= 2; /* Key Data Length field */
|
|
|
|
WPA_PUT_BE16(pos, key_data_len);
|
|
|
|
bin_clear_free(tmp, key_data_len);
|
|
|
|
if (_key_data_len)
|
|
|
|
*_key_data_len = key_data_len;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-09 00:27:22 +02:00
|
|
|
|
|
|
|
|
2017-04-21 17:42:00 +02:00
|
|
|
const u8 * wpa_fils_validate_fils_session(struct wpa_state_machine *sm,
|
|
|
|
const u8 *ies, size_t ies_len,
|
|
|
|
const u8 *fils_session)
|
|
|
|
{
|
|
|
|
const u8 *ie, *end;
|
|
|
|
const u8 *session = NULL;
|
|
|
|
|
|
|
|
if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Not a FILS AKM - reject association");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify Session element */
|
|
|
|
ie = ies;
|
|
|
|
end = ((const u8 *) ie) + ies_len;
|
|
|
|
while (ie + 1 < end) {
|
|
|
|
if (ie + 2 + ie[1] > end)
|
|
|
|
break;
|
|
|
|
if (ie[0] == WLAN_EID_EXTENSION &&
|
|
|
|
ie[1] >= 1 + FILS_SESSION_LEN &&
|
|
|
|
ie[2] == WLAN_EID_EXT_FILS_SESSION) {
|
|
|
|
session = ie;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ie += 2 + ie[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: %s: Could not find FILS Session element in Assoc Req - reject",
|
|
|
|
__func__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fils_session) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: %s: Could not find FILS Session element in STA entry - reject",
|
|
|
|
__func__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(fils_session, session + 3, FILS_SESSION_LEN) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Session mismatch");
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS: Expected FILS Session",
|
|
|
|
fils_session, FILS_SESSION_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS: Received FILS Session",
|
|
|
|
session + 3, FILS_SESSION_LEN);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-21 17:42:00 +02:00
|
|
|
int wpa_fils_validate_key_confirm(struct wpa_state_machine *sm, const u8 *ies,
|
|
|
|
size_t ies_len)
|
|
|
|
{
|
|
|
|
struct ieee802_11_elems elems;
|
|
|
|
|
|
|
|
if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Failed to parse decrypted elements");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-06 12:57:54 +02:00
|
|
|
if (!elems.fils_session) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:42:00 +02:00
|
|
|
if (!elems.fils_key_confirm) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: No FILS Key Confirm element");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elems.fils_key_confirm_len != sm->fils_key_auth_len) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Unexpected Key-Auth length %d (expected %d)",
|
|
|
|
elems.fils_key_confirm_len,
|
|
|
|
(int) sm->fils_key_auth_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(elems.fils_key_confirm, sm->fils_key_auth_sta,
|
|
|
|
sm->fils_key_auth_len) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Key-Auth mismatch");
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS: Received Key-Auth",
|
|
|
|
elems.fils_key_confirm, elems.fils_key_confirm_len);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS: Expected Key-Auth",
|
|
|
|
sm->fils_key_auth_sta, sm->fils_key_auth_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-09 00:27:22 +02:00
|
|
|
int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session,
|
|
|
|
const struct ieee80211_mgmt *mgmt, size_t frame_len,
|
|
|
|
u8 *pos, size_t left)
|
|
|
|
{
|
|
|
|
u16 fc, stype;
|
|
|
|
const u8 *end, *ie_start, *ie, *session, *crypt;
|
|
|
|
const u8 *aad[5];
|
|
|
|
size_t aad_len[5];
|
|
|
|
|
|
|
|
if (!sm || !sm->PTK_valid) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: No KEK to decrypt Assocication Request frame");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Not a FILS AKM - reject association");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = ((const u8 *) mgmt) + frame_len;
|
|
|
|
fc = le_to_host16(mgmt->frame_control);
|
|
|
|
stype = WLAN_FC_GET_STYPE(fc);
|
|
|
|
if (stype == WLAN_FC_STYPE_REASSOC_REQ)
|
|
|
|
ie_start = mgmt->u.reassoc_req.variable;
|
|
|
|
else
|
|
|
|
ie_start = mgmt->u.assoc_req.variable;
|
|
|
|
ie = ie_start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find FILS Session element which is the last unencrypted element in
|
|
|
|
* the frame.
|
|
|
|
*/
|
2017-04-21 17:42:00 +02:00
|
|
|
session = wpa_fils_validate_fils_session(sm, ie, end - ie,
|
|
|
|
fils_session);
|
2015-09-09 00:27:22 +02:00
|
|
|
if (!session) {
|
2017-04-21 17:42:00 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Session validation failed");
|
2015-09-09 00:27:22 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2017-04-21 17:42:00 +02:00
|
|
|
|
2015-09-09 00:27:22 +02:00
|
|
|
crypt = session + 2 + session[1];
|
|
|
|
|
|
|
|
if (end - crypt < AES_BLOCK_SIZE) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Too short frame to include AES-SIV data");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AES-SIV AAD vectors */
|
|
|
|
|
|
|
|
/* The STA's MAC address */
|
|
|
|
aad[0] = mgmt->sa;
|
|
|
|
aad_len[0] = ETH_ALEN;
|
|
|
|
/* The AP's BSSID */
|
|
|
|
aad[1] = mgmt->da;
|
|
|
|
aad_len[1] = ETH_ALEN;
|
|
|
|
/* The STA's nonce */
|
|
|
|
aad[2] = sm->SNonce;
|
|
|
|
aad_len[2] = FILS_NONCE_LEN;
|
|
|
|
/* The AP's nonce */
|
|
|
|
aad[3] = sm->ANonce;
|
|
|
|
aad_len[3] = FILS_NONCE_LEN;
|
|
|
|
/*
|
|
|
|
* The (Re)Association Request frame from the Capability Information
|
|
|
|
* field to the FILS Session element (both inclusive).
|
|
|
|
*/
|
|
|
|
aad[4] = (const u8 *) &mgmt->u.assoc_req.capab_info;
|
2017-02-04 12:05:58 +01:00
|
|
|
aad_len[4] = crypt - aad[4];
|
2015-09-09 00:27:22 +02:00
|
|
|
|
|
|
|
if (aes_siv_decrypt(sm->PTK.kek, sm->PTK.kek_len, crypt, end - crypt,
|
2017-02-04 12:05:58 +01:00
|
|
|
5, aad, aad_len, pos + (crypt - ie_start)) < 0) {
|
2015-09-09 00:27:22 +02:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Invalid AES-SIV data in the frame");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FILS: Decrypted Association Request elements",
|
|
|
|
pos, left - AES_BLOCK_SIZE);
|
|
|
|
|
2017-04-21 17:42:00 +02:00
|
|
|
if (wpa_fils_validate_key_confirm(sm, pos, left - AES_BLOCK_SIZE) < 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Key Confirm validation failed");
|
2015-09-09 00:27:22 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return left - AES_BLOCK_SIZE;
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:43:53 +02:00
|
|
|
|
|
|
|
int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf,
|
2017-01-31 13:38:44 +01:00
|
|
|
size_t current_len, size_t max_len,
|
|
|
|
const struct wpabuf *hlp)
|
2015-09-09 14:43:53 +02:00
|
|
|
{
|
|
|
|
u8 *end = buf + max_len;
|
|
|
|
u8 *pos = buf + current_len;
|
|
|
|
struct ieee80211_mgmt *mgmt;
|
|
|
|
struct wpabuf *plain;
|
|
|
|
const u8 *aad[5];
|
|
|
|
size_t aad_len[5];
|
|
|
|
|
|
|
|
if (!sm || !sm->PTK_valid)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"FILS: Association Response frame before FILS processing",
|
|
|
|
buf, current_len);
|
|
|
|
|
|
|
|
mgmt = (struct ieee80211_mgmt *) buf;
|
|
|
|
|
|
|
|
/* AES-SIV AAD vectors */
|
|
|
|
|
|
|
|
/* The AP's BSSID */
|
|
|
|
aad[0] = mgmt->sa;
|
|
|
|
aad_len[0] = ETH_ALEN;
|
|
|
|
/* The STA's MAC address */
|
|
|
|
aad[1] = mgmt->da;
|
|
|
|
aad_len[1] = ETH_ALEN;
|
|
|
|
/* The AP's nonce */
|
|
|
|
aad[2] = sm->ANonce;
|
|
|
|
aad_len[2] = FILS_NONCE_LEN;
|
|
|
|
/* The STA's nonce */
|
|
|
|
aad[3] = sm->SNonce;
|
|
|
|
aad_len[3] = FILS_NONCE_LEN;
|
|
|
|
/*
|
|
|
|
* The (Re)Association Response frame from the Capability Information
|
|
|
|
* field (the same offset in both Association and Reassociation
|
|
|
|
* Response frames) to the FILS Session element (both inclusive).
|
|
|
|
*/
|
|
|
|
aad[4] = (const u8 *) &mgmt->u.assoc_resp.capab_info;
|
|
|
|
aad_len[4] = pos - aad[4];
|
|
|
|
|
|
|
|
/* The following elements will be encrypted with AES-SIV */
|
2017-04-21 17:42:00 +02:00
|
|
|
plain = fils_prepare_plainbuf(sm, hlp);
|
|
|
|
if (!plain) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Plain buffer prep failed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos + wpabuf_len(plain) + AES_BLOCK_SIZE > end) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"FILS: Not enough room for FILS elements");
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2017-04-21 17:42:00 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_hexdump_buf_key(MSG_DEBUG, "FILS: Association Response plaintext",
|
|
|
|
plain);
|
|
|
|
|
|
|
|
if (aes_siv_encrypt(sm->PTK.kek, sm->PTK.kek_len,
|
|
|
|
wpabuf_head(plain), wpabuf_len(plain),
|
|
|
|
5, aad, aad_len, pos) < 0) {
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2017-04-21 17:42:00 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"FILS: Encrypted Association Response elements",
|
|
|
|
pos, AES_BLOCK_SIZE + wpabuf_len(plain));
|
|
|
|
current_len += wpabuf_len(plain) + AES_BLOCK_SIZE;
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2017-04-21 17:42:00 +02:00
|
|
|
|
|
|
|
sm->fils_completed = 1;
|
|
|
|
|
|
|
|
return current_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wpabuf * fils_prepare_plainbuf(struct wpa_state_machine *sm,
|
|
|
|
const struct wpabuf *hlp)
|
|
|
|
{
|
|
|
|
struct wpabuf *plain;
|
|
|
|
u8 *len, *tmp, *tmp2;
|
|
|
|
u8 hdr[2];
|
|
|
|
u8 *gtk, dummy_gtk[32];
|
|
|
|
size_t gtk_len;
|
|
|
|
struct wpa_group *gsm;
|
2020-03-25 23:08:26 +01:00
|
|
|
size_t plain_len;
|
|
|
|
struct wpa_auth_config *conf = &sm->wpa_auth->conf;
|
2015-09-09 14:43:53 +02:00
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
plain_len = 1000 + ieee80211w_kde_len(sm);
|
|
|
|
if (conf->transition_disable)
|
|
|
|
plain_len += 2 + RSN_SELECTOR_LEN + 1;
|
|
|
|
plain = wpabuf_alloc(plain_len);
|
2015-09-09 14:43:53 +02:00
|
|
|
if (!plain)
|
2017-04-21 17:42:00 +02:00
|
|
|
return NULL;
|
2015-09-09 14:43:53 +02:00
|
|
|
|
|
|
|
/* TODO: FILS Public Key */
|
|
|
|
|
|
|
|
/* FILS Key Confirmation */
|
|
|
|
wpabuf_put_u8(plain, WLAN_EID_EXTENSION); /* Element ID */
|
|
|
|
wpabuf_put_u8(plain, 1 + sm->fils_key_auth_len); /* Length */
|
|
|
|
/* Element ID Extension */
|
|
|
|
wpabuf_put_u8(plain, WLAN_EID_EXT_FILS_KEY_CONFIRM);
|
|
|
|
wpabuf_put_data(plain, sm->fils_key_auth_ap, sm->fils_key_auth_len);
|
|
|
|
|
2017-01-31 13:38:44 +01:00
|
|
|
/* FILS HLP Container */
|
|
|
|
if (hlp)
|
|
|
|
wpabuf_put_buf(plain, hlp);
|
2015-09-09 14:43:53 +02:00
|
|
|
|
|
|
|
/* TODO: FILS IP Address Assignment */
|
|
|
|
|
|
|
|
/* Key Delivery */
|
|
|
|
gsm = sm->group;
|
|
|
|
wpabuf_put_u8(plain, WLAN_EID_EXTENSION); /* Element ID */
|
|
|
|
len = wpabuf_put(plain, 1);
|
|
|
|
wpabuf_put_u8(plain, WLAN_EID_EXT_KEY_DELIVERY);
|
|
|
|
wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN,
|
|
|
|
wpabuf_put(plain, WPA_KEY_RSC_LEN));
|
|
|
|
/* GTK KDE */
|
|
|
|
gtk = gsm->GTK[gsm->GN - 1];
|
|
|
|
gtk_len = gsm->GTK_len;
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
|
2015-09-09 14:43:53 +02:00
|
|
|
/*
|
|
|
|
* Provide unique random GTK to each STA to prevent use
|
|
|
|
* of GTK in the BSS.
|
|
|
|
*/
|
|
|
|
if (random_get_bytes(dummy_gtk, gtk_len) < 0) {
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2017-04-21 17:42:00 +02:00
|
|
|
return NULL;
|
2015-09-09 14:43:53 +02:00
|
|
|
}
|
|
|
|
gtk = dummy_gtk;
|
|
|
|
}
|
|
|
|
hdr[0] = gsm->GN & 0x03;
|
|
|
|
hdr[1] = 0;
|
|
|
|
tmp = wpabuf_put(plain, 0);
|
|
|
|
tmp2 = wpa_add_kde(tmp, RSN_KEY_DATA_GROUPKEY, hdr, 2,
|
|
|
|
gtk, gtk_len);
|
|
|
|
wpabuf_put(plain, tmp2 - tmp);
|
|
|
|
|
2020-02-17 22:08:05 +01:00
|
|
|
/* IGTK KDE and BIGTK KDE */
|
2015-09-09 14:43:53 +02:00
|
|
|
tmp = wpabuf_put(plain, 0);
|
|
|
|
tmp2 = ieee80211w_kde_add(sm, tmp);
|
|
|
|
wpabuf_put(plain, tmp2 - tmp);
|
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
if (conf->transition_disable) {
|
|
|
|
tmp = wpabuf_put(plain, 0);
|
|
|
|
tmp2 = wpa_add_kde(tmp, WFA_KEY_DATA_TRANSITION_DISABLE,
|
|
|
|
&conf->transition_disable, 1, NULL, 0);
|
|
|
|
wpabuf_put(plain, tmp2 - tmp);
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:43:53 +02:00
|
|
|
*len = (u8 *) wpabuf_put(plain, 0) - len - 1;
|
2018-08-06 21:46:36 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
if (wpa_auth_uses_ocv(sm)) {
|
|
|
|
struct wpa_channel_info ci;
|
|
|
|
u8 *pos;
|
|
|
|
|
|
|
|
if (wpa_channel_info(sm->wpa_auth, &ci) != 0) {
|
|
|
|
wpa_printf(MSG_WARNING,
|
|
|
|
"FILS: Failed to get channel info for OCI element");
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2018-08-06 21:46:36 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = wpabuf_put(plain, OCV_OCI_EXTENDED_LEN);
|
|
|
|
if (ocv_insert_extended_oci(&ci, pos) < 0) {
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2018-08-06 21:46:36 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
|
2017-04-21 17:42:00 +02:00
|
|
|
return plain;
|
2015-09-09 14:43:53 +02:00
|
|
|
}
|
|
|
|
|
2015-09-09 18:32:44 +02:00
|
|
|
|
|
|
|
int fils_set_tk(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
enum wpa_alg alg;
|
|
|
|
int klen;
|
|
|
|
|
2017-08-25 15:24:18 +02:00
|
|
|
if (!sm || !sm->PTK_valid) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: No valid PTK available to set TK");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (sm->tk_already_set) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: TK already set to the driver");
|
2015-09-09 18:32:44 +02:00
|
|
|
return -1;
|
2017-08-25 15:24:18 +02:00
|
|
|
}
|
2015-09-09 18:32:44 +02:00
|
|
|
|
|
|
|
alg = wpa_cipher_to_alg(sm->pairwise);
|
|
|
|
klen = wpa_cipher_key_len(sm->pairwise);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Configure TK to the driver");
|
|
|
|
if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
|
2020-01-04 23:10:04 +01:00
|
|
|
sm->PTK.tk, klen, KEY_FLAG_PAIRWISE_RX_TX)) {
|
2015-09-09 18:32:44 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Failed to set TK to the driver");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-08-25 15:24:18 +02:00
|
|
|
sm->tk_already_set = TRUE;
|
2015-09-09 18:32:44 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:42:00 +02:00
|
|
|
|
|
|
|
u8 * hostapd_eid_assoc_fils_session(struct wpa_state_machine *sm, u8 *buf,
|
2017-07-06 12:57:54 +02:00
|
|
|
const u8 *fils_session, struct wpabuf *hlp)
|
2017-04-21 17:42:00 +02:00
|
|
|
{
|
|
|
|
struct wpabuf *plain;
|
|
|
|
u8 *pos = buf;
|
|
|
|
|
|
|
|
/* FILS Session */
|
|
|
|
*pos++ = WLAN_EID_EXTENSION; /* Element ID */
|
|
|
|
*pos++ = 1 + FILS_SESSION_LEN; /* Length */
|
|
|
|
*pos++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
|
|
|
|
os_memcpy(pos, fils_session, FILS_SESSION_LEN);
|
|
|
|
pos += FILS_SESSION_LEN;
|
|
|
|
|
2017-07-06 12:57:54 +02:00
|
|
|
plain = fils_prepare_plainbuf(sm, hlp);
|
2017-04-21 17:42:00 +02:00
|
|
|
if (!plain) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FILS: Plain buffer prep failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(pos, wpabuf_head(plain), wpabuf_len(plain));
|
|
|
|
pos += wpabuf_len(plain);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: plain buf_len: %u", __func__,
|
|
|
|
(unsigned int) wpabuf_len(plain));
|
2019-05-26 14:53:25 +02:00
|
|
|
wpabuf_clear_free(plain);
|
2017-04-21 17:42:00 +02:00
|
|
|
sm->fils_completed = 1;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2015-09-03 14:59:44 +02:00
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
|
|
|
|
|
2018-08-06 21:46:30 +02:00
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
int get_sta_tx_parameters(struct wpa_state_machine *sm, int ap_max_chanwidth,
|
|
|
|
int ap_seg1_idx, int *bandwidth, int *seg1_idx)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = sm->wpa_auth;
|
|
|
|
|
|
|
|
if (!wpa_auth->cb->get_sta_tx_params)
|
|
|
|
return -1;
|
|
|
|
return wpa_auth->cb->get_sta_tx_params(wpa_auth->cb_ctx, sm->addr,
|
|
|
|
ap_max_chanwidth, ap_seg1_idx,
|
|
|
|
bandwidth, seg1_idx);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
|
|
|
|
{
|
2015-09-03 14:59:44 +02:00
|
|
|
struct wpa_authenticator *wpa_auth = sm->wpa_auth;
|
2008-02-28 02:34:43 +01:00
|
|
|
struct wpa_ptk PTK;
|
2015-03-19 12:14:21 +01:00
|
|
|
int ok = 0, psk_found = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
const u8 *pmk = NULL;
|
2017-10-08 15:37:32 +02:00
|
|
|
size_t pmk_len;
|
2015-09-03 14:59:44 +02:00
|
|
|
int ft;
|
|
|
|
const u8 *eapol_key_ie, *key_data, *mic;
|
|
|
|
u16 key_data_length;
|
|
|
|
size_t mic_len, eapol_key_ie_len;
|
|
|
|
struct ieee802_1x_hdr *hdr;
|
|
|
|
struct wpa_eapol_key *key;
|
|
|
|
struct wpa_eapol_ie_parse kde;
|
2019-02-23 17:54:54 +01:00
|
|
|
int vlan_id = 0;
|
2020-01-23 19:56:51 +01:00
|
|
|
int owe_ptk_workaround = !!wpa_auth->conf.owe_ptk_workaround;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING, wpa_ptk);
|
|
|
|
sm->EAPOLKeyReceived = FALSE;
|
2012-01-02 21:36:11 +01:00
|
|
|
sm->update_snonce = FALSE;
|
2015-09-03 16:24:37 +02:00
|
|
|
os_memset(&PTK, 0, sizeof(PTK));
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2017-06-17 22:48:52 +02:00
|
|
|
mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
|
2015-09-03 14:59:44 +02:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/* WPA with IEEE 802.1X: use the derived PMK from EAP
|
|
|
|
* WPA-PSK: iterate through possible PSKs and select the one matching
|
|
|
|
* the packet */
|
|
|
|
for (;;) {
|
2017-09-02 00:02:15 +02:00
|
|
|
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
|
|
|
|
!wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
|
2013-09-01 10:30:26 +02:00
|
|
|
pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
|
2019-02-14 12:34:33 +01:00
|
|
|
sm->p2p_dev_addr, pmk, &pmk_len,
|
|
|
|
&vlan_id);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (pmk == NULL)
|
|
|
|
break;
|
2015-03-19 12:14:21 +01:00
|
|
|
psk_found = 1;
|
2018-02-01 12:03:28 +01:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (wpa_key_mgmt_ft_psk(sm->wpa_key_mgmt)) {
|
|
|
|
os_memcpy(sm->xxkey, pmk, pmk_len);
|
|
|
|
sm->xxkey_len = pmk_len;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2015-10-14 00:18:11 +02:00
|
|
|
} else {
|
2008-02-28 02:34:43 +01:00
|
|
|
pmk = sm->PMK;
|
2015-10-14 00:18:11 +02:00
|
|
|
pmk_len = sm->pmk_len;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2019-04-17 21:52:23 +02:00
|
|
|
if ((!pmk || !pmk_len) && sm->pmksa) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Use PMK from PMKSA cache");
|
|
|
|
pmk = sm->pmksa->pmk;
|
|
|
|
pmk_len = sm->pmksa->pmk_len;
|
|
|
|
}
|
|
|
|
|
2020-01-23 19:56:51 +01:00
|
|
|
if (wpa_derive_ptk(sm, sm->SNonce, pmk, pmk_len, &PTK,
|
|
|
|
owe_ptk_workaround == 2) < 0)
|
2017-02-14 10:09:30 +01:00
|
|
|
break;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2015-09-03 14:59:44 +02:00
|
|
|
if (mic_len &&
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_verify_key_mic(sm->wpa_key_mgmt, pmk_len, &PTK,
|
2014-11-16 14:40:02 +01:00
|
|
|
sm->last_rx_eapol_key,
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->last_rx_eapol_key_len) == 0) {
|
2019-03-23 11:44:42 +01:00
|
|
|
if (sm->PMK != pmk) {
|
|
|
|
os_memcpy(sm->PMK, pmk, pmk_len);
|
|
|
|
sm->pmk_len = pmk_len;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
ok = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-03 14:59:44 +02:00
|
|
|
#ifdef CONFIG_FILS
|
2015-09-03 17:18:53 +02:00
|
|
|
if (!mic_len &&
|
|
|
|
wpa_aead_decrypt(sm, &PTK, sm->last_rx_eapol_key,
|
|
|
|
sm->last_rx_eapol_key_len, NULL) == 0) {
|
2015-09-03 14:59:44 +02:00
|
|
|
ok = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FILS */
|
|
|
|
|
2020-01-23 19:56:51 +01:00
|
|
|
#ifdef CONFIG_OWE
|
|
|
|
if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && pmk_len > 32 &&
|
|
|
|
owe_ptk_workaround == 1) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"OWE: Try PTK derivation workaround with SHA256");
|
|
|
|
owe_ptk_workaround = 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_OWE */
|
|
|
|
|
2018-03-02 11:13:16 +01:00
|
|
|
if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
|
|
|
|
wpa_key_mgmt_sae(sm->wpa_key_mgmt))
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"invalid MIC in msg 2/4 of 4-Way Handshake");
|
2015-03-19 12:14:21 +01:00
|
|
|
if (psk_found)
|
|
|
|
wpa_auth_psk_failure_report(sm->wpa_auth, sm->addr);
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-03 14:59:44 +02:00
|
|
|
/*
|
|
|
|
* Note: last_rx_eapol_key length fields have already been validated in
|
|
|
|
* wpa_receive().
|
|
|
|
*/
|
|
|
|
hdr = (struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
|
|
|
|
key = (struct wpa_eapol_key *) (hdr + 1);
|
|
|
|
mic = (u8 *) (key + 1);
|
|
|
|
key_data = mic + mic_len + 2;
|
|
|
|
key_data_length = WPA_GET_BE16(mic + mic_len);
|
|
|
|
if (key_data_length > sm->last_rx_eapol_key_len - sizeof(*hdr) -
|
|
|
|
sizeof(*key) - mic_len - 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wpa_parse_kde_ies(key_data, key_data_length, &kde) < 0) {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key msg 2/4 with invalid Key Data contents");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (kde.rsn_ie) {
|
|
|
|
eapol_key_ie = kde.rsn_ie;
|
|
|
|
eapol_key_ie_len = kde.rsn_ie_len;
|
|
|
|
} else if (kde.osen) {
|
|
|
|
eapol_key_ie = kde.osen;
|
|
|
|
eapol_key_ie_len = kde.osen_len;
|
|
|
|
} else {
|
|
|
|
eapol_key_ie = kde.wpa_ie;
|
|
|
|
eapol_key_ie_len = kde.wpa_ie_len;
|
|
|
|
}
|
|
|
|
ft = sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt);
|
|
|
|
if (sm->wpa_ie == NULL ||
|
|
|
|
wpa_compare_rsn_ie(ft, sm->wpa_ie, sm->wpa_ie_len,
|
|
|
|
eapol_key_ie, eapol_key_ie_len)) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"WPA IE from (Re)AssocReq did not match with msg 2/4");
|
|
|
|
if (sm->wpa_ie) {
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA IE in AssocReq",
|
|
|
|
sm->wpa_ie, sm->wpa_ie_len);
|
|
|
|
}
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA IE in msg 2/4",
|
|
|
|
eapol_key_ie, eapol_key_ie_len);
|
|
|
|
/* MLME-DEAUTHENTICATE.request */
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_sta_disconnect(wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
2015-09-03 14:59:44 +02:00
|
|
|
return;
|
2019-10-17 23:17:51 +02:00
|
|
|
}
|
|
|
|
if ((!sm->rsnxe && kde.rsnxe) ||
|
|
|
|
(sm->rsnxe && !kde.rsnxe) ||
|
|
|
|
(sm->rsnxe && kde.rsnxe &&
|
|
|
|
(sm->rsnxe_len != kde.rsnxe_len ||
|
|
|
|
os_memcmp(sm->rsnxe, kde.rsnxe, sm->rsnxe_len) != 0))) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"RSNXE from (Re)AssocReq did not match the one in EAPOL-Key msg 2/4");
|
|
|
|
wpa_hexdump(MSG_DEBUG, "RSNXE in AssocReq",
|
|
|
|
sm->rsnxe, sm->rsnxe_len);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "RSNXE in EAPOL-Key msg 2/4",
|
|
|
|
kde.rsnxe, kde.rsnxe_len);
|
|
|
|
/* MLME-DEAUTHENTICATE.request */
|
|
|
|
wpa_sta_disconnect(wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
return;
|
2015-09-03 14:59:44 +02:00
|
|
|
}
|
2018-08-06 21:46:31 +02:00
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
if (wpa_auth_uses_ocv(sm)) {
|
|
|
|
struct wpa_channel_info ci;
|
|
|
|
int tx_chanwidth;
|
|
|
|
int tx_seg1_idx;
|
|
|
|
|
|
|
|
if (wpa_channel_info(wpa_auth, &ci) != 0) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"Failed to get channel info to validate received OCI in EAPOL-Key 2/4");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_sta_tx_parameters(sm,
|
|
|
|
channel_width_to_int(ci.chanwidth),
|
|
|
|
ci.seg1_idx, &tx_chanwidth,
|
|
|
|
&tx_seg1_idx) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ocv_verify_tx_params(kde.oci, kde.oci_len, &ci,
|
|
|
|
tx_chanwidth, tx_seg1_idx) != 0) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
ocv_errorstr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_OCV */
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2015-09-03 14:59:44 +02:00
|
|
|
if (ft && ft_check_msg_2_of_4(wpa_auth, sm, &kde) < 0) {
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_sta_disconnect(wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
2015-09-03 14:59:44 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2015-09-03 14:59:44 +02:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (kde.ip_addr_req && kde.ip_addr_req[0] &&
|
|
|
|
wpa_auth->ip_pool && WPA_GET_BE32(sm->ip_addr) == 0) {
|
|
|
|
int idx;
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"P2P: IP address requested in EAPOL-Key exchange");
|
|
|
|
idx = bitfield_get_first_zero(wpa_auth->ip_pool);
|
|
|
|
if (idx >= 0) {
|
|
|
|
u32 start = WPA_GET_BE32(wpa_auth->conf.ip_addr_start);
|
|
|
|
bitfield_set(wpa_auth->ip_pool, idx);
|
|
|
|
WPA_PUT_BE32(sm->ip_addr, start + idx);
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"P2P: Assigned IP address %u.%u.%u.%u to "
|
|
|
|
MACSTR, sm->ip_addr[0], sm->ip_addr[1],
|
|
|
|
sm->ip_addr[2], sm->ip_addr[3],
|
|
|
|
MAC2STR(sm->addr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-07 20:04:13 +02:00
|
|
|
if (sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
/*
|
|
|
|
* Verify that PMKR1Name from EAPOL-Key message 2/4 matches
|
|
|
|
* with the value we derived.
|
|
|
|
*/
|
2014-06-29 19:15:37 +02:00
|
|
|
if (os_memcmp_const(sm->sup_pmk_r1_name, sm->pmk_r1_name,
|
|
|
|
WPA_PMK_NAME_LEN) != 0) {
|
2010-04-07 20:04:13 +02:00
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"PMKR1Name mismatch in FT 4-way "
|
|
|
|
"handshake");
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from "
|
|
|
|
"Supplicant",
|
|
|
|
sm->sup_pmk_r1_name, WPA_PMK_NAME_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "FT: Derived PMKR1Name",
|
|
|
|
sm->pmk_r1_name, WPA_PMK_NAME_LEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2010-04-07 20:04:13 +02:00
|
|
|
|
2019-02-14 12:34:33 +01:00
|
|
|
if (vlan_id && wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
|
|
|
|
wpa_auth_update_vlan(wpa_auth, sm->addr, vlan_id) < 0) {
|
|
|
|
wpa_sta_disconnect(wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-29 16:39:12 +02:00
|
|
|
sm->pending_1_of_4_timeout = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
|
|
|
|
|
2008-08-31 21:57:28 +02:00
|
|
|
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
/* PSK may have changed from the previous choice, so update
|
|
|
|
* state machine data based on whatever PSK was selected here.
|
|
|
|
*/
|
|
|
|
os_memcpy(sm->PMK, pmk, PMK_LEN);
|
2015-10-14 00:18:11 +02:00
|
|
|
sm->pmk_len = PMK_LEN;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sm->MICVerified = TRUE;
|
|
|
|
|
|
|
|
os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
|
2019-05-25 23:47:17 +02:00
|
|
|
forced_memzero(&PTK, sizeof(PTK));
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->PTK_valid = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, PTKCALCNEGOTIATING2)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING2, wpa_ptk);
|
|
|
|
sm->TimeoutCtr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ieee80211w_kde_len(struct wpa_state_machine *sm)
|
|
|
|
{
|
2020-02-17 22:08:05 +01:00
|
|
|
size_t len = 0;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->mgmt_frame_prot) {
|
2020-02-17 22:08:05 +01:00
|
|
|
len += 2 + RSN_SELECTOR_LEN + WPA_IGTK_KDE_PREFIX_LEN;
|
|
|
|
len += wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
|
|
|
|
}
|
|
|
|
if (sm->mgmt_frame_prot && sm->wpa_auth->conf.beacon_prot) {
|
|
|
|
len += 2 + RSN_SELECTOR_LEN + WPA_BIGTK_KDE_PREFIX_LEN;
|
|
|
|
len += wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 22:08:05 +01:00
|
|
|
return len;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos)
|
|
|
|
{
|
|
|
|
struct wpa_igtk_kde igtk;
|
2020-02-17 22:08:05 +01:00
|
|
|
struct wpa_bigtk_kde bigtk;
|
2008-02-28 02:34:43 +01:00
|
|
|
struct wpa_group *gsm = sm->group;
|
2013-10-26 12:30:28 +02:00
|
|
|
u8 rsc[WPA_KEY_RSC_LEN];
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf = &sm->wpa_auth->conf;
|
|
|
|
size_t len = wpa_cipher_key_len(conf->group_mgmt_cipher);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (!sm->mgmt_frame_prot)
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
igtk.keyid[0] = gsm->GN_igtk;
|
|
|
|
igtk.keyid[1] = 0;
|
2010-03-30 07:57:10 +02:00
|
|
|
if (gsm->wpa_group_state != WPA_GROUP_SETKEYSDONE ||
|
2013-10-26 12:30:28 +02:00
|
|
|
wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, rsc) < 0)
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memset(igtk.pn, 0, sizeof(igtk.pn));
|
2013-10-26 12:30:28 +02:00
|
|
|
else
|
|
|
|
os_memcpy(igtk.pn, rsc, sizeof(igtk.pn));
|
2014-03-12 19:26:37 +01:00
|
|
|
os_memcpy(igtk.igtk, gsm->IGTK[gsm->GN_igtk - 4], len);
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
|
2011-10-18 11:38:32 +02:00
|
|
|
/*
|
|
|
|
* Provide unique random IGTK to each STA to prevent use of
|
|
|
|
* IGTK in the BSS.
|
|
|
|
*/
|
2014-03-12 19:26:37 +01:00
|
|
|
if (random_get_bytes(igtk.igtk, len) < 0)
|
2011-10-18 11:38:32 +02:00
|
|
|
return pos;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_IGTK,
|
2014-03-12 19:26:37 +01:00
|
|
|
(const u8 *) &igtk, WPA_IGTK_KDE_PREFIX_LEN + len,
|
|
|
|
NULL, 0);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
if (!conf->beacon_prot)
|
2020-02-17 22:08:05 +01:00
|
|
|
return pos;
|
|
|
|
|
|
|
|
bigtk.keyid[0] = gsm->GN_bigtk;
|
|
|
|
bigtk.keyid[1] = 0;
|
|
|
|
if (gsm->wpa_group_state != WPA_GROUP_SETKEYSDONE ||
|
|
|
|
wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_bigtk, rsc) < 0)
|
|
|
|
os_memset(bigtk.pn, 0, sizeof(bigtk.pn));
|
|
|
|
else
|
|
|
|
os_memcpy(bigtk.pn, rsc, sizeof(bigtk.pn));
|
|
|
|
os_memcpy(bigtk.bigtk, gsm->BIGTK[gsm->GN_bigtk - 6], len);
|
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_BIGTK,
|
|
|
|
(const u8 *) &bigtk, WPA_BIGTK_KDE_PREFIX_LEN + len,
|
|
|
|
NULL, 0);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-06 21:46:27 +02:00
|
|
|
static int ocv_oci_len(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
if (wpa_auth_uses_ocv(sm))
|
|
|
|
return OCV_OCI_KDE_LEN;
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ocv_oci_add(struct wpa_state_machine *sm, u8 **argpos)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
struct wpa_channel_info ci;
|
|
|
|
|
|
|
|
if (!wpa_auth_uses_ocv(sm))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (wpa_channel_info(sm->wpa_auth, &ci) != 0) {
|
|
|
|
wpa_printf(MSG_WARNING,
|
|
|
|
"Failed to get channel info for OCI element");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ocv_insert_oci_kde(&ci, argpos);
|
|
|
|
#else /* CONFIG_OCV */
|
|
|
|
return 0;
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-07 15:39:36 +01:00
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
static u8 * replace_ie(const char *name, const u8 *old_buf, size_t *len, u8 eid,
|
|
|
|
const u8 *ie, size_t ie_len)
|
|
|
|
{
|
|
|
|
const u8 *elem;
|
|
|
|
u8 *buf;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "TESTING: %s EAPOL override", name);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "TESTING: wpa_ie before override",
|
|
|
|
old_buf, *len);
|
|
|
|
buf = os_malloc(*len + ie_len);
|
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
os_memcpy(buf, old_buf, *len);
|
|
|
|
elem = get_ie(buf, *len, eid);
|
|
|
|
if (elem) {
|
|
|
|
u8 elem_len = 2 + elem[1];
|
|
|
|
|
|
|
|
os_memmove((void *) elem, elem + elem_len,
|
|
|
|
*len - (elem - buf) - elem_len);
|
|
|
|
*len -= elem_len;
|
|
|
|
}
|
|
|
|
os_memcpy(buf + *len, ie, ie_len);
|
|
|
|
*len += ie_len;
|
|
|
|
wpa_hexdump(MSG_DEBUG, "TESTING: wpa_ie after EAPOL override",
|
|
|
|
buf, *len);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
|
|
|
|
{
|
2019-12-07 15:53:08 +01:00
|
|
|
u8 rsc[WPA_KEY_RSC_LEN], *_rsc, *gtk, *kde = NULL, *pos, dummy_gtk[32];
|
2020-03-07 15:39:36 +01:00
|
|
|
size_t gtk_len, kde_len, wpa_ie_len;
|
2008-02-28 02:34:43 +01:00
|
|
|
struct wpa_group *gsm = sm->group;
|
|
|
|
u8 *wpa_ie;
|
2020-03-07 15:39:36 +01:00
|
|
|
int secure, gtkidx, encr = 0;
|
2020-03-07 15:45:52 +01:00
|
|
|
u8 *wpa_ie_buf = NULL, *wpa_ie_buf2 = NULL;
|
2020-03-20 20:04:31 +01:00
|
|
|
u8 hdr[2];
|
2020-03-25 23:08:26 +01:00
|
|
|
struct wpa_auth_config *conf = &sm->wpa_auth->conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
SM_ENTRY_MA(WPA_PTK, PTKINITNEGOTIATING, wpa_ptk);
|
|
|
|
sm->TimeoutEvt = FALSE;
|
2008-12-18 16:15:36 +01:00
|
|
|
|
|
|
|
sm->TimeoutCtr++;
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->wpa_disable_eapol_key_retries && sm->TimeoutCtr > 1) {
|
2017-10-16 17:37:43 +02:00
|
|
|
/* Do not allow retransmission of EAPOL-Key msg 3/4 */
|
|
|
|
return;
|
|
|
|
}
|
2020-03-28 18:29:12 +01:00
|
|
|
if (sm->TimeoutCtr > conf->wpa_pairwise_update_count) {
|
2008-12-18 16:15:36 +01:00
|
|
|
/* No point in sending the EAPOL-Key - we will disconnect
|
|
|
|
* immediately following this. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-10 20:42:54 +02:00
|
|
|
/* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
|
2020-02-17 22:08:05 +01:00
|
|
|
GTK[GN], IGTK, [BIGTK], [FTIE], [TIE * 2])
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
os_memset(rsc, 0, WPA_KEY_RSC_LEN);
|
|
|
|
wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
|
2010-04-10 20:42:54 +02:00
|
|
|
/* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_ie = sm->wpa_auth->wpa_ie;
|
|
|
|
wpa_ie_len = sm->wpa_auth->wpa_ie_len;
|
2020-03-28 18:29:12 +01:00
|
|
|
if (sm->wpa == WPA_VERSION_WPA && (conf->wpa & WPA_PROTO_RSN) &&
|
2020-03-07 15:39:36 +01:00
|
|
|
wpa_ie_len > wpa_ie[1] + 2U && wpa_ie[0] == WLAN_EID_RSN) {
|
2014-12-12 13:03:36 +01:00
|
|
|
/* WPA-only STA, remove RSN IE and possible MDIE */
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_ie = wpa_ie + wpa_ie[1] + 2;
|
2014-12-12 13:03:36 +01:00
|
|
|
if (wpa_ie[0] == WLAN_EID_MOBILITY_DOMAIN)
|
|
|
|
wpa_ie = wpa_ie + wpa_ie[1] + 2;
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_ie_len = wpa_ie[1] + 2;
|
|
|
|
}
|
2019-12-07 15:53:08 +01:00
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->rsne_override_eapol_set) {
|
2020-03-07 15:45:52 +01:00
|
|
|
wpa_ie_buf2 = replace_ie(
|
|
|
|
"RSNE", wpa_ie, &wpa_ie_len, WLAN_EID_RSN,
|
2020-03-28 18:29:12 +01:00
|
|
|
conf->rsne_override_eapol,
|
|
|
|
conf->rsne_override_eapol_len);
|
2020-03-07 15:45:52 +01:00
|
|
|
if (!wpa_ie_buf2)
|
|
|
|
goto done;
|
|
|
|
wpa_ie = wpa_ie_buf2;
|
|
|
|
}
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->rsnxe_override_eapol_set) {
|
2020-03-07 15:39:36 +01:00
|
|
|
wpa_ie_buf = replace_ie(
|
|
|
|
"RSNXE", wpa_ie, &wpa_ie_len, WLAN_EID_RSNX,
|
2020-03-28 18:29:12 +01:00
|
|
|
conf->rsnxe_override_eapol,
|
|
|
|
conf->rsnxe_override_eapol_len);
|
2019-12-07 15:53:08 +01:00
|
|
|
if (!wpa_ie_buf)
|
2020-03-07 15:39:36 +01:00
|
|
|
goto done;
|
2019-12-07 15:53:08 +01:00
|
|
|
wpa_ie = wpa_ie_buf;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"sending 3/4 msg of 4-Way Handshake");
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA2) {
|
2020-03-20 20:04:31 +01:00
|
|
|
if (sm->use_ext_key_id && sm->TimeoutCtr == 1 &&
|
|
|
|
wpa_auth_set_key(sm->wpa_auth, 0,
|
|
|
|
wpa_cipher_to_alg(sm->pairwise),
|
|
|
|
sm->addr,
|
|
|
|
sm->keyidx_active, sm->PTK.tk,
|
|
|
|
wpa_cipher_key_len(sm->pairwise),
|
|
|
|
KEY_FLAG_PAIRWISE_RX)) {
|
|
|
|
wpa_sta_disconnect(sm->wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/* WPA2 send GTK in the 4-way handshake */
|
|
|
|
secure = 1;
|
|
|
|
gtk = gsm->GTK[gsm->GN - 1];
|
|
|
|
gtk_len = gsm->GTK_len;
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->disable_gtk ||
|
2018-05-29 19:09:53 +02:00
|
|
|
sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
|
2011-10-18 11:38:32 +02:00
|
|
|
/*
|
|
|
|
* Provide unique random GTK to each STA to prevent use
|
|
|
|
* of GTK in the BSS.
|
|
|
|
*/
|
|
|
|
if (random_get_bytes(dummy_gtk, gtk_len) < 0)
|
2019-12-07 15:53:08 +01:00
|
|
|
goto done;
|
2011-10-18 11:38:32 +02:00
|
|
|
gtk = dummy_gtk;
|
|
|
|
}
|
2019-09-15 22:08:21 +02:00
|
|
|
gtkidx = gsm->GN;
|
2008-02-28 02:34:43 +01:00
|
|
|
_rsc = rsc;
|
|
|
|
encr = 1;
|
|
|
|
} else {
|
|
|
|
/* WPA does not include GTK in msg 3/4 */
|
|
|
|
secure = 0;
|
|
|
|
gtk = NULL;
|
|
|
|
gtk_len = 0;
|
|
|
|
_rsc = NULL;
|
2011-11-17 21:59:31 +01:00
|
|
|
if (sm->rx_eapol_key_secure) {
|
|
|
|
/*
|
|
|
|
* It looks like Windows 7 supplicant tries to use
|
|
|
|
* Secure bit in msg 2/4 after having reported Michael
|
|
|
|
* MIC failure and it then rejects the 4-way handshake
|
|
|
|
* if msg 3/4 does not set Secure bit. Work around this
|
|
|
|
* by setting the Secure bit here even in the case of
|
|
|
|
* WPA if the supplicant used it first.
|
|
|
|
*/
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
2011-11-17 22:05:19 +01:00
|
|
|
"STA used Secure bit in WPA msg 2/4 - "
|
|
|
|
"set Secure for 3/4 as workaround");
|
2011-11-17 21:59:31 +01:00
|
|
|
secure = 1;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:46:27 +02:00
|
|
|
kde_len = wpa_ie_len + ieee80211w_kde_len(sm) + ocv_oci_len(sm);
|
2020-03-20 20:04:31 +01:00
|
|
|
|
|
|
|
if (sm->use_ext_key_id)
|
|
|
|
kde_len += 2 + RSN_SELECTOR_LEN + 2;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (gtk)
|
|
|
|
kde_len += 2 + RSN_SELECTOR_LEN + 2 + gtk_len;
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-10 20:42:54 +02:00
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
kde_len += 2 + PMKID_LEN; /* PMKR1Name into RSN IE */
|
|
|
|
kde_len += 300; /* FTIE + 2 * TIE */
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2013-03-16 18:13:31 +01:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (WPA_GET_BE32(sm->ip_addr) > 0)
|
|
|
|
kde_len += 2 + RSN_SELECTOR_LEN + 3 * 4;
|
|
|
|
#endif /* CONFIG_P2P */
|
2020-03-25 23:08:26 +01:00
|
|
|
|
|
|
|
if (conf->transition_disable)
|
|
|
|
kde_len += 2 + RSN_SELECTOR_LEN + 1;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
kde = os_malloc(kde_len);
|
|
|
|
if (kde == NULL)
|
2019-12-07 15:53:08 +01:00
|
|
|
goto done;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
pos = kde;
|
|
|
|
os_memcpy(pos, wpa_ie, wpa_ie_len);
|
|
|
|
pos += wpa_ie_len;
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-07 20:04:13 +02:00
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
2015-12-09 23:06:06 +01:00
|
|
|
int res;
|
|
|
|
size_t elen;
|
|
|
|
|
|
|
|
elen = pos - kde;
|
|
|
|
res = wpa_insert_pmkid(kde, &elen, sm->pmk_r1_name);
|
2010-04-07 20:04:13 +02:00
|
|
|
if (res < 0) {
|
|
|
|
wpa_printf(MSG_ERROR, "FT: Failed to insert "
|
|
|
|
"PMKR1Name into RSN IE in EAPOL-Key data");
|
2019-12-07 15:53:08 +01:00
|
|
|
goto done;
|
2010-04-07 20:04:13 +02:00
|
|
|
}
|
2015-12-09 23:06:06 +01:00
|
|
|
pos -= wpa_ie_len;
|
|
|
|
pos += elen;
|
2010-04-07 20:04:13 +02:00
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2020-03-20 20:04:31 +01:00
|
|
|
hdr[1] = 0;
|
|
|
|
|
|
|
|
if (sm->use_ext_key_id) {
|
|
|
|
hdr[0] = sm->keyidx_active & 0x01;
|
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_KEYID, hdr, 2, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (gtk) {
|
2019-09-15 22:08:21 +02:00
|
|
|
hdr[0] = gtkidx & 0x03;
|
2008-02-28 02:34:43 +01:00
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
|
|
|
|
gtk, gtk_len);
|
|
|
|
}
|
|
|
|
pos = ieee80211w_kde_add(sm, pos);
|
2019-12-07 15:53:08 +01:00
|
|
|
if (ocv_oci_add(sm, &pos) < 0)
|
|
|
|
goto done;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2010-04-10 20:42:54 +02:00
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
int res;
|
|
|
|
|
2015-12-09 23:12:59 +01:00
|
|
|
if (sm->assoc_resp_ftie &&
|
|
|
|
kde + kde_len - pos >= 2 + sm->assoc_resp_ftie[1]) {
|
|
|
|
os_memcpy(pos, sm->assoc_resp_ftie,
|
|
|
|
2 + sm->assoc_resp_ftie[1]);
|
|
|
|
res = 2 + sm->assoc_resp_ftie[1];
|
|
|
|
} else {
|
2018-06-05 00:31:43 +02:00
|
|
|
int use_sha384 = wpa_key_mgmt_sha384(sm->wpa_key_mgmt);
|
|
|
|
|
|
|
|
res = wpa_write_ftie(conf, use_sha384,
|
|
|
|
conf->r0_key_holder,
|
2015-12-09 23:12:59 +01:00
|
|
|
conf->r0_key_holder_len,
|
|
|
|
NULL, NULL, pos,
|
|
|
|
kde + kde_len - pos,
|
2020-03-20 20:23:48 +01:00
|
|
|
NULL, 0, 0);
|
2015-12-09 23:12:59 +01:00
|
|
|
}
|
2010-04-10 20:42:54 +02:00
|
|
|
if (res < 0) {
|
|
|
|
wpa_printf(MSG_ERROR, "FT: Failed to insert FTIE "
|
|
|
|
"into EAPOL-Key Key Data");
|
2019-12-07 15:53:08 +01:00
|
|
|
goto done;
|
2010-04-10 20:42:54 +02:00
|
|
|
}
|
|
|
|
pos += res;
|
|
|
|
|
|
|
|
/* TIE[ReassociationDeadline] (TU) */
|
|
|
|
*pos++ = WLAN_EID_TIMEOUT_INTERVAL;
|
|
|
|
*pos++ = 5;
|
|
|
|
*pos++ = WLAN_TIMEOUT_REASSOC_DEADLINE;
|
|
|
|
WPA_PUT_LE32(pos, conf->reassociation_deadline);
|
|
|
|
pos += 4;
|
|
|
|
|
|
|
|
/* TIE[KeyLifetime] (seconds) */
|
|
|
|
*pos++ = WLAN_EID_TIMEOUT_INTERVAL;
|
|
|
|
*pos++ = 5;
|
|
|
|
*pos++ = WLAN_TIMEOUT_KEY_LIFETIME;
|
2017-05-18 15:21:50 +02:00
|
|
|
WPA_PUT_LE32(pos, conf->r0_key_lifetime);
|
2010-04-10 20:42:54 +02:00
|
|
|
pos += 4;
|
|
|
|
}
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2013-03-16 18:13:31 +01:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (WPA_GET_BE32(sm->ip_addr) > 0) {
|
|
|
|
u8 addr[3 * 4];
|
|
|
|
os_memcpy(addr, sm->ip_addr, 4);
|
2020-03-28 18:29:12 +01:00
|
|
|
os_memcpy(addr + 4, conf->ip_addr_mask, 4);
|
|
|
|
os_memcpy(addr + 8, conf->ip_addr_go, 4);
|
2013-03-16 18:13:31 +01:00
|
|
|
pos = wpa_add_kde(pos, WFA_KEY_DATA_IP_ADDR_ALLOC,
|
|
|
|
addr, sizeof(addr), NULL, 0);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
2010-04-10 20:42:54 +02:00
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
if (conf->transition_disable)
|
|
|
|
pos = wpa_add_kde(pos, WFA_KEY_DATA_TRANSITION_DISABLE,
|
|
|
|
&conf->transition_disable, 1, NULL, 0);
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_send_eapol(sm->wpa_auth, sm,
|
2015-09-03 16:24:37 +02:00
|
|
|
(secure ? WPA_KEY_INFO_SECURE : 0) |
|
2017-06-17 22:48:52 +02:00
|
|
|
(wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
|
|
|
|
WPA_KEY_INFO_MIC : 0) |
|
2008-02-28 02:34:43 +01:00
|
|
|
WPA_KEY_INFO_ACK | WPA_KEY_INFO_INSTALL |
|
|
|
|
WPA_KEY_INFO_KEY_TYPE,
|
2019-09-15 22:08:21 +02:00
|
|
|
_rsc, sm->ANonce, kde, pos - kde, 0, encr);
|
2019-12-07 15:53:08 +01:00
|
|
|
done:
|
2008-02-28 02:34:43 +01:00
|
|
|
os_free(kde);
|
2019-12-07 15:53:08 +01:00
|
|
|
os_free(wpa_ie_buf);
|
2020-03-07 15:45:52 +01:00
|
|
|
os_free(wpa_ie_buf2);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK, PTKINITDONE)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk);
|
|
|
|
sm->EAPOLKeyReceived = FALSE;
|
|
|
|
if (sm->Pair) {
|
2012-08-30 10:53:54 +02:00
|
|
|
enum wpa_alg alg = wpa_cipher_to_alg(sm->pairwise);
|
|
|
|
int klen = wpa_cipher_key_len(sm->pairwise);
|
2020-03-20 20:04:31 +01:00
|
|
|
int res;
|
|
|
|
|
|
|
|
if (sm->use_ext_key_id)
|
|
|
|
res = wpa_auth_set_key(sm->wpa_auth, 0, 0, sm->addr,
|
|
|
|
sm->keyidx_active, NULL, 0,
|
|
|
|
KEY_FLAG_PAIRWISE_RX_TX_MODIFY);
|
|
|
|
else
|
|
|
|
res = wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr,
|
|
|
|
0, sm->PTK.tk, klen,
|
|
|
|
KEY_FLAG_PAIRWISE_RX_TX);
|
|
|
|
if (res) {
|
2017-06-17 22:48:52 +02:00
|
|
|
wpa_sta_disconnect(sm->wpa_auth, sm->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
|
|
|
|
sm->pairwise_set = TRUE;
|
|
|
|
|
2019-04-17 21:52:23 +02:00
|
|
|
wpa_auth_set_ptk_rekey_timer(sm);
|
2008-11-06 18:57:21 +01:00
|
|
|
|
2017-03-11 23:32:23 +01:00
|
|
|
if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
|
2017-06-17 22:48:52 +02:00
|
|
|
sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP ||
|
2017-03-11 23:32:23 +01:00
|
|
|
sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
|
|
|
|
WPA_EAPOL_authorized, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 /* IBSS == TRUE */) {
|
|
|
|
sm->keycount++;
|
|
|
|
if (sm->keycount == 2) {
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
|
|
|
|
WPA_EAPOL_portValid, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid,
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyAvailable, 0);
|
|
|
|
wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyDone, 1);
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA)
|
|
|
|
sm->PInitAKeys = TRUE;
|
|
|
|
else
|
|
|
|
sm->has_GTK = TRUE;
|
|
|
|
wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"pairwise key handshake completed (%s)",
|
|
|
|
sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
|
|
|
|
|
2016-10-27 14:18:32 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_ft_push_pmk_r1(sm->wpa_auth, sm->addr);
|
2016-10-27 14:18:32 +02:00
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STEP(WPA_PTK)
|
|
|
|
{
|
|
|
|
struct wpa_authenticator *wpa_auth = sm->wpa_auth;
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf = &wpa_auth->conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (sm->Init)
|
|
|
|
SM_ENTER(WPA_PTK, INITIALIZE);
|
|
|
|
else if (sm->Disconnect
|
2011-02-24 16:35:59 +01:00
|
|
|
/* || FIX: dot11RSNAConfigSALifetime timeout */) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"WPA_PTK: sm->Disconnect");
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, DISCONNECT);
|
2011-02-24 16:35:59 +01:00
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
else if (sm->DeauthenticationRequest)
|
|
|
|
SM_ENTER(WPA_PTK, DISCONNECTED);
|
|
|
|
else if (sm->AuthenticationRequest)
|
|
|
|
SM_ENTER(WPA_PTK, AUTHENTICATION);
|
|
|
|
else if (sm->ReAuthenticationRequest)
|
|
|
|
SM_ENTER(WPA_PTK, AUTHENTICATION2);
|
2017-10-01 11:32:57 +02:00
|
|
|
else if (sm->PTKRequest) {
|
|
|
|
if (wpa_auth_sm_ptk_update(sm) < 0)
|
|
|
|
SM_ENTER(WPA_PTK, DISCONNECTED);
|
|
|
|
else
|
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
|
|
|
} else switch (sm->wpa_ptk_state) {
|
2008-02-28 02:34:43 +01:00
|
|
|
case WPA_PTK_INITIALIZE:
|
|
|
|
break;
|
|
|
|
case WPA_PTK_DISCONNECT:
|
|
|
|
SM_ENTER(WPA_PTK, DISCONNECTED);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_DISCONNECTED:
|
|
|
|
SM_ENTER(WPA_PTK, INITIALIZE);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_AUTHENTICATION:
|
|
|
|
SM_ENTER(WPA_PTK, AUTHENTICATION2);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_AUTHENTICATION2:
|
2008-08-31 21:57:28 +02:00
|
|
|
if (wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_get_eapol(wpa_auth, sm->addr,
|
2008-02-28 02:34:43 +01:00
|
|
|
WPA_EAPOL_keyRun) > 0)
|
|
|
|
SM_ENTER(WPA_PTK, INITPMK);
|
2017-03-11 23:32:23 +01:00
|
|
|
else if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
|
|
|
|
sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE
|
2008-02-28 02:34:43 +01:00
|
|
|
/* FIX: && 802.1X::keyRun */)
|
|
|
|
SM_ENTER(WPA_PTK, INITPSK);
|
2017-06-17 22:48:52 +02:00
|
|
|
else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP)
|
|
|
|
SM_ENTER(WPA_PTK, INITPMK);
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
case WPA_PTK_INITPMK:
|
2020-03-28 18:29:12 +01:00
|
|
|
if (wpa_auth_get_eapol(wpa_auth, sm->addr,
|
2017-06-17 22:48:52 +02:00
|
|
|
WPA_EAPOL_keyAvailable) > 0) {
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
2017-06-17 22:48:52 +02:00
|
|
|
#ifdef CONFIG_DPP
|
|
|
|
} else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP && sm->pmksa) {
|
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
|
|
|
#endif /* CONFIG_DPP */
|
|
|
|
} else {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth->dot11RSNA4WayHandshakeFailures++;
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
2011-02-24 16:35:59 +01:00
|
|
|
"INITPMK - keyAvailable = false");
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, DISCONNECT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WPA_PTK_INITPSK:
|
2020-03-28 18:29:12 +01:00
|
|
|
if (wpa_auth_get_psk(wpa_auth, sm->addr, sm->p2p_dev_addr,
|
2019-02-14 12:34:33 +01:00
|
|
|
NULL, NULL, NULL)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
2017-09-02 00:02:15 +02:00
|
|
|
#ifdef CONFIG_SAE
|
|
|
|
} else if (wpa_auth_uses_sae(sm) && sm->pmksa) {
|
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
|
|
|
#endif /* CONFIG_SAE */
|
|
|
|
} else {
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
2008-02-28 02:34:43 +01:00
|
|
|
"no PSK configured for the STA");
|
|
|
|
wpa_auth->dot11RSNA4WayHandshakeFailures++;
|
|
|
|
SM_ENTER(WPA_PTK, DISCONNECT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WPA_PTK_PTKSTART:
|
|
|
|
if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
|
|
|
|
sm->EAPOLKeyPairwise)
|
|
|
|
SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
|
2020-03-28 18:29:12 +01:00
|
|
|
else if (sm->TimeoutCtr > conf->wpa_pairwise_update_count) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth->dot11RSNA4WayHandshakeFailures++;
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"PTKSTART: Retry limit %u reached",
|
|
|
|
conf->wpa_pairwise_update_count);
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, DISCONNECT);
|
|
|
|
} else if (sm->TimeoutEvt)
|
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_PTKCALCNEGOTIATING:
|
|
|
|
if (sm->MICVerified)
|
|
|
|
SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING2);
|
|
|
|
else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
|
|
|
|
sm->EAPOLKeyPairwise)
|
|
|
|
SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
|
|
|
|
else if (sm->TimeoutEvt)
|
|
|
|
SM_ENTER(WPA_PTK, PTKSTART);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_PTKCALCNEGOTIATING2:
|
|
|
|
SM_ENTER(WPA_PTK, PTKINITNEGOTIATING);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_PTKINITNEGOTIATING:
|
2012-01-02 21:36:11 +01:00
|
|
|
if (sm->update_snonce)
|
|
|
|
SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
|
|
|
|
else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
|
|
|
|
sm->EAPOLKeyPairwise && sm->MICVerified)
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, PTKINITDONE);
|
|
|
|
else if (sm->TimeoutCtr >
|
2020-03-28 18:29:12 +01:00
|
|
|
conf->wpa_pairwise_update_count ||
|
|
|
|
(conf->wpa_disable_eapol_key_retries &&
|
2017-10-16 17:37:43 +02:00
|
|
|
sm->TimeoutCtr > 1)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth->dot11RSNA4WayHandshakeFailures++;
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"PTKINITNEGOTIATING: Retry limit %u reached",
|
|
|
|
conf->wpa_pairwise_update_count);
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK, DISCONNECT);
|
|
|
|
} else if (sm->TimeoutEvt)
|
|
|
|
SM_ENTER(WPA_PTK, PTKINITNEGOTIATING);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_PTKINITDONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK_GROUP, IDLE)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK_GROUP, IDLE, wpa_ptk_group);
|
|
|
|
if (sm->Init) {
|
|
|
|
/* Init flag is not cleared here, so avoid busy
|
|
|
|
* loop by claiming nothing changed. */
|
|
|
|
sm->changed = FALSE;
|
|
|
|
}
|
|
|
|
sm->GTimeoutCtr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK_GROUP, REKEYNEGOTIATING)
|
|
|
|
{
|
|
|
|
u8 rsc[WPA_KEY_RSC_LEN];
|
|
|
|
struct wpa_group *gsm = sm->group;
|
2014-10-11 16:29:50 +02:00
|
|
|
const u8 *kde;
|
|
|
|
u8 *kde_buf = NULL, *pos, hdr[2];
|
2008-02-28 02:34:43 +01:00
|
|
|
size_t kde_len;
|
2011-10-18 11:38:32 +02:00
|
|
|
u8 *gtk, dummy_gtk[32];
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf = &sm->wpa_auth->conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
SM_ENTRY_MA(WPA_PTK_GROUP, REKEYNEGOTIATING, wpa_ptk_group);
|
2008-12-18 16:15:36 +01:00
|
|
|
|
|
|
|
sm->GTimeoutCtr++;
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->wpa_disable_eapol_key_retries && sm->GTimeoutCtr > 1) {
|
2017-10-16 17:37:43 +02:00
|
|
|
/* Do not allow retransmission of EAPOL-Key group msg 1/2 */
|
|
|
|
return;
|
|
|
|
}
|
2020-03-28 18:29:12 +01:00
|
|
|
if (sm->GTimeoutCtr > conf->wpa_group_update_count) {
|
2008-12-18 16:15:36 +01:00
|
|
|
/* No point in sending the EAPOL-Key - we will disconnect
|
|
|
|
* immediately following this. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->wpa == WPA_VERSION_WPA)
|
|
|
|
sm->PInitAKeys = FALSE;
|
|
|
|
sm->TimeoutEvt = FALSE;
|
|
|
|
/* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
|
|
|
|
os_memset(rsc, 0, WPA_KEY_RSC_LEN);
|
|
|
|
if (gsm->wpa_group_state == WPA_GROUP_SETKEYSDONE)
|
|
|
|
wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"sending 1/2 msg of Group Key Handshake");
|
|
|
|
|
2011-10-18 11:38:32 +02:00
|
|
|
gtk = gsm->GTK[gsm->GN - 1];
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
|
2011-10-18 11:38:32 +02:00
|
|
|
/*
|
|
|
|
* Provide unique random GTK to each STA to prevent use
|
|
|
|
* of GTK in the BSS.
|
|
|
|
*/
|
|
|
|
if (random_get_bytes(dummy_gtk, gsm->GTK_len) < 0)
|
|
|
|
return;
|
|
|
|
gtk = dummy_gtk;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->wpa == WPA_VERSION_WPA2) {
|
|
|
|
kde_len = 2 + RSN_SELECTOR_LEN + 2 + gsm->GTK_len +
|
2018-08-06 21:46:27 +02:00
|
|
|
ieee80211w_kde_len(sm) + ocv_oci_len(sm);
|
2014-10-11 16:29:50 +02:00
|
|
|
kde_buf = os_malloc(kde_len);
|
|
|
|
if (kde_buf == NULL)
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
|
2014-10-11 16:29:50 +02:00
|
|
|
kde = pos = kde_buf;
|
2008-02-28 02:34:43 +01:00
|
|
|
hdr[0] = gsm->GN & 0x03;
|
|
|
|
hdr[1] = 0;
|
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
|
2011-10-18 11:38:32 +02:00
|
|
|
gtk, gsm->GTK_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
pos = ieee80211w_kde_add(sm, pos);
|
2018-08-06 21:46:27 +02:00
|
|
|
if (ocv_oci_add(sm, &pos) < 0) {
|
|
|
|
os_free(kde_buf);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-11 16:29:50 +02:00
|
|
|
kde_len = pos - kde;
|
2008-02-28 02:34:43 +01:00
|
|
|
} else {
|
2011-10-18 11:38:32 +02:00
|
|
|
kde = gtk;
|
2014-10-11 16:29:50 +02:00
|
|
|
kde_len = gsm->GTK_len;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wpa_send_eapol(sm->wpa_auth, sm,
|
2015-09-03 16:24:37 +02:00
|
|
|
WPA_KEY_INFO_SECURE |
|
2017-06-17 22:48:52 +02:00
|
|
|
(wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
|
|
|
|
WPA_KEY_INFO_MIC : 0) |
|
2008-02-28 02:34:43 +01:00
|
|
|
WPA_KEY_INFO_ACK |
|
|
|
|
(!sm->Pair ? WPA_KEY_INFO_INSTALL : 0),
|
2017-02-05 12:39:57 +01:00
|
|
|
rsc, NULL, kde, kde_len, gsm->GN, 1);
|
2014-10-11 16:29:50 +02:00
|
|
|
|
|
|
|
os_free(kde_buf);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK_GROUP, REKEYESTABLISHED)
|
|
|
|
{
|
2018-08-06 21:46:31 +02:00
|
|
|
struct wpa_authenticator *wpa_auth = sm->wpa_auth;
|
2020-03-28 18:29:12 +01:00
|
|
|
#ifdef CONFIG_OCV
|
2018-08-06 21:46:31 +02:00
|
|
|
const u8 *key_data, *mic;
|
|
|
|
struct ieee802_1x_hdr *hdr;
|
|
|
|
struct wpa_eapol_key *key;
|
|
|
|
struct wpa_eapol_ie_parse kde;
|
|
|
|
size_t mic_len;
|
|
|
|
u16 key_data_length;
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTRY_MA(WPA_PTK_GROUP, REKEYESTABLISHED, wpa_ptk_group);
|
|
|
|
sm->EAPOLKeyReceived = FALSE;
|
2018-08-06 21:46:31 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_OCV
|
|
|
|
mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: last_rx_eapol_key length fields have already been validated in
|
|
|
|
* wpa_receive().
|
|
|
|
*/
|
|
|
|
hdr = (struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
|
|
|
|
key = (struct wpa_eapol_key *) (hdr + 1);
|
|
|
|
mic = (u8 *) (key + 1);
|
|
|
|
key_data = mic + mic_len + 2;
|
|
|
|
key_data_length = WPA_GET_BE16(mic + mic_len);
|
|
|
|
if (key_data_length > sm->last_rx_eapol_key_len - sizeof(*hdr) -
|
|
|
|
sizeof(*key) - mic_len - 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wpa_parse_kde_ies(key_data, key_data_length, &kde) < 0) {
|
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"received EAPOL-Key group msg 2/2 with invalid Key Data contents");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_auth_uses_ocv(sm)) {
|
|
|
|
struct wpa_channel_info ci;
|
|
|
|
int tx_chanwidth;
|
|
|
|
int tx_seg1_idx;
|
|
|
|
|
|
|
|
if (wpa_channel_info(wpa_auth, &ci) != 0) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"Failed to get channel info to validate received OCI in EAPOL-Key group 1/2");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_sta_tx_parameters(sm,
|
|
|
|
channel_width_to_int(ci.chanwidth),
|
|
|
|
ci.seg1_idx, &tx_chanwidth,
|
|
|
|
&tx_seg1_idx) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ocv_verify_tx_params(kde.oci, kde.oci_len, &ci,
|
|
|
|
tx_chanwidth, tx_seg1_idx) != 0) {
|
|
|
|
wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
ocv_errorstr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_OCV */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->GUpdateStationKeys)
|
|
|
|
sm->group->GKeyDoneStations--;
|
|
|
|
sm->GUpdateStationKeys = FALSE;
|
|
|
|
sm->GTimeoutCtr = 0;
|
|
|
|
/* FIX: MLME.SetProtection.Request(TA, Tx_Rx) */
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
|
2008-02-28 02:34:43 +01:00
|
|
|
"group key handshake completed (%s)",
|
|
|
|
sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
|
|
|
|
sm->has_GTK = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STATE(WPA_PTK_GROUP, KEYERROR)
|
|
|
|
{
|
|
|
|
SM_ENTRY_MA(WPA_PTK_GROUP, KEYERROR, wpa_ptk_group);
|
|
|
|
if (sm->GUpdateStationKeys)
|
|
|
|
sm->group->GKeyDoneStations--;
|
|
|
|
sm->GUpdateStationKeys = FALSE;
|
|
|
|
sm->Disconnect = TRUE;
|
2017-02-06 22:55:42 +01:00
|
|
|
wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_INFO,
|
|
|
|
"group key handshake failed (%s) after %u tries",
|
|
|
|
sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN",
|
|
|
|
sm->wpa_auth->conf.wpa_group_update_count);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SM_STEP(WPA_PTK_GROUP)
|
|
|
|
{
|
2008-10-21 12:54:54 +02:00
|
|
|
if (sm->Init || sm->PtkGroupInit) {
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK_GROUP, IDLE);
|
2008-10-21 12:54:54 +02:00
|
|
|
sm->PtkGroupInit = FALSE;
|
|
|
|
} else switch (sm->wpa_ptk_group_state) {
|
2008-02-28 02:34:43 +01:00
|
|
|
case WPA_PTK_GROUP_IDLE:
|
|
|
|
if (sm->GUpdateStationKeys ||
|
|
|
|
(sm->wpa == WPA_VERSION_WPA && sm->PInitAKeys))
|
|
|
|
SM_ENTER(WPA_PTK_GROUP, REKEYNEGOTIATING);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_GROUP_REKEYNEGOTIATING:
|
|
|
|
if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
|
|
|
|
!sm->EAPOLKeyPairwise && sm->MICVerified)
|
|
|
|
SM_ENTER(WPA_PTK_GROUP, REKEYESTABLISHED);
|
|
|
|
else if (sm->GTimeoutCtr >
|
2017-10-16 17:37:43 +02:00
|
|
|
sm->wpa_auth->conf.wpa_group_update_count ||
|
|
|
|
(sm->wpa_auth->conf.wpa_disable_eapol_key_retries &&
|
|
|
|
sm->GTimeoutCtr > 1))
|
2008-02-28 02:34:43 +01:00
|
|
|
SM_ENTER(WPA_PTK_GROUP, KEYERROR);
|
|
|
|
else if (sm->TimeoutEvt)
|
|
|
|
SM_ENTER(WPA_PTK_GROUP, REKEYNEGOTIATING);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_GROUP_KEYERROR:
|
|
|
|
SM_ENTER(WPA_PTK_GROUP, IDLE);
|
|
|
|
break;
|
|
|
|
case WPA_PTK_GROUP_REKEYESTABLISHED:
|
|
|
|
SM_ENTER(WPA_PTK_GROUP, IDLE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf = &wpa_auth->conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
int ret = 0;
|
2020-02-17 22:08:05 +01:00
|
|
|
size_t len;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
|
|
|
|
inc_byte_array(group->Counter, WPA_NONCE_LEN);
|
2010-11-23 00:05:26 +01:00
|
|
|
if (wpa_gmk_to_gtk(group->GMK, "Group key expansion",
|
|
|
|
wpa_auth->addr, group->GNonce,
|
|
|
|
group->GTK[group->GN - 1], group->GTK_len) < 0)
|
|
|
|
ret = -1;
|
2010-11-22 23:57:14 +01:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "GTK",
|
|
|
|
group->GTK[group->GN - 1], group->GTK_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
|
|
|
|
len = wpa_cipher_key_len(conf->group_mgmt_cipher);
|
2010-11-22 23:57:14 +01:00
|
|
|
os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
|
|
|
|
inc_byte_array(group->Counter, WPA_NONCE_LEN);
|
2010-11-23 00:05:26 +01:00
|
|
|
if (wpa_gmk_to_gtk(group->GMK, "IGTK key expansion",
|
|
|
|
wpa_auth->addr, group->GNonce,
|
2014-03-12 19:26:37 +01:00
|
|
|
group->IGTK[group->GN_igtk - 4], len) < 0)
|
2010-11-23 00:05:26 +01:00
|
|
|
ret = -1;
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "IGTK",
|
2014-03-12 19:26:37 +01:00
|
|
|
group->IGTK[group->GN_igtk - 4], len);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION &&
|
|
|
|
conf->beacon_prot) {
|
|
|
|
len = wpa_cipher_key_len(conf->group_mgmt_cipher);
|
2020-02-17 22:08:05 +01:00
|
|
|
os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
|
|
|
|
inc_byte_array(group->Counter, WPA_NONCE_LEN);
|
|
|
|
if (wpa_gmk_to_gtk(group->GMK, "BIGTK key expansion",
|
|
|
|
wpa_auth->addr, group->GNonce,
|
|
|
|
group->BIGTK[group->GN_bigtk - 6], len) < 0)
|
|
|
|
ret = -1;
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "BIGTK",
|
|
|
|
group->BIGTK[group->GN_bigtk - 6], len);
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_group_gtk_init(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
|
|
|
|
"GTK_INIT (VLAN-ID %d)", group->vlan_id);
|
|
|
|
group->changed = FALSE; /* GInit is not cleared here; avoid loop */
|
|
|
|
group->wpa_group_state = WPA_GROUP_GTK_INIT;
|
|
|
|
|
|
|
|
/* GTK[0..N] = 0 */
|
|
|
|
os_memset(group->GTK, 0, sizeof(group->GTK));
|
|
|
|
group->GN = 1;
|
|
|
|
group->GM = 2;
|
|
|
|
group->GN_igtk = 4;
|
|
|
|
group->GM_igtk = 5;
|
2020-02-17 22:08:05 +01:00
|
|
|
group->GN_bigtk = 6;
|
|
|
|
group->GM_bigtk = 7;
|
2008-02-28 02:34:43 +01:00
|
|
|
/* GTK[GN] = CalcGTK() */
|
|
|
|
wpa_gtk_update(wpa_auth, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wpa_group_update_sta(struct wpa_state_machine *sm, void *ctx)
|
|
|
|
{
|
2012-08-10 15:48:35 +02:00
|
|
|
if (ctx != NULL && ctx != sm->group)
|
|
|
|
return 0;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sm->wpa_ptk_state != WPA_PTK_PTKINITDONE) {
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"Not in PTKINITDONE; skip Group Key update");
|
2011-03-23 16:06:17 +01:00
|
|
|
sm->GUpdateStationKeys = FALSE;
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2008-10-21 12:54:54 +02:00
|
|
|
if (sm->GUpdateStationKeys) {
|
|
|
|
/*
|
2011-03-23 16:06:17 +01:00
|
|
|
* This should not really happen, so add a debug log entry.
|
|
|
|
* Since we clear the GKeyDoneStations before the loop, the
|
|
|
|
* station needs to be counted here anyway.
|
2008-10-21 12:54:54 +02:00
|
|
|
*/
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
2011-03-23 16:06:17 +01:00
|
|
|
"GUpdateStationKeys was already set when "
|
|
|
|
"marking station for GTK rekeying");
|
2008-10-21 12:54:54 +02:00
|
|
|
}
|
2011-03-23 16:06:17 +01:00
|
|
|
|
2012-12-16 17:22:54 +01:00
|
|
|
/* Do not rekey GTK/IGTK when STA is in WNM-Sleep Mode */
|
2012-02-26 16:25:55 +01:00
|
|
|
if (sm->is_wnmsleep)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-23 16:06:17 +01:00
|
|
|
sm->group->GKeyDoneStations++;
|
|
|
|
sm->GUpdateStationKeys = TRUE;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_sm_step(sm);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-12 08:29:27 +02:00
|
|
|
#ifdef CONFIG_WNM_AP
|
2012-12-16 17:22:54 +01:00
|
|
|
/* update GTK when exiting WNM-Sleep Mode */
|
2012-02-26 16:25:55 +01:00
|
|
|
void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm)
|
|
|
|
{
|
2013-12-26 20:08:50 +01:00
|
|
|
if (sm == NULL || sm->is_wnmsleep)
|
2012-02-26 16:25:55 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
wpa_group_update_sta(sm, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag)
|
|
|
|
{
|
2013-12-26 20:08:50 +01:00
|
|
|
if (sm)
|
|
|
|
sm->is_wnmsleep = !!flag;
|
2012-02-26 16:25:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos)
|
|
|
|
{
|
|
|
|
struct wpa_group *gsm = sm->group;
|
2012-12-16 18:46:10 +01:00
|
|
|
u8 *start = pos;
|
2012-02-26 16:25:55 +01:00
|
|
|
|
|
|
|
/*
|
2012-12-16 18:46:10 +01:00
|
|
|
* GTK subelement:
|
2012-02-26 16:25:55 +01:00
|
|
|
* Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
|
2012-12-16 18:46:10 +01:00
|
|
|
* Key[5..32]
|
2012-02-26 16:25:55 +01:00
|
|
|
*/
|
2012-12-16 18:46:10 +01:00
|
|
|
*pos++ = WNM_SLEEP_SUBELEM_GTK;
|
|
|
|
*pos++ = 11 + gsm->GTK_len;
|
2012-02-26 16:25:55 +01:00
|
|
|
/* Key ID in B0-B1 of Key Info */
|
2012-12-16 18:46:10 +01:00
|
|
|
WPA_PUT_LE16(pos, gsm->GN & 0x03);
|
|
|
|
pos += 2;
|
|
|
|
*pos++ = gsm->GTK_len;
|
|
|
|
if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, pos) != 0)
|
2012-02-26 16:25:55 +01:00
|
|
|
return 0;
|
2012-12-16 18:46:10 +01:00
|
|
|
pos += 8;
|
|
|
|
os_memcpy(pos, gsm->GTK[gsm->GN - 1], gsm->GTK_len);
|
|
|
|
pos += gsm->GTK_len;
|
2012-02-26 16:25:55 +01:00
|
|
|
|
2012-12-16 18:46:10 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WNM: GTK Key ID %u in WNM-Sleep Mode exit",
|
|
|
|
gsm->GN);
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WNM: GTK in WNM-Sleep Mode exit",
|
2012-02-26 16:25:55 +01:00
|
|
|
gsm->GTK[gsm->GN - 1], gsm->GTK_len);
|
|
|
|
|
2012-12-16 18:46:10 +01:00
|
|
|
return pos - start;
|
2012-02-26 16:25:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos)
|
|
|
|
{
|
|
|
|
struct wpa_group *gsm = sm->group;
|
2012-12-16 18:46:10 +01:00
|
|
|
u8 *start = pos;
|
2014-03-12 19:26:37 +01:00
|
|
|
size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
|
2012-02-26 16:25:55 +01:00
|
|
|
|
2012-12-16 18:46:10 +01:00
|
|
|
/*
|
|
|
|
* IGTK subelement:
|
|
|
|
* Sub-elem ID[1] | Length[1] | KeyID[2] | PN[6] | Key[16]
|
|
|
|
*/
|
|
|
|
*pos++ = WNM_SLEEP_SUBELEM_IGTK;
|
2014-03-12 19:26:37 +01:00
|
|
|
*pos++ = 2 + 6 + len;
|
2012-12-16 18:46:10 +01:00
|
|
|
WPA_PUT_LE16(pos, gsm->GN_igtk);
|
|
|
|
pos += 2;
|
|
|
|
if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, pos) != 0)
|
2012-02-26 16:25:55 +01:00
|
|
|
return 0;
|
2012-12-16 18:46:10 +01:00
|
|
|
pos += 6;
|
2012-02-26 16:25:55 +01:00
|
|
|
|
2014-03-12 19:26:37 +01:00
|
|
|
os_memcpy(pos, gsm->IGTK[gsm->GN_igtk - 4], len);
|
|
|
|
pos += len;
|
2012-02-26 16:25:55 +01:00
|
|
|
|
2012-12-16 18:46:10 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WNM: IGTK Key ID %u in WNM-Sleep Mode exit",
|
|
|
|
gsm->GN_igtk);
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WNM: IGTK in WNM-Sleep Mode exit",
|
2014-03-12 19:26:37 +01:00
|
|
|
gsm->IGTK[gsm->GN_igtk - 4], len);
|
2012-02-26 16:25:55 +01:00
|
|
|
|
2012-12-16 18:46:10 +01:00
|
|
|
return pos - start;
|
2012-02-26 16:25:55 +01:00
|
|
|
}
|
2019-09-08 16:17:31 +02:00
|
|
|
|
2020-02-17 22:08:05 +01:00
|
|
|
|
|
|
|
int wpa_wnmsleep_bigtk_subelem(struct wpa_state_machine *sm, u8 *pos)
|
|
|
|
{
|
|
|
|
struct wpa_group *gsm = sm->group;
|
|
|
|
u8 *start = pos;
|
|
|
|
size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BIGTK subelement:
|
|
|
|
* Sub-elem ID[1] | Length[1] | KeyID[2] | PN[6] | Key[16]
|
|
|
|
*/
|
|
|
|
*pos++ = WNM_SLEEP_SUBELEM_BIGTK;
|
|
|
|
*pos++ = 2 + 6 + len;
|
|
|
|
WPA_PUT_LE16(pos, gsm->GN_bigtk);
|
|
|
|
pos += 2;
|
|
|
|
if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_bigtk, pos) != 0)
|
|
|
|
return 0;
|
|
|
|
pos += 6;
|
|
|
|
|
|
|
|
os_memcpy(pos, gsm->BIGTK[gsm->GN_bigtk - 6], len);
|
|
|
|
pos += len;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WNM: BIGTK Key ID %u in WNM-Sleep Mode exit",
|
|
|
|
gsm->GN_bigtk);
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WNM: BIGTK in WNM-Sleep Mode exit",
|
|
|
|
gsm->IGTK[gsm->GN_bigtk - 6], len);
|
|
|
|
|
|
|
|
return pos - start;
|
|
|
|
}
|
|
|
|
|
2017-06-12 08:29:27 +02:00
|
|
|
#endif /* CONFIG_WNM_AP */
|
2012-02-26 16:25:55 +01:00
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static void wpa_group_setkeys(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
|
|
|
|
"SETKEYS (VLAN-ID %d)", group->vlan_id);
|
|
|
|
group->changed = TRUE;
|
|
|
|
group->wpa_group_state = WPA_GROUP_SETKEYS;
|
|
|
|
group->GTKReKey = FALSE;
|
|
|
|
tmp = group->GM;
|
|
|
|
group->GM = group->GN;
|
|
|
|
group->GN = tmp;
|
|
|
|
tmp = group->GM_igtk;
|
|
|
|
group->GM_igtk = group->GN_igtk;
|
|
|
|
group->GN_igtk = tmp;
|
2020-02-17 22:08:05 +01:00
|
|
|
tmp = group->GM_bigtk;
|
|
|
|
group->GM_bigtk = group->GN_bigtk;
|
|
|
|
group->GN_bigtk = tmp;
|
2008-02-28 02:34:43 +01:00
|
|
|
/* "GKeyDoneStations = GNoStations" is done in more robust way by
|
|
|
|
* counting the STAs that are marked with GUpdateStationKeys instead of
|
|
|
|
* including all STAs that could be in not-yet-completed state. */
|
|
|
|
wpa_gtk_update(wpa_auth, group);
|
|
|
|
|
2011-03-23 16:06:17 +01:00
|
|
|
if (group->GKeyDoneStations) {
|
|
|
|
wpa_printf(MSG_DEBUG, "wpa_group_setkeys: Unexpected "
|
|
|
|
"GKeyDoneStations=%d when starting new GTK rekey",
|
|
|
|
group->GKeyDoneStations);
|
|
|
|
group->GKeyDoneStations = 0;
|
|
|
|
}
|
2012-08-10 15:48:35 +02:00
|
|
|
wpa_auth_for_each_sta(wpa_auth, wpa_group_update_sta, group);
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "wpa_group_setkeys: GKeyDoneStations=%d",
|
|
|
|
group->GKeyDoneStations);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-23 23:52:46 +01:00
|
|
|
static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf = &wpa_auth->conf;
|
2010-11-23 00:05:26 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (wpa_auth_set_key(wpa_auth, group->vlan_id,
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_cipher_to_alg(conf->wpa_group),
|
2011-01-09 18:44:28 +01:00
|
|
|
broadcast_ether_addr, group->GN,
|
2020-01-04 23:10:04 +01:00
|
|
|
group->GTK[group->GN - 1], group->GTK_len,
|
|
|
|
KEY_FLAG_GROUP_TX_DEFAULT) < 0)
|
2010-11-23 00:05:26 +01:00
|
|
|
ret = -1;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
|
2014-03-12 19:26:37 +01:00
|
|
|
enum wpa_alg alg;
|
|
|
|
size_t len;
|
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
alg = wpa_cipher_to_alg(conf->group_mgmt_cipher);
|
|
|
|
len = wpa_cipher_key_len(conf->group_mgmt_cipher);
|
2014-03-12 19:26:37 +01:00
|
|
|
|
|
|
|
if (ret == 0 &&
|
|
|
|
wpa_auth_set_key(wpa_auth, group->vlan_id, alg,
|
|
|
|
broadcast_ether_addr, group->GN_igtk,
|
2020-01-04 23:10:04 +01:00
|
|
|
group->IGTK[group->GN_igtk - 4], len,
|
|
|
|
KEY_FLAG_GROUP_TX_DEFAULT) < 0)
|
2014-03-12 19:26:37 +01:00
|
|
|
ret = -1;
|
2020-02-17 22:08:05 +01:00
|
|
|
|
2020-03-28 18:29:12 +01:00
|
|
|
if (ret == 0 && conf->beacon_prot &&
|
2020-02-17 22:08:05 +01:00
|
|
|
wpa_auth_set_key(wpa_auth, group->vlan_id, alg,
|
|
|
|
broadcast_ether_addr, group->GN_bigtk,
|
|
|
|
group->BIGTK[group->GN_bigtk - 6], len,
|
|
|
|
KEY_FLAG_GROUP_TX_DEFAULT) < 0)
|
|
|
|
ret = -1;
|
2014-03-12 19:26:37 +01:00
|
|
|
}
|
2010-11-23 00:05:26 +01:00
|
|
|
|
|
|
|
return ret;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-24 21:38:16 +01:00
|
|
|
static int wpa_group_disconnect_cb(struct wpa_state_machine *sm, void *ctx)
|
|
|
|
{
|
|
|
|
if (sm->group == ctx) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Mark STA " MACSTR
|
|
|
|
" for discconnection due to fatal failure",
|
|
|
|
MAC2STR(sm->addr));
|
|
|
|
sm->Disconnect = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_group_fatal_failure(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: group state machine entering state FATAL_FAILURE");
|
|
|
|
group->changed = TRUE;
|
|
|
|
group->wpa_group_state = WPA_GROUP_FATAL_FAILURE;
|
|
|
|
wpa_auth_for_each_sta(wpa_auth, wpa_group_disconnect_cb, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-23 23:52:46 +01:00
|
|
|
static int wpa_group_setkeysdone(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
|
|
|
|
"SETKEYSDONE (VLAN-ID %d)", group->vlan_id);
|
|
|
|
group->changed = TRUE;
|
|
|
|
group->wpa_group_state = WPA_GROUP_SETKEYSDONE;
|
|
|
|
|
2013-12-24 21:38:16 +01:00
|
|
|
if (wpa_group_config_group_keys(wpa_auth, group) < 0) {
|
|
|
|
wpa_group_fatal_failure(wpa_auth, group);
|
2010-11-23 23:52:46 +01:00
|
|
|
return -1;
|
2013-12-24 21:38:16 +01:00
|
|
|
}
|
2010-11-23 23:52:46 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
if (group->GInit) {
|
|
|
|
wpa_group_gtk_init(wpa_auth, group);
|
2013-12-24 21:38:16 +01:00
|
|
|
} else if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE) {
|
|
|
|
/* Do not allow group operations */
|
2008-02-28 02:34:43 +01:00
|
|
|
} else if (group->wpa_group_state == WPA_GROUP_GTK_INIT &&
|
|
|
|
group->GTKAuthenticator) {
|
|
|
|
wpa_group_setkeysdone(wpa_auth, group);
|
|
|
|
} else if (group->wpa_group_state == WPA_GROUP_SETKEYSDONE &&
|
|
|
|
group->GTKReKey) {
|
|
|
|
wpa_group_setkeys(wpa_auth, group);
|
|
|
|
} else if (group->wpa_group_state == WPA_GROUP_SETKEYS) {
|
|
|
|
if (group->GKeyDoneStations == 0)
|
|
|
|
wpa_group_setkeysdone(wpa_auth, group);
|
|
|
|
else if (group->GTKReKey)
|
|
|
|
wpa_group_setkeys(wpa_auth, group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-10 17:54:41 +01:00
|
|
|
static int wpa_sm_step(struct wpa_state_machine *sm)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
if (sm == NULL)
|
2010-01-10 17:54:41 +01:00
|
|
|
return 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (sm->in_step_loop) {
|
|
|
|
/* This should not happen, but if it does, make sure we do not
|
|
|
|
* end up freeing the state machine too early by exiting the
|
|
|
|
* recursive call. */
|
|
|
|
wpa_printf(MSG_ERROR, "WPA: wpa_sm_step() called recursively");
|
2010-01-10 17:54:41 +01:00
|
|
|
return 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sm->in_step_loop = 1;
|
|
|
|
do {
|
|
|
|
if (sm->pending_deinit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sm->changed = FALSE;
|
|
|
|
sm->wpa_auth->group->changed = FALSE;
|
|
|
|
|
|
|
|
SM_STEP_RUN(WPA_PTK);
|
|
|
|
if (sm->pending_deinit)
|
|
|
|
break;
|
|
|
|
SM_STEP_RUN(WPA_PTK_GROUP);
|
|
|
|
if (sm->pending_deinit)
|
|
|
|
break;
|
|
|
|
wpa_group_sm_step(sm->wpa_auth, sm->group);
|
|
|
|
} while (sm->changed || sm->wpa_auth->group->changed);
|
|
|
|
sm->in_step_loop = 0;
|
|
|
|
|
|
|
|
if (sm->pending_deinit) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Completing pending STA state "
|
|
|
|
"machine deinit for " MACSTR, MAC2STR(sm->addr));
|
|
|
|
wpa_free_sta_sm(sm);
|
2010-01-10 17:54:41 +01:00
|
|
|
return 1;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2010-01-10 17:54:41 +01:00
|
|
|
return 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_state_machine *sm = eloop_ctx;
|
|
|
|
wpa_sm_step(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_sm_notify(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm == NULL)
|
|
|
|
return;
|
|
|
|
eloop_register_timeout(0, 0, wpa_sm_call_step, sm, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
int tmp, i;
|
|
|
|
struct wpa_group *group;
|
|
|
|
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
group = wpa_auth->group;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
tmp = group->GM;
|
|
|
|
group->GM = group->GN;
|
|
|
|
group->GN = tmp;
|
|
|
|
tmp = group->GM_igtk;
|
|
|
|
group->GM_igtk = group->GN_igtk;
|
|
|
|
group->GN_igtk = tmp;
|
2020-02-17 22:08:05 +01:00
|
|
|
tmp = group->GM_bigtk;
|
|
|
|
group->GM_bigtk = group->GN_bigtk;
|
|
|
|
group->GN_bigtk = tmp;
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_gtk_update(wpa_auth, group);
|
2011-10-30 21:19:49 +01:00
|
|
|
wpa_group_config_group_keys(wpa_auth, group);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-26 12:09:47 +02:00
|
|
|
static const char * wpa_bool_txt(int val)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2015-04-26 12:09:47 +02:00
|
|
|
return val ? "TRUE" : "FALSE";
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define RSN_SUITE "%02x-%02x-%02x-%d"
|
|
|
|
#define RSN_SUITE_ARG(s) \
|
|
|
|
((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
|
|
|
|
|
|
|
|
int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
|
|
|
|
{
|
2020-03-28 18:29:12 +01:00
|
|
|
struct wpa_auth_config *conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
int len = 0, ret;
|
|
|
|
char pmkid_txt[PMKID_LEN * 2 + 1];
|
2011-02-27 17:59:26 +01:00
|
|
|
#ifdef CONFIG_RSN_PREAUTH
|
|
|
|
const int preauth = 1;
|
|
|
|
#else /* CONFIG_RSN_PREAUTH */
|
|
|
|
const int preauth = 0;
|
|
|
|
#endif /* CONFIG_RSN_PREAUTH */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return len;
|
2020-03-28 18:29:12 +01:00
|
|
|
conf = &wpa_auth->conf;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
ret = os_snprintf(buf + len, buflen - len,
|
|
|
|
"dot11RSNAOptionImplemented=TRUE\n"
|
2011-02-27 17:59:26 +01:00
|
|
|
"dot11RSNAPreauthenticationImplemented=%s\n"
|
2008-02-28 02:34:43 +01:00
|
|
|
"dot11RSNAEnabled=%s\n"
|
|
|
|
"dot11RSNAPreauthenticationEnabled=%s\n",
|
2011-02-27 17:59:26 +01:00
|
|
|
wpa_bool_txt(preauth),
|
2020-03-28 18:29:12 +01:00
|
|
|
wpa_bool_txt(conf->wpa & WPA_PROTO_RSN),
|
|
|
|
wpa_bool_txt(conf->rsn_preauth));
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(buflen - len, ret))
|
2008-02-28 02:34:43 +01:00
|
|
|
return len;
|
|
|
|
len += ret;
|
|
|
|
|
|
|
|
wpa_snprintf_hex(pmkid_txt, sizeof(pmkid_txt),
|
|
|
|
wpa_auth->dot11RSNAPMKIDUsed, PMKID_LEN);
|
|
|
|
|
|
|
|
ret = os_snprintf(
|
|
|
|
buf + len, buflen - len,
|
|
|
|
"dot11RSNAConfigVersion=%u\n"
|
|
|
|
"dot11RSNAConfigPairwiseKeysSupported=9999\n"
|
|
|
|
/* FIX: dot11RSNAConfigGroupCipher */
|
|
|
|
/* FIX: dot11RSNAConfigGroupRekeyMethod */
|
|
|
|
/* FIX: dot11RSNAConfigGroupRekeyTime */
|
|
|
|
/* FIX: dot11RSNAConfigGroupRekeyPackets */
|
|
|
|
"dot11RSNAConfigGroupRekeyStrict=%u\n"
|
|
|
|
"dot11RSNAConfigGroupUpdateCount=%u\n"
|
|
|
|
"dot11RSNAConfigPairwiseUpdateCount=%u\n"
|
|
|
|
"dot11RSNAConfigGroupCipherSize=%u\n"
|
|
|
|
"dot11RSNAConfigPMKLifetime=%u\n"
|
|
|
|
"dot11RSNAConfigPMKReauthThreshold=%u\n"
|
|
|
|
"dot11RSNAConfigNumberOfPTKSAReplayCounters=0\n"
|
|
|
|
"dot11RSNAConfigSATimeout=%u\n"
|
|
|
|
"dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE "\n"
|
|
|
|
"dot11RSNAPairwiseCipherSelected=" RSN_SUITE "\n"
|
|
|
|
"dot11RSNAGroupCipherSelected=" RSN_SUITE "\n"
|
|
|
|
"dot11RSNAPMKIDUsed=%s\n"
|
|
|
|
"dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE "\n"
|
|
|
|
"dot11RSNAPairwiseCipherRequested=" RSN_SUITE "\n"
|
|
|
|
"dot11RSNAGroupCipherRequested=" RSN_SUITE "\n"
|
|
|
|
"dot11RSNATKIPCounterMeasuresInvoked=%u\n"
|
|
|
|
"dot11RSNA4WayHandshakeFailures=%u\n"
|
|
|
|
"dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n",
|
|
|
|
RSN_VERSION,
|
2020-03-28 18:29:12 +01:00
|
|
|
!!conf->wpa_strict_rekey,
|
|
|
|
conf->wpa_group_update_count,
|
|
|
|
conf->wpa_pairwise_update_count,
|
|
|
|
wpa_cipher_key_len(conf->wpa_group) * 8,
|
2008-02-28 02:34:43 +01:00
|
|
|
dot11RSNAConfigPMKLifetime,
|
|
|
|
dot11RSNAConfigPMKReauthThreshold,
|
|
|
|
dot11RSNAConfigSATimeout,
|
|
|
|
RSN_SUITE_ARG(wpa_auth->dot11RSNAAuthenticationSuiteSelected),
|
|
|
|
RSN_SUITE_ARG(wpa_auth->dot11RSNAPairwiseCipherSelected),
|
|
|
|
RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherSelected),
|
|
|
|
pmkid_txt,
|
|
|
|
RSN_SUITE_ARG(wpa_auth->dot11RSNAAuthenticationSuiteRequested),
|
|
|
|
RSN_SUITE_ARG(wpa_auth->dot11RSNAPairwiseCipherRequested),
|
|
|
|
RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherRequested),
|
|
|
|
wpa_auth->dot11RSNATKIPCounterMeasuresInvoked,
|
|
|
|
wpa_auth->dot11RSNA4WayHandshakeFailures);
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(buflen - len, ret))
|
2008-02-28 02:34:43 +01:00
|
|
|
return len;
|
|
|
|
len += ret;
|
|
|
|
|
|
|
|
/* TODO: dot11RSNAConfigPairwiseCiphersTable */
|
|
|
|
/* TODO: dot11RSNAConfigAuthenticationSuitesTable */
|
|
|
|
|
|
|
|
/* Private MIB */
|
|
|
|
ret = os_snprintf(buf + len, buflen - len, "hostapdWPAGroupState=%d\n",
|
|
|
|
wpa_auth->group->wpa_group_state);
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(buflen - len, ret))
|
2008-02-28 02:34:43 +01:00
|
|
|
return len;
|
|
|
|
len += ret;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
int len = 0, ret;
|
|
|
|
u32 pairwise = 0;
|
|
|
|
|
|
|
|
if (sm == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* TODO: FF-FF-FF-FF-FF-FF entry for broadcast/multicast stats */
|
|
|
|
|
|
|
|
/* dot11RSNAStatsEntry */
|
|
|
|
|
2012-08-30 10:53:54 +02:00
|
|
|
pairwise = wpa_cipher_to_suite(sm->wpa == WPA_VERSION_WPA2 ?
|
|
|
|
WPA_PROTO_RSN : WPA_PROTO_WPA,
|
|
|
|
sm->pairwise);
|
|
|
|
if (pairwise == 0)
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = os_snprintf(
|
|
|
|
buf + len, buflen - len,
|
|
|
|
/* TODO: dot11RSNAStatsIndex */
|
|
|
|
"dot11RSNAStatsSTAAddress=" MACSTR "\n"
|
|
|
|
"dot11RSNAStatsVersion=1\n"
|
|
|
|
"dot11RSNAStatsSelectedPairwiseCipher=" RSN_SUITE "\n"
|
|
|
|
/* TODO: dot11RSNAStatsTKIPICVErrors */
|
|
|
|
"dot11RSNAStatsTKIPLocalMICFailures=%u\n"
|
2011-04-05 00:21:27 +02:00
|
|
|
"dot11RSNAStatsTKIPRemoteMICFailures=%u\n"
|
2008-02-28 02:34:43 +01:00
|
|
|
/* TODO: dot11RSNAStatsCCMPReplays */
|
|
|
|
/* TODO: dot11RSNAStatsCCMPDecryptErrors */
|
|
|
|
/* TODO: dot11RSNAStatsTKIPReplays */,
|
|
|
|
MAC2STR(sm->addr),
|
|
|
|
RSN_SUITE_ARG(pairwise),
|
|
|
|
sm->dot11RSNAStatsTKIPLocalMICFailures,
|
|
|
|
sm->dot11RSNAStatsTKIPRemoteMICFailures);
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(buflen - len, ret))
|
2008-02-28 02:34:43 +01:00
|
|
|
return len;
|
|
|
|
len += ret;
|
|
|
|
|
|
|
|
/* Private MIB */
|
|
|
|
ret = os_snprintf(buf + len, buflen - len,
|
2019-07-24 11:58:49 +02:00
|
|
|
"wpa=%d\n"
|
|
|
|
"AKMSuiteSelector=" RSN_SUITE "\n"
|
2008-02-28 02:34:43 +01:00
|
|
|
"hostapdWPAPTKState=%d\n"
|
|
|
|
"hostapdWPAPTKGroupState=%d\n",
|
2019-07-24 11:58:49 +02:00
|
|
|
sm->wpa,
|
|
|
|
RSN_SUITE_ARG(wpa_akm_to_suite(sm->wpa_key_mgmt)),
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->wpa_ptk_state,
|
|
|
|
sm->wpa_ptk_group_state);
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(buflen - len, ret))
|
2008-02-28 02:34:43 +01:00
|
|
|
return len;
|
|
|
|
len += ret;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
if (wpa_auth)
|
|
|
|
wpa_auth->dot11RSNATKIPCounterMeasuresInvoked++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_pairwise_set(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
return sm && sm->pairwise_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-22 13:05:53 +01:00
|
|
|
int wpa_auth_get_pairwise(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
return sm->pairwise;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-16 13:35:18 +01:00
|
|
|
const u8 * wpa_auth_get_pmk(struct wpa_state_machine *sm, int *len)
|
|
|
|
{
|
|
|
|
if (!sm)
|
|
|
|
return NULL;
|
|
|
|
*len = sm->pmk_len;
|
|
|
|
return sm->PMK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm == NULL)
|
|
|
|
return -1;
|
|
|
|
return sm->wpa_key_mgmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm == NULL)
|
|
|
|
return 0;
|
|
|
|
return sm->wpa;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-14 15:15:35 +02:00
|
|
|
int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (!sm || !wpa_key_mgmt_ft(sm->wpa_key_mgmt))
|
|
|
|
return 0;
|
|
|
|
return sm->tk_already_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-25 15:24:18 +02:00
|
|
|
int wpa_auth_sta_fils_tk_already_set(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (!sm || !wpa_key_mgmt_fils(sm->wpa_key_mgmt))
|
|
|
|
return 0;
|
|
|
|
return sm->tk_already_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
|
|
|
|
struct rsn_pmksa_cache_entry *entry)
|
|
|
|
{
|
|
|
|
if (sm == NULL || sm->pmksa != entry)
|
|
|
|
return -1;
|
|
|
|
sm->pmksa = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct rsn_pmksa_cache_entry *
|
|
|
|
wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
return sm ? sm->pmksa : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm)
|
|
|
|
sm->dot11RSNAStatsTKIPLocalMICFailures++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth, size_t *len)
|
|
|
|
{
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return NULL;
|
|
|
|
*len = wpa_auth->wpa_ie_len;
|
|
|
|
return wpa_auth->wpa_ie;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
|
2015-10-14 00:18:11 +02:00
|
|
|
unsigned int pmk_len,
|
2008-02-28 02:34:43 +01:00
|
|
|
int session_timeout, struct eapol_state_machine *eapol)
|
|
|
|
{
|
2011-07-05 16:13:04 +02:00
|
|
|
if (sm == NULL || sm->wpa != WPA_VERSION_WPA2 ||
|
|
|
|
sm->wpa_auth->conf.disable_pmksa_caching)
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
|
|
|
|
2019-04-28 14:52:08 +02:00
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (pmk_len >= 2 * PMK_LEN && wpa_key_mgmt_ft(sm->wpa_key_mgmt) &&
|
|
|
|
wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
|
|
|
|
!wpa_key_mgmt_sha384(sm->wpa_key_mgmt)) {
|
|
|
|
/* Cache MPMK/XXKey instead of initial part from MSK */
|
|
|
|
pmk = pmk + PMK_LEN;
|
|
|
|
pmk_len = PMK_LEN;
|
|
|
|
} else
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2017-02-16 20:18:18 +01:00
|
|
|
if (wpa_key_mgmt_sha384(sm->wpa_key_mgmt)) {
|
2015-10-14 00:18:11 +02:00
|
|
|
if (pmk_len > PMK_LEN_SUITE_B_192)
|
|
|
|
pmk_len = PMK_LEN_SUITE_B_192;
|
|
|
|
} else if (pmk_len > PMK_LEN) {
|
|
|
|
pmk_len = PMK_LEN;
|
|
|
|
}
|
|
|
|
|
2019-04-28 14:52:08 +02:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "RSN: Cache PMK", pmk, pmk_len);
|
2016-02-15 03:23:37 +01:00
|
|
|
if (pmksa_cache_auth_add(sm->wpa_auth->pmksa, pmk, pmk_len, NULL,
|
2015-01-25 15:49:18 +01:00
|
|
|
sm->PTK.kck, sm->PTK.kck_len,
|
2009-01-14 21:01:26 +01:00
|
|
|
sm->wpa_auth->addr, sm->addr, session_timeout,
|
|
|
|
eapol, sm->wpa_key_mgmt))
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *pmk, size_t len, const u8 *sta_addr,
|
|
|
|
int session_timeout,
|
|
|
|
struct eapol_state_machine *eapol)
|
|
|
|
{
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2019-04-28 14:52:08 +02:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "RSN: Cache PMK from preauth", pmk, len);
|
2016-02-15 03:23:37 +01:00
|
|
|
if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, len, NULL,
|
2014-11-16 12:22:46 +01:00
|
|
|
NULL, 0,
|
|
|
|
wpa_auth->addr,
|
2009-01-14 21:01:26 +01:00
|
|
|
sta_addr, session_timeout, eapol,
|
|
|
|
WPA_KEY_MGMT_IEEE8021X))
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-18 12:00:29 +02:00
|
|
|
int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
2016-02-15 03:23:37 +01:00
|
|
|
const u8 *pmk, const u8 *pmkid)
|
2014-10-18 12:00:29 +02:00
|
|
|
{
|
|
|
|
if (wpa_auth->conf.disable_pmksa_caching)
|
|
|
|
return -1;
|
|
|
|
|
2019-04-28 14:52:08 +02:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "RSN: Cache PMK from SAE", pmk, PMK_LEN);
|
2016-02-15 03:23:37 +01:00
|
|
|
if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, PMK_LEN, pmkid,
|
2014-11-16 12:22:46 +01:00
|
|
|
NULL, 0,
|
2014-10-18 12:00:29 +02:00
|
|
|
wpa_auth->addr, addr, 0, NULL,
|
|
|
|
WPA_KEY_MGMT_SAE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-23 16:45:44 +01:00
|
|
|
void wpa_auth_add_sae_pmkid(struct wpa_state_machine *sm, const u8 *pmkid)
|
|
|
|
{
|
|
|
|
os_memcpy(sm->pmkid, pmkid, PMKID_LEN);
|
|
|
|
sm->pmkid_set = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-18 13:14:18 +02:00
|
|
|
int wpa_auth_pmksa_add2(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
|
|
|
const u8 *pmk, size_t pmk_len, const u8 *pmkid,
|
|
|
|
int session_timeout, int akmp)
|
|
|
|
{
|
|
|
|
if (wpa_auth->conf.disable_pmksa_caching)
|
|
|
|
return -1;
|
|
|
|
|
2019-04-28 14:52:08 +02:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "RSN: Cache PMK (2)", pmk, PMK_LEN);
|
2017-06-18 13:14:18 +02:00
|
|
|
if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, pmk_len, pmkid,
|
|
|
|
NULL, 0, wpa_auth->addr, addr, session_timeout,
|
|
|
|
NULL, akmp))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-05 17:55:32 +02:00
|
|
|
void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *sta_addr)
|
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *pmksa;
|
|
|
|
|
|
|
|
if (wpa_auth == NULL || wpa_auth->pmksa == NULL)
|
|
|
|
return;
|
|
|
|
pmksa = pmksa_cache_auth_get(wpa_auth->pmksa, sta_addr, NULL);
|
|
|
|
if (pmksa) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Remove PMKSA cache entry for "
|
|
|
|
MACSTR " based on request", MAC2STR(sta_addr));
|
|
|
|
pmksa_cache_free_entry(wpa_auth->pmksa, pmksa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-09 10:16:12 +01:00
|
|
|
int wpa_auth_pmksa_list(struct wpa_authenticator *wpa_auth, char *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
if (!wpa_auth || !wpa_auth->pmksa)
|
|
|
|
return 0;
|
|
|
|
return pmksa_cache_auth_list(wpa_auth->pmksa, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-09 10:16:13 +01:00
|
|
|
void wpa_auth_pmksa_flush(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
if (wpa_auth && wpa_auth->pmksa)
|
|
|
|
pmksa_cache_auth_flush(wpa_auth->pmksa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-02 11:32:07 +01:00
|
|
|
#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
|
|
|
|
#ifdef CONFIG_MESH
|
|
|
|
|
|
|
|
int wpa_auth_pmksa_list_mesh(struct wpa_authenticator *wpa_auth, const u8 *addr,
|
|
|
|
char *buf, size_t len)
|
|
|
|
{
|
|
|
|
if (!wpa_auth || !wpa_auth->pmksa)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return pmksa_cache_auth_list_mesh(wpa_auth->pmksa, addr, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct rsn_pmksa_cache_entry *
|
|
|
|
wpa_auth_pmksa_create_entry(const u8 *aa, const u8 *spa, const u8 *pmk,
|
|
|
|
const u8 *pmkid, int expiration)
|
|
|
|
{
|
|
|
|
struct rsn_pmksa_cache_entry *entry;
|
|
|
|
struct os_reltime now;
|
|
|
|
|
|
|
|
entry = pmksa_cache_auth_create_entry(pmk, PMK_LEN, pmkid, NULL, 0, aa,
|
|
|
|
spa, 0, NULL, WPA_KEY_MGMT_SAE);
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
os_get_reltime(&now);
|
|
|
|
entry->expiration = now.sec + expiration;
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_pmksa_add_entry(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct rsn_pmksa_cache_entry *entry)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!wpa_auth || !wpa_auth->pmksa)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = pmksa_cache_auth_add_entry(wpa_auth->pmksa, entry);
|
|
|
|
if (ret < 0)
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"RSN: Failed to store external PMKSA cache for "
|
|
|
|
MACSTR, MAC2STR(entry->spa));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_MESH */
|
|
|
|
#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
|
|
|
|
|
|
|
|
|
2016-03-09 10:16:14 +01:00
|
|
|
struct rsn_pmksa_cache_entry *
|
2015-09-04 23:04:21 +02:00
|
|
|
wpa_auth_pmksa_get(struct wpa_authenticator *wpa_auth, const u8 *sta_addr,
|
|
|
|
const u8 *pmkid)
|
2016-03-09 10:16:14 +01:00
|
|
|
{
|
|
|
|
if (!wpa_auth || !wpa_auth->pmksa)
|
|
|
|
return NULL;
|
2015-09-04 23:04:21 +02:00
|
|
|
return pmksa_cache_auth_get(wpa_auth->pmksa, sta_addr, pmkid);
|
2016-03-09 10:16:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry *pmksa,
|
|
|
|
struct wpa_state_machine *sm,
|
|
|
|
struct wpa_authenticator *wpa_auth,
|
|
|
|
u8 *pmkid, u8 *pmk)
|
|
|
|
{
|
|
|
|
if (!sm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sm->pmksa = pmksa;
|
2016-03-22 19:37:46 +01:00
|
|
|
os_memcpy(pmk, pmksa->pmk, PMK_LEN);
|
|
|
|
os_memcpy(pmkid, pmksa->pmkid, PMKID_LEN);
|
|
|
|
os_memcpy(wpa_auth->dot11RSNAPMKIDUsed, pmksa->pmkid, PMKID_LEN);
|
2016-03-09 10:16:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-26 14:22:55 +02:00
|
|
|
/*
|
|
|
|
* Remove and free the group from wpa_authenticator. This is triggered by a
|
|
|
|
* callback to make sure nobody is currently iterating the group list while it
|
|
|
|
* gets modified.
|
|
|
|
*/
|
|
|
|
static void wpa_group_free(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
struct wpa_group *prev = wpa_auth->group;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Remove group state machine for VLAN-ID %d",
|
|
|
|
group->vlan_id);
|
|
|
|
|
|
|
|
while (prev) {
|
|
|
|
if (prev->next == group) {
|
|
|
|
/* This never frees the special first group as needed */
|
|
|
|
prev->next = group->next;
|
|
|
|
os_free(group);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = prev->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Increase the reference counter for group */
|
|
|
|
static void wpa_group_get(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
/* Skip the special first group */
|
|
|
|
if (wpa_auth->group == group)
|
|
|
|
return;
|
|
|
|
|
|
|
|
group->references++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Decrease the reference counter and maybe free the group */
|
|
|
|
static void wpa_group_put(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_group *group)
|
|
|
|
{
|
|
|
|
/* Skip the special first group */
|
|
|
|
if (wpa_auth->group == group)
|
|
|
|
return;
|
|
|
|
|
|
|
|
group->references--;
|
|
|
|
if (group->references)
|
|
|
|
return;
|
|
|
|
wpa_group_free(wpa_auth, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a group that has its references counter set to zero. Caller needs to
|
|
|
|
* call wpa_group_get() on the return value to mark the entry in use.
|
|
|
|
*/
|
2008-02-28 02:34:43 +01:00
|
|
|
static struct wpa_group *
|
|
|
|
wpa_auth_add_group(struct wpa_authenticator *wpa_auth, int vlan_id)
|
|
|
|
{
|
|
|
|
struct wpa_group *group;
|
|
|
|
|
|
|
|
if (wpa_auth == NULL || wpa_auth->group == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Add group state machine for VLAN-ID %d",
|
|
|
|
vlan_id);
|
2011-08-09 13:56:16 +02:00
|
|
|
group = wpa_group_init(wpa_auth, vlan_id, 0);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (group == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
group->next = wpa_auth->group->next;
|
|
|
|
wpa_auth->group->next = group;
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-05 16:14:26 +02:00
|
|
|
/*
|
|
|
|
* Enforce that the group state machine for the VLAN is running, increase
|
|
|
|
* reference counter as interface is up. References might have been increased
|
|
|
|
* even if a negative value is returned.
|
|
|
|
* Returns: -1 on error (group missing, group already failed); otherwise, 0
|
|
|
|
*/
|
|
|
|
int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id)
|
|
|
|
{
|
|
|
|
struct wpa_group *group;
|
|
|
|
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
group = wpa_auth->group;
|
|
|
|
while (group) {
|
|
|
|
if (group->vlan_id == vlan_id)
|
|
|
|
break;
|
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group == NULL) {
|
|
|
|
group = wpa_auth_add_group(wpa_auth, vlan_id);
|
|
|
|
if (group == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Ensure group state machine running for VLAN ID %d",
|
|
|
|
vlan_id);
|
|
|
|
|
|
|
|
wpa_group_get(wpa_auth, group);
|
|
|
|
group->num_setup_iface++;
|
|
|
|
|
|
|
|
if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decrease reference counter, expected to be zero afterwards.
|
|
|
|
* returns: -1 on error (group not found, group in fail state)
|
|
|
|
* -2 if wpa_group is still referenced
|
|
|
|
* 0 else
|
|
|
|
*/
|
|
|
|
int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id)
|
|
|
|
{
|
|
|
|
struct wpa_group *group;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (wpa_auth == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
group = wpa_auth->group;
|
|
|
|
while (group) {
|
|
|
|
if (group->vlan_id == vlan_id)
|
|
|
|
break;
|
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Try stopping group state machine for VLAN ID %d",
|
|
|
|
vlan_id);
|
|
|
|
|
|
|
|
if (group->num_setup_iface <= 0) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"WPA: wpa_auth_release_group called more often than wpa_auth_ensure_group for VLAN ID %d, skipping.",
|
|
|
|
vlan_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
group->num_setup_iface--;
|
|
|
|
|
|
|
|
if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
if (group->references > 1) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPA: Cannot stop group state machine for VLAN ID %d as references are still hold",
|
|
|
|
vlan_id);
|
|
|
|
ret = -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_group_put(wpa_auth, group);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id)
|
|
|
|
{
|
|
|
|
struct wpa_group *group;
|
|
|
|
|
|
|
|
if (sm == NULL || sm->wpa_auth == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
group = sm->wpa_auth->group;
|
|
|
|
while (group) {
|
|
|
|
if (group->vlan_id == vlan_id)
|
|
|
|
break;
|
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group == NULL) {
|
|
|
|
group = wpa_auth_add_group(sm->wpa_auth, vlan_id);
|
|
|
|
if (group == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sm->group == group)
|
|
|
|
return 0;
|
|
|
|
|
2013-12-24 21:38:16 +01:00
|
|
|
if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
|
|
|
|
return -1;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Moving STA " MACSTR " to use group state "
|
|
|
|
"machine for VLAN ID %d", MAC2STR(sm->addr), vlan_id);
|
|
|
|
|
2015-04-26 14:22:55 +02:00
|
|
|
wpa_group_get(sm->wpa_auth, group);
|
|
|
|
wpa_group_put(sm->wpa_auth, sm->group);
|
2008-02-28 02:34:43 +01:00
|
|
|
sm->group = group;
|
2015-04-26 14:22:55 +02:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2011-03-29 16:39:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct wpa_state_machine *sm, int ack)
|
|
|
|
{
|
|
|
|
if (wpa_auth == NULL || sm == NULL)
|
|
|
|
return;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key TX status for STA " MACSTR
|
|
|
|
" ack=%d", MAC2STR(sm->addr), ack);
|
|
|
|
if (sm->pending_1_of_4_timeout && ack) {
|
|
|
|
/*
|
|
|
|
* Some deployed supplicant implementations update their SNonce
|
|
|
|
* for each EAPOL-Key 2/4 message even within the same 4-way
|
|
|
|
* handshake and then fail to use the first SNonce when
|
|
|
|
* deriving the PTK. This results in unsuccessful 4-way
|
|
|
|
* handshake whenever the relatively short initial timeout is
|
|
|
|
* reached and EAPOL-Key 1/4 is retransmitted. Try to work
|
|
|
|
* around this by increasing the timeout now that we know that
|
|
|
|
* the station has received the frame.
|
|
|
|
*/
|
|
|
|
int timeout_ms = eapol_key_timeout_subseq;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPA: Increase initial EAPOL-Key 1/4 "
|
|
|
|
"timeout by %u ms because of acknowledged frame",
|
|
|
|
timeout_ms);
|
|
|
|
eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
|
|
|
|
eloop_register_timeout(timeout_ms / 1000,
|
|
|
|
(timeout_ms % 1000) * 1000,
|
|
|
|
wpa_send_eapol_timeout, wpa_auth, sm);
|
|
|
|
}
|
2017-10-19 11:16:18 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
if (sm->eapol_status_cb) {
|
|
|
|
sm->eapol_status_cb(sm->eapol_status_cb_ctx1,
|
|
|
|
sm->eapol_status_cb_ctx2);
|
|
|
|
sm->eapol_status_cb = NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
2011-03-29 16:39:12 +02:00
|
|
|
}
|
2012-09-30 18:51:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_uses_sae(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm == NULL)
|
|
|
|
return 0;
|
|
|
|
return wpa_key_mgmt_sae(sm->wpa_key_mgmt);
|
|
|
|
}
|
2013-12-28 12:41:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm)
|
|
|
|
{
|
|
|
|
if (sm == NULL)
|
|
|
|
return 0;
|
|
|
|
return sm->wpa_key_mgmt == WPA_KEY_MGMT_FT_SAE;
|
|
|
|
}
|
2013-03-16 18:13:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr)
|
|
|
|
{
|
|
|
|
if (sm == NULL || WPA_GET_BE32(sm->ip_addr) == 0)
|
|
|
|
return -1;
|
|
|
|
os_memcpy(addr, sm->ip_addr, 4);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
2015-01-16 14:55:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
|
|
|
|
struct radius_das_attrs *attr)
|
|
|
|
{
|
|
|
|
return pmksa_cache_auth_radius_das_disconnect(wpa_auth->pmksa, attr);
|
|
|
|
}
|
2015-02-10 17:19:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
struct wpa_group *group;
|
|
|
|
|
|
|
|
if (!wpa_auth)
|
|
|
|
return;
|
|
|
|
for (group = wpa_auth->group; group; group = group->next)
|
|
|
|
wpa_group_config_group_keys(wpa_auth, group);
|
|
|
|
}
|
2017-02-21 11:18:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_FILS
|
|
|
|
|
|
|
|
struct wpa_auth_fils_iter_data {
|
|
|
|
struct wpa_authenticator *auth;
|
|
|
|
const u8 *cache_id;
|
|
|
|
struct rsn_pmksa_cache_entry *pmksa;
|
|
|
|
const u8 *spa;
|
|
|
|
const u8 *pmkid;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int wpa_auth_fils_iter(struct wpa_authenticator *a, void *ctx)
|
|
|
|
{
|
|
|
|
struct wpa_auth_fils_iter_data *data = ctx;
|
|
|
|
|
2017-03-23 11:41:22 +01:00
|
|
|
if (a == data->auth || !a->conf.fils_cache_id_set ||
|
2017-02-21 11:18:58 +01:00
|
|
|
os_memcmp(a->conf.fils_cache_id, data->cache_id,
|
|
|
|
FILS_CACHE_ID_LEN) != 0)
|
|
|
|
return 0;
|
|
|
|
data->pmksa = pmksa_cache_auth_get(a->pmksa, data->spa, data->pmkid);
|
|
|
|
return data->pmksa != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct rsn_pmksa_cache_entry *
|
|
|
|
wpa_auth_pmksa_get_fils_cache_id(struct wpa_authenticator *wpa_auth,
|
|
|
|
const u8 *sta_addr, const u8 *pmkid)
|
|
|
|
{
|
|
|
|
struct wpa_auth_fils_iter_data idata;
|
|
|
|
|
|
|
|
if (!wpa_auth->conf.fils_cache_id_set)
|
|
|
|
return NULL;
|
|
|
|
idata.auth = wpa_auth;
|
|
|
|
idata.cache_id = wpa_auth->conf.fils_cache_id;
|
|
|
|
idata.pmksa = NULL;
|
|
|
|
idata.spa = sta_addr;
|
|
|
|
idata.pmkid = pmkid;
|
|
|
|
wpa_auth_for_each_auth(wpa_auth, wpa_auth_fils_iter, &idata);
|
|
|
|
return idata.pmksa;
|
|
|
|
}
|
|
|
|
|
2017-04-02 21:38:48 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
2018-06-05 00:31:43 +02:00
|
|
|
int wpa_auth_write_fte(struct wpa_authenticator *wpa_auth, int use_sha384,
|
|
|
|
u8 *buf, size_t len)
|
2017-04-02 21:38:48 +02:00
|
|
|
{
|
|
|
|
struct wpa_auth_config *conf = &wpa_auth->conf;
|
|
|
|
|
2018-06-05 00:31:43 +02:00
|
|
|
return wpa_write_ftie(conf, use_sha384, conf->r0_key_holder,
|
2017-04-02 21:38:48 +02:00
|
|
|
conf->r0_key_holder_len,
|
2020-03-20 20:23:48 +01:00
|
|
|
NULL, NULL, buf, len, NULL, 0, 0);
|
2017-04-02 21:38:48 +02:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
|
|
|
|
2017-04-21 19:43:57 +02:00
|
|
|
|
|
|
|
void wpa_auth_get_fils_aead_params(struct wpa_state_machine *sm,
|
|
|
|
u8 *fils_anonce, u8 *fils_snonce,
|
|
|
|
u8 *fils_kek, size_t *fils_kek_len)
|
|
|
|
{
|
|
|
|
os_memcpy(fils_anonce, sm->ANonce, WPA_NONCE_LEN);
|
|
|
|
os_memcpy(fils_snonce, sm->SNonce, WPA_NONCE_LEN);
|
|
|
|
os_memcpy(fils_kek, sm->PTK.kek, WPA_KEK_MAX_LEN);
|
|
|
|
*fils_kek_len = sm->PTK.kek_len;
|
|
|
|
}
|
|
|
|
|
2019-04-17 21:52:23 +02:00
|
|
|
|
|
|
|
void wpa_auth_add_fils_pmk_pmkid(struct wpa_state_machine *sm, const u8 *pmk,
|
|
|
|
size_t pmk_len, const u8 *pmkid)
|
|
|
|
{
|
|
|
|
os_memcpy(sm->PMK, pmk, pmk_len);
|
|
|
|
sm->pmk_len = pmk_len;
|
|
|
|
os_memcpy(sm->pmkid, pmkid, PMKID_LEN);
|
|
|
|
sm->pmkid_set = 1;
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:18:58 +01:00
|
|
|
#endif /* CONFIG_FILS */
|
2017-10-14 15:53:27 +02:00
|
|
|
|
|
|
|
|
2019-03-13 16:24:29 +01:00
|
|
|
void wpa_auth_set_auth_alg(struct wpa_state_machine *sm, u16 auth_alg)
|
|
|
|
{
|
|
|
|
if (sm)
|
|
|
|
sm->auth_alg = auth_alg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-17 22:51:53 +01:00
|
|
|
#ifdef CONFIG_DPP2
|
|
|
|
void wpa_auth_set_dpp_z(struct wpa_state_machine *sm, const struct wpabuf *z)
|
|
|
|
{
|
|
|
|
if (sm) {
|
|
|
|
wpabuf_clear_free(sm->dpp_z);
|
|
|
|
sm->dpp_z = z ? wpabuf_dup(z) : NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DPP2 */
|
|
|
|
|
|
|
|
|
2018-01-31 17:01:00 +01:00
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
2017-10-14 16:23:59 +02:00
|
|
|
|
2017-10-19 11:16:18 +02:00
|
|
|
int wpa_auth_resend_m1(struct wpa_state_machine *sm, int change_anonce,
|
|
|
|
void (*cb)(void *ctx1, void *ctx2),
|
|
|
|
void *ctx1, void *ctx2)
|
2017-10-14 16:23:59 +02:00
|
|
|
{
|
|
|
|
const u8 *anonce = sm->ANonce;
|
|
|
|
u8 anonce_buf[WPA_NONCE_LEN];
|
|
|
|
|
|
|
|
if (change_anonce) {
|
|
|
|
if (random_get_bytes(anonce_buf, WPA_NONCE_LEN))
|
|
|
|
return -1;
|
|
|
|
anonce = anonce_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"sending 1/4 msg of 4-Way Handshake (TESTING)");
|
|
|
|
wpa_send_eapol(sm->wpa_auth, sm,
|
|
|
|
WPA_KEY_INFO_ACK | WPA_KEY_INFO_KEY_TYPE, NULL,
|
|
|
|
anonce, NULL, 0, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-19 11:16:18 +02:00
|
|
|
int wpa_auth_resend_m3(struct wpa_state_machine *sm,
|
|
|
|
void (*cb)(void *ctx1, void *ctx2),
|
|
|
|
void *ctx1, void *ctx2)
|
2017-10-14 16:23:59 +02:00
|
|
|
{
|
2017-11-01 10:10:47 +01:00
|
|
|
u8 rsc[WPA_KEY_RSC_LEN], *_rsc, *gtk, *kde, *pos;
|
|
|
|
u8 *opos;
|
2017-10-14 16:23:59 +02:00
|
|
|
size_t gtk_len, kde_len;
|
|
|
|
struct wpa_group *gsm = sm->group;
|
|
|
|
u8 *wpa_ie;
|
2019-09-15 22:08:21 +02:00
|
|
|
int wpa_ie_len, secure, gtkidx, encr = 0;
|
2020-03-20 20:04:31 +01:00
|
|
|
u8 hdr[2];
|
2017-10-14 16:23:59 +02:00
|
|
|
|
|
|
|
/* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
|
2020-02-17 22:08:05 +01:00
|
|
|
GTK[GN], IGTK, [BIGTK], [FTIE], [TIE * 2])
|
2017-10-14 16:23:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Use 0 RSC */
|
|
|
|
os_memset(rsc, 0, WPA_KEY_RSC_LEN);
|
|
|
|
/* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
|
|
|
|
wpa_ie = sm->wpa_auth->wpa_ie;
|
|
|
|
wpa_ie_len = sm->wpa_auth->wpa_ie_len;
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA &&
|
|
|
|
(sm->wpa_auth->conf.wpa & WPA_PROTO_RSN) &&
|
|
|
|
wpa_ie_len > wpa_ie[1] + 2 && wpa_ie[0] == WLAN_EID_RSN) {
|
|
|
|
/* WPA-only STA, remove RSN IE and possible MDIE */
|
|
|
|
wpa_ie = wpa_ie + wpa_ie[1] + 2;
|
|
|
|
if (wpa_ie[0] == WLAN_EID_MOBILITY_DOMAIN)
|
|
|
|
wpa_ie = wpa_ie + wpa_ie[1] + 2;
|
|
|
|
wpa_ie_len = wpa_ie[1] + 2;
|
|
|
|
}
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"sending 3/4 msg of 4-Way Handshake (TESTING)");
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA2) {
|
|
|
|
/* WPA2 send GTK in the 4-way handshake */
|
|
|
|
secure = 1;
|
|
|
|
gtk = gsm->GTK[gsm->GN - 1];
|
|
|
|
gtk_len = gsm->GTK_len;
|
2019-09-15 22:08:21 +02:00
|
|
|
gtkidx = gsm->GN;
|
2017-10-14 16:23:59 +02:00
|
|
|
_rsc = rsc;
|
|
|
|
encr = 1;
|
|
|
|
} else {
|
|
|
|
/* WPA does not include GTK in msg 3/4 */
|
|
|
|
secure = 0;
|
|
|
|
gtk = NULL;
|
|
|
|
gtk_len = 0;
|
|
|
|
_rsc = NULL;
|
|
|
|
if (sm->rx_eapol_key_secure) {
|
|
|
|
/*
|
|
|
|
* It looks like Windows 7 supplicant tries to use
|
|
|
|
* Secure bit in msg 2/4 after having reported Michael
|
|
|
|
* MIC failure and it then rejects the 4-way handshake
|
|
|
|
* if msg 3/4 does not set Secure bit. Work around this
|
|
|
|
* by setting the Secure bit here even in the case of
|
|
|
|
* WPA if the supplicant used it first.
|
|
|
|
*/
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"STA used Secure bit in WPA msg 2/4 - "
|
|
|
|
"set Secure for 3/4 as workaround");
|
|
|
|
secure = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:46:27 +02:00
|
|
|
kde_len = wpa_ie_len + ieee80211w_kde_len(sm) + ocv_oci_len(sm);
|
2020-03-20 20:04:31 +01:00
|
|
|
|
|
|
|
if (sm->use_ext_key_id)
|
|
|
|
kde_len += 2 + RSN_SELECTOR_LEN + 2;
|
|
|
|
|
2017-10-14 16:23:59 +02:00
|
|
|
if (gtk)
|
|
|
|
kde_len += 2 + RSN_SELECTOR_LEN + 2 + gtk_len;
|
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
kde_len += 2 + PMKID_LEN; /* PMKR1Name into RSN IE */
|
|
|
|
kde_len += 300; /* FTIE + 2 * TIE */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
|
|
|
kde = os_malloc(kde_len);
|
|
|
|
if (kde == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
pos = kde;
|
|
|
|
os_memcpy(pos, wpa_ie, wpa_ie_len);
|
|
|
|
pos += wpa_ie_len;
|
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
int res;
|
|
|
|
size_t elen;
|
|
|
|
|
|
|
|
elen = pos - kde;
|
|
|
|
res = wpa_insert_pmkid(kde, &elen, sm->pmk_r1_name);
|
|
|
|
if (res < 0) {
|
|
|
|
wpa_printf(MSG_ERROR, "FT: Failed to insert "
|
|
|
|
"PMKR1Name into RSN IE in EAPOL-Key data");
|
|
|
|
os_free(kde);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pos -= wpa_ie_len;
|
|
|
|
pos += elen;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
2020-03-20 20:04:31 +01:00
|
|
|
hdr[1] = 0;
|
|
|
|
|
|
|
|
if (sm->use_ext_key_id) {
|
|
|
|
hdr[0] = sm->keyidx_active & 0x01;
|
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_KEYID, hdr, 2, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2017-10-14 16:23:59 +02:00
|
|
|
if (gtk) {
|
2019-09-15 22:08:21 +02:00
|
|
|
hdr[0] = gtkidx & 0x03;
|
2017-10-14 16:23:59 +02:00
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
|
|
|
|
gtk, gtk_len);
|
|
|
|
}
|
|
|
|
opos = pos;
|
|
|
|
pos = ieee80211w_kde_add(sm, pos);
|
2018-04-01 19:16:47 +02:00
|
|
|
if (pos - opos >= 2 + RSN_SELECTOR_LEN + WPA_IGTK_KDE_PREFIX_LEN) {
|
|
|
|
/* skip KDE header and keyid */
|
|
|
|
opos += 2 + RSN_SELECTOR_LEN + 2;
|
2017-10-14 16:23:59 +02:00
|
|
|
os_memset(opos, 0, 6); /* clear PN */
|
|
|
|
}
|
2018-08-06 21:46:27 +02:00
|
|
|
if (ocv_oci_add(sm, &pos) < 0) {
|
|
|
|
os_free(kde);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-10-14 16:23:59 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R_AP
|
|
|
|
if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
|
|
|
|
int res;
|
|
|
|
struct wpa_auth_config *conf;
|
|
|
|
|
|
|
|
conf = &sm->wpa_auth->conf;
|
|
|
|
if (sm->assoc_resp_ftie &&
|
|
|
|
kde + kde_len - pos >= 2 + sm->assoc_resp_ftie[1]) {
|
|
|
|
os_memcpy(pos, sm->assoc_resp_ftie,
|
|
|
|
2 + sm->assoc_resp_ftie[1]);
|
|
|
|
res = 2 + sm->assoc_resp_ftie[1];
|
|
|
|
} else {
|
2018-06-05 00:31:43 +02:00
|
|
|
int use_sha384 = wpa_key_mgmt_sha384(sm->wpa_key_mgmt);
|
|
|
|
|
|
|
|
res = wpa_write_ftie(conf, use_sha384,
|
|
|
|
conf->r0_key_holder,
|
2017-10-14 16:23:59 +02:00
|
|
|
conf->r0_key_holder_len,
|
|
|
|
NULL, NULL, pos,
|
|
|
|
kde + kde_len - pos,
|
2020-03-20 20:23:48 +01:00
|
|
|
NULL, 0, 0);
|
2017-10-14 16:23:59 +02:00
|
|
|
}
|
|
|
|
if (res < 0) {
|
|
|
|
wpa_printf(MSG_ERROR, "FT: Failed to insert FTIE "
|
|
|
|
"into EAPOL-Key Key Data");
|
|
|
|
os_free(kde);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pos += res;
|
|
|
|
|
|
|
|
/* TIE[ReassociationDeadline] (TU) */
|
|
|
|
*pos++ = WLAN_EID_TIMEOUT_INTERVAL;
|
|
|
|
*pos++ = 5;
|
|
|
|
*pos++ = WLAN_TIMEOUT_REASSOC_DEADLINE;
|
|
|
|
WPA_PUT_LE32(pos, conf->reassociation_deadline);
|
|
|
|
pos += 4;
|
|
|
|
|
|
|
|
/* TIE[KeyLifetime] (seconds) */
|
|
|
|
*pos++ = WLAN_EID_TIMEOUT_INTERVAL;
|
|
|
|
*pos++ = 5;
|
|
|
|
*pos++ = WLAN_TIMEOUT_KEY_LIFETIME;
|
2017-05-18 15:21:50 +02:00
|
|
|
WPA_PUT_LE32(pos, conf->r0_key_lifetime);
|
2017-10-14 16:23:59 +02:00
|
|
|
pos += 4;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R_AP */
|
|
|
|
|
|
|
|
wpa_send_eapol(sm->wpa_auth, sm,
|
|
|
|
(secure ? WPA_KEY_INFO_SECURE : 0) |
|
|
|
|
(wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
|
|
|
|
WPA_KEY_INFO_MIC : 0) |
|
|
|
|
WPA_KEY_INFO_ACK | WPA_KEY_INFO_INSTALL |
|
|
|
|
WPA_KEY_INFO_KEY_TYPE,
|
2019-09-15 22:08:21 +02:00
|
|
|
_rsc, sm->ANonce, kde, pos - kde, 0, encr);
|
2017-10-14 16:23:59 +02:00
|
|
|
os_free(kde);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-19 11:16:18 +02:00
|
|
|
int wpa_auth_resend_group_m1(struct wpa_state_machine *sm,
|
|
|
|
void (*cb)(void *ctx1, void *ctx2),
|
|
|
|
void *ctx1, void *ctx2)
|
2017-10-14 15:53:27 +02:00
|
|
|
{
|
|
|
|
u8 rsc[WPA_KEY_RSC_LEN];
|
|
|
|
struct wpa_group *gsm = sm->group;
|
|
|
|
const u8 *kde;
|
2017-11-01 10:10:47 +01:00
|
|
|
u8 *kde_buf = NULL, *pos, hdr[2];
|
|
|
|
u8 *opos;
|
2017-10-14 15:53:27 +02:00
|
|
|
size_t kde_len;
|
|
|
|
u8 *gtk;
|
|
|
|
|
|
|
|
/* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
|
|
|
|
os_memset(rsc, 0, WPA_KEY_RSC_LEN);
|
|
|
|
/* Use 0 RSC */
|
|
|
|
wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
|
|
|
|
"sending 1/2 msg of Group Key Handshake (TESTING)");
|
|
|
|
|
|
|
|
gtk = gsm->GTK[gsm->GN - 1];
|
|
|
|
if (sm->wpa == WPA_VERSION_WPA2) {
|
|
|
|
kde_len = 2 + RSN_SELECTOR_LEN + 2 + gsm->GTK_len +
|
2018-08-06 21:46:27 +02:00
|
|
|
ieee80211w_kde_len(sm) + ocv_oci_len(sm);
|
2017-10-14 15:53:27 +02:00
|
|
|
kde_buf = os_malloc(kde_len);
|
|
|
|
if (kde_buf == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
kde = pos = kde_buf;
|
|
|
|
hdr[0] = gsm->GN & 0x03;
|
|
|
|
hdr[1] = 0;
|
|
|
|
pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
|
|
|
|
gtk, gsm->GTK_len);
|
|
|
|
opos = pos;
|
|
|
|
pos = ieee80211w_kde_add(sm, pos);
|
2018-04-01 19:16:47 +02:00
|
|
|
if (pos - opos >=
|
|
|
|
2 + RSN_SELECTOR_LEN + WPA_IGTK_KDE_PREFIX_LEN) {
|
|
|
|
/* skip KDE header and keyid */
|
|
|
|
opos += 2 + RSN_SELECTOR_LEN + 2;
|
2017-10-14 15:53:27 +02:00
|
|
|
os_memset(opos, 0, 6); /* clear PN */
|
|
|
|
}
|
2018-08-06 21:46:27 +02:00
|
|
|
if (ocv_oci_add(sm, &pos) < 0) {
|
|
|
|
os_free(kde_buf);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-10-14 15:53:27 +02:00
|
|
|
kde_len = pos - kde;
|
|
|
|
} else {
|
|
|
|
kde = gtk;
|
|
|
|
kde_len = gsm->GTK_len;
|
|
|
|
}
|
|
|
|
|
2017-10-19 11:16:18 +02:00
|
|
|
sm->eapol_status_cb = cb;
|
|
|
|
sm->eapol_status_cb_ctx1 = ctx1;
|
|
|
|
sm->eapol_status_cb_ctx2 = ctx2;
|
|
|
|
|
2017-10-14 15:53:27 +02:00
|
|
|
wpa_send_eapol(sm->wpa_auth, sm,
|
|
|
|
WPA_KEY_INFO_SECURE |
|
|
|
|
(wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
|
|
|
|
WPA_KEY_INFO_MIC : 0) |
|
|
|
|
WPA_KEY_INFO_ACK |
|
|
|
|
(!sm->Pair ? WPA_KEY_INFO_INSTALL : 0),
|
|
|
|
rsc, NULL, kde, kde_len, gsm->GN, 1);
|
|
|
|
|
|
|
|
os_free(kde_buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-14 16:23:59 +02:00
|
|
|
|
2017-10-25 10:26:10 +02:00
|
|
|
|
|
|
|
int wpa_auth_rekey_gtk(struct wpa_authenticator *wpa_auth)
|
|
|
|
{
|
|
|
|
if (!wpa_auth)
|
|
|
|
return -1;
|
|
|
|
eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
|
|
|
|
return eloop_register_timeout(0, 0, wpa_rekey_gtk, wpa_auth, NULL);
|
|
|
|
}
|
|
|
|
|
2017-10-14 15:53:27 +02:00
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|