Skip to content

Build a EAP library from hostapd source code - #381

Merged
mereacre merged 4 commits into
mainfrom
feat/compile-eap-library-from-hostap
Jan 10, 2023
Merged

Build a EAP library from hostapd source code#381
mereacre merged 4 commits into
mainfrom
feat/compile-eap-library-from-hostap

Conversation

@aloisklink

Copy link
Copy Markdown
Contributor

libeap is an implementation of the EAP state machine (https://en.wikipedia.org/wiki/Extensible_Authentication_Protocol) from the hostapd project. In this PR, libeap doesn't do anything useful, but in future PRs, edgesec's RADIUS server will use this EAP (https://en.wikipedia.org/wiki/Extensible_Authentication_Protocol) library for more complex WiFi authentication.

This PR was adapted from PR #376.

By default, hostapd's EAP files are for internal use only.
We adapted the eap_example/ project in v2.10 of the hostap Git repo for how to make an independent EAP library, see https://w1.fi/cgit/hostap/tree/eap_example/Makefile?h=hostap_2_10

This PR also adds some basic tests to confirm whether the EAP library from hostapd works.

These tests are also adapted from the eap_example/ folder in the hostapd Git source repository, see https://w1.fi/cgit/hostap/tree/eap_example?h=hostap_2_10


Differences to PR #376

  • CMake variable to build libeap is now called BUILD_HOSTAPD_EAP_LIB to make it clearer that it comes from HOSTAPD.
  • All code referencing OpenSSL 1.1.1 has been removed.
    • Removed linking to OpenSSL::Crypto in EAP code, it seems like it's not needed (maybe it's auto-linking to my OS's OpenSSL library?
  • Build libeap separate from hostapd.
    Important: This was causing race conditions in the previous code, as the libeap build was overwriting the hostapd build, because they both used the same SOURCE_DIR, and since BUILD_IN_SOURCE was set to TRUE, they also had the same BINARY_DIR (build dir).
  • Undoes most changes in lib/hostapd.config.in. The only thing we add (compared to master) is a custom config option called CONFIG_LIBEAP_INSTALL_DIR, which we can use to control the CONFIG_LIBEAP_INSTALL_DIR.
  • Simplify libeal Makefile.
    • We can make it a .mak file instead of a .mak.in file by moving all configuration into the .config.in file. This means our IDE can understand the Makefile better.
    • Mainly just copies https://w1.fi/cgit/hostap/tree/eap_example/Makefile?h=hostap_2_10 and ignores https://w1.fi/cgit/hostap/tree/hostapd/Makefile?h=hostap_2_10.
      • Smaller and simpler Makefile

      • Less modifications needed to Makefile from upstream source.

        git diff --no-index -w ~/Documents/hostap/eap_example/Makefile lib/libeap.mak
        diff --git a/home/alois/Documents/hostap/eap_example/Makefile b/lib/libeap.mak
        index 691466f0..7a5f6193 100644
        --- a/home/alois/Documents/hostap/eap_example/Makefile
        +++ b/lib/libeap.mak
        @@ -1,4 +1,11 @@
        -ALL=eap_example
        +# SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
        +# SPDX-FileCopyrightText: © 2023, Edgesec contributors
        +# SPDX-License-Identifier: BSD-3-clause
        +#
        +# This Makefile is adapted from https://w1.fi/cgit/hostap/tree/eap_example/Makefile?h=hostap_2_10
        +# The main added feature is a `make install` command.
        +
        +CONFIG_FILE = .config
        
         include ../src/build.rules
        
        @@ -79,6 +86,7 @@ OBJS_server += ../src/eap_server/eap_server.o
         OBJS_server += ../src/eap_server/eap_server_identity.o
         OBJS_server += ../src/eap_server/eap_server_methods.o
         OBJS_server += ../src/eap_server/eap_server_tls_common.o
        +
         CFLAGS += -DEAP_SERVER
        
        
        @@ -110,8 +118,27 @@ libeap.so: $(EAP_LIBS) $(OBJS_lib)
        
         endif
        
        -eap_example: $(OBJS_ex) $(LIBEAP)
        -	$(LDO) $(LDFLAGS) -o eap_example $(OBJS_ex) -L. -leap $(LIBS)
        +ALL=$(LIBEAP)
        +INSTALL_DIR=$(CONFIG_LIBEAP_INSTALL_DIR)
        +
        +.PHONY: install
        +install: $(LIBEAP)
        +	mkdir -p $(INSTALL_DIR)/lib
        +	cp $^ $(INSTALL_DIR)/lib
        +	mkdir -p $(INSTALL_DIR)/include/eap_common
        +	cp ../src/eap_common/*.h $(INSTALL_DIR)/include/eap_common
        +	mkdir -p $(INSTALL_DIR)/include/eap_peer
        +	cp ../src/eap_peer/*.h $(INSTALL_DIR)/include/eap_peer
        +	mkdir -p $(INSTALL_DIR)/include/eap_server
        +	cp ../src/eap_server/*.h $(INSTALL_DIR)/include/eap_server
        +	mkdir -p $(INSTALL_DIR)/include/crypto
        +	cp ../src/crypto/*.h $(INSTALL_DIR)/include/crypto
        +	mkdir -p $(INSTALL_DIR)/include/utils
        +	cp ../src/utils/*.h $(INSTALL_DIR)/include/utils
        +	mkdir -p $(INSTALL_DIR)/include/tls
        +	cp ../src/tls/*.h $(INSTALL_DIR)/include/tls
        +	mkdir -p $(INSTALL_DIR)/include/common
        +	cp ../src/common/*.h $(INSTALL_DIR)/include/common
        
         clean: common-clean
         	rm -f core *~ *.o *.d libeap.a libeap.so
  • Skip compiling/testing some EAP methods. The following EAP methods were not included in the eap_example/ folder, so I've also made sure not to compile them. THE FOLLOWING ARE NOT COMPILED:
    • EAP_SERVER_SIM
    • EAP_SERVER_AKA
    • EAP_SERVER_AKA_PRIME
    • EAP_SERVER_FAST
    • EAP_SERVER_IKEV2
    • EAP_SERVER_TNC
  • Improve Doxygen documentation and licensing.

aloisklink and others added 4 commits January 9, 2023 12:42
Use an early-return to exit early when `BUILD_ONLY_DOCS` is true.
Add CMake build configuration to compile an EAP library from the
hostapd v2.10 soure code.

In future commits, edgesec's RADIUS server will use this
EAP (https://en.wikipedia.org/wiki/Extensible_Authentication_Protocol)
library for more complex WiFi authentication.

By default, hostapd's EAP files are for internal use only.
We adapted the `eap_example/` project in the `hostap` Git repo
for how to make an independent EAP library,
see https://w1.fi/cgit/hostap/tree/eap_example/Makefile?h=hostap_2_10

Co-authored-by: Alois Klink <alois@nquiringminds.com>
Add some basic tests to confirm whether the EAP library from
hostapd works.

These tests are adapted from the `eap_example/` folder in the
hostapd Git source repository, see
https://w1.fi/cgit/hostap/tree/eap_example?h=hostap_2_10

Co-authored-by: Alois Klink <alois@nquiringminds.com>
Builds the EAP library as part of the "linux" preset, so that it is
automatically tested in continuous integration by GitHub Actions.
@aloisklink

aloisklink commented Jan 9, 2023

Copy link
Copy Markdown
Contributor Author

I've made this in a separate comment, since it was too big for the original comment.

git diff of files changes in this PR compared to #376
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c48b6bf4..6a9cb31b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,8 +77,7 @@ option(BUILD_CMOCKA_LIB "Build cmocka library" OFF)
 option(BUILD_UUID_LIB "Build uuid library" ON)
 option(BUILD_PCAP_LIB "Build pcap library" ON)
 option(BUILD_PROTOBUFC_LIB "Build protobuf-c library" ON)
-option(BUILD_EAP_LIB "Build hostapd eap library" OFF)
-option(BUILD_SQLHOOK "Build sqlhook library" OFF)
+option(BUILD_HOSTAPD_EAP_LIB "Build hostapd eap library" OFF)
 
 option(USE_NETLINK_SERVICE "Use netlink service" OFF)
 cmake_dependent_option(BUILD_MNL_LIB "Build mnl library" ON USE_NETLINK_SERVICE OFF)
@@ -100,8 +99,7 @@ cmake_dependent_option(BUILD_UCI_LIB "Build OpenWRT UCI library" ON USE_UCI_SERV
 option(USE_GENERIC_IP_SERVICE "Use generic ip service" OFF)
 
 option(USE_CRYPTO_SERVICE "Use the crypto service" OFF)
-cmake_dependent_option(BUILD_OPENSSL_LIB "Build OpenSSL 1.1.1" ON "BUILD_HOSTAPD OR BUILD_EAP_LIB" OFF)
-cmake_dependent_option(BUILD_OPENSSL3_LIB "Build OpenSSL 3" ON USE_CRYPTO_SERVICE OFF)
+cmake_dependent_option(BUILD_OPENSSL_LIB "Build OpenSSL" ON USE_CRYPTO_SERVICE OFF)
 
 option(USE_ZYMKEY4_HSM "Use the Zymkey4 HSM" OFF)
 cmake_dependent_option(CONFIGURE_COVERAGE "Configure for code coverage (requires lcov)" OFF BUILD_TESTING OFF)
@@ -192,7 +190,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
 # Include the libraries
-include(openssl) # openssl 1.1.1 Used only for hostapd
 include(hostapd)
 include(cmocka)
 include(minIni)
@@ -202,7 +199,7 @@ include(netlink)
 include(nl)
 include(uuid)
 include(pcap)
-include(openssl3)
+include(openssl)
 include(sqlite)
 include(zymkey4)
 include(uci)
diff --git a/CMakePresets.json b/CMakePresets.json
index 5dbd4518..270878f4 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -36,7 +36,7 @@
         "USE_RADIUS_SERVICE": true,
         "BUILD_HOSTAPD": false,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false,
+        "BUILD_OPENSSL_LIB": false,
         "BUILD_CMOCKA_LIB": true
       }
     },
@@ -53,9 +53,9 @@
         "USE_GENERIC_IP_SERVICE": false,
         "USE_RADIUS_SERVICE": true,
         "BUILD_HOSTAPD": true,
-        "BUILD_EAP_LIB": true,
+        "BUILD_HOSTAPD_EAP_LIB": true,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false
+        "BUILD_OPENSSL_LIB": false
       }
     },
     {
@@ -85,7 +85,7 @@
         "USE_RADIUS_SERVICE": false,
         "BUILD_HOSTAPD": false,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false,
+        "BUILD_OPENSSL_LIB": false,
         "USE_HEADER_MIDDLEWARE": true,
         "USE_CAPTURE_SERVICE": true,
         "BUILD_SQLITE_LIB": true,
@@ -100,7 +100,7 @@
       "description": "Build for Linux using encrypted crypto service",
       "cacheVariables": {
         "USE_CRYPTO_SERVICE": true,
-        "BUILD_OPENSSL3_LIB": true
+        "BUILD_OPENSSL_LIB": true
       }
     },
     {
@@ -167,9 +167,8 @@
         "USE_RADIUS_SERVICE": true,
         "USE_MDNS_SERVICE": true,
         "BUILD_HOSTAPD": false,
-        "BUILD_EAP_LIB": true,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false
+        "BUILD_OPENSSL_LIB": false
       }
     },
     {
diff --git a/debian/copyright b/debian/copyright
index e12a148a..89ec1d24 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -44,6 +44,11 @@ Copyright: 2002-2019, Jouni Malinen <j@w1.fi>
            2021-2022, NquiringMinds Ltd.
 License: BSD-3-clause
 
+Files: lib/libeap.mak tests/radius/eap_test_peer.c tests/radius/eap_test_server.c tests/radius/test_libeap.c
+Copyright: 2007, Jouni Malinen <j@w1.fi>
+           2023, Edgesec contributors
+License: BSD-3-clause
+
 Files: tests/radius/radius_client.*
 Copyright: 2002-2015, Jouni Malinen <j@w1.fi>
 License: BSD-3-clause
diff --git a/lib/hostapd.cmake b/lib/hostapd.cmake
index dbb5a149..2ea6d5ee 100644
--- a/lib/hostapd.cmake
+++ b/lib/hostapd.cmake
@@ -3,20 +3,14 @@
 # v3.14.0+ is required by BUILD_IN_SOURCE + SOURCE_SUBDIR together
 include(ExternalProject)
 
-set(HOSTAPD_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}")
-set(LIBEAP_INSTALL_ROOT "${CMAKE_CURRENT_BINARY_DIR}/lib")
-set(LIBEAP_INSTALL_DIR "${LIBEAP_INSTALL_ROOT}/libeap")
-set(LIBEAP_INCLUDE_DIR "${LIBEAP_INSTALL_DIR}/include")
-set(LIBEAP_LIB_DIR "${LIBEAP_INSTALL_DIR}/lib")
+if (BUILD_ONLY_DOCS)
+  return()
+endif()
 
-if ((BUILD_HOSTAPD OR BUILD_EAP_LIB) AND NOT (BUILD_ONLY_DOCS))
-  find_package(PkgConfig)
-  if ("${CMAKE_GENERATOR}" MATCHES "Makefiles")
-    set(MAKE_COMMAND "$(MAKE)") # recursive make (uses the same make as the main project)
-  else()
-    set(MAKE_COMMAND "make")
-  endif ()
+if (BUILD_HOSTAPD)
+  set(HOSTAPD_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 
+  include(FindPkgConfig)
   if (NOT PKG_CONFIG_FOUND)
     message(FATAL_ERROR "pkg-config is required to build hostapd, but could not be found")
   endif()
@@ -35,24 +29,11 @@ if ((BUILD_HOSTAPD OR BUILD_EAP_LIB) AND NOT (BUILD_ONLY_DOCS))
     @ONLY
   )
 
-  configure_file(
-    "${CMAKE_CURRENT_LIST_DIR}/eap.Makefile.in"
-    "${CMAKE_CURRENT_BINARY_DIR}/eap.Makefile"
-    @ONLY
-  )
-
-  FetchContent_Declare(hostapdsrc
+  ExternalProject_Add(
+    hostapd_externalproject
     URL https://w1.fi/releases/hostapd-2.10.tar.gz
     URL_HASH SHA512=243baa82d621f859d2507d8d5beb0ebda15a75548a62451dc9bca42717dcc8607adac49b354919a41d8257d16d07ac7268203a79750db0cfb34b51f80ff1ce8f
     DOWNLOAD_DIR "${EP_DOWNLOAD_DIR}" # if empty string, uses default download dir
-  )
-  FetchContent_MakeAvailable(hostapdsrc)
-endif ()
-
-if (BUILD_HOSTAPD AND NOT (BUILD_ONLY_DOCS))
-  ExternalProject_Add(
-    hostapd_project
-    SOURCE_DIR ${hostapdsrc_SOURCE_DIR}
     INSTALL_DIR "${HOSTAPD_INSTALL_DIR}"
     BUILD_IN_SOURCE true
     SOURCE_SUBDIR "hostapd" # we only care about hostapd, not the entire hostap dir
@@ -62,36 +43,71 @@ if (BUILD_HOSTAPD AND NOT (BUILD_ONLY_DOCS))
         "${CMAKE_CURRENT_BINARY_DIR}/hostapd.config"
         <BINARY_DIR>/.config
     INSTALL_COMMAND cmake -E copy <BINARY_DIR>/hostapd <INSTALL_DIR>/hostapd
+    STEP_TARGETS download # may be used by hostapd_eap externalproject
   )
   set(HOSTAPD "${HOSTAPD_INSTALL_DIR}/hostapd")
-endif ()
+endif (BUILD_HOSTAPD)
 
-if (BUILD_EAP_LIB AND NOT (BUILD_ONLY_DOCS))
-  file(MAKE_DIRECTORY "${LIBEAP_INdiff --git a/CMakeLists.txt b/CMakeLists.txt
index c48b6bf4..6a9cb31b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,8 +77,7 @@ option(BUILD_CMOCKA_LIB "Build cmocka library" OFF)
 option(BUILD_UUID_LIB "Build uuid library" ON)
 option(BUILD_PCAP_LIB "Build pcap library" ON)
 option(BUILD_PROTOBUFC_LIB "Build protobuf-c library" ON)
-option(BUILD_EAP_LIB "Build hostapd eap library" OFF)
-option(BUILD_SQLHOOK "Build sqlhook library" OFF)
+option(BUILD_HOSTAPD_EAP_LIB "Build hostapd eap library" OFF)
 
 option(USE_NETLINK_SERVICE "Use netlink service" OFF)
 cmake_dependent_option(BUILD_MNL_LIB "Build mnl library" ON USE_NETLINK_SERVICE OFF)
@@ -100,8 +99,7 @@ cmake_dependent_option(BUILD_UCI_LIB "Build OpenWRT UCI library" ON USE_UCI_SERV
 option(USE_GENERIC_IP_SERVICE "Use generic ip service" OFF)
 
 option(USE_CRYPTO_SERVICE "Use the crypto service" OFF)
-cmake_dependent_option(BUILD_OPENSSL_LIB "Build OpenSSL 1.1.1" ON "BUILD_HOSTAPD OR BUILD_EAP_LIB" OFF)
-cmake_dependent_option(BUILD_OPENSSL3_LIB "Build OpenSSL 3" ON USE_CRYPTO_SERVICE OFF)
+cmake_dependent_option(BUILD_OPENSSL_LIB "Build OpenSSL" ON USE_CRYPTO_SERVICE OFF)
 
 option(USE_ZYMKEY4_HSM "Use the Zymkey4 HSM" OFF)
 cmake_dependent_option(CONFIGURE_COVERAGE "Configure for code coverage (requires lcov)" OFF BUILD_TESTING OFF)
@@ -192,7 +190,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
 # Include the libraries
-include(openssl) # openssl 1.1.1 Used only for hostapd
 include(hostapd)
 include(cmocka)
 include(minIni)
@@ -202,7 +199,7 @@ include(netlink)
 include(nl)
 include(uuid)
 include(pcap)
-include(openssl3)
+include(openssl)
 include(sqlite)
 include(zymkey4)
 include(uci)
diff --git a/CMakePresets.json b/CMakePresets.json
index 5dbd4518..270878f4 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -36,7 +36,7 @@
         "USE_RADIUS_SERVICE": true,
         "BUILD_HOSTAPD": false,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false,
+        "BUILD_OPENSSL_LIB": false,
         "BUILD_CMOCKA_LIB": true
       }
     },
@@ -53,9 +53,9 @@
         "USE_GENERIC_IP_SERVICE": false,
         "USE_RADIUS_SERVICE": true,
         "BUILD_HOSTAPD": true,
-        "BUILD_EAP_LIB": true,
+        "BUILD_HOSTAPD_EAP_LIB": true,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false
+        "BUILD_OPENSSL_LIB": false
       }
     },
     {
@@ -85,7 +85,7 @@
         "USE_RADIUS_SERVICE": false,
         "BUILD_HOSTAPD": false,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false,
+        "BUILD_OPENSSL_LIB": false,
         "USE_HEADER_MIDDLEWARE": true,
         "USE_CAPTURE_SERVICE": true,
         "BUILD_SQLITE_LIB": true,
@@ -100,7 +100,7 @@
       "description": "Build for Linux using encrypted crypto service",
       "cacheVariables": {
         "USE_CRYPTO_SERVICE": true,
-        "BUILD_OPENSSL3_LIB": true
+        "BUILD_OPENSSL_LIB": true
       }
     },
     {
@@ -167,9 +167,8 @@
         "USE_RADIUS_SERVICE": true,
         "USE_MDNS_SERVICE": true,
         "BUILD_HOSTAPD": false,
-        "BUILD_EAP_LIB": true,
         "USE_CRYPTO_SERVICE": false,
-        "BUILD_OPENSSL3_LIB": false
+        "BUILD_OPENSSL_LIB": false
       }
     },
     {
diff --git a/debian/copyright b/debian/copyright
index e12a148a..89ec1d24 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -44,6 +44,11 @@ Copyright: 2002-2019, Jouni Malinen <j@w1.fi>
            2021-2022, NquiringMinds Ltd.
 License: BSD-3-clause
 
+Files: lib/libeap.mak tests/radius/eap_test_peer.c tests/radius/eap_test_server.c tests/radius/test_libeap.c
+Copyright: 2007, Jouni Malinen <j@w1.fi>
+           2023, Edgesec contributors
+License: BSD-3-clause
+
 Files: tests/radius/radius_client.*
 Copyright: 2002-2015, Jouni Malinen <j@w1.fi>
 License: BSD-3-clause
diff --git a/lib/hostapd.cmake b/lib/hostapd.cmake
index dbb5a149..2ea6d5ee 100644
--- a/lib/hostapd.cmake
+++ b/lib/hostapd.cmake
@@ -3,20 +3,14 @@
 # v3.14.0+ is required by BUILD_IN_SOURCE + SOURCE_SUBDIR together
 include(ExternalProject)
 
-set(HOSTAPD_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}")
-set(LIBEAP_INSTALL_ROOT "${CMAKE_CURRENT_BINARY_DIR}/lib")
-set(LIBEAP_INSTALL_DIR "${LIBEAP_INSTALL_ROOT}/libeap")
-set(LIBEAP_INCLUDE_DIR "${LIBEAP_INSTALL_DIR}/include")
-set(LIBEAP_LIB_DIR "${LIBEAP_INSTALL_DIR}/lib")
+if (BUILD_ONLY_DOCS)
+  return()
+endif()
 
-if ((BUILD_HOSTAPD OR BUILD_EAP_LIB) AND NOT (BUILD_ONLY_DOCS))
-  find_package(PkgConfig)
-  if ("${CMAKE_GENERATOR}" MATCHES "Makefiles")
-    set(MAKE_COMMAND "$(MAKE)") # recursive make (uses the same make as the main project)
-  else()
-    set(MAKE_COMMAND "make")
-  endif ()
+if (BUILD_HOSTAPD)
+  set(HOSTAPD_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 
+  include(FindPkgConfig)
   if (NOT PKG_CONFIG_FOUND)
     message(FATAL_ERROR "pkg-config is required to build hostapd, but could not be found")
   endif()
@@ -35,24 +29,11 @@ if ((BUILD_HOSTAPD OR BUILD_EAP_LIB) AND NOT (BUILD_ONLY_DOCS))
     @ONLY
   )
 
-  configure_file(
-    "${CMAKE_CURRENT_LIST_DIR}/eap.Makefile.in"
-    "${CMAKE_CURRENT_BINARY_DIR}/eap.Makefile"
-    @ONLY
-  )
-
-  FetchContent_Declare(hostapdsrc
+  ExternalProject_Add(
+    hostapd_externalproject
     URL https://w1.fi/releases/hostapd-2.10.tar.gz
     URL_HASH SHA512=243baa82d621f859d2507d8d5beb0ebda15a75548a62451dc9bca42717dcc8607adac49b354919a41d8257d16d07ac7268203a79750db0cfb34b51f80ff1ce8f
     DOWNLOAD_DIR "${EP_DOWNLOAD_DIR}" # if empty string, uses default download dir
-  )
-  FetchContent_MakeAvailable(hostapdsrc)
-endif ()
-
-if (BUILD_HOSTAPD AND NOT (BUILD_ONLY_DOCS))
-  ExternalProject_Add(
-    hostapd_project
-    SOURCE_DIR ${hostapdsrc_SOURCE_DIR}
     INSTALL_DIR "${HOSTAPD_INSTALL_DIR}"
     BUILD_IN_SOURCE true
     SOURCE_SUBDIR "hostapd" # we only care about hostapd, not the entire hostap dir
@@ -62,36 +43,71 @@ if (BUILD_HOSTAPD AND NOT (BUILD_ONLY_DOCS))
         "${CMAKE_CURRENT_BINARY_DIR}/hostapd.config"
         <BINARY_DIR>/.config
     INSTALL_COMMAND cmake -E copy <BINARY_DIR>/hostapd <INSTALL_DIR>/hostapd
+    STEP_TARGETS download # may be used by hostapd_eap externalproject
   )
   set(HOSTAPD "${HOSTAPD_INSTALL_DIR}/hostapd")
-endif ()
+endif (BUILD_HOSTAPD)
 
-if (BUILD_EAP_LIB AND NOT (BUILD_ONLY_DOCS))
-  file(MAKE_DIRECTORY "${LIBEAP_INCLUDE_DIR}")
-  file(MAKE_DIRECTORY "${LIBEAP_INCLUDE_DIR}/utils")
+# Builds the hostapd::libeap library.
+# See https://w1.fi/cgit/hostap/tree/eap_example?h=hostap_2_10
+#
+# This build process is kind of a mess, since we need to modify how hostapd
+# builds this library, since by default it's not a seperate file
+if (BUILD_HOSTAPD_EAP_LIB)
+  set(LIBEAP_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib/libeap")
 
+  configure_file(
+    "${CMAKE_CURRENT_LIST_DIR}/hostapd.config.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/hostapd-eap.config"
+    @ONLY
+  )
+
+  if ("${CMAKE_GENERATOR}" MATCHES "Makefiles")
+    set(MAKE_COMMAND "$(MAKE)") # recursive make (uses the same make as the main project)
+  else()
+    # just run make in a subprocess. We use single-process, but hostapd is a small project
+    set(MAKE_COMMAND "make")
+  endif ()
+
+  set(EAPLIB_SOURCE_DIR "${hostapdsrc_SOURCE_DIR}/libeap")
+  ExternalProject_Add(
+      hostapd_libeap_project
+      URL https://w1.fi/releases/hostapd-2.10.tar.gz
+      URL_HASH SHA512=243baa82d621f859d2507d8d5beb0ebda15a75548a62451dc9bca42717dcc8607adac49b354919a41d8257d16d07ac7268203a79750db0cfb34b51f80ff1ce8f
+      DOWNLOAD_DIR "${EP_DOWNLOAD_DIR}" # if empty string, uses default download dir
+      BUILD_IN_SOURCE true
+      INSTALL_DIR "${LIBEAP_INSTALL_DIR}" # we have to set this in the `.config` file
+      CONFIGURE_COMMAND
+        COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/libeap
+        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/libeap.mak" <SOURCE_DIR>/libeap/Makefile
+        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/hostapd-eap.config" <SOURCE_DIR>/libeap/.config
+      BUILD_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}" -C <BINARY_DIR>/libeap
+      INSTALL_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}" -C <BINARY_DIR>/libeap install
+  )
+  ExternalProject_Add_StepDependencies(
+    hostapd_libeap_project
+    configure
+    "${CMAKE_CURRENT_LIST_DIR}/libeap.mak"
+    "${CMAKE_CURRENT_BINARY_DIR}/hostapd-eap.config"
+  )
+
+  if (TARGET hostapd_externalproject-download)
+    # If we're building hostapd_externalproject, wait for it to download to prevent
+    # a race-condition
+    add_dependencies(hostapd_libeap_project hostapd_externalproject-download)
+  endif()
+
+  # Hardcoded to be static, we can set CONFIG_SOLIB=yes in `.config` if we really want a shared-library
   set(LIBEAP_LIB "${LIBEAP_INSTALL_DIR}/lib/libeap.a")
   add_library(hostapd::libeap STATIC IMPORTED)
 
-  set(EAPLIB_SOURCE_DIR "${hostapdsrc_SOURCE_DIR}/eaplib")
-  ExternalProject_Add(
-      libeap_project
-      SOURCE_DIR ${hostapdsrc_SOURCE_DIR}
-      INSTALL_DIR ${LIBEAP_INSTALL_DIR}
-      BUILD_IN_SOURCE true
-      CONFIGURE_COMMAND
-        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/eap.Makefile <SOURCE_DIR>/Makefile
-        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/hostapd.config" <SOURCE_DIR>/.config
-      BUILD_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}"
-      INSTALL_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}" install
-  )
+  set(LIBEAP_INCLUDE_DIRS "${LIBEAP_INSTALL_DIR}/include" "${LIBEAP_INSTALL_DIR}/include/utils")
+  file(MAKE_DIRECTORY "${LIBEAP_INSTALL_DIR}/include" "${LIBEAP_INSTALL_DIR}/include/utils")
 
-  set(LIBEAP_INTERFACE_DIRS "${LIBEAP_INCLUDE_DIR}" "${LIBEAP_INCLUDE_DIR}/utils")
   set_target_properties(hostapd::libeap PROPERTIES
       IMPORTED_LOCATION "${LIBEAP_LIB}"
-      INTERFACE_LINK_LIBRARIES OpenSSL::Crypto
-      INTERFACE_INCLUDE_DIRECTORIES "${LIBEAP_INTERFACE_DIRS}"
+      INTERFACE_INCLUDE_DIRECTORIES "${LIBEAP_INCLUDE_DIRS}"
   )
 
-  add_dependencies(hostapd::libeap libeap_project)
-endif ()
+  add_dependencies(hostapd::libeap hostapd_libeap_project)
+endif (BUILD_HOSTAPD_EAP_LIB)
diff --git a/lib/hostapd.config.in b/lib/hostapd.config.in
index b2153e61..3e0e5491 100644
--- a/lib/hostapd.config.in
+++ b/lib/hostapd.config.in
@@ -3,8 +3,6 @@
 # Automatically generated from CMake.
 CC="@CMAKE_C_COMPILER@"
 PKG_CONFIG="@PKG_CONFIG_EXECUTABLE@"
-CFLAGS += -I@LIBOPENSSL_INCLUDE_PATH@
-LIBS += -L@LIBOPENSSL_LIB_PATH@
 
 # Driver interface for Host AP driver
 CONFIG_DRIVER_HOSTAP=y
@@ -72,34 +70,34 @@ CONFIG_EAP_GTC=y
 CONFIG_EAP_TTLS=y
 
 # EAP-SIM for the integrated EAP server
-CONFIG_EAP_SIM=y
+#CONFIG_EAP_SIM=y
 
 # EAP-AKA for the integrated EAP server
-CONFIG_EAP_AKA=y
+#CONFIG_EAP_AKA=y
 
 # EAP-AKA' for the integrated EAP server
 # This requires CONFIG_EAP_AKA to be enabled, too.
-CONFIG_EAP_AKA_PRIME=y
+#CONFIG_EAP_AKA_PRIME=y
 
 # EAP-PAX for the integrated EAP server
-CONFIG_EAP_PAX=y
+#CONFIG_EAP_PAX=y
 
 # EAP-PSK for the integrated EAP server (this is _not_ needed for WPA-PSK)
-CONFIG_EAP_PSK=y
+#CONFIG_EAP_PSK=y
 
 # EAP-pwd for the integrated EAP server (secure authentication with a password)
-CONFIG_EAP_PWD=y
+#CONFIG_EAP_PWD=y
 
 # EAP-SAKE for the integrated EAP server
-CONFIG_EAP_SAKE=y
+#CONFIG_EAP_SAKE=y
 
 # EAP-GPSK for the integrated EAP server
-CONFIG_EAP_GPSK=y
+#CONFIG_EAP_GPSK=y
 # Include support for optional SHA256 cipher suite in EAP-GPSK
-CONFIG_EAP_GPSK_SHA256=y
+#CONFIG_EAP_GPSK_SHA256=y
 
 # EAP-FAST for the integrated EAP server
-CONFIG_EAP_FAST=y
+#CONFIG_EAP_FAST=y
 
 # EAP-TEAP for the integrated EAP server
 # Note: The current EAP-TEAP implementation is experimental and should not be
@@ -109,7 +107,7 @@ CONFIG_EAP_FAST=y
 # any other implementation. This should not be used for anything else than
 # experimentation and interoperability testing until those issues has been
 # resolved.
-CONFIG_EAP_TEAP=y
+#CONFIG_EAP_TEAP=y
 
 # Wi-Fi Protected Setup (WPS)
 #CONFIG_WPS=y
@@ -119,13 +117,13 @@ CONFIG_EAP_TEAP=y
 #CONFIG_WPS_NFC=y
 
 # EAP-IKEv2
-CONFIG_EAP_IKEV2=y
+#CONFIG_EAP_IKEV2=y
 
 # Trusted Network Connect (EAP-TNC)
-CONFIG_EAP_TNC=y
+#CONFIG_EAP_TNC=y
 
 # EAP-EKE for the integrated EAP server
-CONFIG_EAP_EKE=y
+#CONFIG_EAP_EKE=y
 
 # PKCS#12 (PFX) support (used to read private key and certificate file from
 # a file that usually has extension .p12 or .pfx)
@@ -270,7 +268,7 @@ CONFIG_VLAN_NETLINK=y
 # internal = Internal TLSv1 implementation (experimental)
 # linux = Linux kernel AF_ALG and internal TLSv1 implementation (experimental)
 # none = Empty template
-CONFIG_TLS=openssl
+#CONFIG_TLS=openssl
 
 # TLS-based EAP methods require at least TLS v1.0. Newer version of TLS (v1.1)
 # can be enabled to get a stronger construction of messages when block ciphers
@@ -324,7 +322,7 @@ CONFIG_HS20=y
 # connect to this hostapd. These options allow, for example, to drop a
 # certain percentage of probe requests or auth/(re)assoc frames.
 #
-CONFIG_TESTING_OPTIONS=y
+#CONFIG_TESTING_OPTIONS=y
 
 # Automatic Channel Selection
 # This will allow hostapd to pick the channel automatically when channel is set
@@ -380,3 +378,9 @@ CONFIG_TESTING_OPTIONS=y
 # Override default value for the wpa_disable_eapol_key_retries configuration
 # parameter. See that parameter in hostapd.conf for more details.
 #CFLAGS += -DDEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES=1
+
+# EAP Install location
+# Added by @aloislink for the edgesec project
+CONFIG_LIBEAP_INSTALL_DIR=@LIBEAP_INSTALL_DIR@
+# Set to `yes` exactly to create libeap.so instead of libeap.a
+# CONFIG_SOLIB=yes
diff --git a/lib/libeap.mak b/lib/libeap.mak
new file mode 100644
index 00000000..7a5f6193
--- /dev/null
+++ b/lib/libeap.mak
@@ -0,0 +1,146 @@
+# SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+# SPDX-FileCopyrightText: © 2023, Edgesec contributors
+# SPDX-License-Identifier: BSD-3-clause
+#
+# This Makefile is adapted from https://w1.fi/cgit/hostap/tree/eap_example/Makefile?h=hostap_2_10
+# The main added feature is a `make install` command.
+
+CONFIG_FILE = .config
+
+include ../src/build.rules
+
+CFLAGS += -I.
+CFLAGS += -I../src
+CFLAGS += -I../src/utils
+
+
+EAP_LIBS += ../src/utils/libutils.a
+EAP_LIBS += ../src/crypto/libcrypto.a
+EAP_LIBS += ../src/tls/libtls.a
+
+OBJS_both += ../src/eap_common/eap_peap_common.o
+OBJS_both += ../src/eap_common/eap_psk_common.o
+OBJS_both += ../src/eap_common/eap_pax_common.o
+OBJS_both += ../src/eap_common/eap_sake_common.o
+OBJS_both += ../src/eap_common/eap_gpsk_common.o
+OBJS_both += ../src/eap_common/chap.o
+
+OBJS_peer += ../src/eap_peer/eap_tls.o
+OBJS_peer += ../src/eap_peer/eap_peap.o
+OBJS_peer += ../src/eap_peer/eap_ttls.o
+OBJS_peer += ../src/eap_peer/eap_md5.o
+OBJS_peer += ../src/eap_peer/eap_mschapv2.o
+OBJS_peer += ../src/eap_peer/mschapv2.o
+OBJS_peer += ../src/eap_peer/eap_otp.o
+OBJS_peer += ../src/eap_peer/eap_gtc.o
+OBJS_peer += ../src/eap_peer/eap_leap.o
+OBJS_peer += ../src/eap_peer/eap_psk.o
+OBJS_peer += ../src/eap_peer/eap_pax.o
+OBJS_peer += ../src/eap_peer/eap_sake.o
+OBJS_peer += ../src/eap_peer/eap_gpsk.o
+OBJS_peer += ../src/eap_peer/eap.o
+OBJS_peer += ../src/eap_common/eap_common.o
+OBJS_peer += ../src/eap_peer/eap_methods.o
+OBJS_peer += ../src/eap_peer/eap_tls_common.o
+
+CFLAGS += -DEAP_TLS
+CFLAGS += -DEAP_PEAP
+CFLAGS += -DEAP_TTLS
+CFLAGS += -DEAP_MD5
+CFLAGS += -DEAP_MSCHAPv2
+CFLAGS += -DEAP_GTC
+CFLAGS += -DEAP_OTP
+CFLAGS += -DEAP_LEAP
+CFLAGS += -DEAP_PSK
+CFLAGS += -DEAP_PAX
+CFLAGS += -DEAP_SAKE
+CFLAGS += -DEAP_GPSK -DEAP_GPSK_SHA256
+
+CFLAGS += -DEAP_SERVER_IDENTITY
+CFLAGS += -DEAP_SERVER_TLS
+CFLAGS += -DEAP_SERVER_PEAP
+CFLAGS += -DEAP_SERVER_TTLS
+CFLAGS += -DEAP_SERVER_MD5
+CFLAGS += -DEAP_SERVER_MSCHAPV2
+CFLAGS += -DEAP_SERVER_GTC
+CFLAGS += -DEAP_SERVER_PSK
+CFLAGS += -DEAP_SERVER_PAX
+CFLAGS += -DEAP_SERVER_SAKE
+CFLAGS += -DEAP_SERVER_GPSK -DEAP_SERVER_GPSK_SHA256
+
+CFLAGS += -DIEEE8021X_EAPOL
+
+
+# Optional components to add EAP server support
+OBJS_server += ../src/eap_server/eap_server_tls.o
+OBJS_server += ../src/eap_server/eap_server_peap.o
+OBJS_server += ../src/eap_server/eap_server_ttls.o
+OBJS_server += ../src/eap_server/eap_server_md5.o
+OBJS_server += ../src/eap_server/eap_server_mschapv2.o
+OBJS_server += ../src/eap_server/eap_server_gtc.o
+OBJS_server += ../src/eap_server/eap_server_psk.o
+OBJS_server += ../src/eap_server/eap_server_pax.o
+OBJS_server += ../src/eap_server/eap_server_sake.o
+OBJS_server += ../src/eap_server/eap_server_gpsk.o
+OBJS_server += ../src/eap_server/eap_server.o
+OBJS_server += ../src/eap_server/eap_server_identity.o
+OBJS_server += ../src/eap_server/eap_server_methods.o
+OBJS_server += ../src/eap_server/eap_server_tls_common.o
+
+CFLAGS += -DEAP_SERVER
+
+
+OBJS_lib=$(OBJS_both) $(OBJS_peer) $(OBJS_server)
+_OBJS_VAR := OBJS_lib
+include ../src/objs.mk
+
+OBJS_ex = eap_example.o eap_example_peer.o eap_example_server.o
+_OBJS_VAR := OBJS_ex
+include ../src/objs.mk
+
+_OBJS_VAR := EAP_LIBS
+include ../src/objs.mk
+
+
+ifneq ($(CONFIG_SOLIB), yes)
+LIBEAP = libeap.a
+libeap.a: $(EAP_LIBS) $(OBJS_lib)
+	$(AR) crT libeap.a $^
+	$(RANLIB) libeap.a
+
+else
+CFLAGS  += -fPIC -DPIC
+LDFLAGS += -shared
+
+LIBEAP  = libeap.so
+libeap.so: $(EAP_LIBS) $(OBJS_lib)
+	$(LDO) $(LDFLAGS) $^ -o $(LIBEAP)
+
+endif
+
+ALL=$(LIBEAP)
+INSTALL_DIR=$(CONFIG_LIBEAP_INSTALL_DIR)
+
+.PHONY: install
+install: $(LIBEAP)
+	mkdir -p $(INSTALL_DIR)/lib
+	cp $^ $(INSTALL_DIR)/lib
+	mkdir -p $(INSTALL_DIR)/include/eap_common
+	cp ../src/eap_common/*.h $(INSTALL_DIR)/include/eap_common
+	mkdir -p $(INSTALL_DIR)/include/eap_peer
+	cp ../src/eap_peer/*.h $(INSTALL_DIR)/include/eap_peer
+	mkdir -p $(INSTALL_DIR)/include/eap_server
+	cp ../src/eap_server/*.h $(INSTALL_DIR)/include/eap_server
+	mkdir -p $(INSTALL_DIR)/include/crypto
+	cp ../src/crypto/*.h $(INSTALL_DIR)/include/crypto
+	mkdir -p $(INSTALL_DIR)/include/utils
+	cp ../src/utils/*.h $(INSTALL_DIR)/include/utils
+	mkdir -p $(INSTALL_DIR)/include/tls
+	cp ../src/tls/*.h $(INSTALL_DIR)/include/tls
+	mkdir -p $(INSTALL_DIR)/include/common
+	cp ../src/common/*.h $(INSTALL_DIR)/include/common
+
+clean: common-clean
+	rm -f core *~ *.o *.d libeap.a libeap.so
+
+-include $(OBJS:%.o=%.d)
diff --git a/tests/radius/CMakeLists.txt b/tests/radius/CMakeLists.txt
index d2f46c22..d1e2ea16 100644
--- a/tests/radius/CMakeLists.txt
+++ b/tests/radius/CMakeLists.txt
@@ -2,21 +2,21 @@ include_directories(
   "${PROJECT_SOURCE_DIR}/src"
 )
 
-if (BUILD_EAP_LIB)
+if (TARGET hostapd::libeap)
   set(EAP_TEST_DIR "${CMAKE_SOURCE_DIR}/tests/data/eap/")
   add_compile_definitions(EAP_TEST_DIR="${EAP_TEST_DIR}")
 
   add_library(eap_test_peer eap_test_peer.c)
-  target_link_libraries(eap_test_peer PRIVATE hostapd::libeap OpenSSL::Crypto)
+  target_link_libraries(eap_test_peer PRIVATE hostapd::libeap)
   target_compile_definitions(eap_test_peer PRIVATE _DEFAULT_SOURCE _BSD_SOURCE IEEE8021X_EAPOL)
 
   add_library(eap_test_server eap_test_server.c)
-  target_link_libraries(eap_test_server PRIVATE hostapd::libeap OpenSSL::Crypto)
+  target_link_libraries(eap_test_server PRIVATE hostapd::libeap)
   target_compile_definitions(eap_test_server PRIVATE _DEFAULT_SOURCE _BSD_SOURCE IEEE8021X_EAPOL)
 
   add_cmocka_test(test_libeap
     SOURCES test_libeap.c
-    LINK_LIBRARIES eap_test_peer eap_test_server hostapd::libeap cmocka::cmocka OpenSSL::SSL OpenSSL::Crypto
+    LINK_LIBRARIES eap_test_peer eap_test_server hostapd::libeap cmocka::cmocka
   )
   target_compile_definitions(test_libeap PRIVATE _DEFAULT_SOURCE _BSD_SOURCE IEEE8021X_EAPOL)
 endif ()
diff --git a/tests/radius/eap_test_peer.c b/tests/radius/eap_test_peer.c
index 153d3b7c..6e1ea2d3 100644
--- a/tests/radius/eap_test_peer.c
+++ b/tests/radius/eap_test_peer.c
@@ -1,16 +1,19 @@
 /**
  * @file
- * @author Alexandru Mereacre
- * @date 2023
- * @copyright
- * SPDX-FileCopyrightText: Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- * SPDX-License-Identifier: BSD license
- * @version hostapd-2.10
- * @brief Example application showing how EAP peer code from wpa_supplicant can be used as a library.
+ * @brief Example application showing how EAP peer code from wpa_supplicant can
+ * be used as a library.
+ * @author Alexandru Mereacre, Jouni Malinen
+ * @copyright SPDX-FileCopyrightText: © 2023 edgesec contributors
+ * @copyright SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+ * @copyright SPDX-License-Identifier: BSD-3-clause
+ * @version Adapted from [hostap 2.10 -
+ * `eap_example/eap_example_peer.c`](https://w1.fi/cgit/hostap/tree/eap_example/eap_example_peer.c?h=hostap_2_10)
  */
 
 #include <utils/includes.h>
+
 #include <utils/common.h>
+
 #include <eap_peer/eap.h>
 #include <eap_peer/eap_config.h>
 #include <utils/wpabuf.h>
@@ -164,55 +167,55 @@ static void peer_notify_pending(void *ctx) {
 static int eap_peer_register_methods(void) {
   int ret = 0;
 
-// #ifdef EAP_MD5
+  // #ifdef EAP_MD5
   if (ret == 0)
     ret = eap_peer_md5_register();
-// #endif /* EAP_MD5 */
+  // #endif /* EAP_MD5 */
 
-// #ifdef EAP_TLS
+  // #ifdef EAP_TLS
   if (ret == 0)
     ret = eap_peer_tls_register();
-// #endif /* EAP_TLS */
+  // #endif /* EAP_TLS */
 
-// #ifdef EAP_MSCHAPv2
+  // #ifdef EAP_MSCHAPv2
   if (ret == 0)
     ret = eap_peer_mschapv2_register();
-// #endif /* EAP_MSCHAPv2 */
+  // #endif /* EAP_MSCHAPv2 */
 
-// #ifdef EAP_PEAP
+  // #ifdef EAP_PEAP
   if (ret == 0)
     ret = eap_peer_peap_register();
-// #endif /* EAP_PEAP */
+  // #endif /* EAP_PEAP */
 
-// #ifdef EAP_TTLS
+  // #ifdef EAP_TTLS
   if (ret == 0)
     ret = eap_peer_ttls_register();
-// #endif /* EAP_TTLS */
+  // #endif /* EAP_TTLS */
 
-// #ifdef EAP_GTC
+  // #ifdef EAP_GTC
   if (ret == 0)
     ret = eap_peer_gtc_register();
-// #endif /* EAP_GTC */
+  // #endif /* EAP_GTC */
 
-// #ifdef EAP_OTP
+  // #ifdef EAP_OTP
   if (ret == 0)
     ret = eap_peer_otp_register();
-// #endif /* EAP_OTP */
+    // #endif /* EAP_OTP */
 
 #ifdef EAP_SIM
   if (ret == 0)
     ret = eap_peer_sim_register();
 #endif /* EAP_SIM */
 
-// #ifdef EAP_LEAP
+  // #ifdef EAP_LEAP
   if (ret == 0)
     ret = eap_peer_leap_register();
-// #endif /* EAP_LEAP */
+  // #endif /* EAP_LEAP */
 
-// #ifdef EAP_PSK
+  // #ifdef EAP_PSK
   if (ret == 0)
     ret = eap_peer_psk_register();
-// #endif /* EAP_PSK */
+    // #endif /* EAP_PSK */
 
 #ifdef EAP_AKA
   if (ret == 0)
@@ -229,20 +232,20 @@ static int eap_peer_register_methods(void) {
     ret = eap_peer_fast_register();
 #endif /* EAP_FAST */
 
-// #ifdef EAP_PAX
+  // #ifdef EAP_PAX
   if (ret == 0)
     ret = eap_peer_pax_register();
-// #endif /* EAP_PAX */
+  // #endif /* EAP_PAX */
 
-// #ifdef EAP_SAKE
+  // #ifdef EAP_SAKE
   if (ret == 0)
     ret = eap_peer_sake_register();
-// #endif /* EAP_SAKE */
+  // #endif /* EAP_SAKE */
 
-// #ifdef EAP_GPSK
+  // #ifdef EAP_GPSK
   if (ret == 0)
     ret = eap_peer_gpsk_register();
-// #endif /* EAP_GPSK */
+    // #endif /* EAP_GPSK */
 
 #ifdef EAP_WSC
   if (ret == 0)
@@ -278,8 +281,8 @@ int eap_test_peer_init(void) {
 
   eap_ctx.eap_config.anonymous_identity = (u8 *)os_strdup("01:02:03:04:05:06");
   eap_ctx.eap_config.anonymous_identity_len = 17;
-	eap_ctx.eap_config.machine_identity = (u8 *)os_strdup("01:02:03:04:05:06");
-	eap_ctx.eap_config.machine_identity_len = 17;
+  eap_ctx.eap_config.machine_identity = (u8 *)os_strdup("01:02:03:04:05:06");
+  eap_ctx.eap_config.machine_identity_len = 17;
 
   eap_ctx.eap_config.cert.ca_cert = os_strdup(EAP_TEST_DIR "ca.pem");
   eap_ctx.eap_config.cert.client_cert = os_strdup(EAP_TEST_DIR "client.pem");
diff --git a/tests/radius/eap_test_server.c b/tests/radius/eap_test_server.c
index f6a786e2..2f7b600e 100644
--- a/tests/radius/eap_test_server.c
+++ b/tests/radius/eap_test_server.c
@@ -1,17 +1,19 @@
 /**
  * @file
- * @author Alexandru Mereacre
- * @date 2023
- * @copyright
- * SPDX-FileCopyrightText: Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- * SPDX-License-Identifier: BSD license
- * @version hostapd-2.10
- * @brief Example application showing how EAP server code from hostapd can be used as a library.
+ * @brief Example application showing how EAP server code from hostapd can be
+ * used as a library.
+ * @author Alexandru Mereacre, Jouni Malinen
+ * @copyright SPDX-FileCopyrightText: © 2023 edgesec contributors
+ * @copyright SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+ * @copyright SPDX-License-Identifier: BSD-3-clause
+ * @version Adapted from [hostap 2.10 -
+ * `eap_example/eap_example_server.c`](https://w1.fi/cgit/hostap/tree/eap_example/eap_example_server.c?h=hostap_2_10)
  */
 
 #include <utils/includes.h>
 
 #include <utils/common.h>
+
 #include <crypto/tls.h>
 #include <eap_server/eap.h>
 #include <utils/wpabuf.h>
@@ -85,105 +87,105 @@ static int eap_test_server_init_tls(void) {
 static int eap_server_register_methods(void) {
   int ret = 0;
 
-// #ifdef EAP_SERVER_IDENTITY
+  // #ifdef EAP_SERVER_IDENTITY
   if (ret == 0)
     ret = eap_server_identity_register();
-// #endif /* EAP_SERVER_IDENTITY */
+  // #endif /* EAP_SERVER_IDENTITY */
 
-// #ifdef EAP_SERVER_MD5
+  // #ifdef EAP_SERVER_MD5
   if (ret == 0)
     ret = eap_server_md5_register();
-// #endif /* EAP_SERVER_MD5 */
+  // #endif /* EAP_SERVER_MD5 */
 
-// #ifdef EAP_SERVER_TLS
+  // #ifdef EAP_SERVER_TLS
   if (ret == 0)
     ret = eap_server_tls_register();
-// #endif /* EAP_SERVER_TLS */
+  // #endif /* EAP_SERVER_TLS */
 
-// #ifdef EAP_SERVER_MSCHAPV2
+  // #ifdef EAP_SERVER_MSCHAPV2
   if (ret == 0)
     ret = eap_server_mschapv2_register();
-// #endif /* EAP_SERVER_MSCHAPV2 */
+  // #endif /* EAP_SERVER_MSCHAPV2 */
 
-// #ifdef EAP_SERVER_PEAP
+  // #ifdef EAP_SERVER_PEAP
   if (ret == 0)
     ret = eap_server_peap_register();
-// #endif /* EAP_SERVER_PEAP */
+    // #endif /* EAP_SERVER_PEAP */
 
 #ifdef EAP_SERVER_TLV
   if (ret == 0)
     ret = eap_server_tlv_register();
 #endif /* EAP_SERVER_TLV */
 
-// #ifdef EAP_SERVER_GTC
+  // #ifdef EAP_SERVER_GTC
   if (ret == 0)
     ret = eap_server_gtc_register();
-// #endif /* EAP_SERVER_GTC */
+  // #endif /* EAP_SERVER_GTC */
 
-// #ifdef EAP_SERVER_TTLS
+  // #ifdef EAP_SERVER_TTLS
   if (ret == 0)
     ret = eap_server_ttls_register();
-// #endif /* EAP_SERVER_TTLS */
+    // #endif /* EAP_SERVER_TTLS */
 
-// #ifdef EAP_SERVER_SIM
+#ifdef EAP_SERVER_SIM
   if (ret == 0)
     ret = eap_server_sim_register();
-// #endif /* EAP_SERVER_SIM */
+#endif /* EAP_SERVER_SIM */
 
-// #ifdef EAP_SERVER_AKA
+#ifdef EAP_SERVER_AKA
   if (ret == 0)
     ret = eap_server_aka_register();
-// #endif /* EAP_SERVER_AKA */
+#endif /* EAP_SERVER_AKA */
 
-// #ifdef EAP_SERVER_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
   if (ret == 0)
     ret = eap_server_aka_prime_register();
-// #endif /* EAP_SERVER_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
 
-// #ifdef EAP_SERVER_PAX
+  // #ifdef EAP_SERVER_PAX
   if (ret == 0)
     ret = eap_server_pax_register();
-// #endif /* EAP_SERVER_PAX */
+  // #endif /* EAP_SERVER_PAX */
 
-// #ifdef EAP_SERVER_PSK
+  // #ifdef EAP_SERVER_PSK
   if (ret == 0)
     ret = eap_server_psk_register();
-// #endif /* EAP_SERVER_PSK */
+  // #endif /* EAP_SERVER_PSK */
 
-// #ifdef EAP_SERVER_SAKE
+  // #ifdef EAP_SERVER_SAKE
   if (ret == 0)
     ret = eap_server_sake_register();
-// #endif /* EAP_SERVER_SAKE */
+  // #endif /* EAP_SERVER_SAKE */
 
-// #ifdef EAP_SERVER_GPSK
+  // #ifdef EAP_SERVER_GPSK
   if (ret == 0)
     ret = eap_server_gpsk_register();
-// #endif /* EAP_SERVER_GPSK */
+    // #endif /* EAP_SERVER_GPSK */
 
 #ifdef EAP_SERVER_VENDOR_TEST
   if (ret == 0)
     ret = eap_server_vendor_test_register();
 #endif /* EAP_SERVER_VENDOR_TEST */
 
-// #ifdef EAP_SERVER_FAST
+#ifdef EAP_SERVER_FAST
   if (ret == 0)
     ret = eap_server_fast_register();
-// #endif /* EAP_SERVER_FAST */
+#endif /* EAP_SERVER_FAST */
 
 #ifdef EAP_SERVER_WSC
   if (ret == 0)
     ret = eap_server_wsc_register();
 #endif /* EAP_SERVER_WSC */
 
-// #ifdef EAP_SERVER_IKEV2
+#ifdef EAP_SERVER_IKEV2
   if (ret == 0)
     ret = eap_server_ikev2_register();
-// #endif /* EAP_SERVER_IKEV2 */
+#endif /* EAP_SERVER_IKEV2 */
 
-// #ifdef EAP_SERVER_TNC
+#ifdef EAP_SERVER_TNC
   if (ret == 0)
     ret = eap_server_tnc_register();
-// #endif /* EAP_SERVER_TNC */
+#endif /* EAP_SERVER_TNC */
 
   return ret;
 }
@@ -208,7 +210,7 @@ int eap_test_server_init(void) {
   eap_conf.ssl_ctx = eap_ctx.tls_ctx;
 
   eap_conf.max_auth_rounds = 100;
-	eap_conf.max_auth_rounds_short = 50;
+  eap_conf.max_auth_rounds_short = 50;
 
   os_memset(&eap_sess, 0, sizeof(eap_sess));
   eap_ctx.eap = eap_server_sm_init(&eap_ctx, &eap_cb, &eap_conf, &eap_sess);
diff --git a/tests/radius/test_libeap.c b/tests/radius/test_libeap.c
index 558a5fdc..5e101029 100644
--- a/tests/radius/test_libeap.c
+++ b/tests/radius/test_libeap.c
@@ -1,13 +1,13 @@
 /**
  * @file
- * @author Alexandru Mereacre
- * @date 2023
- * @copyright
- * SPDX-FileCopyrightText: Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- * SPDX-License-Identifier: BSD license
- * @version hostapd-2.10
  * @brief Test showing how EAP peer and server code from
  * wpa_supplicant/hostapd can be used as a library for a EAP-TLS connection.
+ * @author Alexandru Mereacre, Jouni Malinen
+ * @copyright SPDX-FileCopyrightText: © 2023 edgesec contributors
+ * @copyright SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+ * @copyright SPDX-License-Identifier: BSD-3-clause
+ * @version Adapted from [hostap 2.10 -
+ * `eap_example/eap_example.c`](https://w1.fi/cgit/hostap/tree/eap_example/eap_example.c?h=hostap_2_10)
  */
 
 #include <setjmp.h>
CLUDE_DIR}")
-  file(MAKE_DIRECTORY "${LIBEAP_INCLUDE_DIR}/utils")
+# Builds the hostapd::libeap library.
+# See https://w1.fi/cgit/hostap/tree/eap_example?h=hostap_2_10
+#
+# This build process is kind of a mess, since we need to modify how hostapd
+# builds this library, since by default it's not a seperate file
+if (BUILD_HOSTAPD_EAP_LIB)
+  set(LIBEAP_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib/libeap")
 
+  configure_file(
+    "${CMAKE_CURRENT_LIST_DIR}/hostapd.config.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/hostapd-eap.config"
+    @ONLY
+  )
+
+  if ("${CMAKE_GENERATOR}" MATCHES "Makefiles")
+    set(MAKE_COMMAND "$(MAKE)") # recursive make (uses the same make as the main project)
+  else()
+    # just run make in a subprocess. We use single-process, but hostapd is a small project
+    set(MAKE_COMMAND "make")
+  endif ()
+
+  set(EAPLIB_SOURCE_DIR "${hostapdsrc_SOURCE_DIR}/libeap")
+  ExternalProject_Add(
+      hostapd_libeap_project
+      URL https://w1.fi/releases/hostapd-2.10.tar.gz
+      URL_HASH SHA512=243baa82d621f859d2507d8d5beb0ebda15a75548a62451dc9bca42717dcc8607adac49b354919a41d8257d16d07ac7268203a79750db0cfb34b51f80ff1ce8f
+      DOWNLOAD_DIR "${EP_DOWNLOAD_DIR}" # if empty string, uses default download dir
+      BUILD_IN_SOURCE true
+      INSTALL_DIR "${LIBEAP_INSTALL_DIR}" # we have to set this in the `.config` file
+      CONFIGURE_COMMAND
+        COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/libeap
+        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/libeap.mak" <SOURCE_DIR>/libeap/Makefile
+        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/hostapd-eap.config" <SOURCE_DIR>/libeap/.config
+      BUILD_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}" -C <BINARY_DIR>/libeap
+      INSTALL_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}" -C <BINARY_DIR>/libeap install
+  )
+  ExternalProject_Add_StepDependencies(
+    hostapd_libeap_project
+    configure
+    "${CMAKE_CURRENT_LIST_DIR}/libeap.mak"
+    "${CMAKE_CURRENT_BINARY_DIR}/hostapd-eap.config"
+  )
+
+  if (TARGET hostapd_externalproject-download)
+    # If we're building hostapd_externalproject, wait for it to download to prevent
+    # a race-condition
+    add_dependencies(hostapd_libeap_project hostapd_externalproject-download)
+  endif()
+
+  # Hardcoded to be static, we can set CONFIG_SOLIB=yes in `.config` if we really want a shared-library
   set(LIBEAP_LIB "${LIBEAP_INSTALL_DIR}/lib/libeap.a")
   add_library(hostapd::libeap STATIC IMPORTED)
 
-  set(EAPLIB_SOURCE_DIR "${hostapdsrc_SOURCE_DIR}/eaplib")
-  ExternalProject_Add(
-      libeap_project
-      SOURCE_DIR ${hostapdsrc_SOURCE_DIR}
-      INSTALL_DIR ${LIBEAP_INSTALL_DIR}
-      BUILD_IN_SOURCE true
-      CONFIGURE_COMMAND
-        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/eap.Makefile <SOURCE_DIR>/Makefile
-        COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/hostapd.config" <SOURCE_DIR>/.config
-      BUILD_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}"
-      INSTALL_COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}" "${MAKE_COMMAND}" install
-  )
+  set(LIBEAP_INCLUDE_DIRS "${LIBEAP_INSTALL_DIR}/include" "${LIBEAP_INSTALL_DIR}/include/utils")
+  file(MAKE_DIRECTORY "${LIBEAP_INSTALL_DIR}/include" "${LIBEAP_INSTALL_DIR}/include/utils")
 
-  set(LIBEAP_INTERFACE_DIRS "${LIBEAP_INCLUDE_DIR}" "${LIBEAP_INCLUDE_DIR}/utils")
   set_target_properties(hostapd::libeap PROPERTIES
       IMPORTED_LOCATION "${LIBEAP_LIB}"
-      INTERFACE_LINK_LIBRARIES OpenSSL::Crypto
-      INTERFACE_INCLUDE_DIRECTORIES "${LIBEAP_INTERFACE_DIRS}"
+      INTERFACE_INCLUDE_DIRECTORIES "${LIBEAP_INCLUDE_DIRS}"
   )
 
-  add_dependencies(hostapd::libeap libeap_project)
-endif ()
+  add_dependencies(hostapd::libeap hostapd_libeap_project)
+endif (BUILD_HOSTAPD_EAP_LIB)
diff --git a/lib/hostapd.config.in b/lib/hostapd.config.in
index b2153e61..3e0e5491 100644
--- a/lib/hostapd.config.in
+++ b/lib/hostapd.config.in
@@ -3,8 +3,6 @@
 # Automatically generated from CMake.
 CC="@CMAKE_C_COMPILER@"
 PKG_CONFIG="@PKG_CONFIG_EXECUTABLE@"
-CFLAGS += -I@LIBOPENSSL_INCLUDE_PATH@
-LIBS += -L@LIBOPENSSL_LIB_PATH@
 
 # Driver interface for Host AP driver
 CONFIG_DRIVER_HOSTAP=y
@@ -72,34 +70,34 @@ CONFIG_EAP_GTC=y
 CONFIG_EAP_TTLS=y
 
 # EAP-SIM for the integrated EAP server
-CONFIG_EAP_SIM=y
+#CONFIG_EAP_SIM=y
 
 # EAP-AKA for the integrated EAP server
-CONFIG_EAP_AKA=y
+#CONFIG_EAP_AKA=y
 
 # EAP-AKA' for the integrated EAP server
 # This requires CONFIG_EAP_AKA to be enabled, too.
-CONFIG_EAP_AKA_PRIME=y
+#CONFIG_EAP_AKA_PRIME=y
 
 # EAP-PAX for the integrated EAP server
-CONFIG_EAP_PAX=y
+#CONFIG_EAP_PAX=y
 
 # EAP-PSK for the integrated EAP server (this is _not_ needed for WPA-PSK)
-CONFIG_EAP_PSK=y
+#CONFIG_EAP_PSK=y
 
 # EAP-pwd for the integrated EAP server (secure authentication with a password)
-CONFIG_EAP_PWD=y
+#CONFIG_EAP_PWD=y
 
 # EAP-SAKE for the integrated EAP server
-CONFIG_EAP_SAKE=y
+#CONFIG_EAP_SAKE=y
 
 # EAP-GPSK for the integrated EAP server
-CONFIG_EAP_GPSK=y
+#CONFIG_EAP_GPSK=y
 # Include support for optional SHA256 cipher suite in EAP-GPSK
-CONFIG_EAP_GPSK_SHA256=y
+#CONFIG_EAP_GPSK_SHA256=y
 
 # EAP-FAST for the integrated EAP server
-CONFIG_EAP_FAST=y
+#CONFIG_EAP_FAST=y
 
 # EAP-TEAP for the integrated EAP server
 # Note: The current EAP-TEAP implementation is experimental and should not be
@@ -109,7 +107,7 @@ CONFIG_EAP_FAST=y
 # any other implementation. This should not be used for anything else than
 # experimentation and interoperability testing until those issues has been
 # resolved.
-CONFIG_EAP_TEAP=y
+#CONFIG_EAP_TEAP=y
 
 # Wi-Fi Protected Setup (WPS)
 #CONFIG_WPS=y
@@ -119,13 +117,13 @@ CONFIG_EAP_TEAP=y
 #CONFIG_WPS_NFC=y
 
 # EAP-IKEv2
-CONFIG_EAP_IKEV2=y
+#CONFIG_EAP_IKEV2=y
 
 # Trusted Network Connect (EAP-TNC)
-CONFIG_EAP_TNC=y
+#CONFIG_EAP_TNC=y
 
 # EAP-EKE for the integrated EAP server
-CONFIG_EAP_EKE=y
+#CONFIG_EAP_EKE=y
 
 # PKCS#12 (PFX) support (used to read private key and certificate file from
 # a file that usually has extension .p12 or .pfx)
@@ -270,7 +268,7 @@ CONFIG_VLAN_NETLINK=y
 # internal = Internal TLSv1 implementation (experimental)
 # linux = Linux kernel AF_ALG and internal TLSv1 implementation (experimental)
 # none = Empty template
-CONFIG_TLS=openssl
+#CONFIG_TLS=openssl
 
 # TLS-based EAP methods require at least TLS v1.0. Newer version of TLS (v1.1)
 # can be enabled to get a stronger construction of messages when block ciphers
@@ -324,7 +322,7 @@ CONFIG_HS20=y
 # connect to this hostapd. These options allow, for example, to drop a
 # certain percentage of probe requests or auth/(re)assoc frames.
 #
-CONFIG_TESTING_OPTIONS=y
+#CONFIG_TESTING_OPTIONS=y
 
 # Automatic Channel Selection
 # This will allow hostapd to pick the channel automatically when channel is set
@@ -380,3 +378,9 @@ CONFIG_TESTING_OPTIONS=y
 # Override default value for the wpa_disable_eapol_key_retries configuration
 # parameter. See that parameter in hostapd.conf for more details.
 #CFLAGS += -DDEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES=1
+
+# EAP Install location
+# Added by @aloislink for the edgesec project
+CONFIG_LIBEAP_INSTALL_DIR=@LIBEAP_INSTALL_DIR@
+# Set to `yes` exactly to create libeap.so instead of libeap.a
+# CONFIG_SOLIB=yes
diff --git a/lib/libeap.mak b/lib/libeap.mak
new file mode 100644
index 00000000..7a5f6193
--- /dev/null
+++ b/lib/libeap.mak
@@ -0,0 +1,146 @@
+# SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+# SPDX-FileCopyrightText: © 2023, Edgesec contributors
+# SPDX-License-Identifier: BSD-3-clause
+#
+# This Makefile is adapted from https://w1.fi/cgit/hostap/tree/eap_example/Makefile?h=hostap_2_10
+# The main added feature is a `make install` command.
+
+CONFIG_FILE = .config
+
+include ../src/build.rules
+
+CFLAGS += -I.
+CFLAGS += -I../src
+CFLAGS += -I../src/utils
+
+
+EAP_LIBS += ../src/utils/libutils.a
+EAP_LIBS += ../src/crypto/libcrypto.a
+EAP_LIBS += ../src/tls/libtls.a
+
+OBJS_both += ../src/eap_common/eap_peap_common.o
+OBJS_both += ../src/eap_common/eap_psk_common.o
+OBJS_both += ../src/eap_common/eap_pax_common.o
+OBJS_both += ../src/eap_common/eap_sake_common.o
+OBJS_both += ../src/eap_common/eap_gpsk_common.o
+OBJS_both += ../src/eap_common/chap.o
+
+OBJS_peer += ../src/eap_peer/eap_tls.o
+OBJS_peer += ../src/eap_peer/eap_peap.o
+OBJS_peer += ../src/eap_peer/eap_ttls.o
+OBJS_peer += ../src/eap_peer/eap_md5.o
+OBJS_peer += ../src/eap_peer/eap_mschapv2.o
+OBJS_peer += ../src/eap_peer/mschapv2.o
+OBJS_peer += ../src/eap_peer/eap_otp.o
+OBJS_peer += ../src/eap_peer/eap_gtc.o
+OBJS_peer += ../src/eap_peer/eap_leap.o
+OBJS_peer += ../src/eap_peer/eap_psk.o
+OBJS_peer += ../src/eap_peer/eap_pax.o
+OBJS_peer += ../src/eap_peer/eap_sake.o
+OBJS_peer += ../src/eap_peer/eap_gpsk.o
+OBJS_peer += ../src/eap_peer/eap.o
+OBJS_peer += ../src/eap_common/eap_common.o
+OBJS_peer += ../src/eap_peer/eap_methods.o
+OBJS_peer += ../src/eap_peer/eap_tls_common.o
+
+CFLAGS += -DEAP_TLS
+CFLAGS += -DEAP_PEAP
+CFLAGS += -DEAP_TTLS
+CFLAGS += -DEAP_MD5
+CFLAGS += -DEAP_MSCHAPv2
+CFLAGS += -DEAP_GTC
+CFLAGS += -DEAP_OTP
+CFLAGS += -DEAP_LEAP
+CFLAGS += -DEAP_PSK
+CFLAGS += -DEAP_PAX
+CFLAGS += -DEAP_SAKE
+CFLAGS += -DEAP_GPSK -DEAP_GPSK_SHA256
+
+CFLAGS += -DEAP_SERVER_IDENTITY
+CFLAGS += -DEAP_SERVER_TLS
+CFLAGS += -DEAP_SERVER_PEAP
+CFLAGS += -DEAP_SERVER_TTLS
+CFLAGS += -DEAP_SERVER_MD5
+CFLAGS += -DEAP_SERVER_MSCHAPV2
+CFLAGS += -DEAP_SERVER_GTC
+CFLAGS += -DEAP_SERVER_PSK
+CFLAGS += -DEAP_SERVER_PAX
+CFLAGS += -DEAP_SERVER_SAKE
+CFLAGS += -DEAP_SERVER_GPSK -DEAP_SERVER_GPSK_SHA256
+
+CFLAGS += -DIEEE8021X_EAPOL
+
+
+# Optional components to add EAP server support
+OBJS_server += ../src/eap_server/eap_server_tls.o
+OBJS_server += ../src/eap_server/eap_server_peap.o
+OBJS_server += ../src/eap_server/eap_server_ttls.o
+OBJS_server += ../src/eap_server/eap_server_md5.o
+OBJS_server += ../src/eap_server/eap_server_mschapv2.o
+OBJS_server += ../src/eap_server/eap_server_gtc.o
+OBJS_server += ../src/eap_server/eap_server_psk.o
+OBJS_server += ../src/eap_server/eap_server_pax.o
+OBJS_server += ../src/eap_server/eap_server_sake.o
+OBJS_server += ../src/eap_server/eap_server_gpsk.o
+OBJS_server += ../src/eap_server/eap_server.o
+OBJS_server += ../src/eap_server/eap_server_identity.o
+OBJS_server += ../src/eap_server/eap_server_methods.o
+OBJS_server += ../src/eap_server/eap_server_tls_common.o
+
+CFLAGS += -DEAP_SERVER
+
+
+OBJS_lib=$(OBJS_both) $(OBJS_peer) $(OBJS_server)
+_OBJS_VAR := OBJS_lib
+include ../src/objs.mk
+
+OBJS_ex = eap_example.o eap_example_peer.o eap_example_server.o
+_OBJS_VAR := OBJS_ex
+include ../src/objs.mk
+
+_OBJS_VAR := EAP_LIBS
+include ../src/objs.mk
+
+
+ifneq ($(CONFIG_SOLIB), yes)
+LIBEAP = libeap.a
+libeap.a: $(EAP_LIBS) $(OBJS_lib)
+	$(AR) crT libeap.a $^
+	$(RANLIB) libeap.a
+
+else
+CFLAGS  += -fPIC -DPIC
+LDFLAGS += -shared
+
+LIBEAP  = libeap.so
+libeap.so: $(EAP_LIBS) $(OBJS_lib)
+	$(LDO) $(LDFLAGS) $^ -o $(LIBEAP)
+
+endif
+
+ALL=$(LIBEAP)
+INSTALL_DIR=$(CONFIG_LIBEAP_INSTALL_DIR)
+
+.PHONY: install
+install: $(LIBEAP)
+	mkdir -p $(INSTALL_DIR)/lib
+	cp $^ $(INSTALL_DIR)/lib
+	mkdir -p $(INSTALL_DIR)/include/eap_common
+	cp ../src/eap_common/*.h $(INSTALL_DIR)/include/eap_common
+	mkdir -p $(INSTALL_DIR)/include/eap_peer
+	cp ../src/eap_peer/*.h $(INSTALL_DIR)/include/eap_peer
+	mkdir -p $(INSTALL_DIR)/include/eap_server
+	cp ../src/eap_server/*.h $(INSTALL_DIR)/include/eap_server
+	mkdir -p $(INSTALL_DIR)/include/crypto
+	cp ../src/crypto/*.h $(INSTALL_DIR)/include/crypto
+	mkdir -p $(INSTALL_DIR)/include/utils
+	cp ../src/utils/*.h $(INSTALL_DIR)/include/utils
+	mkdir -p $(INSTALL_DIR)/include/tls
+	cp ../src/tls/*.h $(INSTALL_DIR)/include/tls
+	mkdir -p $(INSTALL_DIR)/include/common
+	cp ../src/common/*.h $(INSTALL_DIR)/include/common
+
+clean: common-clean
+	rm -f core *~ *.o *.d libeap.a libeap.so
+
+-include $(OBJS:%.o=%.d)
diff --git a/tests/radius/CMakeLists.txt b/tests/radius/CMakeLists.txt
index d2f46c22..d1e2ea16 100644
--- a/tests/radius/CMakeLists.txt
+++ b/tests/radius/CMakeLists.txt
@@ -2,21 +2,21 @@ include_directories(
   "${PROJECT_SOURCE_DIR}/src"
 )
 
-if (BUILD_EAP_LIB)
+if (TARGET hostapd::libeap)
   set(EAP_TEST_DIR "${CMAKE_SOURCE_DIR}/tests/data/eap/")
   add_compile_definitions(EAP_TEST_DIR="${EAP_TEST_DIR}")
 
   add_library(eap_test_peer eap_test_peer.c)
-  target_link_libraries(eap_test_peer PRIVATE hostapd::libeap OpenSSL::Crypto)
+  target_link_libraries(eap_test_peer PRIVATE hostapd::libeap)
   target_compile_definitions(eap_test_peer PRIVATE _DEFAULT_SOURCE _BSD_SOURCE IEEE8021X_EAPOL)
 
   add_library(eap_test_server eap_test_server.c)
-  target_link_libraries(eap_test_server PRIVATE hostapd::libeap OpenSSL::Crypto)
+  target_link_libraries(eap_test_server PRIVATE hostapd::libeap)
   target_compile_definitions(eap_test_server PRIVATE _DEFAULT_SOURCE _BSD_SOURCE IEEE8021X_EAPOL)
 
   add_cmocka_test(test_libeap
     SOURCES test_libeap.c
-    LINK_LIBRARIES eap_test_peer eap_test_server hostapd::libeap cmocka::cmocka OpenSSL::SSL OpenSSL::Crypto
+    LINK_LIBRARIES eap_test_peer eap_test_server hostapd::libeap cmocka::cmocka
   )
   target_compile_definitions(test_libeap PRIVATE _DEFAULT_SOURCE _BSD_SOURCE IEEE8021X_EAPOL)
 endif ()
diff --git a/tests/radius/eap_test_peer.c b/tests/radius/eap_test_peer.c
index 153d3b7c..6e1ea2d3 100644
--- a/tests/radius/eap_test_peer.c
+++ b/tests/radius/eap_test_peer.c
@@ -1,16 +1,19 @@
 /**
  * @file
- * @author Alexandru Mereacre
- * @date 2023
- * @copyright
- * SPDX-FileCopyrightText: Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- * SPDX-License-Identifier: BSD license
- * @version hostapd-2.10
- * @brief Example application showing how EAP peer code from wpa_supplicant can be used as a library.
+ * @brief Example application showing how EAP peer code from wpa_supplicant can
+ * be used as a library.
+ * @author Alexandru Mereacre, Jouni Malinen
+ * @copyright SPDX-FileCopyrightText: © 2023 edgesec contributors
+ * @copyright SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+ * @copyright SPDX-License-Identifier: BSD-3-clause
+ * @version Adapted from [hostap 2.10 -
+ * `eap_example/eap_example_peer.c`](https://w1.fi/cgit/hostap/tree/eap_example/eap_example_peer.c?h=hostap_2_10)
  */
 
 #include <utils/includes.h>
+
 #include <utils/common.h>
+
 #include <eap_peer/eap.h>
 #include <eap_peer/eap_config.h>
 #include <utils/wpabuf.h>
@@ -164,55 +167,55 @@ static void peer_notify_pending(void *ctx) {
 static int eap_peer_register_methods(void) {
   int ret = 0;
 
-// #ifdef EAP_MD5
+  // #ifdef EAP_MD5
   if (ret == 0)
     ret = eap_peer_md5_register();
-// #endif /* EAP_MD5 */
+  // #endif /* EAP_MD5 */
 
-// #ifdef EAP_TLS
+  // #ifdef EAP_TLS
   if (ret == 0)
     ret = eap_peer_tls_register();
-// #endif /* EAP_TLS */
+  // #endif /* EAP_TLS */
 
-// #ifdef EAP_MSCHAPv2
+  // #ifdef EAP_MSCHAPv2
   if (ret == 0)
     ret = eap_peer_mschapv2_register();
-// #endif /* EAP_MSCHAPv2 */
+  // #endif /* EAP_MSCHAPv2 */
 
-// #ifdef EAP_PEAP
+  // #ifdef EAP_PEAP
   if (ret == 0)
     ret = eap_peer_peap_register();
-// #endif /* EAP_PEAP */
+  // #endif /* EAP_PEAP */
 
-// #ifdef EAP_TTLS
+  // #ifdef EAP_TTLS
   if (ret == 0)
     ret = eap_peer_ttls_register();
-// #endif /* EAP_TTLS */
+  // #endif /* EAP_TTLS */
 
-// #ifdef EAP_GTC
+  // #ifdef EAP_GTC
   if (ret == 0)
     ret = eap_peer_gtc_register();
-// #endif /* EAP_GTC */
+  // #endif /* EAP_GTC */
 
-// #ifdef EAP_OTP
+  // #ifdef EAP_OTP
   if (ret == 0)
     ret = eap_peer_otp_register();
-// #endif /* EAP_OTP */
+    // #endif /* EAP_OTP */
 
 #ifdef EAP_SIM
   if (ret == 0)
     ret = eap_peer_sim_register();
 #endif /* EAP_SIM */
 
-// #ifdef EAP_LEAP
+  // #ifdef EAP_LEAP
   if (ret == 0)
     ret = eap_peer_leap_register();
-// #endif /* EAP_LEAP */
+  // #endif /* EAP_LEAP */
 
-// #ifdef EAP_PSK
+  // #ifdef EAP_PSK
   if (ret == 0)
     ret = eap_peer_psk_register();
-// #endif /* EAP_PSK */
+    // #endif /* EAP_PSK */
 
 #ifdef EAP_AKA
   if (ret == 0)
@@ -229,20 +232,20 @@ static int eap_peer_register_methods(void) {
     ret = eap_peer_fast_register();
 #endif /* EAP_FAST */
 
-// #ifdef EAP_PAX
+  // #ifdef EAP_PAX
   if (ret == 0)
     ret = eap_peer_pax_register();
-// #endif /* EAP_PAX */
+  // #endif /* EAP_PAX */
 
-// #ifdef EAP_SAKE
+  // #ifdef EAP_SAKE
   if (ret == 0)
     ret = eap_peer_sake_register();
-// #endif /* EAP_SAKE */
+  // #endif /* EAP_SAKE */
 
-// #ifdef EAP_GPSK
+  // #ifdef EAP_GPSK
   if (ret == 0)
     ret = eap_peer_gpsk_register();
-// #endif /* EAP_GPSK */
+    // #endif /* EAP_GPSK */
 
 #ifdef EAP_WSC
   if (ret == 0)
@@ -278,8 +281,8 @@ int eap_test_peer_init(void) {
 
   eap_ctx.eap_config.anonymous_identity = (u8 *)os_strdup("01:02:03:04:05:06");
   eap_ctx.eap_config.anonymous_identity_len = 17;
-	eap_ctx.eap_config.machine_identity = (u8 *)os_strdup("01:02:03:04:05:06");
-	eap_ctx.eap_config.machine_identity_len = 17;
+  eap_ctx.eap_config.machine_identity = (u8 *)os_strdup("01:02:03:04:05:06");
+  eap_ctx.eap_config.machine_identity_len = 17;
 
   eap_ctx.eap_config.cert.ca_cert = os_strdup(EAP_TEST_DIR "ca.pem");
   eap_ctx.eap_config.cert.client_cert = os_strdup(EAP_TEST_DIR "client.pem");
diff --git a/tests/radius/eap_test_server.c b/tests/radius/eap_test_server.c
index f6a786e2..2f7b600e 100644
--- a/tests/radius/eap_test_server.c
+++ b/tests/radius/eap_test_server.c
@@ -1,17 +1,19 @@
 /**
  * @file
- * @author Alexandru Mereacre
- * @date 2023
- * @copyright
- * SPDX-FileCopyrightText: Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- * SPDX-License-Identifier: BSD license
- * @version hostapd-2.10
- * @brief Example application showing how EAP server code from hostapd can be used as a library.
+ * @brief Example application showing how EAP server code from hostapd can be
+ * used as a library.
+ * @author Alexandru Mereacre, Jouni Malinen
+ * @copyright SPDX-FileCopyrightText: © 2023 edgesec contributors
+ * @copyright SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+ * @copyright SPDX-License-Identifier: BSD-3-clause
+ * @version Adapted from [hostap 2.10 -
+ * `eap_example/eap_example_server.c`](https://w1.fi/cgit/hostap/tree/eap_example/eap_example_server.c?h=hostap_2_10)
  */
 
 #include <utils/includes.h>
 
 #include <utils/common.h>
+
 #include <crypto/tls.h>
 #include <eap_server/eap.h>
 #include <utils/wpabuf.h>
@@ -85,105 +87,105 @@ static int eap_test_server_init_tls(void) {
 static int eap_server_register_methods(void) {
   int ret = 0;
 
-// #ifdef EAP_SERVER_IDENTITY
+  // #ifdef EAP_SERVER_IDENTITY
   if (ret == 0)
     ret = eap_server_identity_register();
-// #endif /* EAP_SERVER_IDENTITY */
+  // #endif /* EAP_SERVER_IDENTITY */
 
-// #ifdef EAP_SERVER_MD5
+  // #ifdef EAP_SERVER_MD5
   if (ret == 0)
     ret = eap_server_md5_register();
-// #endif /* EAP_SERVER_MD5 */
+  // #endif /* EAP_SERVER_MD5 */
 
-// #ifdef EAP_SERVER_TLS
+  // #ifdef EAP_SERVER_TLS
   if (ret == 0)
     ret = eap_server_tls_register();
-// #endif /* EAP_SERVER_TLS */
+  // #endif /* EAP_SERVER_TLS */
 
-// #ifdef EAP_SERVER_MSCHAPV2
+  // #ifdef EAP_SERVER_MSCHAPV2
   if (ret == 0)
     ret = eap_server_mschapv2_register();
-// #endif /* EAP_SERVER_MSCHAPV2 */
+  // #endif /* EAP_SERVER_MSCHAPV2 */
 
-// #ifdef EAP_SERVER_PEAP
+  // #ifdef EAP_SERVER_PEAP
   if (ret == 0)
     ret = eap_server_peap_register();
-// #endif /* EAP_SERVER_PEAP */
+    // #endif /* EAP_SERVER_PEAP */
 
 #ifdef EAP_SERVER_TLV
   if (ret == 0)
     ret = eap_server_tlv_register();
 #endif /* EAP_SERVER_TLV */
 
-// #ifdef EAP_SERVER_GTC
+  // #ifdef EAP_SERVER_GTC
   if (ret == 0)
     ret = eap_server_gtc_register();
-// #endif /* EAP_SERVER_GTC */
+  // #endif /* EAP_SERVER_GTC */
 
-// #ifdef EAP_SERVER_TTLS
+  // #ifdef EAP_SERVER_TTLS
   if (ret == 0)
     ret = eap_server_ttls_register();
-// #endif /* EAP_SERVER_TTLS */
+    // #endif /* EAP_SERVER_TTLS */
 
-// #ifdef EAP_SERVER_SIM
+#ifdef EAP_SERVER_SIM
   if (ret == 0)
     ret = eap_server_sim_register();
-// #endif /* EAP_SERVER_SIM */
+#endif /* EAP_SERVER_SIM */
 
-// #ifdef EAP_SERVER_AKA
+#ifdef EAP_SERVER_AKA
   if (ret == 0)
     ret = eap_server_aka_register();
-// #endif /* EAP_SERVER_AKA */
+#endif /* EAP_SERVER_AKA */
 
-// #ifdef EAP_SERVER_AKA_PRIME
+#ifdef EAP_SERVER_AKA_PRIME
   if (ret == 0)
     ret = eap_server_aka_prime_register();
-// #endif /* EAP_SERVER_AKA_PRIME */
+#endif /* EAP_SERVER_AKA_PRIME */
 
-// #ifdef EAP_SERVER_PAX
+  // #ifdef EAP_SERVER_PAX
   if (ret == 0)
     ret = eap_server_pax_register();
-// #endif /* EAP_SERVER_PAX */
+  // #endif /* EAP_SERVER_PAX */
 
-// #ifdef EAP_SERVER_PSK
+  // #ifdef EAP_SERVER_PSK
   if (ret == 0)
     ret = eap_server_psk_register();
-// #endif /* EAP_SERVER_PSK */
+  // #endif /* EAP_SERVER_PSK */
 
-// #ifdef EAP_SERVER_SAKE
+  // #ifdef EAP_SERVER_SAKE
   if (ret == 0)
     ret = eap_server_sake_register();
-// #endif /* EAP_SERVER_SAKE */
+  // #endif /* EAP_SERVER_SAKE */
 
-// #ifdef EAP_SERVER_GPSK
+  // #ifdef EAP_SERVER_GPSK
   if (ret == 0)
     ret = eap_server_gpsk_register();
-// #endif /* EAP_SERVER_GPSK */
+    // #endif /* EAP_SERVER_GPSK */
 
 #ifdef EAP_SERVER_VENDOR_TEST
   if (ret == 0)
     ret = eap_server_vendor_test_register();
 #endif /* EAP_SERVER_VENDOR_TEST */
 
-// #ifdef EAP_SERVER_FAST
+#ifdef EAP_SERVER_FAST
   if (ret == 0)
     ret = eap_server_fast_register();
-// #endif /* EAP_SERVER_FAST */
+#endif /* EAP_SERVER_FAST */
 
 #ifdef EAP_SERVER_WSC
   if (ret == 0)
     ret = eap_server_wsc_register();
 #endif /* EAP_SERVER_WSC */
 
-// #ifdef EAP_SERVER_IKEV2
+#ifdef EAP_SERVER_IKEV2
   if (ret == 0)
     ret = eap_server_ikev2_register();
-// #endif /* EAP_SERVER_IKEV2 */
+#endif /* EAP_SERVER_IKEV2 */
 
-// #ifdef EAP_SERVER_TNC
+#ifdef EAP_SERVER_TNC
   if (ret == 0)
     ret = eap_server_tnc_register();
-// #endif /* EAP_SERVER_TNC */
+#endif /* EAP_SERVER_TNC */
 
   return ret;
 }
@@ -208,7 +210,7 @@ int eap_test_server_init(void) {
   eap_conf.ssl_ctx = eap_ctx.tls_ctx;
 
   eap_conf.max_auth_rounds = 100;
-	eap_conf.max_auth_rounds_short = 50;
+  eap_conf.max_auth_rounds_short = 50;
 
   os_memset(&eap_sess, 0, sizeof(eap_sess));
   eap_ctx.eap = eap_server_sm_init(&eap_ctx, &eap_cb, &eap_conf, &eap_sess);
diff --git a/tests/radius/test_libeap.c b/tests/radius/test_libeap.c
index 558a5fdc..5e101029 100644
--- a/tests/radius/test_libeap.c
+++ b/tests/radius/test_libeap.c
@@ -1,13 +1,13 @@
 /**
  * @file
- * @author Alexandru Mereacre
- * @date 2023
- * @copyright
- * SPDX-FileCopyrightText: Copyright (c) 2007, Jouni Malinen <j@w1.fi>
- * SPDX-License-Identifier: BSD license
- * @version hostapd-2.10
  * @brief Test showing how EAP peer and server code from
  * wpa_supplicant/hostapd can be used as a library for a EAP-TLS connection.
+ * @author Alexandru Mereacre, Jouni Malinen
+ * @copyright SPDX-FileCopyrightText: © 2023 edgesec contributors
+ * @copyright SPDX-FileCopyrightText: © 2007, Jouni Malinen <j@w1.fi>
+ * @copyright SPDX-License-Identifier: BSD-3-clause
+ * @version Adapted from [hostap 2.10 -
+ * `eap_example/eap_example.c`](https://w1.fi/cgit/hostap/tree/eap_example/eap_example.c?h=hostap_2_10)
  */
 
 #include <setjmp.h>

@aloisklink aloisklink changed the title Feat/compile eap library from hostap Build a EAP library from hostapd source code Jan 9, 2023
@codecov

codecov Bot commented Jan 9, 2023

Copy link
Copy Markdown

Codecov Report

Merging #381 (8281e94) into main (8ca34db) will increase coverage by 0.53%.
The diff coverage is 81.13%.

@@            Coverage Diff             @@
##             main     #381      +/-   ##
==========================================
+ Coverage   51.77%   52.31%   +0.53%     
==========================================
  Files         139      142       +3     
  Lines       19317    19651     +334     
==========================================
+ Hits        10001    10280     +279     
- Misses       9316     9371      +55     
Impacted Files Coverage Δ
tests/radius/eap_test_peer.c 73.84% <73.84%> (ø)
tests/radius/eap_test_server.c 89.83% <89.83%> (ø)
tests/radius/test_libeap.c 100.00% <100.00%> (ø)
src/ap/ap_service.c 51.70% <0.00%> (+4.54%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@mereacre
mereacre self-requested a review January 10, 2023 10:28

@mereacre mereacre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@mereacre
mereacre merged commit 927cb26 into main Jan 10, 2023
@mereacre
mereacre deleted the feat/compile-eap-library-from-hostap branch January 10, 2023 10:34
@aloisklink aloisklink mentioned this pull request May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants