How to make Qt use OpenSsl on Windows
-
Hi,
I'm making a desktop app on Linux and Windows with Qt.
I've tried over and over again to make Qt on Windows use OpenSsl (I absolutely need to import a pkcs12) without success.
It works without any problem on Linux, but for some reason, it doesn't on Windows...Here's a code sample of the problem:
qDebug() << "QSslSocket support ssl?" << QSslSocket::supportsSsl(); qDebug() << "QSslSocket::sslLibraryBuildVersion: " << QSslSocket::sslLibraryBuildVersionString(); _socket = new QSslSocket(this); QSslConfiguration config; QFile pkcs(path + "/ca.pfx"); pkcs.open(QFile::ReadOnly); QSslKey key; QSslCertificate caCert; static bool import = QSslCertificate::importPkcs12(&pkcs, &key, &caCert);
This code gives these outputs:
QSslSocket support ssl? true QSslSocket::sslLibraryBuildVersion: "Secure Channel (NTDDI: 0xA00000B)" qt.network.ssl: The backend "schannel" cannot read PKCS12 format qt.network.ssl: Available TLS backend does not support PKCS12
I've tried to configure my CMakeLists.txt to force OpenSsl with these lines:
find_package(OpenSSL REQUIRED) ... target_link_libraries(MyApp OpenSSL::SSL OpenSSL::Crypto) target_include_directories(MyApp PRIVATE ${OPENSSL_INCLUDE_DIR})
Nothing works, I still have the same outputs.
I also tried the
configure
script with-I
and-L
option, but couldn't make it run (always had cmake and MinGW errors).I must say that I use CLion to develop my app, so I don't have a
.pro
file.Is there any way to force OpenSsl in Qt on a Windows machine?
Thanks!
-
@ArtiFAS Secure channel is the built-in alternative on Windows. To make OpenSSL work (I assume you are using prebuilt Qt right?), you need to put OpenSSL libraries next to the
.exe
file of your application. That's it. Qt even ships with some OpenSSL libs, if you opted to install them they are in<qt installation dir>/tools/OpenSSL
.If Qt will still favour secure channel, you can compile Qt yourself and force OpenSSL through configure flags. But that, I'd say, is last resort.
-
@sierdzio Thanks for your reply and sorry about the delay.
I've tried putting the libssl-xxx.dll and libcrypto-xxx.dll file in the build directory (with the .exe), but it does not seem to work.
I still get the same error.
The CMakeLists.txt is still the same.
Do you have an idea of something else I could be doing wrong?
Thanks for the help!