diff --git a/.gitmodules b/.gitmodules index 5211eee3b..d72f23112 100644 --- a/.gitmodules +++ b/.gitmodules @@ -141,3 +141,6 @@ url = https://github.com/gabime/spdlog.git shallow = true branch = v2.x +[submodule "externals/libressl"] + path = externals/libressl + url = https://github.com/shadexternals/libressl diff --git a/CMakeLists.txt b/CMakeLists.txt index 71bf7aead..3bef30ca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,6 +234,7 @@ find_package(miniz 3.1 CONFIG) find_package(nlohmann_json 3.12 CONFIG) find_package(PNG 1.6 MODULE) find_package(OpenAL CONFIG) +find_package(LibreSSL 4.3.1 MODULE) find_package(RenderDoc 1.6.0 MODULE) find_package(SDL3 3.1.2 CONFIG) find_package(stb MODULE) diff --git a/cmake/FindLibreSSL.cmake b/cmake/FindLibreSSL.cmake new file mode 100644 index 000000000..988a43c01 --- /dev/null +++ b/cmake/FindLibreSSL.cmake @@ -0,0 +1,235 @@ +# SPDX-FileCopyrightText: Copyright (c) 2019 John Norrbin +# SPDX-License-Identifier: MIT + +#[=======================================================================[ + +Copyright (c) 2019 John Norrbin + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +FindLibreSSL +------------ + +Find the LibreSSL encryption library. + +Optional Components +^^^^^^^^^^^^^^^^^^^ + +This module supports two optional components: SSL and TLS. Both +components have associated imported targets, as described below. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module defines the following imported targets: + +LibreSSL::Crypto + The LibreSSL crypto library, if found. + +LibreSSL::SSL + The LibreSSL ssl library, if found. Requires and includes LibreSSL::Crypto automatically. + +LibreSSL::TLS + The LibreSSL tls library, if found. Requires and includes LibreSSL::SSL and LibreSSL::Crypto automatically. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +LIBRESSL_FOUND + System has the LibreSSL library. If no components are requested it only requires the crypto library. +LIBRESSL_INCLUDE_DIR + The LibreSSL include directory. +LIBRESSL_CRYPTO_LIBRARY + The LibreSSL crypto library. +LIBRESSL_SSL_LIBRARY + The LibreSSL SSL library. +LIBRESSL_TLS_LIBRARY + The LibreSSL TLS library. +LIBRESSL_LIBRARIES + All LibreSSL libraries. +LIBRESSL_VERSION + This is set to $major.$minor.$revision (e.g. 2.6.8). + +Hints +^^^^^ + +Set LIBRESSL_ROOT_DIR to the root directory of an LibreSSL installation. + +]=======================================================================] + +INCLUDE(FindPackageHandleStandardArgs) + +# Set Hints +set(_LIBRESSL_ROOT_HINTS + ${LIBRESSL_ROOT_DIR} + ENV LIBRESSL_ROOT_DIR +) + +# Set Paths +if (WIN32) + file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles) + set(_LIBRESSL_ROOT_PATHS + "${_programfiles}/LibreSSL" + ) + unset(_programfiles) +elseif(APPLE) + # Homebrew installs LibreSSL here + set(_LIBRESSL_ROOT_PATHS + "/usr/local/opt/libressl" + ) +else() + set(_LIBRESSL_ROOT_PATHS + "/usr/local/" + ) +endif() + +# Combine +set(_LIBRESSL_ROOT_HINTS_AND_PATHS + HINTS ${_LIBRESSL_ROOT_HINTS} + PATHS ${_LIBRESSL_ROOT_PATHS} +) + +# Find Include Path +find_path(LIBRESSL_INCLUDE_DIR + NAMES + tls.h + ${_LIBRESSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + include +) + +# Find Crypto Library +find_library(LIBRESSL_CRYPTO_LIBRARY + NAMES + libcrypto + crypto + NAMES_PER_DIR + ${_LIBRESSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + lib +) + +# Find SSL Library +find_library(LIBRESSL_SSL_LIBRARY + NAMES + libssl + ssl + NAMES_PER_DIR + ${_LIBRESSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + lib +) + +# Find TLS Library +find_library(LIBRESSL_TLS_LIBRARY + NAMES + libtls + tls + NAMES_PER_DIR + ${_LIBRESSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + lib +) + +# Set Libraries +set(LIBRESSL_LIBRARIES ${LIBRESSL_CRYPTO_LIBRARY} ${LIBRESSL_SSL_LIBRARY} ${LIBRESSL_TLS_LIBRARY}) + +# Mark Variables As Advanced +mark_as_advanced(LIBRESSL_INCLUDE_DIR LIBRESSL_LIBRARIES LIBRESSL_CRYPTO_LIBRARY LIBRESSL_SSL_LIBRARY LIBRESSL_TLS_LIBRARY) + +# Find Version File +if(LIBRESSL_INCLUDE_DIR AND EXISTS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h") + + # Get Version From File + file(STRINGS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSLV.H REGEX "#define LIBRESSL_VERSION_TEXT[ ]+\".*\"") + + # Match Version String + string(REGEX REPLACE ".*\".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\"" "\\1;\\2;\\3" LIBRESSL_VERSION_LIST "${OPENSSLV.H}") + + # Split Parts + list(GET LIBRESSL_VERSION_LIST 0 LIBRESSL_VERSION_MAJOR) + list(GET LIBRESSL_VERSION_LIST 1 LIBRESSL_VERSION_MINOR) + list(GET LIBRESSL_VERSION_LIST 2 LIBRESSL_VERSION_REVISION) + + # Set Version String + set(LIBRESSL_VERSION "${LIBRESSL_VERSION_MAJOR}.${LIBRESSL_VERSION_MINOR}.${LIBRESSL_VERSION_REVISION}") + +endif() + +# Set Find Package Arguments +find_package_handle_standard_args(LibreSSL + REQUIRED_VARS + LIBRESSL_CRYPTO_LIBRARY + LIBRESSL_INCLUDE_DIR + VERSION_VAR + LIBRESSL_VERSION + HANDLE_COMPONENTS + FAIL_MESSAGE + "Could NOT find LibreSSL, try setting the path to LibreSSL using the LIBRESSL_ROOT_DIR environment variable" +) + +# LibreSSL Found +if(LIBRESSL_FOUND) + + # Set LibreSSL::Crypto + if(NOT TARGET LibreSSL::Crypto AND EXISTS "${LIBRESSL_CRYPTO_LIBRARY}") + + # Add Library + add_library(LibreSSL::Crypto UNKNOWN IMPORTED) + + # Set Properties + set_target_properties( + LibreSSL::Crypto + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBRESSL_CRYPTO_LIBRARY}" + ) + + endif() # LibreSSL::Crypto + + # Set LibreSSL::SSL + if(NOT TARGET LibreSSL::SSL AND EXISTS "${LIBRESSL_SSL_LIBRARY}") + + # Add Library + add_library(LibreSSL::SSL UNKNOWN IMPORTED) + + # Set Properties + set_target_properties( + LibreSSL::SSL + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBRESSL_SSL_LIBRARY}" + INTERFACE_LINK_LIBRARIES LibreSSL::Crypto + ) + + endif() # LibreSSL::SSL + + # Set LibreSSL::TLS + if(NOT TARGET LibreSSL::TLS AND EXISTS "${LIBRESSL_TLS_LIBRARY}") + add_library(LibreSSL::TLS UNKNOWN IMPORTED) + set_target_properties( + LibreSSL::TLS + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBRESSL_TLS_LIBRARY}" + INTERFACE_LINK_LIBRARIES LibreSSL::SSL + ) + + endif() # LibreSSL::TLS + +endif(LIBRESSL_FOUND) diff --git a/externals/CLI11 b/externals/CLI11 index 30d783eb6..12ba4ac4d 160000 --- a/externals/CLI11 +++ b/externals/CLI11 @@ -1 +1 @@ -Subproject commit 30d783eb61a2bf83ae29fcde70691eac852a7b7d +Subproject commit 12ba4ac4dbaa6489cb07e01be796e2bc074ef4f4 diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index ed5e903fa..56ccaed23 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -327,7 +327,35 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) add_subdirectory(openal-soft EXCLUDE_FROM_ALL) endif() +# LibreSSL +if (TARGET LibreSSL::SSL OR TARGET LibreSSL::Crypto) + set(SSL_DEPENDENCIES LibreSSL::SSL LibreSSL::Crypto) +elseif (TARGET OpenSSL::SSL OR TARGET OpenSSL::Crypto) + set(SSL_DEPENDENCIES OpenSSL::SSL OpenSSL::Crypto) +else() + set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "" FORCE) + set(LIBRESSL_APPS OFF CACHE BOOL "" FORCE) + set(LIBRESSL_TESTS OFF CACHE BOOL "" FORCE) + add_subdirectory(libressl EXCLUDE_FROM_ALL) + get_directory_property(SSL_DEPENDENCIES DIRECTORY libressl DEFINITION OPENSSL_LIBS) +endif() + # cpp-httplib add_library(Cpp_Httplib INTERFACE) target_include_directories(Cpp_Httplib INTERFACE cpp-httplib/) +if (TARGET ZLIB::ZLIB) + target_link_libraries(Cpp_Httplib INTERFACE ZLIB::ZLIB) + target_compile_definitions(Cpp_Httplib INTERFACE CPPHTTPLIB_ZLIB_SUPPORT) + message(STATUS "cpp-httplib: zlib support enabled (gzip response decompression)") +else() + message(STATUS "cpp-httplib: zlib not available — gzip responses will arrive uncompressed") +endif() + +if (DEFINED SSL_DEPENDENCIES) + target_link_libraries(Cpp_Httplib INTERFACE ${SSL_DEPENDENCIES}) + target_compile_definitions(Cpp_Httplib INTERFACE CPPHTTPLIB_OPENSSL_SUPPORT) + message(STATUS "cpp-httplib: SSL support enabled (TLS connections)") +else() + message(STATUS "cpp-httplib: OpenSSL/LibreSSL not available — libSceHttp HTTPS will fall back to mock at runtime.") +endif() diff --git a/externals/cpp-httplib b/externals/cpp-httplib index 09d00c099..28f8264d1 160000 --- a/externals/cpp-httplib +++ b/externals/cpp-httplib @@ -1 +1 @@ -Subproject commit 09d00c099ca828aa31bb1bfbadff2d9f1fd8be98 +Subproject commit 28f8264d134a576422cd0f99f19719c2749d9e47 diff --git a/externals/libressl b/externals/libressl new file mode 160000 index 000000000..b0504086d --- /dev/null +++ b/externals/libressl @@ -0,0 +1 @@ +Subproject commit b0504086dbbc186724b0cc92e6ba1832c245de0b diff --git a/externals/libusb b/externals/libusb index f21a2f3c4..d087ea865 160000 --- a/externals/libusb +++ b/externals/libusb @@ -1 +1 @@ -Subproject commit f21a2f3c4f82b3539220ea0b9933888a4de8d23c +Subproject commit d087ea86539ab1f1ec42faf86e2357e2fad126a6 diff --git a/externals/openal-soft b/externals/openal-soft index f120be6e2..83ea7236c 160000 --- a/externals/openal-soft +++ b/externals/openal-soft @@ -1 +1 @@ -Subproject commit f120be6e2e7d2eb37a70f8adb5a98e5a645c5349 +Subproject commit 83ea7236c6f23fc98e2b62eb9c5b3abfd4b2be86