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.
Please 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
See Question&Answers more detail:os