Skip to content

Commit

Permalink
Added OpenSSL3.x support based on the work on @Meltie2013 and @i-am-fyre
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1arm committed Oct 20, 2023
1 parent ea76829 commit 6f6608f
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

Expand Down Expand Up @@ -109,6 +109,8 @@ find_package(DL REQUIRED)
find_package(ZLIB QUIET)
find_package(BZip2 QUIET)

#static linkage for openssl libs
set(OPENSSL_USE_STATIC_LIBS ON)
find_package(OpenSSL REQUIRED)

include(${CMAKE_SOURCE_DIR}/cmake/GenRevision.cmake)
Expand Down
6 changes: 6 additions & 0 deletions src/mangosd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ target_include_directories(mangosd
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${OPENSSL_INCLUDE_DIR}
)

target_compile_definitions(mangosd
Expand All @@ -76,6 +77,11 @@ target_link_libraries(mangosd
$<$<BOOL:${SOAP}>:gsoap>
Threads::Threads
DL::DL
${OPENSSL_LIBRARIES}
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3)
OpenSSL::Crypto
#endif()

)

install(
Expand Down
30 changes: 30 additions & 0 deletions src/mangosd/mangosd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
# include <openssl/provider.h>
#endif
#include <ace/Version.h>
#include <ace/Get_Opt.h>

Expand Down Expand Up @@ -391,11 +394,38 @@ int main(int argc, char** argv)
sLog.outString("Using configuration file %s.", cfg_file);

DETAIL_LOG("Using SSL version: %s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));

#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
OSSL_PROVIDER* legacy;
OSSL_PROVIDER* deflt;

/* Load Multiple providers into the default (NULL) library context */
legacy = OSSL_PROVIDER_load(NULL, "legacy");
if (legacy == NULL) {
sLog.outError("Failed to load OpenSSL 3.x Legacy provider\n");
#ifdef WIN32
sLog.outError("\nPlease check you have set the following Enviroment Varible:\n");
sLog.outError("OPENSSL_MODULES=C:\\OpenSSL-Win64\\bin\n");
sLog.outError("(where C:\\OpenSSL-Win64\\bin is the location you installed OpenSSL\n");
#endif
Log::WaitBeforeContinueIfNeed();
return 0;
}
deflt = OSSL_PROVIDER_load(NULL, "default");
if (deflt == NULL) {
sLog.outError("Failed to load OpenSSL 3.x Default provider\n");
OSSL_PROVIDER_unload(legacy);
Log::WaitBeforeContinueIfNeed();
return 0;
}
#else
if (SSLeay() < 0x10100000L || SSLeay() > 0x10200000L)
{
DETAIL_LOG("WARNING: OpenSSL version may be out of date or unsupported. Logins to server may not work!");
DETAIL_LOG("WARNING: Minimal required version [OpenSSL 1.1.x] and Maximum supported version [OpenSSL 1.2]");
}
#endif


DETAIL_LOG("Using ACE: %s", ACE_VERSION);

Expand Down
5 changes: 5 additions & 0 deletions src/realmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ target_include_directories(realmd
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h
${OPENSSL_INCLUDE_DIR}
)

target_link_libraries(realmd
PUBLIC
shared
Threads::Threads
DL::DL
${OPENSSL_LIBRARIES}
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3)
OpenSSL::Crypto
#endif()
)

install(
Expand Down
32 changes: 32 additions & 0 deletions src/realmd/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
# include <openssl/provider.h>
#endif

#include <ace/Get_Opt.h>
#include <ace/Dev_Poll_Reactor.h>
Expand Down Expand Up @@ -221,11 +224,40 @@ extern int main(int argc, char** argv)
}

DETAIL_LOG("Using SSL version: %s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));

#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
OSSL_PROVIDER* legacy;
OSSL_PROVIDER* deflt;

/* Load Multiple providers into the default (NULL) library context */
legacy = OSSL_PROVIDER_load(NULL, "legacy");
if (legacy == NULL)
{
sLog.outError("Failed to load OpenSSL 3.x Legacy provider\n");
#ifdef WIN32
sLog.outError("\nPlease check you have set the following Enviroment Varible:\n");
sLog.outError("OPENSSL_MODULES=C:\\OpenSSL-Win64\\bin\n");
sLog.outError("(where C:\\OpenSSL-Win64\\bin is the location you installed OpenSSL\n");
#endif
Log::WaitBeforeContinueIfNeed();
return 0;
}
deflt = OSSL_PROVIDER_load(NULL, "default");
if (deflt == NULL)
{
sLog.outError("Failed to load OpenSSL 3.x Default provider\n");
OSSL_PROVIDER_unload(legacy);
Log::WaitBeforeContinueIfNeed();
return 0;
}
#else
if (SSLeay() < 0x10100000L || SSLeay() > 0x10200000L)
{
DETAIL_LOG("WARNING: OpenSSL version may be out of date or unsupported. Logins to server may not work!");
DETAIL_LOG("WARNING: Minimal required version [OpenSSL 1.1.x] and Maximum supported version [OpenSSL 1.2]");
}
#endif


DETAIL_LOG("Using ACE: %s", ACE_VERSION);

Expand Down
11 changes: 11 additions & 0 deletions src/shared/Auth/ARC4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,27 @@
*/

#include "ARC4.h"
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
#include <openssl/provider.h>
#endif

ARC4::ARC4(uint8 len) : m_ctx()
{
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
OSSL_PROVIDER_load(NULL, "legacy");
#endif

m_ctx = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
}

ARC4::ARC4(uint8 *seed, uint8 len) : m_ctx()
{
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
OSSL_PROVIDER_load(NULL, "legacy");
#endif

m_ctx = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
Expand Down
3 changes: 3 additions & 0 deletions src/shared/Auth/Sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "Common/Common.h"
#include <openssl/sha.h>
#include <openssl/crypto.h>
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
# include <openssl/provider.h>
#endif

class BigNumber;

Expand Down
2 changes: 2 additions & 0 deletions src/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ target_include_directories(shared
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${OPENSSL_INCLUDE_DIR}
${TGT_INCL}
)

Expand All @@ -237,5 +238,6 @@ target_link_libraries(shared
ace
utf8
MySQL::MySQL
${OPENSSL_LIBRARIES}
OpenSSL::Crypto
)
4 changes: 4 additions & 0 deletions src/tools/Extractor_projects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ target_link_libraries(mmap-extractor
RecastNavigation::Recast
Threads::Threads
DL::DL
${OPENSSL_LIBRARIES}
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3)
OpenSSL::Crypto
#endif()
)

install(
Expand Down

0 comments on commit 6f6608f

Please sign in to comment.