PDA

View Full Version : How to resolve OpenSSL library dependency ?



npatil15
9th August 2019, 08:17
Hi Everyone,

I'm using REST api, using QNetworkAccessManager and QNetworkRequest.

For this I need OpenSSL installed in my system, but if somehow user doesn't have OpenSSL installed in his system then my tool creates a problem by giving an error like below,


Error creating SSL context ()

So just to resolve this, I want to add this library dependency on my project file.

So can someone will help me how I can proceed with this, regarding which version of library or path dependency of headers/lib/dll and all.

Note: I need this for both Linux and Windows platform.

Thanks

anda_skoa
9th August 2019, 15:56
I doubt this will be a problem on Linux, it is simply too unlikely that any system would not have OpenSSL installed.

For Windows you need to bundle the SSL lib used by your Qt build.

Cheers,
_

npatil15
12th August 2019, 07:46
I haven't tested on Linux yet and now that issue is on Windows only.
I have downloaded some pre-compiled lib and dll and tried to add in .pro file. (Source: https://indy.fulgan.com/SSL/openssl-1.0.2s-x64_86-win64.zip)

unix:!macx|win32: LIBS += -L$$PWD/../../../thirdparty/openssl/lib/ -llibeay32 -lssleay32

INCLUDEPATH += $$PWD/../../../thirdparty/openssl/include
DEPENDPATH += $$PWD/../../../thirdparty/openssl/include
dependencies.files += $$PWD/../../../thirdparty/openssl/bin/libeay32.dll
dependencies.files += $$PWD/../../../thirdparty/openssl/bin/ssleay32.dll
export(INCLUDEPATH)
export(LIBS)
export(dependencies.files)

By doing this above, now I can have .dll besides my application, but still on running it causing this same error.
Again I have tried to check with this below and gets false result

qDebug()<<"Suppport"<<QSslSocket::supportsSsl();

anda_skoa
12th August 2019, 08:15
OpenSSL isn't linked, it is dynamically opened. Like a plugin.

If Qt is correctly built, there is no need for any change in the application's .pro file.

Did you build Qt yourself with the library you've downloaded or do you use a pre-built Qt?

Cheers,
_

npatil15
12th August 2019, 09:12
I'm using pre-built Qt.
And that I didn't understand how I can make OpenSSL to open it dynamically?

npatil15
13th August 2019, 07:22
Now I have compiled openssl-1.1.1c.tar (https://www.openssl.org/source/), which created .dll (libcrypto-1_1-x64.dll and libssl-1_1-x64.dll).
In the project file, I just have added these below lines,

dependencies.files += $$PWD/../../../thirdparty/openssl/bin/libcrypto-1_1-x64.dll
dependencies.files += $$PWD/../../../thirdparty/openssl/bin/libssl-1_1-x64.dll

In above I have tried with renaming libcrypto-1_1-x64 to libcrypto and libssl-1_1-x64 to libssl.

Note: Path is correct I have checked with debugging (message()).

Also, I have tried with adding INCLUDEPATH/DEPENDPATH/LIBS

But still, it doesn't look working. What I'm missing? Does that version is not supporting for me ?

npatil15
13th August 2019, 12:16
Hi,

I have found a solution.
The problem I'm facing is that I haven't chosen the right version, so first choose the right version of OpenSSH, use below command to get the version QT looking for and find the nearest version of OpenSSH

qDebug()<<"SSL Lib Version "<<QSslSocket::sslLibraryBuildVersionString()

Now find and download that nearest or exact version of OpenSSH on ftp://ftp.openssl.org/source

You need Perl, so install it from https://www.activestate.com/products/activeperl/downloads/. I have used ActivePerl 5.26 version.
Open compiler as an administrator, VS2015 x64 Native Tools Command Prompt (hope you have that as we need nmake tool to build it).

Follow the path of your SSH lib and use below command to build it.
- perl Configure VC-WIN64A no-asm --prefix=E:\ssl
- ms\do_nasm.bat
- nmake -f ms\ntdll.mak
- nmake -f ms\ntdll.mak install

Hope now you will have all dll/lib/includes in E:\ssl folder.
Now in project file just add below two lines which will copies that dll beside your application.

dependencies.files += $${YOURPATH}/ssl/bin/libeay32.dll
dependencies.files += $${YOURPATH}/ssl/bin/ssleay32.dll

Horrreeyyy, now you shlould get rid-off from this error (Error creating SSL context () )

Cheers :)