From: "cron2 (Code Review)" Date: Tue, 12 Dec 2023 07:14:00 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="LROy6U+my0w="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Fix building mbed TLS with CMake and allow specifying custom directories List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , MaxF , openvpn-devel --LROy6U+my0w= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/37= 7?usp=3Demail ) Change subject: Fix building mbed TLS with CMake and allow specifying custo= m directories ...................................................................... Fix building mbed TLS with CMake and allow specifying custom directories When installing mbed TLS 2.x and 3.x in parallel, it is useful to point cmake to the version that should be used. This fixes also building mbed TLS versions with cmake. Change-Id: I7fd9e730e87210d2b7d090c8f9c7c6734bd7374e Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Message-Id: <20231211170549.85749-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 763.html Signed-off-by: Gert Doering --- M CMakeLists.txt M config.h.cmake.in M src/openvpn/mbedtls_compat.h 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 577bc5d..d40b213 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ endif () option(MBED "BUILD with mbed" OFF) +set(MBED_INCLUDE_PATH "" CACHE STRING "Path to mbed TLS include directory") +set(MBED_LIBRARY_PATH "" CACHE STRING "Path to mbed library directory") option(WOLFSSL "BUILD with wolfSSL" OFF) option(ENABLE_LZ4 "BUILD with lz4" ON) option(ENABLE_LZO "BUILD with lzo" ON) @@ -239,9 +241,33 @@ pkg_search_module(pkcs11-helper libpkcs11-helper-1 REQUIRED IMPORTED_T= ARGET) endif () +function(check_mbed_configuration) + if (NOT (MBED_INCLUDE_PATH STREQUAL "") ) + set(CMAKE_REQUIRED_INCLUDES ${MBED_INCLUDE_PATH}) + endif () + if (NOT (MBED_LIBRARY_PATH STREQUAL "")) + set(CMAKE_REQUIRED_LINK_OPTIONS "-L${MBED_LIBRARY_PATH}") + endif () + set(CMAKE_REQUIRED_LIBRARIES "mbedtls;mbedx509;mbedcrypto") + check_symbol_exists(mbedtls_ctr_drbg_update_ret mbedtls/ctr_drbg.h HAV= E_MBEDTLS_CTR_DRBG_UPDATE_RET) + check_symbol_exists(mbedtls_ssl_conf_export_keys_ext_cb mbedtls/ssl.h = HAVE_MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB) + check_include_files(psa/crypto.h HAVE_MBEDTLS_PSA_CRYPTO_H) +endfunction() + +if (${MBED}) + check_mbed_configuration() +endif() + function(add_library_deps target) if (${MBED}) - target_link_libraries(${target} -lmbedtls -lmbedx509 -lmbedcrypto) + if (NOT (MBED_INCLUDE_PATH STREQUAL "") ) + target_include_directories(${target} PRIVATE ${MBED_INCLUDE_PA= TH}) + endif () + if(NOT (MBED_LIBRARY_PATH STREQUAL "")) + target_link_directories(${target} PRIVATE ${MBED_LIBRARY_PATH}) + endif () + + target_link_libraries(${target} PRIVATE -lmbedtls -lmbedx509 -lmbe= dcrypto) elseif (${WOLFSSL}) pkg_search_module(wolfssl wolfssl REQUIRED) target_link_libraries(${target} PUBLIC ${wolfssl_LINK_LIBRARIES}) diff --git a/config.h.cmake.in b/config.h.cmake.in index baf9556..6c846f2 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -378,11 +378,11 @@ /* Define to 1 if you have the header file. */ #undef HAVE_VFORK_H -/* we always assume a recent mbed TLS version */ -#define HAVE_MBEDTLS_PSA_CRYPTO_H 1 +/* Availability of different mbed TLS features and APIs */ +#cmakedefine01 HAVE_MBEDTLS_PSA_CRYPTO_H #define HAVE_MBEDTLS_SSL_TLS_PRF 1 -#define HAVE_MBEDTLS_SSL_SET_EXPORT_KEYS_CB 1 -#define HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET 1 +#cmakedefine01 HAVE_MBEDTLS_SSL_SET_EXPORT_KEYS_CB +#cmakedefine01 HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET /* Path to ifconfig tool */ #define IFCONFIG_PATH "@IFCONFIG_PATH@" diff --git a/src/openvpn/mbedtls_compat.h b/src/openvpn/mbedtls_compat.h index 610215b..d742b54 100644 --- a/src/openvpn/mbedtls_compat.h +++ b/src/openvpn/mbedtls_compat.h @@ -77,13 +77,13 @@ const unsigned char *additional, size_t add_len) { -#if HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET +#if MBEDTLS_VERSION_NUMBER > 0x03000000 + return mbedtls_ctr_drbg_update(ctx, additional, add_len); +#elif HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET return mbedtls_ctr_drbg_update_ret(ctx, additional, add_len); -#elif MBEDTLS_VERSION_NUMBER < 0x03020100 +#else mbedtls_ctr_drbg_update(ctx, additional, add_len); return 0; -#else - return mbedtls_ctr_drbg_update(ctx, additional, add_len); #endif /* HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET */ } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/377?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I7fd9e730e87210d2b7d090c8f9c7c6734bd7374e Gerrit-Change-Number: 377 Gerrit-PatchSet: 7 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: MaxF Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --LROy6U+my0w= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Fix building mbed TLS with CMake and allow spe=
cifying custom directories

When installing mbed TLS 2.x and 3.x in p= arallel, it is useful to point
cmake to the version that should be used.=

This fixes also building mbed TLS versions with cmake.

Chang= e-Id: I7fd9e730e87210d2b7d090c8f9c7c6734bd7374e
Signed-off-by: Arne Schw= abe <arne@...1227...>
Acked-by: Frank Lichtenheld <frank@...2716...= 1...>
Message-Id: <20231211170549.85749-1-frank@...2641...>
= URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 763.html
Signed-off-by: Gert Doering <gert@...1296...>
---
M= CMakeLists.txt
M config.h.cmake.in
M src/openvpn/mbedtls_compat.h3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 577bc= 5d..d40b213 100644
--- a/CMakeLists.txt
+++= b/CMakeLists.txt
@@ -32,6 +32,8 @@
endif = ()

option(MBED "BUILD with mbed&quo= t; OFF)
+set(MBED_INC= LUDE_PATH "" CACHE STRING "Path to mbed TLS include director= y")
+set(MBED_LI= BRARY_PATH "" CACHE STRING "Path to mbed library directory&q= uot;)
option(WOLFSSL "BUILD with wolfSSL" OFF)
option(ENABLE_LZ4 "BUILD with lz4" ON)
= option(ENABLE_LZO "BUILD with lzo" ON)
@@ = -239,9 +241,33 @@
pkg_search_module(pkcs11-helper libp= kcs11-helper-1 REQUIRED IMPORTED_TARGET)
endif ()
+function(c= heck_mbed_configuration)
+ if (NOT (MBED_INCLUDE_PATH STREQUAL "") )
+ set(CMAKE_REQUIRED_INCLUDE= S ${MBED_INCLUDE_PATH})

+ endif ()
+ = if (NOT (MBED_LIBRARY_PATH STREQUAL ""))
+ set(CMAKE_REQUIRED_LINK_OPTIONS &= quot;-L${MBED_LIBRARY_PATH}")
+ endif ()
+ set(CMAKE_REQUIRED_LIBRARIES "mbedtls;mbedx509;mbedcrypto&= quot;)
+ check_sym= bol_exists(mbedtls_ctr_drbg_update_ret mbedtls/ctr_drbg.h HAVE_MBEDTLS_CTR_= DRBG_UPDATE_RET)
+ = check_symbol_exists(mbedtls_ssl_conf_export_keys_ext_cb mbedtls/ssl.h HAVE= _MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB)
+ check_include_files(psa/crypto.h HAVE_MBEDTLS_PSA_CRY= PTO_H)
+endfunction()=
+
+if (${MBED})
+ check_mbed_configuration()
+endif()
+
function(add_library_deps ta= rget)
if (${MBED})
- target_link_libraries(${target} -lmbedtls -lmbedx= 509 -lmbedcrypto)
+ = if (NOT (MBED_INCLUDE_PATH STREQUAL "") )
+ target_include_directorie= s(${target} PRIVATE ${MBED_INCLUDE_PATH})
+ endif ()
+ if(NOT (MBED_LIBRARY_PATH STREQUAL "")= )
+ target= _link_directories(${target} PRIVATE ${MBED_LIBRARY_PATH})
+ endif ()
+
+ target_link_libraries(${target} PRIVATE -lmbedtls -= lmbedx509 -lmbedcrypto)
elseif (${WOLFSSL})
= pkg_search_module(wolfssl wolfssl REQUIRED)
= target_link_libraries(${target} PUBLIC ${wolfssl_LINK_LIBRARIES})<= /span>
diff --git a/config.h.cmake.in b/config.h.cmake.inindex baf9556..6c846f2 100644
--- a/config.h.cmake.= in
+++ b/config.h.cmake.in
@@ -378,11 +378,= 11 @@
/* Define to 1 if you have the <vfork.h> heade= r file. */
#undef HAVE_VFORK_H
-/* we always assume a recent mb= ed TLS version */
-#def= ine HAVE_MBEDTLS_PSA_CRYPTO_H 1
+/* Availability of different mbed TLS features and APIs */

+#cmakedefine01 HAVE_MBED= TLS_PSA_CRYPTO_H
#define HAVE_MBEDTLS_SSL_TLS_PRF 1=
-#define HAVE_MBEDTLS_SSL_SET= _EXPORT_KEYS_CB 1
-#def= ine HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET 1
+#cmakedefine01 HAVE_MBEDTLS_SSL_SET_EXPORT_KEYS_CB
+#cmakedefine01 HAVE_MBEDT= LS_CTR_DRBG_UPDATE_RET

/* Path to ifconf= ig tool */
#define IFCONFIG_PATH "@IFCONFIG_PATH@&quo= t;
diff --git a/src/openvpn/mbedtls_compat.h b/src/openvpn/= mbedtls_compat.h
index 610215b..d742b54 100644
--- a/src/openvpn/mbedtls_compat.h

+++ b/src/openvpn/mb= edtls_compat.h
@@ -77,13 +77,13 @@
= const unsigned char *additional,
= size_t add_len)
{
= -#if HAVE_MBEDTLS_CTR_DRBG_UPDATE= _RET
+#if MBEDTLS_VER= SION_NUMBER > 0x03000000
+ return mbedtls_ctr_drbg_update(ctx, additional, add_len);
+#elif HAVE_MBEDTLS_CTR_DR= BG_UPDATE_RET
return mbedtls_ctr_drbg_update_ret(ctx, = additional, add_len);
-= #elif MBEDTLS_VERSION_NUMBER < 0x03020100
+#else
mbedtls_ctr_drbg_update= (ctx, additional, add_len);
return 0;
-#else
- return mbedtls_ctr_drbg_update(ctx, additional, ad= d_len);
#endif /* HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET */
}


To vie= w, visit = change 377. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7fd9e730e87210d2b7d090c8f9c= 7c6734bd7374e
Gerrit-Change-Number: 377
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: MaxF <max@...2606...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--LROy6U+my0w=--