From: "plaisthos (Code Review)" Date: Wed, 29 Nov 2023 12:20:37 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <721273e48f2fcdf5055f7a710f09b8341f9e24b5-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="9PcgLfvmZG0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Allow specifying custom mbed TLS directories with CMake List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel , MaxF --9PcgLfvmZG0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: MaxF, flichtenheld. Hello flichtenheld, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/377?usp=3Demail to look at the new patch set (#5). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld Change subject: Allow specifying custom mbed TLS directories with CMake ...................................................................... Allow specifying custom mbed TLS directories with CMake When installing mbed TLS 2.x and 3.x in parallel, it is useful to point cmake to the version that should be used. Change-Id: I7fd9e730e87210d2b7d090c8f9c7c6734bd7374e Signed-off-by: Arne Schwabe --- M CMakeLists.txt M config.h.cmake.in M src/openvpn/mbedtls_compat.h 3 files changed, 34 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/77/377/5 diff --git a/CMakeLists.txt b/CMakeLists.txt index d21c9bd..236c78a 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) @@ -231,9 +233,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 19b79bc..d140204 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -387,10 +387,10 @@ #undef HAVE_VSNPRINTF /* we always assume a recent mbed TLS version */ -#define HAVE_MBEDTLS_PSA_CRYPTO_H 1 +#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: 5 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: MaxF Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-Attention: MaxF Gerrit-MessageType: newpatchset --9PcgLfvmZG0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: MaxF, flichtenheld.

plaisthos uploaded patch set #5 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/377?usp=3Demail">View Chang= e

The following approvals got outdated and were removed: Code-Review-1 by flichtenheld

Allow specifying custom mbed TLS directories =
with CMake

When installing mbed TLS 2.x and 3.x in parallel, it is u= seful to point
cmake to the version that should be used.

Change-I= d: I7fd9e730e87210d2b7d090c8f9c7c6734bd7374e
Signed-off-by: Arne Schwabe= <arne@...1227...>
---
M CMakeLists.txt
M config.h.cmake.in<= br>M src/openvpn/mbedtls_compat.h
3 files changed, 34 insertions(+), 8 d= eletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/=
changes/77/377/5
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d21c9bd..236c78a 100644
--- a/CMakeLists.t= xt
+++ b/CMakeLists.txt
@@ -32,6 +32,8 @@
endif ()

option(MBED &qu= ot;BUILD with mbed" OFF)
+set(MBED_INCLUDE_PATH "" CACHE STRING "Path to mbe= d TLS include directory")
+set(MBED_LIBRARY_PATH "" CACHE STRING "Path to mb= ed library directory")
option(WOLFSSL "BUILD wit= h wolfSSL" OFF)
option(ENABLE_LZ4 "BUILD with lz= 4" ON)
option(ENABLE_LZO "BUILD with lzo" O= N)
@@ -231,9 +233,33 @@
pkg_search_mod= ule(pkcs11-helper libpkcs11-helper-1 REQUIRED IMPORTED_TARGET)
endif ()


+function(check_mbed_configuration)
+ if (NOT (MBED_INCLUDE_PATH STREQUAL "&q= uot;) )
+ set(= CMAKE_REQUIRED_INCLUDES ${MBED_INCLUDE_PATH})
+ endif ()
+ if (NOT (MBED_LIBRARY_PATH STREQUAL ""))
+ set(CMAKE_REQ= UIRED_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 HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET)
+ check_symbol_exists(mbedtls_ssl_conf_export_keys_ext_c= b 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_configurat= ion()
+endif()=
+
function= (add_library_deps target)
if (${MBED})
- target_link_libraries(${targe= t} -lmbedtls -lmbedx509 -lmbedcrypto)

+ if (NOT (MBED_INCLUDE_PATH STREQUAL "")= )
+ targe= t_include_directories(${target} PRIVATE ${MBED_INCLUDE_PATH})
+ endif ()

+ if(NOT (MBED_LIBRARY_PATH ST= REQUAL ""))
+ target_link_directories(${target} PRIVATE ${MBED_LIBRARY_PATH= })
+ endif ()<= /span>
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ target_link_libraries($= {target} PRIVATE -lmbedtls -lmbedx509 -lmbedcrypto)

el= seif (${WOLFSSL})
pkg_search_module(wolfssl wolfss= l REQUIRED)
target_link_libraries(${target} PUBLIC= ${wolfssl_LINK_LIBRARIES})
diff --git a/config.h.cmake.in = b/config.h.cmake.in
index 19b79bc..d140204 100644--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -387,10 +387,10 @@
#undef HAVE_VSNPRINTF

/* we always assume a recent mbed TLS vers= ion */
-#define HAVE_MB= EDTLS_PSA_CRYPTO_H 1
= +#cmakedefine01 HAVE_MBEDTLS_PSA_CRYPTO_H
#define HAVE_MBE= DTLS_SSL_TLS_PRF 1
-#de= fine HAVE_MBEDTLS_SSL_SET_EXPORT_KEYS_CB 1
-#define HAVE_MBEDTLS_CTR_DRBG_UPDATE_RET 1
<= span style=3D"color: hsl(120, 100%, 40%);">+#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/mbedtl= s_compat.h b/src/openvpn/mbedtls_compat.h
index 610215b..d7= 42b54 100644
--- a/src/openvpn/mbedtls_compat.h
<= span>+++ b/src/openvpn/mbedtls_compat.h

@@ -77,13 +77,13 @@=
const unsigned char *addit= ional,
size_t add_len)
{
-#if HAV= E_MBEDTLS_CTR_DRBG_UPDATE_RET
+#if MBEDTLS_VERSION_NUMBER > 0x03000000
+ return mbedtls_ctr_drbg_update(ctx, a= dditional, 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_C= TR_DRBG_UPDATE_RET */
}

=

To view, visit change 377. To unsubscribe, or for help writi= ng mail filters, visit setti= ngs.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7fd9e730e87210d2b7d090c8f9c= 7c6734bd7374e
Gerrit-Change-Number: 377
Gerrit-PatchSet: 5
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-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: MaxF <max@...2606...> =
Gerrit-MessageType: newpatchset
--9PcgLfvmZG0=--