summarylogtreecommitdiffstats
path: root/0003-archlinux-compat-Replace-mbedTLS-by-OpenSSL-for-CURL.patch
blob: 0c82b2efef73eda65e7c0e53bbdd580159140167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From e7441b9ca6d56e34ca368799539ab867cb315536 Mon Sep 17 00:00:00 2001
From: KokaKiwi <kokakiwi+git@kokakiwi.net>
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 <filesystem>
 #include <cstdio>
 
-#include <mbedtls/ssl.h>
+#include <openssl/ssl.h>
 
 #include <curl/curl.h>
 #include <nlohmann/json.hpp>
@@ -50,15 +50,19 @@ namespace hex {
     }
 
     static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userdata) {
-        auto* cfg = static_cast<mbedtls_ssl_config*>(sslctx);
-
-        static mbedtls_x509_crt crt;
-        mbedtls_x509_crt_init(&crt);
+        SSL_CTX *opensslctx = static_cast<SSL_CTX*>(sslctx);
 
         auto cacert = romfs::get("cacert.pem");
-        mbedtls_x509_crt_parse(&crt, reinterpret_cast<const u8*>(cacert.data()), cacert.size());
+        BIO *bio = BIO_new_mem_buf(reinterpret_cast<const u8*>(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