diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index bd8402f19..b4fe35d55 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -10,11 +10,6 @@ set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE ON) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/microtar ${CMAKE_CURRENT_BINARY_DIR}/external/microtar EXCLUDE_FROM_ALL) set_target_properties(microtar PROPERTIES POSITION_INDEPENDENT_CODE ON) -set(LIBROMFS_RESOURCE_LOCATION ${IMHEX_BASE_FOLDER}/resources/romfs) -set(LIBROMFS_PROJECT_NAME imhex) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/external/libromfs EXCLUDE_FROM_ALL) -set_target_properties(${LIBROMFS_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE ON) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/intervaltree ${CMAKE_CURRENT_BINARY_DIR}/external/intervaltree EXCLUDE_FROM_ALL) set_target_properties(intervaltree PROPERTIES POSITION_INDEPENDENT_CODE ON) @@ -175,4 +170,3 @@ if (APPLE) endif () target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${FMT_LIBRARIES} ${Python_LIBRARIES} libpl intervaltree) -target_link_libraries(libimhex PRIVATE libromfs-imhex) diff --git a/lib/libimhex/include/hex/helpers/net.hpp b/lib/libimhex/include/hex/helpers/net.hpp index 8614c3898..4bda03a73 100644 --- a/lib/libimhex/include/hex/helpers/net.hpp +++ b/lib/libimhex/include/hex/helpers/net.hpp @@ -10,13 +10,12 @@ #include #include +#include #include #include #include -using CURL = void; -struct curl_slist; namespace hex { @@ -54,12 +53,14 @@ namespace hex { void cancel() { this->m_shouldCancel = true; } static void setProxy(const std::string &url); + static void setCACert(const std::string &content); private: void setCommonSettings(std::string &response, const std::string &url, u32 timeout = 2000, const std::map &extraHeaders = {}, const std::string &body = {}); std::optional execute(); friend int progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow); + friend CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userData); private: CURL *m_ctx; @@ -71,6 +72,7 @@ namespace hex { bool m_shouldCancel = false; static std::string s_proxyUrl; + static std::string s_caCert; }; } \ No newline at end of file diff --git a/lib/libimhex/source/helpers/net.cpp b/lib/libimhex/source/helpers/net.cpp index 3e80eed06..8f706b3e4 100644 --- a/lib/libimhex/source/helpers/net.cpp +++ b/lib/libimhex/source/helpers/net.cpp @@ -9,11 +9,8 @@ #include #include -#include #include -#include - namespace hex { Net::Net() { @@ -45,7 +42,7 @@ namespace hex { } [[maybe_unused]] - static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userData) { + CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userData) { hex::unused(ctx, userData); auto *cfg = static_cast(sslctx); @@ -53,8 +50,7 @@ namespace hex { auto crt = static_cast(userData); mbedtls_x509_crt_init(crt); - auto cacert = romfs::get("cacert.pem").string(); - mbedtls_x509_crt_parse(crt, reinterpret_cast(cacert.data()), cacert.size()); + mbedtls_x509_crt_parse(crt, reinterpret_cast(Net::s_caCert.data()), Net::s_caCert.size()); mbedtls_ssl_conf_ca_chain(cfg, crt, nullptr); @@ -296,9 +292,13 @@ namespace hex { } std::string Net::s_proxyUrl; - void Net::setProxy(const std::string &url) { Net::s_proxyUrl = url; } + std::string Net::s_caCert; + void Net::setCACert(const std::string &content) { + Net::s_caCert = content; + } + } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 729a18575..fcf86886f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -17,6 +17,11 @@ add_executable(main ${APPLICATION_TYPE} target_include_directories(main PUBLIC include) setupCompilerWarnings(main) +set(LIBROMFS_RESOURCE_LOCATION ${IMHEX_BASE_FOLDER}/resources/romfs) +set(LIBROMFS_PROJECT_NAME imhex) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../lib/external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/main/libromfs EXCLUDE_FROM_ALL) +set_target_properties(${LIBROMFS_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(main PROPERTIES OUTPUT_NAME "imhex" RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.. diff --git a/main/source/init/splash_window.cpp b/main/source/init/splash_window.cpp index fea00893f..f1694bf4f 100644 --- a/main/source/init/splash_window.cpp +++ b/main/source/init/splash_window.cpp @@ -89,7 +89,6 @@ namespace hex::init { } bool WindowSplash::loop() { - hex::log::debug("Using romfs: '{}'", romfs::name()); auto splash = romfs::get("splash.png"); ImGui::Texture splashTexture = ImGui::Texture(reinterpret_cast(splash.data()), splash.size()); diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index d8a738b8b..3eca190b2 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -49,6 +50,14 @@ namespace hex::init { return true; } + bool setupEnvironment() { + hex::log::debug("Using romfs: '{}'", romfs::name()); + + Net::setCACert(std::string(romfs::get("cacert.pem").string())); + + return true; + } + bool createDirectories() { bool result = true; @@ -327,6 +336,7 @@ namespace hex::init { std::vector getInitTasks() { return { + { "Setting up environment", setupEnvironment, false }, { "Creating directories", createDirectories, false }, { "Loading settings", loadSettings, false }, { "Loading plugins", loadPlugins, false },