QNetworkAccessManager to a HTTPS troubles
-
I am trying to connect to a secure website and am having trouble understanding the steps to get there, i think i am supposed to use
QSslSocket
, which i try to do, but then i get this error when i useQSslSocket::connectToHostEncrypted
:qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
What am i missing ?
-
Hi,
What version of Qt are you using ?
On what platform ?
With what version of OpenSSL ? -
@reonZ said in QNetworkAccessManager to a HTTPS troubles:
do i need to build my own Qt ?,
No need to build Qt; you just need to install OpenSSL and add it to your
PATH
.The bitness of OpenSSL must match the bitness of your Qt libraries (so if you use 32-bit Qt, install 32-bit OpenSSL). Qt 5.12 uses OpenSSL 1.1.0.
-
Hi @reonZ, no apology required :)
@reonZ said in QNetworkAccessManager to a HTTPS troubles:
i just installed OpenSSL 1.1.0j
Good.
and added
INCLUDEPATH += C:/OpenSSL-Win64/include
in my .pro, but now what ? i have no idea how i am supposed to use it.I meant your PATH environment variable, not your project INCLUDEPATH. See https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/ and add the folder that contains the OpenSSL DLLs (not the include folder).
You don't need to do anything else. Just run your Qt program. It will search for the OpenSSL DLL in your PATH and load it automatically.
Anyway, I notice that you've installed 64-bit OpenSSL, which will only work with 64-bit apps. Are you using 64-bit Qt or 32-bit Qt?
-
@reonZ said in QNetworkAccessManager to a HTTPS troubles:
I did put it in my windows PATH, tried both the
C:\OpenSSL-Win32\bin
andC:\OpenSSL-Win64\bin
version just in case and i still have the same error- Are you using 32-bit or 64-bit Qt?
- Where did you download OpenSSL from?
- What does
QSslSocket::sslLibraryBuildVersionString()
return? - What does
QSslSocket::sslLibraryVersionString()
return?
(i restarted Qt each time).
I'm not 100% sure, but you'll also need to make sure that Windows has recorded the changes. Did you close all the Windows dialogs after changing the settings?
-
Relevant bugreports:
https://bugreports.qt.io/browse/QTBUG-72015
https://bugreports.qt.io/browse/QTBUG-72016Basically you can get that if you have misconfigured the socket - no private key, or local certificate. The error is nondescriptive, so you need to make sure (if you use any of those two) that both exist and are valid, and you do that manually. Could you provide the snippet you use to connect to said server?
-
1/ In Qt creator it says
Based on Qt 5.12.0 (MVSC 2015, 32 bit)
2/ From herehttp://slproweb.com/products/Win32OpenSSL.html
3/QSslSocket::sslLibraryBuildVersionString()
returnsOpenSSL 1.0.2p 14 Aug 2018
4/QSslSocket::sslLibraryVersionString()
returns emptyAnd yes, i made sure to close all the dialog windows before restarting Qt.
-
Hi,
Following item 3, Qt was built using OpenSSL 1.0.2 so you have to download the most recent version of the 1.0 series of OpenSSL. You can't use 1.1 in this case because they broke API and ABI compatibility.
-
Go to the Run part of the Project panel and modify the PATH environment variable there to also contain the path to your 1.0 version of OpenSSL dlls.
-
Then I would ensure that this folder is the first to appear in the list and also that there are no other versions of OpenSSL on the system, for example in the Windows specific folders.
-
@SGaist Alright it is working now, i indeed needed to install the 64bit version and not the 32 bit:
QSslSocket::sslLibraryBuildVersionString() "OpenSSL 1.0.2p 14 Aug 2018" QSslSocket::sslLibraryVersionString() "OpenSSL 1.0.2q 20 Nov 2018"
I also received the result from
QNetworkAccessManager::get
Thanks a lot for all the help, you guys are awesome.
Edit: i still always have this in the output console though
QNetworkReplyHttpImplPrivate::_q_startOperation was called more than once
but it is not related to this because i had it on non secure get too.