mirror of
https://github.com/obgm/libcoap.git
synced 2025-10-14 02:19:34 +08:00
Zephyr: Add wolfSSL DTLS backend support
- Add wolfSSL detection and configuration in zephyr/CMakeLists.txt - Set wolfSSL to take priority over mbedTLS when both are available - Bypass find_package() call and link wolfSSL library directly - Prevent system wolfSSL library conflicts with ZEPHYR_BASE checks - Fix compiler warnings in coap_wolfssl.c for unused functions
This commit is contained in:
@@ -652,12 +652,17 @@ if(ENABLE_DTLS)
|
||||
endif()
|
||||
|
||||
if(WITH_WOLFSSL)
|
||||
find_library(WOLFSSL_LIBRARY wolfssl HINTS /usr/local/lib)
|
||||
find_path(WOLFSSL_INCLUDE_DIR wolfssl/wolfcrypt/settings.h HINTS /usr/local/include)
|
||||
if(WOLFSSL_LIBRARY AND WOLFSSL_INCLUDE_DIR)
|
||||
message(STATUS "compiling with wolfssl support")
|
||||
if(NOT ZEPHYR_BASE)
|
||||
find_library(WOLFSSL_LIBRARY wolfssl HINTS /usr/local/lib)
|
||||
find_path(WOLFSSL_INCLUDE_DIR wolfssl/wolfcrypt/settings.h HINTS /usr/local/include)
|
||||
if(WOLFSSL_LIBRARY AND WOLFSSL_INCLUDE_DIR)
|
||||
message(STATUS "compiling with wolfssl support")
|
||||
else()
|
||||
message(FATAL_ERROR "WolfSSL not found")
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "WolfSSL not found")
|
||||
# Zephyr handles wolfSSL configuration via zephyr/CMakeLists.txt
|
||||
message(STATUS "compiling with wolfssl support (Zephyr)")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@@ -655,6 +655,7 @@ coap_dtls_psk_client_callback(WOLFSSL *ssl,
|
||||
return max_psk_len;
|
||||
}
|
||||
|
||||
#if !COAP_DISABLE_TCP
|
||||
static unsigned int
|
||||
coap_dtls_psk_client_cs_callback(WOLFSSL *ssl, const char *hint,
|
||||
char *identity, unsigned int max_identity_len,
|
||||
@@ -670,6 +671,7 @@ coap_dtls_psk_client_cs_callback(WOLFSSL *ssl, const char *hint,
|
||||
(void)ciphersuite;
|
||||
return key_len;
|
||||
}
|
||||
#endif /* !COAP_DISABLE_TCP */
|
||||
|
||||
#endif /* COAP_CLIENT_SUPPORT */
|
||||
|
||||
@@ -807,6 +809,7 @@ coap_dtls_info_callback(const WOLFSSL *ssl, int where, int ret) {
|
||||
}
|
||||
}
|
||||
|
||||
#if !COAP_DISABLE_TCP
|
||||
/*
|
||||
* strm
|
||||
* return +ve data amount
|
||||
@@ -888,6 +891,7 @@ coap_sock_write(WOLFSSL *ssl, char *in, int inl, void *ctx) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif /* !COAP_DISABLE_TCP */
|
||||
|
||||
static void
|
||||
coap_set_user_prefs(WOLFSSL_CTX *ctx) {
|
||||
@@ -1877,6 +1881,7 @@ coap_dtls_context_load_pki_trust_store(coap_context_t *ctx) {
|
||||
#else /* LIBWOLFSSL_VERSION_HEX < 0x05005002 */
|
||||
coap_log_warn("coap_context_set_pki_trust_store: (D)TLS environment "
|
||||
"not supported for wolfSSL < v5.5.2 or –enable-sys-ca-certs not defined\n");
|
||||
return 0;
|
||||
#endif /* WOLFSSL_SYS_CA_CERTS */
|
||||
}
|
||||
|
||||
|
@@ -12,14 +12,23 @@
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
if(CONFIG_LIBCOAP)
|
||||
if(CONFIG_MBEDTLS)
|
||||
if(CONFIG_MBEDTLS AND NOT CONFIG_WOLFSSL)
|
||||
set(ENABLE_DTLS ON)
|
||||
set(DTLS_BACKEND "zephyr" CACHE STRING "Zephyr build")
|
||||
set_property(
|
||||
CACHE DTLS_BACKEND
|
||||
PROPERTY STRINGS
|
||||
zephyr)
|
||||
set_property(CACHE DTLS_BACKEND PROPERTY STRINGS zephyr wolfssl)
|
||||
set(COAP_WITH_LIBMBEDTLS 1)
|
||||
message(STATUS "libcoap: Using mbedTLS for DTLS")
|
||||
elseif(CONFIG_WOLFSSL)
|
||||
set(ENABLE_DTLS ON)
|
||||
set(DTLS_BACKEND "wolfssl" CACHE STRING "Zephyr build")
|
||||
set_property(CACHE DTLS_BACKEND PROPERTY STRINGS zephyr wolfssl)
|
||||
set(COAP_WITH_LIBWOLFSSL 1)
|
||||
# Set wolfSSL variables to prevent find_package call
|
||||
set(wolfSSL_FOUND TRUE CACHE BOOL "wolfSSL found via Zephyr module")
|
||||
set(WOLFSSL_INCLUDE_DIR "${ZEPHYR_BASE}/../modules/crypto/wolfssl" CACHE PATH "wolfSSL include dir")
|
||||
set(WOLFSSL_LIBRARIES "wolfSSL" CACHE STRING "wolfSSL library")
|
||||
set(HAVE_LIBWOLFSSL 1 CACHE STRING "Have wolfSSL library")
|
||||
message(STATUS "libcoap: Using wolfSSL for DTLS")
|
||||
else()
|
||||
set(ENABLE_DTLS OFF)
|
||||
endif()
|
||||
@@ -112,6 +121,11 @@ if(CONFIG_LIBCOAP)
|
||||
target_link_libraries(coap-3 PUBLIC mbedTLS)
|
||||
endif()
|
||||
|
||||
if(CONFIG_WOLFSSL)
|
||||
target_compile_definitions(coap-3 PRIVATE WOLFSSL_USER_SETTINGS)
|
||||
target_link_libraries(coap-3 PUBLIC wolfSSL)
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS coap-3)
|
||||
|
||||
target_link_libraries(app PUBLIC coap-3)
|
||||
|
Reference in New Issue
Block a user