3

Good day.

I am creating an application that requires the use of OpenSSL.

Problem:

The problem is having read the documentation several times over, I still do not quite understand how I can add SSL support.

There are numerous threads for adding SSL to windows applications, but extremely few for Linux, which does not provide alot of details.

I reviewed the provided project file, but no ssl linking is done here.

What I tried:

In my application, I run the following code:

if (!QSslSocket::supportsSsl()) {
    QMessageBox::critical(0, "Application Notice", "We care about your security. \nPlease install OpenSSL.");
    return -1;
}

Which displays the message when the check is done.

To added SSL support, I reviewed the QT provided example securesocketclient of implementing SSL

  • Environment Variable

Adding OPENSSL_LIBS environment variable

Reviewing the documentation, it mentions adding an environment variable which allows qmake to find the location of the openssl lib file.

I have a standard openssl installation with headers

Binary location

$ which openssl
/usr/bin/openssl

Headers location

$ locate openssl/aes.h
/opt/Qt5.9.1/5.9.1/Src/qtwebengine/src/3rdparty/chromium/third_party/boringssl/src/include/openssl/aes.h
/usr/include/openssl/aes.h
/usr/include/openssl-1.0/openssl/aes.h

Libs location

/usr/lib/libssl.so
/usr/lib/libssl.so.1.0.0
/usr/lib/libssl.so.1.1
/usr/lib/libssl3.so
/usr/lib/openssl-1.0/libssl.so
/usr/lib/openssl-1.0/pkgconfig/libssl.pc

/usr/lib32/libssl.so
/usr/lib32/libssl.so.1.0.0
/usr/lib32/libssl.so.1.1
/usr/lib32/libssl3.so
/usr/lib32/openssl-1.0/libssl.so
/usr/lib32/openssl-1.0/pkgconfig/libssl.pc

I figure that the provided env variable points to the incorrect location:

OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto'

I modified it according to my system (I do not think this is correct though):

OPENSSL_LIBS='-L/usr/lib -lssl -lcrypto'
  • Configuration Flag

Also noted in the documentation, a configuration flag -openssl-linked is required.

Having searched for a way to add this flag to a configuration file (as there is none present in my project directory)

According to this, I added the flag to my project file:

QMAKE_CXXFLAGS += -openssl-linked

BUT, still no SSL support.

Question:

Given my .pro file below, how can I add OpenSSL support to my Qt application given a standard install of OpenSSL?


Application Output

Debugging starts
qt.network.ssl: QSslSocket: cannot resolve CRYPTO_num_locks
qt.network.ssl: QSslSocket: cannot resolve CRYPTO_set_id_callback
qt.network.ssl: QSslSocket: cannot resolve CRYPTO_set_locking_callback
qt.network.ssl: QSslSocket: cannot resolve ERR_free_strings
qt.network.ssl: QSslSocket: cannot resolve EVP_CIPHER_CTX_cleanup
qt.network.ssl: QSslSocket: cannot resolve EVP_CIPHER_CTX_init
qt.network.ssl: QSslSocket: cannot resolve sk_new_null
qt.network.ssl: QSslSocket: cannot resolve sk_push
qt.network.ssl: QSslSocket: cannot resolve sk_free
qt.network.ssl: QSslSocket: cannot resolve sk_num
qt.network.ssl: QSslSocket: cannot resolve sk_pop_free
qt.network.ssl: QSslSocket: cannot resolve sk_value
qt.network.ssl: QSslSocket: cannot resolve SSL_library_init
qt.network.ssl: QSslSocket: cannot resolve SSL_load_error_strings
qt.network.ssl: QSslSocket: cannot resolve SSL_get_ex_new_index
qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method
qt.network.ssl: QSslSocket: cannot resolve SSLv3_client_method
qt.network.ssl: QSslSocket: cannot resolve SSLv23_client_method
qt.network.ssl: QSslSocket: cannot resolve SSLv2_server_method
qt.network.ssl: QSslSocket: cannot resolve SSLv3_server_method
qt.network.ssl: QSslSocket: cannot resolve SSLv23_server_method
qt.network.ssl: QSslSocket: cannot resolve X509_STORE_CTX_get_chain
qt.network.ssl: QSslSocket: cannot resolve OPENSSL_add_all_algorithms_noconf
qt.network.ssl: QSslSocket: cannot resolve OPENSSL_add_all_algorithms_conf
qt.network.ssl: QSslSocket: cannot resolve SSLeay
qt.network.ssl: QSslSocket: cannot resolve SSLeay_version
qt.network.ssl: Incompatible version of OpenSSL
Debugging has finished

pro file

#-------------------------------------------------
#
# Project created by QtCreator 2017-12-02T18:53:15
#
#-------------------------------------------------

QT       += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = MySSLApp
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
    main.cpp \
    mainwindow.cpp \
    loginform.cpp \
    networkthread.cpp \
    sslclient.cpp

HEADERS += \
    mainwindow.h \
    loginform.h \
    networkthread.h \
    sslclient.h

FORMS += \
    mainwindow.ui \
    loginform.ui

RESOURCES += \
    resources.qrc

OPENSSL_LIBS='-L/usr/lib -lssl -lcrypto'

QMAKE_CXXFLAGS += -openssl-linked
jww
  • 97,681
  • 90
  • 411
  • 885
CybeX
  • 2,060
  • 3
  • 48
  • 115
  • Do you set those options when building your application, or when building Qt? The doc mentions that you need to set those when building Qt. – Karsten Koop Dec 04 '17 at 09:46
  • Well I feel like a fool. I missed that, 2 times. I set when building my application. – CybeX Dec 04 '17 at 09:50
  • @KarstenKoop thank you for noticing that, however provided the `securesocketclient` example, is there any linking of sorts or anything related I should do for my application? Since before I added these configuration, it still informed me that there is no SSL support. – CybeX Dec 04 '17 at 09:53
  • It seems your OpenSSL libraries are installed in /usr/lib, so it's a bit strange they cannot be found. Did you just install the package from your distribution? Which Linux distro is this? Did you also install Qt from a package, or compile it yourself? – Karsten Koop Dec 04 '17 at 10:39
  • @KarstenKoop Used pacman to install the default openssl-1.0. Distro: Archlinux. OpenSSL was installed while installing distro, it is required by the system. Qt-Creator was install from package (from website, community edition). I am currently compiling OpenSSl since I saw came accros a SO thread relating to a similar issue: Build SSL version : `1.1 Nov 2017` vs Runtime SSL Version : `0` – CybeX Dec 04 '17 at 10:49
  • can you provide path to your ssl.h? maybe you’re missing openssl development package? – Hayati Gonultas Dec 12 '17 at 08:37
  • @HayatiGonultas thank you for the response. In arch linux, the development package is automatically installed. https://www.archlinux.org/packages/core/x86_64/openssl/ . regarding `ssl.h`, it is found at `/usr/include/openssl/ssl.h`. I did however resolve the issue by reinstalling my OS alongside OpenSSL `OpenSSL 1.0.2g`, this had resolved the issue. Source of OpenSSL package -> https://www.openssl.org/source/old/1.0.2/openssl-1.0.2g.tar.gz – CybeX Dec 12 '17 at 08:45
  • That is great. Thanks sharing your solution. – Hayati Gonultas Dec 12 '17 at 08:58
  • @HayatiGonultas I will submit an official answer to close the post. – CybeX Dec 12 '17 at 08:58
  • 1
    [How to Include OpenSSL in a Qt project](https://stackoverflow.com/q/14681012/608639), [Changing OpenSSL include path for qmake](https://stackoverflow.com/q/20592001/608639), [How to tell Qt to use different OpenSSL](https://stackoverflow.com/q/40429278/608639), [How to implement OpenSSL in Qt?](https://stackoverflow.com/q/43384887/608639), [Is there any way to building static Qt with static OpenSSL?](https://stackoverflow.com/q/20843180/608639), etc – jww Jan 14 '18 at 09:18
  • @jww thanks for the informative update. *I need to create an answer for this.* – CybeX Jan 14 '18 at 12:58
  • community is still waiting for the official answer, I will try out the 1.0.2.g version I also have the very same issues while compiling for arm. Also I read you could not cross compile openssl with he latest Ubuntu. – Yvain Apr 17 '19 at 15:03

0 Answers0