From 8d0a62e99852b81851f2eb92ce64f8a931fdd42e Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Mon, 10 Jan 2022 15:48:20 +0100 Subject: [PATCH 3/3] archlinux-compat: Replace mbedTLS by OpenSSL for CURL --- plugins/libimhex/CMakeLists.txt | 6 ++++-- plugins/libimhex/source/helpers/net.cpp | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/libimhex/CMakeLists.txt b/plugins/libimhex/CMakeLists.txt index d2c1bd4..56dd879 100644 --- a/plugins/libimhex/CMakeLists.txt +++ b/plugins/libimhex/CMakeLists.txt @@ -82,6 +82,7 @@ endif() find_package(mbedTLS 2.26.0 REQUIRED) +find_package(OpenSSL REQUIRED) configurePython() pkg_search_module(MAGIC libmagic>=5.39) @@ -155,7 +156,7 @@ endif () add_library(libimhex SHARED ${LIBIMHEX_SOURCES}) set_target_properties(libimhex PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_include_directories(libimhex PUBLIC include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} ${MAGIC_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${YARA_INCLUDE_DIRS}) +target_include_directories(libimhex PUBLIC include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} ${MAGIC_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${YARA_INCLUDE_DIRS}) target_link_directories(libimhex PUBLIC ${MBEDTLS_LIBRARY_DIR} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS}) if (APPLE) @@ -163,4 +164,5 @@ if (APPLE) target_link_libraries(libimhex PUBLIC ${FOUNDATION}) endif () -target_link_libraries(libimhex PUBLIC imgui nfd magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES} libromfs) +target_link_libraries(libimhex PUBLIC imgui nfd magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar + ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${OPENSSL_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES} libromfs) diff --git a/plugins/libimhex/source/helpers/net.cpp b/plugins/libimhex/source/helpers/net.cpp index 7b304a4..2a39bec 100644 --- a/plugins/libimhex/source/helpers/net.cpp +++ b/plugins/libimhex/source/helpers/net.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -50,15 +50,19 @@ namespace hex { } static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userdata) { - auto* cfg = static_cast(sslctx); - - static mbedtls_x509_crt crt; - mbedtls_x509_crt_init(&crt); + SSL_CTX *opensslctx = static_cast(sslctx); auto cacert = romfs::get("cacert.pem"); - mbedtls_x509_crt_parse(&crt, reinterpret_cast(cacert.data()), cacert.size()); + BIO *bio = BIO_new_mem_buf(reinterpret_cast(cacert.data()), cacert.size()); + + X509 *cert = nullptr; + PEM_read_bio_X509(bio, &cert, 0, nullptr); + + X509_STORE *store = SSL_CTX_get_cert_store(opensslctx); + X509_STORE_add_cert(store, cert); - mbedtls_ssl_conf_ca_chain(cfg, &crt, nullptr); + X509_free(cert); + BIO_free(bio); return CURLE_OK; } @@ -243,4 +247,4 @@ namespace hex { return { }; } -} \ No newline at end of file +} -- 2.34.1