2016-11-02 23:46:18 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-10-25 00:43:08 +02:00
|
|
|
* Copyright (C) 2013-2019 Intel Corporation. All rights reserved.
|
2016-11-02 23:46:18 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
2018-06-22 02:32:55 +02:00
|
|
|
struct handshake_state;
|
2018-09-22 18:48:15 +02:00
|
|
|
enum crypto_cipher;
|
2018-06-22 02:32:55 +02:00
|
|
|
|
2017-09-22 05:06:40 +02:00
|
|
|
enum handshake_kde {
|
2020-09-14 15:51:16 +02:00
|
|
|
/* 802.11-2016 Table 12-6 in section 12.7.2 */
|
2017-09-22 05:06:40 +02:00
|
|
|
HANDSHAKE_KDE_GTK = 0x000fac01,
|
|
|
|
HANDSHAKE_KDE_MAC_ADDRESS = 0x000fac03,
|
|
|
|
HANDSHAKE_KDE_PMKID = 0x000fac04,
|
|
|
|
HANDSHAKE_KDE_SMK = 0x000fac05,
|
|
|
|
HANDSHAKE_KDE_NONCE = 0x000fac06,
|
|
|
|
HANDSHAKE_KDE_LIFETIME = 0x000fac07,
|
|
|
|
HANDSHAKE_KDE_ERROR = 0x000fac08,
|
|
|
|
HANDSHAKE_KDE_IGTK = 0x000fac09,
|
|
|
|
HANDSHAKE_KDE_KEY_ID = 0x000fac0a,
|
|
|
|
HANDSHAKE_KDE_MULTIBAND_GTK = 0x000fac0b,
|
|
|
|
HANDSHAKE_KDE_MULTIBAND_KEY_ID = 0x000fac0c,
|
2020-09-14 15:51:16 +02:00
|
|
|
/* Wi-Fi P2P Technical Specification v1.7 4.2.8 */
|
|
|
|
HANDSHAKE_KDE_IP_ADDRESS_REQ = 0x506f9a04,
|
|
|
|
HANDSHAKE_KDE_IP_ADDRESS_ALLOC = 0x506f9a05,
|
2017-09-22 05:06:40 +02:00
|
|
|
};
|
|
|
|
|
2018-06-22 20:13:27 +02:00
|
|
|
enum handshake_event {
|
|
|
|
HANDSHAKE_EVENT_STARTED,
|
|
|
|
HANDSHAKE_EVENT_SETTING_KEYS,
|
2018-07-03 23:36:33 +02:00
|
|
|
HANDSHAKE_EVENT_SETTING_KEYS_FAILED,
|
2018-06-22 20:13:27 +02:00
|
|
|
HANDSHAKE_EVENT_COMPLETE,
|
2019-01-25 20:23:10 +01:00
|
|
|
HANDSHAKE_EVENT_FAILED,
|
|
|
|
HANDSHAKE_EVENT_REKEY_FAILED,
|
2019-10-28 15:05:00 +01:00
|
|
|
HANDSHAKE_EVENT_EAP_NOTIFY,
|
2018-06-22 20:13:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*handshake_event_func_t)(struct handshake_state *hs,
|
|
|
|
enum handshake_event event,
|
2019-10-28 15:04:57 +01:00
|
|
|
void *user_data, ...);
|
2018-06-22 20:13:27 +02:00
|
|
|
|
2016-11-02 23:46:18 +01:00
|
|
|
typedef bool (*handshake_get_nonce_func_t)(uint8_t nonce[]);
|
2018-06-22 02:32:55 +02:00
|
|
|
typedef void (*handshake_install_tk_func_t)(struct handshake_state *hs,
|
|
|
|
const uint8_t *tk, uint32_t cipher);
|
|
|
|
typedef void (*handshake_install_gtk_func_t)(struct handshake_state *hs,
|
2020-04-02 07:41:02 +02:00
|
|
|
uint16_t key_index,
|
2016-11-02 23:46:18 +01:00
|
|
|
const uint8_t *gtk, uint8_t gtk_len,
|
|
|
|
const uint8_t *rsc, uint8_t rsc_len,
|
2018-06-22 02:32:55 +02:00
|
|
|
uint32_t cipher);
|
|
|
|
typedef void (*handshake_install_igtk_func_t)(struct handshake_state *hs,
|
2020-04-02 07:41:02 +02:00
|
|
|
uint16_t key_index,
|
2016-11-02 23:46:18 +01:00
|
|
|
const uint8_t *igtk, uint8_t igtk_len,
|
|
|
|
const uint8_t *ipn, uint8_t ipn_len,
|
2018-06-22 02:32:55 +02:00
|
|
|
uint32_t cipher);
|
2016-11-02 23:46:18 +01:00
|
|
|
|
|
|
|
void __handshake_set_get_nonce_func(handshake_get_nonce_func_t func);
|
|
|
|
void __handshake_set_install_tk_func(handshake_install_tk_func_t func);
|
|
|
|
void __handshake_set_install_gtk_func(handshake_install_gtk_func_t func);
|
|
|
|
void __handshake_set_install_igtk_func(handshake_install_igtk_func_t func);
|
|
|
|
|
|
|
|
struct handshake_state {
|
|
|
|
uint32_t ifindex;
|
|
|
|
uint8_t spa[6];
|
|
|
|
uint8_t aa[6];
|
2018-08-25 03:54:24 +02:00
|
|
|
uint8_t *authenticator_ie;
|
|
|
|
uint8_t *supplicant_ie;
|
2016-11-02 23:46:18 +01:00
|
|
|
uint8_t *mde;
|
|
|
|
uint8_t *fte;
|
|
|
|
enum ie_rsn_cipher_suite pairwise_cipher;
|
|
|
|
enum ie_rsn_cipher_suite group_cipher;
|
|
|
|
enum ie_rsn_cipher_suite group_management_cipher;
|
|
|
|
enum ie_rsn_akm_suite akm_suite;
|
2018-03-15 12:06:53 +01:00
|
|
|
uint8_t pmk[64];
|
2019-01-14 21:54:17 +01:00
|
|
|
size_t pmk_len;
|
2016-11-02 23:46:18 +01:00
|
|
|
uint8_t snonce[32];
|
|
|
|
uint8_t anonce[32];
|
2019-05-10 22:19:29 +02:00
|
|
|
uint8_t ptk[136];
|
2019-05-10 22:19:30 +02:00
|
|
|
uint8_t pmk_r0[48];
|
2016-11-02 23:46:18 +01:00
|
|
|
uint8_t pmk_r0_name[16];
|
2019-05-10 22:19:30 +02:00
|
|
|
uint8_t pmk_r1[48];
|
2016-11-02 23:46:18 +01:00
|
|
|
uint8_t pmk_r1_name[16];
|
2018-08-07 23:29:10 +02:00
|
|
|
uint8_t pmkid[16];
|
2019-05-10 22:19:26 +02:00
|
|
|
uint8_t fils_ft[48];
|
|
|
|
uint8_t fils_ft_len;
|
2016-11-02 23:46:18 +01:00
|
|
|
struct l_settings *settings_8021x;
|
2021-07-08 21:10:15 +02:00
|
|
|
struct l_ecc_point **ecc_sae_pts;
|
2016-11-02 23:46:18 +01:00
|
|
|
bool have_snonce : 1;
|
|
|
|
bool ptk_complete : 1;
|
|
|
|
bool wpa_ie : 1;
|
2019-06-11 00:46:56 +02:00
|
|
|
bool osen_ie : 1;
|
2016-11-02 23:46:18 +01:00
|
|
|
bool have_pmk : 1;
|
|
|
|
bool mfp : 1;
|
2018-06-20 20:05:16 +02:00
|
|
|
bool have_anonce : 1;
|
2018-08-07 23:29:10 +02:00
|
|
|
bool have_pmkid : 1;
|
2018-08-15 19:36:18 +02:00
|
|
|
bool authenticator : 1;
|
netdev: signal handshake complete after setting all keys
Currently, netdev triggers the HANDSHAKE_COMPLETE event after completing
the SET_STATION (after setting the pairwise key). Depending on the timing
this may happen before the GTK/IGTK are set which will result in group
traffic not working initially (the GTK/IGTK would still get set, but group
traffic would not work immediately after DBus said you were connected, this
mainly poses a problem with autotests).
In order to fix this, several flags were added in netdev_handshake_state:
ptk_installed, gtk_installed, igtk_installed, and completed. Each of these
flags are set true when their respective keys are set, and in each key
callback we try to trigger the handshake complete event (assuming all the
flags are true). Initially the gtk/igtk flags are set to true, for reasons
explained below.
In the WPA2 case, all the key setter functions are called sequentially from
eapol. With this change, the PTK is now set AFTER the gtk/igtk. This is
because the gtk/igtk are optional and only set if group traffic is allowed.
If the gtk/igtk are not used, we set the PTK and can immediately trigger the
handshake complete event (since gtk_installed/igtk_installed are initialized
as true). When the gtk/igtk are being set, we immediately set their flags to
false and wait for their callbacks in addition to the PTK callback. Doing it
this way handles both group traffic and non group traffic paths.
WPA1 throws a wrench into this since the group keys are obtained in a
separate handshake. For this case a new flag was added to the handshake_state,
'wait_for_gtk'. This allows netdev to set the PTK after the initial 4-way,
but still wait for the gtk/igtk setters to get called before triggering the
handshake complete event. As a precaution, netdev sets a timeout that will
trigger if the gtk/igtk setters are never called. In this case we can still
complete the connection, but print a warning that group traffic will not be
allowed.
2018-10-26 18:44:58 +02:00
|
|
|
bool wait_for_gtk : 1;
|
2019-01-25 20:23:09 +01:00
|
|
|
bool no_rekey : 1;
|
2019-04-10 23:52:30 +02:00
|
|
|
bool support_fils : 1;
|
2016-11-02 23:46:18 +01:00
|
|
|
uint8_t ssid[32];
|
|
|
|
size_t ssid_len;
|
2018-08-07 23:29:06 +02:00
|
|
|
char *passphrase;
|
2016-11-02 23:46:18 +01:00
|
|
|
uint8_t r0khid[48];
|
|
|
|
size_t r0khid_len;
|
|
|
|
uint8_t r1khid[6];
|
2018-09-22 18:48:14 +02:00
|
|
|
uint8_t gtk[32];
|
|
|
|
uint8_t gtk_rsc[6];
|
2019-07-16 04:45:12 +02:00
|
|
|
uint8_t proto_version : 2;
|
2018-09-22 18:48:14 +02:00
|
|
|
unsigned int gtk_index;
|
2019-04-22 19:11:43 +02:00
|
|
|
struct erp_cache_entry *erp_cache;
|
2020-09-14 15:51:16 +02:00
|
|
|
bool support_ip_allocation : 1;
|
|
|
|
uint32_t client_ip_addr;
|
|
|
|
uint32_t subnet_mask;
|
|
|
|
uint32_t go_ip_addr;
|
2016-11-02 23:46:18 +01:00
|
|
|
void *user_data;
|
2018-06-22 02:32:55 +02:00
|
|
|
|
|
|
|
void (*free)(struct handshake_state *s);
|
2018-06-22 20:13:27 +02:00
|
|
|
|
|
|
|
handshake_event_func_t event_func;
|
2016-11-02 23:46:18 +01:00
|
|
|
};
|
|
|
|
|
2019-10-28 15:04:57 +01:00
|
|
|
#define handshake_event(hs, event, ...) \
|
|
|
|
do { \
|
|
|
|
if (!(hs)->event_func) \
|
|
|
|
break; \
|
|
|
|
\
|
|
|
|
(hs)->event_func((hs), event, (hs)->user_data, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
2016-11-02 23:46:18 +01:00
|
|
|
void handshake_state_free(struct handshake_state *s);
|
|
|
|
|
|
|
|
void handshake_state_set_supplicant_address(struct handshake_state *s,
|
|
|
|
const uint8_t *spa);
|
|
|
|
void handshake_state_set_authenticator_address(struct handshake_state *s,
|
|
|
|
const uint8_t *aa);
|
2018-08-15 19:36:18 +02:00
|
|
|
void handshake_state_set_authenticator(struct handshake_state *s, bool auth);
|
2018-03-15 12:06:53 +01:00
|
|
|
void handshake_state_set_pmk(struct handshake_state *s, const uint8_t *pmk,
|
|
|
|
size_t pmk_len);
|
2019-04-18 01:46:17 +02:00
|
|
|
void handshake_state_set_ptk(struct handshake_state *s, const uint8_t *ptk,
|
|
|
|
size_t ptk_len);
|
2016-11-02 23:46:18 +01:00
|
|
|
void handshake_state_set_8021x_config(struct handshake_state *s,
|
|
|
|
struct l_settings *settings);
|
2019-06-07 21:17:00 +02:00
|
|
|
bool handshake_state_set_authenticator_ie(struct handshake_state *s,
|
|
|
|
const uint8_t *ie);
|
|
|
|
bool handshake_state_set_supplicant_ie(struct handshake_state *s,
|
|
|
|
const uint8_t *ie);
|
2016-11-02 23:46:18 +01:00
|
|
|
void handshake_state_set_ssid(struct handshake_state *s,
|
|
|
|
const uint8_t *ssid, size_t ssid_len);
|
|
|
|
void handshake_state_set_mde(struct handshake_state *s,
|
|
|
|
const uint8_t *mde);
|
|
|
|
void handshake_state_set_fte(struct handshake_state *s, const uint8_t *fte);
|
|
|
|
|
|
|
|
void handshake_state_set_kh_ids(struct handshake_state *s,
|
|
|
|
const uint8_t *r0khid, size_t r0khid_len,
|
|
|
|
const uint8_t *r1khid);
|
|
|
|
|
2018-06-22 20:13:27 +02:00
|
|
|
void handshake_state_set_event_func(struct handshake_state *s,
|
|
|
|
handshake_event_func_t func,
|
|
|
|
void *user_data);
|
2018-08-07 23:29:06 +02:00
|
|
|
void handshake_state_set_passphrase(struct handshake_state *s,
|
|
|
|
const char *passphrase);
|
2021-07-08 21:10:15 +02:00
|
|
|
bool handshake_state_add_ecc_sae_pt(struct handshake_state *s,
|
|
|
|
const struct l_ecc_point *pt);
|
2019-01-25 20:23:09 +01:00
|
|
|
void handshake_state_set_no_rekey(struct handshake_state *s, bool no_rekey);
|
2018-06-22 20:13:27 +02:00
|
|
|
|
2019-05-10 22:19:26 +02:00
|
|
|
void handshake_state_set_fils_ft(struct handshake_state *s,
|
|
|
|
const uint8_t *fils_ft,
|
|
|
|
size_t fils_ft_len);
|
|
|
|
|
2019-07-16 04:45:12 +02:00
|
|
|
void handshake_state_set_protocol_version(struct handshake_state *s,
|
|
|
|
uint8_t proto_version);
|
|
|
|
|
2016-11-02 23:46:18 +01:00
|
|
|
void handshake_state_new_snonce(struct handshake_state *s);
|
2018-06-20 20:05:16 +02:00
|
|
|
void handshake_state_new_anonce(struct handshake_state *s);
|
2016-11-02 23:46:18 +01:00
|
|
|
void handshake_state_set_anonce(struct handshake_state *s,
|
|
|
|
const uint8_t *anonce);
|
2018-08-07 23:29:10 +02:00
|
|
|
void handshake_state_set_pmkid(struct handshake_state *s, const uint8_t *pmkid);
|
2016-11-02 23:46:18 +01:00
|
|
|
bool handshake_state_derive_ptk(struct handshake_state *s);
|
2019-01-17 21:25:30 +01:00
|
|
|
size_t handshake_state_get_ptk_size(struct handshake_state *s);
|
2019-05-10 22:19:29 +02:00
|
|
|
size_t handshake_state_get_kck_len(struct handshake_state *s);
|
2019-01-17 21:25:30 +01:00
|
|
|
const uint8_t *handshake_state_get_kck(struct handshake_state *s);
|
2019-04-18 02:02:06 +02:00
|
|
|
size_t handshake_state_get_kek_len(struct handshake_state *s);
|
2019-01-17 21:25:30 +01:00
|
|
|
const uint8_t *handshake_state_get_kek(struct handshake_state *s);
|
2016-11-02 23:46:18 +01:00
|
|
|
void handshake_state_install_ptk(struct handshake_state *s);
|
|
|
|
|
|
|
|
void handshake_state_install_gtk(struct handshake_state *s,
|
2020-04-02 07:41:02 +02:00
|
|
|
uint16_t gtk_key_index,
|
2016-11-02 23:46:18 +01:00
|
|
|
const uint8_t *gtk, size_t gtk_len,
|
|
|
|
const uint8_t *rsc, uint8_t rsc_len);
|
|
|
|
|
|
|
|
void handshake_state_install_igtk(struct handshake_state *s,
|
2020-04-02 07:41:02 +02:00
|
|
|
uint16_t igtk_key_index,
|
2017-01-31 03:42:51 +01:00
|
|
|
const uint8_t *igtk, size_t igtk_len,
|
|
|
|
const uint8_t *ipn);
|
2016-11-02 23:46:18 +01:00
|
|
|
|
|
|
|
void handshake_state_override_pairwise_cipher(struct handshake_state *s,
|
|
|
|
enum ie_rsn_cipher_suite pairwise);
|
|
|
|
|
2017-04-15 13:58:45 +02:00
|
|
|
bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid);
|
|
|
|
|
2017-01-31 03:42:52 +01:00
|
|
|
bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,
|
|
|
|
size_t key_len, uint8_t *key_out);
|
|
|
|
|
2018-09-22 18:48:14 +02:00
|
|
|
void handshake_state_set_gtk(struct handshake_state *s, const uint8_t *key,
|
|
|
|
unsigned int key_index, const uint8_t *rsc);
|
|
|
|
|
2016-11-02 23:46:18 +01:00
|
|
|
bool handshake_util_ap_ie_matches(const uint8_t *msg_ie,
|
|
|
|
const uint8_t *scan_ie, bool is_wpa);
|
|
|
|
|
|
|
|
const uint8_t *handshake_util_find_gtk_kde(const uint8_t *data, size_t data_len,
|
|
|
|
size_t *out_gtk_len);
|
|
|
|
const uint8_t *handshake_util_find_igtk_kde(const uint8_t *data,
|
|
|
|
size_t data_len, size_t *out_igtk_len);
|
2017-04-15 13:58:46 +02:00
|
|
|
const uint8_t *handshake_util_find_pmkid_kde(const uint8_t *data,
|
|
|
|
size_t data_len);
|
2018-09-22 18:48:15 +02:00
|
|
|
void handshake_util_build_gtk_kde(enum crypto_cipher cipher, const uint8_t *key,
|
|
|
|
unsigned int key_index, uint8_t *to);
|