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
12
  • 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. Commented Dec 4, 2017 at 9:46
  • Well I feel like a fool. I missed that, 2 times. I set when building my application. Commented Dec 4, 2017 at 9: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. Commented Dec 4, 2017 at 9: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? Commented Dec 4, 2017 at 10:39
  • 1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.