From a2d805421829484d70bb308bf5ea9407b17c8083 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 14 Jun 2018 19:57:24 -0500 Subject: [PATCH] eap: Separate private bits into eap-private.h --- Makefile.am | 5 +- src/eap-aka.c | 3 ++ src/eap-gtc.c | 1 + src/eap-md5.c | 1 + src/eap-mschapv2.c | 1 + src/eap-peap.c | 1 + src/eap-private.h | 130 +++++++++++++++++++++++++++++++++++++++++++++ src/eap-pwd.c | 1 + src/eap-sim.c | 3 ++ src/eap-tls.c | 1 + src/eap-ttls.c | 1 + src/eap-wsc.c | 1 + src/eap.c | 1 + src/eap.h | 105 ++---------------------------------- src/simutil.c | 2 + src/simutil.h | 2 - 16 files changed, 153 insertions(+), 106 deletions(-) create mode 100644 src/eap-private.h diff --git a/Makefile.am b/Makefile.am index 9d5c06cf..bb0ae603 100644 --- a/Makefile.am +++ b/Makefile.am @@ -90,7 +90,8 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h \ src/wscutil.h src/wscutil.c \ src/wsc.h src/wsc.c \ src/eap-wsc.h src/eap-wsc.c \ - src/eap.h src/eap.c src/eap-md5.c \ + src/eap.h src/eap.c src/eap-private.h \ + src/eap-md5.c \ src/eap-tls.c src/eap-ttls.c \ src/eap-mschapv2.c src/eap-mschapv2.h \ src/backtrace.h src/backtrace.c \ @@ -153,7 +154,7 @@ monitor_iwmon_SOURCES = monitor/main.c linux/nl80211.h \ src/watchlist.h src/watchlist.c \ src/eapol.h src/eapol.c \ src/handshake.h src/handshake.c \ - src/eap.h src/eap.c \ + src/eap.h src/eap.c src/eap-private.h \ src/eap-tls.c src/eap-ttls.c monitor_iwmon_LDADD = ell/libell-internal.la endif diff --git a/src/eap-aka.c b/src/eap-aka.c index ae95603b..dc73e17a 100644 --- a/src/eap-aka.c +++ b/src/eap-aka.c @@ -29,6 +29,9 @@ #include #include +#include "eap.h" +#include "eap-private.h" + #include "crypto.h" #include "simutil.h" #include "simauth.h" diff --git a/src/eap-gtc.c b/src/eap-gtc.c index 10387925..f99af133 100644 --- a/src/eap-gtc.c +++ b/src/eap-gtc.c @@ -29,6 +29,7 @@ #include #include "eap.h" +#include "eap-private.h" struct eap_gtc_state { char *secret; diff --git a/src/eap-md5.c b/src/eap-md5.c index 0d2fbd6c..d0f9e43d 100644 --- a/src/eap-md5.c +++ b/src/eap-md5.c @@ -29,6 +29,7 @@ #include #include "eap.h" +#include "eap-private.h" struct eap_md5_state { char *secret; diff --git a/src/eap-mschapv2.c b/src/eap-mschapv2.c index 915a1b68..7273499a 100644 --- a/src/eap-mschapv2.c +++ b/src/eap-mschapv2.c @@ -26,6 +26,7 @@ #include #include "eap.h" +#include "eap-private.h" #include "eap-mschapv2.h" #define MSCHAPV2_CHAL_LEN 16 diff --git a/src/eap-peap.c b/src/eap-peap.c index ef0640b6..e5b79490 100644 --- a/src/eap-peap.c +++ b/src/eap-peap.c @@ -31,6 +31,7 @@ #include #include "eap.h" +#include "eap-private.h" /* * Protected EAP Protocol (PEAP): EAP type 25 as described in: diff --git a/src/eap-private.h b/src/eap-private.h new file mode 100644 index 00000000..a25848f8 --- /dev/null +++ b/src/eap-private.h @@ -0,0 +1,130 @@ +/* + * + * Wireless daemon for Linux + * + * Copyright (C) 2013-2018 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 +#include +#include +#include + +struct eap_state; + +/* EAP method API */ + +enum eap_type { + EAP_TYPE_IDENTITY = 1, + EAP_TYPE_NOTIFICATION = 2, + EAP_TYPE_NAK = 3, + __EAP_TYPE_MIN_METHOD = 4, + EAP_TYPE_MD5_CHALLENGE = 4, + EAP_TYPE_GTC = 6, + EAP_TYPE_TLS_EAP = 13, + EAP_TYPE_SIM = 18, + EAP_TYPE_TTLS = 21, + EAP_TYPE_AKA = 23, + EAP_TYPE_PEAP = 25, + EAP_TYPE_EXTENSIONS = 33, + EAP_TYPE_AKA_PRIME = 50, + EAP_TYPE_MSCHAPV2 = 26, + EAP_TYPE_PWD = 52, + EAP_TYPE_EXPANDED = 254, +}; + +enum eap_code { + EAP_CODE_REQUEST = 1, + EAP_CODE_RESPONSE = 2, + EAP_CODE_SUCCESS = 3, + EAP_CODE_FAILURE = 4, +}; + +struct eap_method { + enum eap_type request_type; + uint8_t vendor_id[3]; + uint32_t vendor_type; + bool exports_msk; + const char *name; + + int (*check_settings)(struct l_settings *settings, + struct l_queue *secrets, const char *prefix, + struct l_queue **out_missing); + + bool (*load_settings)(struct eap_state *eap, + struct l_settings *settings, + const char *prefix); + + /* Reset the internal state back to initial conditions */ + bool (*reset_state)(struct eap_state *eap); + void (*free)(struct eap_state *eap); + + void (*handle_request)(struct eap_state *eap, + const uint8_t *pkt, size_t len); + void (*handle_retransmit)(struct eap_state *eap, + const uint8_t *pkt, size_t len); + const char *(*get_identity)(struct eap_state *eap); +}; + +struct eap_method_desc { + const char *name; + int (*init)(void); + void (*exit)(void); +} __attribute__((aligned(8))); + +#define EAP_METHOD_BUILTIN(name, init, exit) \ + static struct eap_method_desc __eap_builtin_ ## name \ + __attribute__((used, section("__eap"), aligned(8))) = { \ + #name, init, exit \ + }; \ + +int eap_register_method(struct eap_method *method); +int eap_unregister_method(struct eap_method *method); + +/* Private EAP API */ + +int __eap_check_settings(struct l_settings *settings, struct l_queue *secrets, + const char *prefix, bool set_key_material, + struct l_queue **missing); +void __eap_handle_request(struct eap_state *eap, uint16_t id, + const uint8_t *pkt, size_t len); + +void eap_discard_success_and_failure(struct eap_state *eap, bool discard); + +void eap_set_data(struct eap_state *eap, void *data); +void *eap_get_data(struct eap_state *eap); + +void eap_send_response(struct eap_state *eap, + enum eap_type request_type, + uint8_t *buf, size_t len); + +void eap_set_key_material(struct eap_state *eap, + const uint8_t *msk_data, size_t msk_len, + const uint8_t *emsk_data, size_t emsk_len, + const uint8_t *iv, size_t iv_len); + +void eap_start_complete_timeout(struct eap_state *eap); + +bool eap_method_is_success(struct eap_state *eap); +void eap_method_success(struct eap_state *eap); +void eap_method_error(struct eap_state *eap); +void eap_method_event(struct eap_state *eap, unsigned int type, + const void *data); + +void eap_save_last_id(struct eap_state *eap, uint8_t *last_id); +void eap_restore_last_id(struct eap_state *eap, uint8_t last_id); diff --git a/src/eap-pwd.c b/src/eap-pwd.c index 6f4f74da..c98e4f5b 100644 --- a/src/eap-pwd.c +++ b/src/eap-pwd.c @@ -27,6 +27,7 @@ #include #include "eap.h" +#include "eap-private.h" #include "util.h" #include "ecc.h" diff --git a/src/eap-sim.c b/src/eap-sim.c index f0eedaf8..ec1f215e 100644 --- a/src/eap-sim.c +++ b/src/eap-sim.c @@ -29,6 +29,9 @@ #include #include +#include "eap.h" +#include "eap-private.h" + #include "crypto.h" #include "simutil.h" #include "simauth.h" diff --git a/src/eap-tls.c b/src/eap-tls.c index ec4512de..b952cf10 100644 --- a/src/eap-tls.c +++ b/src/eap-tls.c @@ -32,6 +32,7 @@ #include #include "eap.h" +#include "eap-private.h" struct eap_tls_state { char *ca_cert; diff --git a/src/eap-ttls.c b/src/eap-ttls.c index 702d946d..3e660115 100644 --- a/src/eap-ttls.c +++ b/src/eap-ttls.c @@ -31,6 +31,7 @@ #include #include "eap.h" +#include "eap-private.h" struct eap_ttls_state { char *ca_cert; diff --git a/src/eap-wsc.c b/src/eap-wsc.c index d8854037..4642fb36 100644 --- a/src/eap-wsc.c +++ b/src/eap-wsc.c @@ -31,6 +31,7 @@ #include "crypto.h" #include "eap.h" +#include "eap-private.h" #include "wscutil.h" #include "util.h" #include "eap-wsc.h" diff --git a/src/eap.c b/src/eap.c index 09647961..3f073782 100644 --- a/src/eap.c +++ b/src/eap.c @@ -30,6 +30,7 @@ #include #include "eap.h" +#include "eap-private.h" static uint32_t default_mtu; struct l_queue *eap_methods; diff --git a/src/eap.h b/src/eap.h index ea8a71a2..a8d36dae 100644 --- a/src/eap.h +++ b/src/eap.h @@ -57,18 +57,16 @@ typedef void (*eap_complete_func_t)(enum eap_result result, void *user_data); typedef void (*eap_event_func_t)(unsigned int event, const void *event_data, void *user_data); +bool eap_secret_info_match(const void *a, const void *b); +void eap_secret_info_free(void *data); + struct eap_state *eap_new(eap_tx_packet_func_t tx_packet, eap_complete_func_t complete, void *user_data); void eap_free(struct eap_state *eap); -bool eap_secret_info_match(const void *a, const void *b); void eap_append_secret(struct l_queue **out_missing, enum eap_secret_type type, const char *id, const char *id2, const char *parameter); -void eap_secret_info_free(void *data); -int __eap_check_settings(struct l_settings *settings, struct l_queue *secrets, - const char *prefix, bool set_key_material, - struct l_queue **missing); int eap_check_settings(struct l_settings *settings, struct l_queue *secrets, const char *prefix, bool set_key_material, struct l_queue **out_missing); @@ -85,102 +83,5 @@ size_t eap_get_mtu(struct eap_state *eap); void eap_rx_packet(struct eap_state *eap, const uint8_t *pkt, size_t len); -void __eap_handle_request(struct eap_state *eap, uint16_t id, - const uint8_t *pkt, size_t len); - -void eap_discard_success_and_failure(struct eap_state *eap, bool discard); - void eap_init(uint32_t default_mtu); void eap_exit(void); - -/* EAP method API */ - -enum eap_type { - EAP_TYPE_IDENTITY = 1, - EAP_TYPE_NOTIFICATION = 2, - EAP_TYPE_NAK = 3, - __EAP_TYPE_MIN_METHOD = 4, - EAP_TYPE_MD5_CHALLENGE = 4, - EAP_TYPE_GTC = 6, - EAP_TYPE_TLS_EAP = 13, - EAP_TYPE_SIM = 18, - EAP_TYPE_TTLS = 21, - EAP_TYPE_AKA = 23, - EAP_TYPE_PEAP = 25, - EAP_TYPE_EXTENSIONS = 33, - EAP_TYPE_AKA_PRIME = 50, - EAP_TYPE_MSCHAPV2 = 26, - EAP_TYPE_PWD = 52, - EAP_TYPE_EXPANDED = 254, -}; - -enum eap_code { - EAP_CODE_REQUEST = 1, - EAP_CODE_RESPONSE = 2, - EAP_CODE_SUCCESS = 3, - EAP_CODE_FAILURE = 4, -}; - -struct eap_method { - enum eap_type request_type; - uint8_t vendor_id[3]; - uint32_t vendor_type; - bool exports_msk; - const char *name; - - int (*check_settings)(struct l_settings *settings, - struct l_queue *secrets, const char *prefix, - struct l_queue **out_missing); - - bool (*load_settings)(struct eap_state *eap, - struct l_settings *settings, - const char *prefix); - - /* Reset the internal state back to initial conditions */ - bool (*reset_state)(struct eap_state *eap); - void (*free)(struct eap_state *eap); - - void (*handle_request)(struct eap_state *eap, - const uint8_t *pkt, size_t len); - void (*handle_retransmit)(struct eap_state *eap, - const uint8_t *pkt, size_t len); - const char *(*get_identity)(struct eap_state *eap); -}; - -struct eap_method_desc { - const char *name; - int (*init)(void); - void (*exit)(void); -} __attribute__((aligned(8))); - -#define EAP_METHOD_BUILTIN(name, init, exit) \ - static struct eap_method_desc __eap_builtin_ ## name \ - __attribute__((used, section("__eap"), aligned(8))) = { \ - #name, init, exit \ - }; \ - -int eap_register_method(struct eap_method *method); -int eap_unregister_method(struct eap_method *method); - -void eap_set_data(struct eap_state *eap, void *data); -void *eap_get_data(struct eap_state *eap); - -void eap_send_response(struct eap_state *eap, - enum eap_type request_type, - uint8_t *buf, size_t len); - -void eap_set_key_material(struct eap_state *eap, - const uint8_t *msk_data, size_t msk_len, - const uint8_t *emsk_data, size_t emsk_len, - const uint8_t *iv, size_t iv_len); - -void eap_start_complete_timeout(struct eap_state *eap); - -bool eap_method_is_success(struct eap_state *eap); -void eap_method_success(struct eap_state *eap); -void eap_method_error(struct eap_state *eap); -void eap_method_event(struct eap_state *eap, unsigned int type, - const void *data); - -void eap_save_last_id(struct eap_state *eap, uint8_t *last_id); -void eap_restore_last_id(struct eap_state *eap, uint8_t last_id); diff --git a/src/simutil.c b/src/simutil.c index 5ead02ac..7e4beab4 100644 --- a/src/simutil.c +++ b/src/simutil.c @@ -25,6 +25,8 @@ #include #include +#include "eap-private.h" + #include "crypto.h" #include "simutil.h" diff --git a/src/simutil.h b/src/simutil.h index 229e4e38..945e3d37 100644 --- a/src/simutil.h +++ b/src/simutil.h @@ -20,8 +20,6 @@ * */ -#include "eap.h" - /* * EAP-SIM/EAP-AKA shared values */