commit 410ee2f6b97f0eee468f4b31dfa339dec7e42eaa
parent 6f833d6cad2bf85d6acd693e2633c4e01c0b6589
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Thu, 20 Sep 2018 16:38:24 -0700
eap-tls-common: introduce utility functions for eap-tls
Diffstat:
3 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
@@ -97,7 +97,8 @@ eap_sources = src/eap.c src/eap.h src/eap-private.h \
src/wscutil.h src/wscutil.c \
src/simutil.h src/simutil.c \
src/simauth.h src/simauth.c \
- src/watchlist.h src/watchlist.c
+ src/watchlist.h src/watchlist.c \
+ src/eap-tls-common.h src/eap-tls-common.c
if DAEMON
libexec_PROGRAMS += src/iwd
@@ -318,7 +319,8 @@ unit_test_eapol_SOURCES = unit/test-eapol.c \
src/handshake.h src/handshake.c \
src/eap.h src/eap.c src/eap-private.h \
src/eap-tls.c src/eap-ttls.c \
- src/eap-md5.c src/util.c
+ src/eap-md5.c src/util.c \
+ src/eap-tls-common.h src/eap-tls-common.c
unit_test_eapol_LDADD = ell/libell-internal.la
unit_test_ssid_to_utf8_SOURCES = src/util.h src/util.c \
diff --git a/src/eap-tls-common.c b/src/eap-tls-common.c
@@ -0,0 +1,72 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ell/ell.h>
+
+#include "eap-tls-common.h"
+
+struct databuf *databuf_new(size_t capacity)
+{
+ struct databuf *databuf;
+
+ if (!capacity)
+ return NULL;
+
+ databuf = l_new(struct databuf, 1);
+ databuf->data = l_malloc(capacity);
+ databuf->capacity = capacity;
+
+ return databuf;
+}
+
+void databuf_append(struct databuf *databuf, const uint8_t *data,
+ size_t data_len)
+{
+ size_t new_len;
+
+ if (!databuf)
+ return;
+
+ new_len = databuf->len + data_len;
+
+ if (new_len > databuf->capacity) {
+ databuf->capacity = new_len * 2;
+ databuf->data = l_realloc(databuf->data, databuf->capacity);
+ }
+
+ memcpy(databuf->data + databuf->len, data, data_len);
+
+ databuf->len = new_len;
+}
+
+void databuf_free(struct databuf *databuf)
+{
+ if (!databuf)
+ return;
+
+ l_free(databuf->data);
+ l_free(databuf);
+}
diff --git a/src/eap-tls-common.h b/src/eap-tls-common.h
@@ -0,0 +1,33 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 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
+ *
+ */
+
+struct databuf {
+ uint8_t *data;
+ size_t len;
+ size_t capacity;
+};
+
+struct databuf;
+struct databuf *databuf_new(size_t capacity);
+void databuf_append(struct databuf *databuf, const uint8_t *data,
+ size_t data_len);
+void databuf_free(struct databuf *databuf);