summarylogtreecommitdiffstats
path: root/0002-archlinux-compat-Replace-mbedTLS-by-OpenSSL-for-CURL.patch
blob: f743b02370c3194489fc7853719417824fd2d97e (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 beba8c5a3d44b240d5e77273d71b2d7ca61046a6 Mon Sep 17 00:00:00 2001
From: KokaKiwi <kokakiwi+git@kokakiwi.net>
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 <filesystem>
 #include <cstdio>
 
-#include <mbedtls/ssl.h>
+#include <openssl/ssl.h>
 
 #include <curl/curl.h>
 #include <nlohmann/json.hpp>
@@ -51,15 +51,19 @@ namespace hex {
     }
 
     static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userdata) {
-        auto *cfg = static_cast<mbedtls_ssl_config *>(sslctx);
+        SSL_CTX *opensslctx = static_cast<SSL_CTX*>(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<const u8 *>(cacert.data()), cacert.size());
 
-        auto cacert = romfs::get("cacert.pem").string();
-        mbedtls_x509_crt_parse(&crt, reinterpret_cast<const u8 *>(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