2014-12-19 01:10:10 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
enum eapol_protocol_version {
|
|
|
|
EAPOL_PROTOCOL_VERSION_2001 = 1,
|
2014-12-19 21:25:57 +01:00
|
|
|
EAPOL_PROTOCOL_VERSION_2004 = 2,
|
2014-12-19 01:10:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 802.1X-2010: Table 11-5—Descriptor Type value assignments
|
|
|
|
* The WPA key type of 254 comes from somewhere else. Seems it is a legacy
|
|
|
|
* value that might still be used by older implementations
|
|
|
|
*/
|
|
|
|
enum eapol_descriptor_type {
|
|
|
|
EAPOL_DESCRIPTOR_TYPE_RC4 = 1,
|
|
|
|
EAPOL_DESCRIPTOR_TYPE_80211 = 2,
|
|
|
|
EAPOL_DESCRIPTOR_TYPE_WPA = 254,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum eapol_key_descriptor_version {
|
|
|
|
EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4 = 1,
|
|
|
|
EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES = 2,
|
|
|
|
EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES = 3,
|
|
|
|
};
|
|
|
|
|
2015-02-24 17:54:23 +01:00
|
|
|
struct eapol_sm;
|
|
|
|
|
2015-10-30 11:12:18 +01:00
|
|
|
struct eapol_header {
|
2014-12-19 01:10:10 +01:00
|
|
|
uint8_t protocol_version;
|
|
|
|
uint8_t packet_type;
|
|
|
|
__be16 packet_len;
|
2015-10-30 11:12:18 +01:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct eapol_frame {
|
|
|
|
struct eapol_header header;
|
|
|
|
uint8_t data[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct eapol_key {
|
|
|
|
struct eapol_header header;
|
2014-12-19 01:10:10 +01:00
|
|
|
uint8_t descriptor_type;
|
|
|
|
#if defined(__LITTLE_ENDIAN_BITFIELD)
|
|
|
|
bool key_mic:1;
|
|
|
|
bool secure:1;
|
|
|
|
bool error:1;
|
|
|
|
bool request:1;
|
|
|
|
bool encrypted_key_data:1;
|
|
|
|
bool smk_message:1;
|
|
|
|
uint8_t reserved2:2;
|
|
|
|
uint8_t key_descriptor_version:3;
|
|
|
|
bool key_type:1;
|
2015-05-06 01:48:34 +02:00
|
|
|
uint8_t wpa_key_id:2; /* Bits 4-5 reserved in RSN, Key ID in WPA */
|
2014-12-19 01:10:10 +01:00
|
|
|
bool install:1;
|
|
|
|
bool key_ack:1;
|
|
|
|
#elif defined (__BIG_ENDIAN_BITFIELD)
|
|
|
|
uint8_t reserved2:2;
|
|
|
|
bool smk_message:1;
|
|
|
|
bool encrypted_key_data:1;
|
|
|
|
bool request:1;
|
|
|
|
bool error:1;
|
|
|
|
bool secure:1;
|
|
|
|
bool key_mic:1;
|
|
|
|
bool key_ack:1;
|
|
|
|
bool install:1;
|
2015-05-06 01:48:34 +02:00
|
|
|
uint8_t wpa_key_id:2; /* Bits 4-5 reserved in RSN, Key ID in WPA */
|
2014-12-19 01:10:10 +01:00
|
|
|
bool key_type:1;
|
|
|
|
uint8_t key_descriptor_version:3;
|
|
|
|
#else
|
|
|
|
#error "Please fix <asm/byteorder.h>"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__be16 key_length;
|
2015-02-13 20:54:50 +01:00
|
|
|
__be64 key_replay_counter;
|
2014-12-19 01:10:10 +01:00
|
|
|
uint8_t key_nonce[32];
|
|
|
|
uint8_t eapol_key_iv[16];
|
2014-12-19 22:45:17 +01:00
|
|
|
uint8_t key_rsc[8];
|
|
|
|
uint8_t reserved[8];
|
2014-12-19 01:10:10 +01:00
|
|
|
uint8_t key_mic_data[16];
|
|
|
|
__be16 key_data_len;
|
|
|
|
uint8_t key_data[0];
|
|
|
|
} __attribute__ ((packed));
|
2014-12-24 20:43:59 +01:00
|
|
|
|
2015-03-20 17:43:17 +01:00
|
|
|
typedef int (*eapol_tx_packet_func_t)(uint32_t ifindex, const uint8_t *aa,
|
2015-10-30 11:12:18 +01:00
|
|
|
const uint8_t *spa,
|
|
|
|
const struct eapol_frame *ef,
|
2015-03-20 03:53:19 +01:00
|
|
|
void *user_data);
|
2015-02-24 18:09:42 +01:00
|
|
|
typedef bool (*eapol_get_nonce_func_t)(uint8_t nonce[]);
|
2015-03-26 04:35:12 +01:00
|
|
|
typedef void (*eapol_install_tk_func_t)(uint32_t ifindex, const uint8_t *aa,
|
2015-05-22 04:10:21 +02:00
|
|
|
const uint8_t *tk, uint32_t cipher,
|
2015-03-26 04:35:12 +01:00
|
|
|
void *user_data);
|
2015-03-26 05:26:31 +01:00
|
|
|
typedef void (*eapol_install_gtk_func_t)(uint32_t ifindex, uint8_t key_index,
|
|
|
|
const uint8_t *gtk, uint8_t gtk_len,
|
|
|
|
const uint8_t *rsc, uint8_t rsc_len,
|
2015-05-22 04:08:47 +02:00
|
|
|
uint32_t cipher, void *user_data);
|
2016-10-25 23:45:16 +02:00
|
|
|
typedef void (*eapol_install_igtk_func_t)(uint32_t ifindex, uint8_t key_index,
|
|
|
|
const uint8_t *igtk, uint8_t igtk_len,
|
|
|
|
const uint8_t *ipn, uint8_t ipn_len,
|
|
|
|
uint32_t cipher, void *user_data);
|
2015-03-30 03:30:14 +02:00
|
|
|
typedef void (*eapol_deauthenticate_func_t)(uint32_t ifindex, const uint8_t *aa,
|
|
|
|
const uint8_t *spa,
|
|
|
|
uint16_t reason_code,
|
|
|
|
void *user_data);
|
2016-06-23 00:49:15 +02:00
|
|
|
typedef void (*eapol_rekey_offload_func_t)(uint32_t ifindex,
|
|
|
|
const uint8_t *kek,
|
|
|
|
const uint8_t *kck,
|
|
|
|
uint64_t replay_counter,
|
|
|
|
void *user_data);
|
2016-09-13 20:30:54 +02:00
|
|
|
typedef void (*eapol_sm_event_func_t)(unsigned int event,
|
|
|
|
const void *event_data,
|
|
|
|
void *user_data);
|
2015-02-24 18:09:42 +01:00
|
|
|
|
2014-12-28 05:37:39 +01:00
|
|
|
bool eapol_calculate_mic(const uint8_t *kck, const struct eapol_key *frame,
|
|
|
|
uint8_t *mic);
|
2015-02-19 04:13:09 +01:00
|
|
|
bool eapol_verify_mic(const uint8_t *kck, const struct eapol_key *frame);
|
2014-12-28 05:37:39 +01:00
|
|
|
|
2015-02-14 03:37:17 +01:00
|
|
|
uint8_t *eapol_decrypt_key_data(const uint8_t *kek,
|
2015-02-24 22:59:36 +01:00
|
|
|
const struct eapol_key *frame,
|
|
|
|
size_t *decrypted_size);
|
2015-02-14 03:37:17 +01:00
|
|
|
|
2015-01-22 16:58:23 +01:00
|
|
|
const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len);
|
2014-12-28 05:31:03 +01:00
|
|
|
|
2015-02-23 22:39:26 +01:00
|
|
|
bool eapol_verify_ptk_1_of_4(const struct eapol_key *ek);
|
|
|
|
bool eapol_verify_ptk_2_of_4(const struct eapol_key *ek);
|
2015-05-06 01:48:35 +02:00
|
|
|
bool eapol_verify_ptk_3_of_4(const struct eapol_key *ek, bool is_wpa);
|
|
|
|
bool eapol_verify_ptk_4_of_4(const struct eapol_key *ek, bool is_wpa);
|
2015-05-06 01:48:34 +02:00
|
|
|
bool eapol_verify_gtk_1_of_2(const struct eapol_key *ek, bool is_wpa);
|
2015-05-06 05:04:21 +02:00
|
|
|
bool eapol_verify_gtk_2_of_2(const struct eapol_key *ek, bool is_wpa);
|
2015-02-13 23:08:33 +01:00
|
|
|
|
2014-12-28 05:33:46 +01:00
|
|
|
struct eapol_key *eapol_create_ptk_2_of_4(
|
|
|
|
enum eapol_protocol_version protocol,
|
|
|
|
enum eapol_key_descriptor_version version,
|
2015-02-13 20:54:50 +01:00
|
|
|
uint64_t key_replay_counter,
|
2014-12-28 05:33:46 +01:00
|
|
|
const uint8_t snonce[],
|
|
|
|
size_t extra_len,
|
2015-05-06 01:48:35 +02:00
|
|
|
const uint8_t *extra_data,
|
|
|
|
bool is_wpa);
|
2015-02-13 21:10:28 +01:00
|
|
|
|
|
|
|
struct eapol_key *eapol_create_ptk_4_of_4(
|
|
|
|
enum eapol_protocol_version protocol,
|
|
|
|
enum eapol_key_descriptor_version version,
|
2015-05-06 01:48:35 +02:00
|
|
|
uint64_t key_replay_counter,
|
|
|
|
bool is_wpa);
|
|
|
|
|
|
|
|
struct eapol_key *eapol_create_gtk_2_of_2(
|
|
|
|
enum eapol_protocol_version protocol,
|
|
|
|
enum eapol_key_descriptor_version version,
|
|
|
|
uint64_t key_replay_counter,
|
2015-05-18 21:31:11 +02:00
|
|
|
bool is_wpa, uint8_t wpa_key_id);
|
2015-02-24 17:54:23 +01:00
|
|
|
|
2016-09-12 17:02:04 +02:00
|
|
|
void __eapol_rx_packet(uint32_t ifindex, const uint8_t *aa,
|
2015-10-30 11:12:19 +01:00
|
|
|
const uint8_t *frame, size_t len);
|
2015-02-24 18:10:42 +01:00
|
|
|
void __eapol_set_tx_packet_func(eapol_tx_packet_func_t func);
|
2016-09-12 17:02:04 +02:00
|
|
|
void __eapol_set_tx_user_data(void *user_data);
|
|
|
|
|
2015-02-24 18:09:42 +01:00
|
|
|
void __eapol_set_get_nonce_func(eapol_get_nonce_func_t func);
|
2015-03-26 04:35:12 +01:00
|
|
|
void __eapol_set_install_tk_func(eapol_install_tk_func_t func);
|
2015-03-26 05:26:31 +01:00
|
|
|
void __eapol_set_install_gtk_func(eapol_install_gtk_func_t func);
|
2016-10-25 23:45:16 +02:00
|
|
|
void __eapol_set_install_igtk_func(eapol_install_igtk_func_t func);
|
2015-03-30 03:30:14 +02:00
|
|
|
void __eapol_set_deauthenticate_func(eapol_deauthenticate_func_t func);
|
2016-06-23 00:49:15 +02:00
|
|
|
void __eapol_set_rekey_offload_func(eapol_rekey_offload_func_t func);
|
|
|
|
void __eapol_update_replay_counter(uint32_t ifindex, const uint8_t *spa,
|
|
|
|
const uint8_t *aa, uint64_t replay_counter);
|
2015-02-24 18:09:42 +01:00
|
|
|
|
2015-02-24 17:54:23 +01:00
|
|
|
struct eapol_sm *eapol_sm_new();
|
|
|
|
void eapol_sm_free(struct eapol_sm *sm);
|
2015-02-24 17:55:50 +01:00
|
|
|
|
2016-08-10 23:32:45 +02:00
|
|
|
void eapol_sm_set_protocol_version(struct eapol_sm *sm,
|
|
|
|
enum eapol_protocol_version protocol_version);
|
|
|
|
|
2015-03-20 03:09:36 +01:00
|
|
|
void eapol_sm_set_supplicant_address(struct eapol_sm *sm, const uint8_t *spa);
|
2015-03-20 03:13:24 +01:00
|
|
|
void eapol_sm_set_authenticator_address(struct eapol_sm *sm, const uint8_t *aa);
|
2015-02-24 17:57:25 +01:00
|
|
|
void eapol_sm_set_pmk(struct eapol_sm *sm, const uint8_t *pmk);
|
2015-10-30 11:12:20 +01:00
|
|
|
void eapol_sm_set_8021x_config(struct eapol_sm *sm,
|
|
|
|
struct l_settings *settings);
|
2016-10-11 08:36:48 +02:00
|
|
|
void eapol_sm_set_use_eapol_start(struct eapol_sm *sm, bool enabled);
|
2015-02-24 17:58:03 +01:00
|
|
|
void eapol_sm_set_ap_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie,
|
|
|
|
size_t len);
|
2015-05-19 07:05:53 +02:00
|
|
|
bool eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie,
|
2015-02-24 17:58:43 +01:00
|
|
|
size_t len);
|
2015-04-11 06:46:58 +02:00
|
|
|
void eapol_sm_set_ap_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie,
|
|
|
|
size_t len);
|
2015-05-19 07:05:53 +02:00
|
|
|
bool eapol_sm_set_own_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie,
|
2015-04-11 06:46:58 +02:00
|
|
|
size_t len);
|
2015-03-26 04:34:05 +01:00
|
|
|
void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data);
|
2016-09-13 20:30:54 +02:00
|
|
|
void eapol_sm_set_event_func(struct eapol_sm *sm, eapol_sm_event_func_t func);
|
2016-06-15 00:16:04 +02:00
|
|
|
|
|
|
|
uint32_t eapol_sm_get_pairwise_cipher(struct eapol_sm *sm);
|
2016-06-15 00:16:31 +02:00
|
|
|
uint32_t eapol_sm_get_group_cipher(struct eapol_sm *sm);
|
2016-06-15 02:42:48 +02:00
|
|
|
const uint8_t *eapol_sm_get_own_ie(struct eapol_sm *sm, size_t *out_ie_len);
|
2016-06-15 00:16:04 +02:00
|
|
|
|
2016-10-04 05:48:08 +02:00
|
|
|
void eapol_register(uint32_t ifindex, struct eapol_sm *sm);
|
|
|
|
void eapol_start(struct eapol_sm *sm);
|
2015-03-30 03:58:40 +02:00
|
|
|
void eapol_cancel(uint32_t ifindex);
|
2015-02-24 18:12:22 +01:00
|
|
|
|
2016-09-12 17:02:04 +02:00
|
|
|
void eapol_pae_open();
|
|
|
|
void eapol_pae_close();
|
|
|
|
|
2015-02-24 18:08:03 +01:00
|
|
|
bool eapol_init();
|
|
|
|
bool eapol_exit();
|