Why is QsslSocket working with Qt 5.3 but not Qt 5.7 on Debian Stretch?

前端 未结 6 1714
野趣味
野趣味 2021-01-01 09:46

I have an app that uses the QWebSocket class but not SSL. It works fine when I execute a version compiled with Qt 5.3 but a Qt 5.7 executable freezes on the following warnin

相关标签:
6条回答
  • 2021-01-01 10:23

    TL;DR

    Debian Stretch is shipped with OpenSSL 1.1; Qt uses OpenSSL 1.0; give Qt what it needs:

    apt install libssl1.0-dev
    

    Detailed answer

    From this answer about OpenSSL and Qt, I found a hint and I displayed SSL library version used for compile-time and run-time using:

    qDebug()<<"SSL version use for build: "<<QSslSocket::sslLibraryBuildVersionString();
    qDebug()<<"SSL version use for run-time: "<<QSslSocket::sslLibraryVersionNumber();
    qDebug()<<QCoreApplication::libraryPaths();
    

    And it displays:

    SSL version use for build:  "OpenSSL 1.0.1e-fips 11 Feb 2013"
    ... lot of SSL warnings...
    SSL version use for run-time:  0
    ("/opt/Qt/5.8/gcc_64/plugins", "/home/Project/..../build...Desktop_Qt_5_8_0_GCC_64bit-Release/src/release/build_linux_64")
    

    But Debian Stretch is shipped with OpenSSL 1.1. As expected, all the threads on the Web about this issue are true: this is an OpenSSL library version compatibility issue.

    I "apt install libssl1.0-dev" and the problem was solved. I still have 2 SSL warnings about SSLv3, but at least this is only warning (I read something on the Web about it, no way to find it again).

    SSL version use for build:  "OpenSSL 1.0.1e-fips 11 Feb 2013"
    QSslSocket: cannot resolve SSLv3_client_method
    QSslSocket: cannot resolve SSLv3_server_method
    SSL version use for run-time:  268443839
    ("/opt/Qt/5.8/gcc_64/plugins", "/home/Project/..../build...Desktop_Qt_5_8_0_GCC_64bit-Release/src/release/build_linux_64")
    

    Summary

    Until Qt supports OpenSSL 1.1, you can either:

    1. Install OpenSSL 1.0 (possible in Debian)
    2. Compile OpenSSL 1.0 and install it (I did not test, but should work as 1.)
    3. Ship OpenSSL 1.0 with your Qt application (I did not test, but should work as 1.)
    4. Recompile Qt with "-openssl-linked" option (according to this answer, I did not test and I do not want to)
    0 讨论(0)
  • 2021-01-01 10:24

    I had the same problem on a debian stretch server. I fixed it with the help of 7hibaults comment.

    Running the following command fixed the problem for me:

    sudo apt-get install libssl1.0-dev
    
    0 讨论(0)
  • 2021-01-01 10:25

    You have to change this symlinks in /usr/lib/x86_64-linux-gnu from:

    libcrypto.solibcrypto.so.1.1
    libssl.solibssl.so.1.1

    to:

    libcrypto.solibcrypto.so.1.0.2
    libssl.solibssl.so.1.0.2

    0 讨论(0)
  • 2021-01-01 10:27

    I have problem with Qt 5.11.1 on Ubuntu 16.04.

    I got the ssl version used for Qt by running

    qDebug()<<"SSL version use for build: "<<QSslSocket::sslLibraryBuildVersionString();
    

    Which print

    SSL version use for build: "OpenSSL 1.0.2k-fips 26 Jan 2017"

    I resolved the problem by building openssl-1.0.2k got from here http://www.linuxfromscratch.org/blfs/view/8.0/postlfs/openssl.html.

    Then run the command to build

    ./config --prefix=./usr --openssldir=./etc/ssl  --libdir=lib   shared   zlib-dynamic
    make
    

    After make successfully completed I got follwing library build in current directory

    path/openssl-1.0.2k/libssl.so.1.0.0
    path/openssl-1.0.2k/libssl.so
    path/openssl-1.0.2k/libcrypto.so.1.0.0
    path/openssl-1.0.2k/libcrypto.so 
    

    Then Open QtCreator, Projects > Desktop Qt 5.11.1 GCC 64bit > Build > Build Environment > Add : Variable LD_LIBRARY_PATH with value path/openssl-1.0.2k.

    In my case LD_LIBRARY_PATH already exist with some value so I edited it like :/home/user/Qt5.11.1/Tools/QtCreator/lib/Qt/lib::path/openssl-1.0.2k

    The above steps resolve the ssl warning problem with Qt5.11.1 on Ubuntu 16.04.

    0 讨论(0)
  • 2021-01-01 10:29

    Fylhan's answer does not work under Debian Buster as libssl1.0-dev was a transition package and is not supported anymore.

    There is a bug report on Qt's Website and from Giuseppe d'Angelo's comment there are the following workarounds :

    Workaround 1

    If your distribution has a directory for OpenSSL 1.0 with the right symlinks (e.g. Arch has /usr/lib/openssl-1.0/libssl.so) use LD_LIBRARY_PATH to force that directory to be searched first.

    Workaround 2

    Make your own directory with symlinks, and use LD_LIBRARY_PATH for that.

    Workaround 3

    Rebuild your own Qt.

    I could fix the problem using the second solution, commands detailed below in my case:

    1. mkdir openssl1.0 ; cd openssl1.0
    2. cp /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 libssl.so.1.0.2
    3. ln -s libssl.so.1.0.2 libssl.so
    4. in QtCreator, Projects > Desktop Qt 5.8.0 > Build > Build Environment > Add : Variable LD_LIBRARY_PATH, Value /path/to/dir/openssl1.0 (or add LD_LIBRARY_PATH="/path/to/dir/openssl1.0" before your command from the console)

    You could need to do the same with libcrypto.so as well, but this was enough for me. This solution prevents you from changing the symlinks for the whole system.

    0 讨论(0)
  • 2021-01-01 10:44

    You have to install the following package with the following command in order to fix the problem:

    sudo apt install libssl1.0-dev
    
    0 讨论(0)
提交回复
热议问题