From 410ee2f6b97f0eee468f4b31dfa339dec7e42eaa Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Thu, 20 Sep 2018 16:38:24 -0700 Subject: [PATCH] eap-tls-common: introduce utility functions for eap-tls --- Makefile.am | 6 ++-- src/eap-tls-common.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ src/eap-tls-common.h | 33 ++++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/eap-tls-common.c create mode 100644 src/eap-tls-common.h diff --git a/Makefile.am b/Makefile.am index c7654731..937f105f 100644 --- 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 new file mode 100644 index 00000000..f46c0b90 --- /dev/null +++ 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 +#endif + +#include + +#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 new file mode 100644 index 00000000..50c93ff6 --- /dev/null +++ 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);