2018-04-03 22:58:53 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-10-25 00:43:08 +02:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation. All rights reserved.
|
2018-04-03 22:58:53 +02: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-04-28 04:28:44 +02:00
|
|
|
#include <errno.h>
|
2018-04-03 22:58:53 +02:00
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2019-04-03 18:34:22 +02:00
|
|
|
#include "src/missing.h"
|
|
|
|
#include "src/eap.h"
|
|
|
|
#include "src/eap-private.h"
|
2018-04-03 22:58:53 +02:00
|
|
|
|
2020-03-06 20:16:27 +01:00
|
|
|
#define EAP_GTC_MAX_PASSWORD_LEN 2048
|
|
|
|
|
2018-04-03 22:58:53 +02:00
|
|
|
struct eap_gtc_state {
|
2018-10-25 20:56:37 +02:00
|
|
|
char *password;
|
2018-04-03 22:58:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void eap_gtc_free(struct eap_state *eap)
|
|
|
|
{
|
|
|
|
struct eap_gtc_state *gtc = eap_get_data(eap);
|
|
|
|
|
|
|
|
eap_set_data(eap, NULL);
|
|
|
|
|
2019-03-19 01:25:24 +01:00
|
|
|
if (gtc->password)
|
|
|
|
explicit_bzero(gtc->password, strlen(gtc->password));
|
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
l_free(gtc->password);
|
2018-04-03 22:58:53 +02:00
|
|
|
l_free(gtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eap_gtc_handle_request(struct eap_state *eap,
|
|
|
|
const uint8_t *pkt, size_t len)
|
|
|
|
{
|
|
|
|
struct eap_gtc_state *gtc = eap_get_data(eap);
|
2018-10-25 20:56:37 +02:00
|
|
|
size_t secret_len = strlen(gtc->password);
|
2018-04-03 22:58:53 +02:00
|
|
|
uint8_t response[5 + secret_len];
|
|
|
|
|
2019-12-12 02:23:01 +01:00
|
|
|
if (len < 8 || strncmp((const char *)pkt, "Password", 8))
|
|
|
|
l_warn("GTC request not understood, proceeding anyway: %.*s",
|
|
|
|
(int) len, (const char *) pkt);
|
2018-04-03 22:58:53 +02:00
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
memcpy(response + 5, gtc->password, secret_len);
|
2018-04-03 22:58:53 +02:00
|
|
|
|
2020-08-13 02:50:17 +02:00
|
|
|
eap_method_respond(eap, response, 5 + secret_len);
|
2018-04-03 22:58:53 +02:00
|
|
|
|
|
|
|
eap_method_success(eap);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-28 04:28:44 +02:00
|
|
|
static int eap_gtc_check_settings(struct l_settings *settings,
|
2018-04-18 07:03:29 +02:00
|
|
|
struct l_queue *secrets,
|
|
|
|
const char *prefix,
|
|
|
|
struct l_queue **out_missing)
|
|
|
|
{
|
2018-07-31 21:04:39 +02:00
|
|
|
const struct eap_secret_info *secret;
|
2018-10-25 20:56:37 +02:00
|
|
|
char identity_key[72];
|
|
|
|
char password_key[72];
|
|
|
|
char password_key_old[72];
|
|
|
|
|
|
|
|
L_AUTO_FREE_VAR(char *, identity);
|
|
|
|
L_AUTO_FREE_VAR(char *, password) = NULL;
|
2018-04-18 07:03:29 +02:00
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
snprintf(identity_key, sizeof(identity_key), "%sIdentity", prefix);
|
|
|
|
snprintf(password_key, sizeof(password_key), "%sPassword", prefix);
|
2018-07-31 21:04:39 +02:00
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
identity = l_settings_get_string(settings, "Security", identity_key);
|
2018-07-31 21:04:39 +02:00
|
|
|
|
|
|
|
if (!identity) {
|
2018-10-25 20:56:37 +02:00
|
|
|
secret = l_queue_find(secrets, eap_secret_info_match,
|
|
|
|
identity_key);
|
|
|
|
if (secret)
|
|
|
|
return 0;
|
2018-04-18 07:03:29 +02:00
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
eap_append_secret(out_missing, EAP_SECRET_REMOTE_USER_PASSWORD,
|
|
|
|
identity_key, password_key, NULL,
|
|
|
|
EAP_CACHE_TEMPORARY);
|
2018-07-31 21:04:39 +02:00
|
|
|
|
|
|
|
return 0;
|
2018-04-18 07:03:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
password = l_settings_get_string(settings, "Security", password_key);
|
|
|
|
|
|
|
|
if (!password) {
|
|
|
|
snprintf(password_key_old, sizeof(password_key_old),
|
|
|
|
"%sGTC-Secret", prefix);
|
|
|
|
password = l_settings_get_string(settings, "Security",
|
|
|
|
password_key_old);
|
2018-10-25 21:25:28 +02:00
|
|
|
if (password) {
|
2019-03-19 01:25:24 +01:00
|
|
|
explicit_bzero(password, strlen(password));
|
2018-10-25 21:25:28 +02:00
|
|
|
l_warn("Setting '%s' is deprecated, use '%s' instead",
|
|
|
|
password_key_old, password_key);
|
2018-10-25 20:56:37 +02:00
|
|
|
return 0;
|
2018-10-25 21:25:28 +02:00
|
|
|
}
|
2018-08-09 02:33:17 +02:00
|
|
|
|
2018-10-25 20:56:37 +02:00
|
|
|
secret = l_queue_find(secrets, eap_secret_info_match,
|
|
|
|
password_key);
|
|
|
|
if (secret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
eap_append_secret(out_missing, EAP_SECRET_REMOTE_PASSWORD,
|
|
|
|
password_key, NULL, identity,
|
|
|
|
EAP_CACHE_TEMPORARY);
|
2019-03-19 01:25:24 +01:00
|
|
|
} else
|
|
|
|
explicit_bzero(password, strlen(password));
|
2018-07-31 21:04:39 +02:00
|
|
|
|
2018-04-28 04:28:44 +02:00
|
|
|
return 0;
|
2018-04-18 07:03:29 +02:00
|
|
|
}
|
|
|
|
|
2018-04-03 22:58:53 +02:00
|
|
|
static bool eap_gtc_load_settings(struct eap_state *eap,
|
|
|
|
struct l_settings *settings,
|
|
|
|
const char *prefix)
|
|
|
|
{
|
|
|
|
struct eap_gtc_state *gtc;
|
2018-10-25 20:56:37 +02:00
|
|
|
char password_key[72];
|
|
|
|
char *password;
|
|
|
|
|
|
|
|
snprintf(password_key, sizeof(password_key), "%sPassword", prefix);
|
|
|
|
password = l_settings_get_string(settings, "Security", password_key);
|
|
|
|
|
|
|
|
if (!password) {
|
|
|
|
snprintf(password_key, sizeof(password_key), "%sGTC-Secret",
|
|
|
|
prefix);
|
|
|
|
password = l_settings_get_string(settings, "Security",
|
|
|
|
password_key);
|
2019-02-08 18:32:12 +01:00
|
|
|
if (!password)
|
2018-10-25 20:56:37 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-04-03 22:58:53 +02:00
|
|
|
|
2020-03-06 20:16:27 +01:00
|
|
|
/*
|
|
|
|
* Limit length to prevent a stack overflow
|
|
|
|
*/
|
|
|
|
if (strlen(password) > EAP_GTC_MAX_PASSWORD_LEN) {
|
|
|
|
l_free(password);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:58:53 +02:00
|
|
|
gtc = l_new(struct eap_gtc_state, 1);
|
2018-10-25 20:56:37 +02:00
|
|
|
gtc->password = password;
|
|
|
|
|
2018-04-03 22:58:53 +02:00
|
|
|
eap_set_data(eap, gtc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct eap_method eap_gtc = {
|
|
|
|
.request_type = EAP_TYPE_GTC,
|
|
|
|
.exports_msk = false,
|
|
|
|
.name = "GTC",
|
|
|
|
.free = eap_gtc_free,
|
|
|
|
.handle_request = eap_gtc_handle_request,
|
2018-04-18 07:03:29 +02:00
|
|
|
.check_settings = eap_gtc_check_settings,
|
2018-04-03 22:58:53 +02:00
|
|
|
.load_settings = eap_gtc_load_settings,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int eap_gtc_init(void)
|
|
|
|
{
|
|
|
|
l_debug("");
|
|
|
|
return eap_register_method(&eap_gtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eap_gtc_exit(void)
|
|
|
|
{
|
|
|
|
l_debug("");
|
|
|
|
eap_unregister_method(&eap_gtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAP_METHOD_BUILTIN(eap_gtc, eap_gtc_init, eap_gtc_exit)
|