From beba8c5a3d44b240d5e77273d71b2d7ca61046a6 Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Mon, 10 Jan 2022 15:48:20 +0100 Subject: [PATCH 2/3] archlinux-compat: Replace mbedTLS by OpenSSL for CURL --- lib/libimhex/CMakeLists.txt | 6 ++++-- lib/libimhex/source/helpers/net.cpp | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index c23cd36..55d0ab6 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/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) @@ -156,7 +157,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) @@ -164,4 +165,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/lib/libimhex/source/helpers/net.cpp b/lib/libimhex/source/helpers/net.cpp index af86328..f6d8b63 100644 --- a/lib/libimhex/source/helpers/net.cpp +++ b/lib/libimhex/source/helpers/net.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -51,15 +51,19 @@ namespace hex { } static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userdata) { - auto *cfg = static_cast(sslctx); + SSL_CTX *opensslctx = static_cast(sslctx); - static mbedtls_x509_crt crt; - mbedtls_x509_crt_init(&crt); + auto cacert = romfs::get("cacert.pem"); + BIO *bio = BIO_new_mem_buf(reinterpret_cast(cacert.data()), cacert.size()); - auto cacert = romfs::get("cacert.pem").string(); - mbedtls_x509_crt_parse(&crt, reinterpret_cast(cacert.data()), cacert.size()); + X509 *cert = nullptr; + PEM_read_bio_X509(bio, &cert, 0, nullptr); - mbedtls_ssl_conf_ca_chain(cfg, &crt, nullptr); + X509_STORE *store = SSL_CTX_get_cert_store(opensslctx); + X509_STORE_add_cert(store, cert); + + X509_free(cert); + BIO_free(bio); return CURLE_OK; } @@ -244,4 +248,4 @@ namespace hex { return {}; } -} \ No newline at end of file +} -- 2.35.1