QSslSocket: TLS initialization Failed
-
That's the version of OpenSSL that was used when building Qt.
-
@SGaist I seem to have the same problem. I'm currently linking against openssl 1.0.2q. Is that a problem? Also I added a library path in Qt main where it can find the ssl dlls: QCoreApplication::addLibraryPath("c:/OpenSSL-Win64/bin");
Still it reports the initialization problems with SSL:
qDebug() << QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString();
gives me:
false "OpenSSL 1.0.2p 14 Aug 2018" ""
and then:
QSslSocket::connectToHostEncrypted: TLS initialization failed ssl\qsslsocket.cpp: 457
What to do?
-
You should rather modify the PATH environnement variable in the Run part of the Project panel so it can be found at run time.
-
I have the exact same situation as Hans. Same output from the program. I did a search and looky what I found... looks like M$ put libcrypto.dll in the system32 folder and that overrides getting dlls from the program path. Could it be somebody other than MS? I have .NET Framework 1.1, Win10 Dev Kit, Visual Studio 2017 Community, Strawberry Perl, Python, OpenSSL 1.1.1.a, some MS Visual C++ Redistributables, and MS System CLR Types for SQL Server. Nobody else should have done something like that. Also there is no libssl.dll in system32. I'm using OpenSSL 1.1.1a so libcrypto.dll and libssl.dll replace libeay32.dll and ssleay32.dll.
This is a fresh install of Win10 I did about a week ago or so. I added this to the beginning of the qDebug() with dbReply being a QNetworkReply:
qDebug() << dbReply->errorString() << QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString();
The total output is:
"Unknown error" false "OpenSSL 1.0.2p 14 Aug 2018" ""
How do I remedy the situation if system32 takes priority over the program path?
-
First: use the same series of OpenSSL as was used to build Qt. OpenSSL 1.1 broke API and ABI compatibility with regards to the 1.0 series.
As for the rogue OpenSSL version in system32, it might very well be an application you installed or an application provided by the manufacturer of your machine. Neither are supposed to do that.
-
I am running the program straight from Qt Creator when all this happens. Even without the dll's present in the application build directory the program still gives the same output from the qDebug() line. I'm thinking the dll is loaded elsewhere, perhaps from the system32 directory. I did a search for the dll using Process Explorer and all that turned up was Chrome and Avast.
If you look at the search for libcrypto.dll I did it shows up in a subfolder of the C:\Windows\WinSxS directory - does this imply it's been installed by a Windows component as opposed to a program?
Also I was wrong about system32 taking the highest priority for loading dll's; see here. It says the directory from which the program is loaded takes top priority for loading dll's; however when I place the libcrypto-1_1.dll and libssl-1_1.dll in the shadow build directory or the release subdirectory of the shadow build directory the qDebug() line shows again the wrong version of OpenSSL being loaded. The only possible explanation of that behavior I could find is on the dll path search page I linked to:
If a DLL with the same module name is already loaded in memory, the system checks only for redirection and a manifest before resolving to the loaded DLL, no matter which directory it is in. The system does not search for the DLL.
Any ideas?
-
Yes, as already suggested, use OpenSSL 1.0 since it's the version that was used to build the version of Qt you are using.
As already written, OpenSSL broke API and ABI compatibility between 1.1 and 1.0.
It requires a different backend that is available since 5.10 but you have to select it when building Qt.If you want OpenSSL 1.1, you should move to Qt 5.12 as IIRC this is now the default backend.
-
I currently am using 5.12 which dumps the OpenSSL version mentioned before from QSslSocket::sslLibraryBuildVersionString(). Why does the Qt dynamic libraries (that's what you download to be used with Qt Creator/VS or whatever right?) only support a specific version of OpenSSL? When you use
INCLUDEPATH += "C:\Build-OpenSSL-VC-32\include"
and
LIBS += -LC:\Build-OpenSSL-VC-32\lib -llibcrypto -llibssl
why doesn't it override whatever OpenSSL was used to build Qt? After all the includes and libraries contain all the OpenSSL code right? Does Qt have to know which functions it can call within the OpenSSL libraries and therefore since API/ABI compatibility broke with 1.1 it is restricted to whatever was used to build Qt?
-
By default, for international distribution reason, Qt is not linked to OpenSSL but dlopens the dll if available.
And yes, the version is restricted to what was used to build Qt as with any other dependency you may have.
-
@SGaist said in QSslSocket: TLS initialization Failed:
Yes, as already suggested, use OpenSSL 1.0 since it's the version that was used to build the version of Qt you are using.
As already written, OpenSSL broke API and ABI compatibility between 1.1 and 1.0.
It requires a different backend that is available since 5.10 but you have to select it when building Qt.
If you want OpenSSL 1.1, you should move to Qt 5.12 as IIRC this is now the default backend.When you say you have to select it when building Qt your'e referring to a static build right? Is there any way to do it for whatever version of dynamic Qt Qt Creator uses? Just curious.
-
No, static or dynamic build doesn't play a role.
Qt and Qt Creator are two linked but independent projects so I'm not sure what you are asking here.
-
OK let me explain - when you use the Qt Online Installer you select for it to install 5.12 MSVC 2017 64bit or whatever you wish. That is a preconfigured dynamic build of the Qt libraries right? There's no way to change whatever OpenSSL is used for that Qt build since it's preconfigured right?
-
Right, you can't switch from the 1.0 to the 1.1 backend used for the reasons already explained.
-
I should like to add as a warning to future folks, which may include myself, that matching the exact version that your Qt libraries are using may be absolutely necessary. Look on the qt wiki for the version of openssl that was compiled against. The page will be of the form https://wiki.qt.io/Qt_5.12_Tools_and_Versions . Once you find your version, one of the links from https://wiki.openssl.org/index.php/Binaries points to https://indy.fulgan.com/SSL/ which has older binaries.
-
@Ross Thank Ross this was exactly my problem : I tried with the 1.1.1 versions of libeay32.dll and ssleay32.dll. With 1.0.2p version (used with Qt5.13 beta) it works perfectly.
Note to other previous answers : no need to add anything in the includepath of the .pro file. Juste add the RIGHT dll's in the same directory than the executable .
-
steps:
1- Firstly you need to find your SSL version for your windows machine( SSL version strictly depends on QT versions) with this function:
qDebug() << QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString();
-
After that run your code and call the above function. It will print your required SSL version in application output. In my case, it was “OpenSSL 1.0.2p 14 Aug 2018” “” which may be different for all the users.
-
Download SSL libraries from here
4- Paste all the files/content of SSL folder (which you have extracted) into the build directory inside the debug folder.
- if you have doubt. then visit this post for complete info.
-
-
@Rishabh3354 said in QSslSocket: TLS initialization Failed:
- Download SSL libraries from here
Or from here for 1.1.x builds.
By the way, thank you for the summarized step-by-step solution.
-
Recently I ran into this problem, Solution I found is .
-
Open Qt MaintenanceTool
-
select and install OpenSLL form list
-
got to .pro file remove old SSL libs and include path from there
-
Add following libs for OpenSll 1.1.1 d
MSVC_PATH = "C:/Qt/Qt5.14/5.14.1/mingw73_64" LIBS += -L$$MSVC_PATH/../../Tools/OpenSSL/Win_x64/lib -lcrypto -lssl INCLUDEPATH+= $$MSVC_PATH/../../Tools/OpenSSL/Win_x64/include
Changes need to do in is code some old openssl functions are to directly accessible.
-