From 3798b129c032dbd2ac1ccab071ad3ad4ebc2edf3 Mon Sep 17 00:00:00 2001 From: Erik van Pienbroek Date: Wed, 6 Feb 2013 22:08:40 +0100 Subject: [PATCH] Try harder to locate external OpenSSL libraries on win32 When OpenSSL is built using MSVC then the library names are named ssleay32.dll and libeay32. However, when OpenSSL is built with GCC then different library names are used like libssl-10.dll and libcrypto-10.dll (depending on the version of OpenSSL used) Change-Id: Icb79a5f82d2a511752bfc904f53a58423ce4b86b Reviewed-by: Thiago Macieira Reviewed-by: Peter Hartmann Reviewed-by: Richard J. Moore --- .../ssl/qsslsocket_openssl_symbols.cpp | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index 31cfa2d00a3..e880a2452f3 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -447,28 +447,46 @@ static QStringList findAllLibCrypto() # endif #ifdef Q_OS_WIN +static bool tryToLoadOpenSslWin32Library(QLatin1String ssleay32LibName, QLatin1String libeay32LibName, QPair &pair) +{ + pair.first = 0; + pair.second = 0; + + QSystemLibrary *ssleay32 = new QSystemLibrary(ssleay32LibName); + if (!ssleay32->load(false)) { + delete ssleay32; + return FALSE; + } + + QSystemLibrary *libeay32 = new QSystemLibrary(libeay32LibName); + if (!libeay32->load(false)) { + delete ssleay32; + delete libeay32; + return FALSE; + } + + pair.first = ssleay32; + pair.second = libeay32; + return TRUE; +} + static QPair loadOpenSslWin32() { QPair pair; pair.first = 0; pair.second = 0; - QSystemLibrary *ssleay32 = new QSystemLibrary(QLatin1String("ssleay32")); - if (!ssleay32->load(false)) { - // Cannot find ssleay32.dll - delete ssleay32; - return pair; + // When OpenSSL is built using MSVC then the libraries are named 'ssleay32.dll' and 'libeay32'dll'. + // When OpenSSL is built using GCC then different library names are used (depending on the OpenSSL version) + // The oldest version of a GCC-based OpenSSL which can be detected by the code below is 0.9.8g (released in 2007) + if (!tryToLoadOpenSslWin32Library(QLatin1String("ssleay32"), QLatin1String("libeay32"), pair)) { + if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-10"), QLatin1String("libcrypto-10"), pair)) { + if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-8"), QLatin1String("libcrypto-8"), pair)) { + tryToLoadOpenSslWin32Library(QLatin1String("libssl-7"), QLatin1String("libcrypto-7"), pair); + } + } } - QSystemLibrary *libeay32 = new QSystemLibrary(QLatin1String("libeay32")); - if (!libeay32->load(false)) { - delete ssleay32; - delete libeay32; - return pair; - } - - pair.first = ssleay32; - pair.second = libeay32; return pair; } #else