commit 87c411f81683f65816ab21885ed1c9357b7ce340
parent 514d442db136d844aeb0ab903366588aeb8e66d6
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Fri, 16 Nov 2018 14:15:31 -0800
eap-tls-common: Introduce a common tls state and load settings
Diffstat:
2 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/src/eap-tls-common.c b/src/eap-tls-common.c
@@ -29,6 +29,7 @@
#include <ell/ell.h>
#include "src/eap.h"
+#include "src/eap-private.h"
#include "src/eap-tls-common.h"
struct databuf *databuf_new(size_t capacity)
@@ -74,6 +75,40 @@ void databuf_free(struct databuf *databuf)
l_free(databuf);
}
+struct eap_tls_state {
+ enum eap_tls_version version_negotiated;
+
+ char *ca_cert;
+ char *client_cert;
+ char *client_key;
+ char *passphrase;
+};
+
+static void __eap_tls_common_state_reset(struct eap_tls_state *eap_tls)
+{
+ eap_tls->version_negotiated = EAP_TLS_VERSION_NOT_NEGOTIATED;
+}
+
+void eap_tls_common_state_free(struct eap_state *eap)
+{
+ struct eap_tls_state *eap_tls = eap_get_data(eap);
+
+ __eap_tls_common_state_reset(eap_tls);
+
+ eap_set_data(eap, NULL);
+
+ l_free(eap_tls->ca_cert);
+ l_free(eap_tls->client_cert);
+ l_free(eap_tls->client_key);
+
+ if (eap_tls->passphrase) {
+ memset(eap_tls->passphrase, 0, strlen(eap_tls->passphrase));
+ l_free(eap_tls->passphrase);
+ }
+
+ l_free(eap_tls);
+}
+
int eap_tls_common_settings_check(struct l_settings *settings,
struct l_queue *secrets,
const char *prefix,
@@ -188,3 +223,36 @@ int eap_tls_common_settings_check(struct l_settings *settings,
return 0;
}
+
+bool eap_tls_common_settings_load(struct eap_state *eap,
+ struct l_settings *settings,
+ const char *prefix)
+{
+ struct eap_tls_state *eap_tls;
+ char setting_key[72];
+
+ eap_tls = l_new(struct eap_tls_state, 1);
+
+ eap_tls->version_negotiated = EAP_TLS_VERSION_NOT_NEGOTIATED;
+
+ snprintf(setting_key, sizeof(setting_key), "%sCACert", prefix);
+ eap_tls->ca_cert = l_settings_get_string(settings, "Security",
+ setting_key);
+
+ snprintf(setting_key, sizeof(setting_key), "%sClientCert", prefix);
+ eap_tls->client_cert = l_settings_get_string(settings, "Security",
+ setting_key);
+
+ snprintf(setting_key, sizeof(setting_key), "%sClientKey", prefix);
+ eap_tls->client_key = l_settings_get_string(settings, "Security",
+ setting_key);
+
+ snprintf(setting_key, sizeof(setting_key), "%sClientKeyPassphrase",
+ prefix);
+ eap_tls->passphrase = l_settings_get_string(settings, "Security",
+ setting_key);
+
+ eap_set_data(eap, eap_tls);
+
+ return true;
+}
diff --git a/src/eap-tls-common.h b/src/eap-tls-common.h
@@ -32,7 +32,19 @@ void databuf_append(struct databuf *databuf, const uint8_t *data,
size_t data_len);
void databuf_free(struct databuf *databuf);
+enum eap_tls_version {
+ EAP_TLS_VERSION_0 = 0x00,
+ EAP_TLS_VERSION_1 = 0x01,
+ EAP_TLS_VERSION_MASK = 0x07,
+ EAP_TLS_VERSION_NOT_NEGOTIATED = 0x08,
+};
+
+void eap_tls_common_state_free(struct eap_state *eap);
+
int eap_tls_common_settings_check(struct l_settings *settings,
struct l_queue *secrets,
const char *prefix,
struct l_queue **out_missing);
+bool eap_tls_common_settings_load(struct eap_state *eap,
+ struct l_settings *settings,
+ const char *prefix);