解决Qt5使用SSL的“qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method”错误

时间:2021-11-19 12:38:31

在使用Qt的网络组件连接某些服务器时, 会提示“qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method”的错误, 导致连接失败。

经查资料得知这是由于SSLv2由于某些漏洞导致的不安全原因, 在某些linux发行版里禁用掉了SSLv2。

解决办法是自己重新编译openssl,加上SSLv2的支持

1.  下载代码:

git clone https://github.com/openssl/openssl.git

2. 编译

我的测试结果是openssl1.1不工作,但是openssl1.0工作

git checkout OpenSSL_1_0_0-stable
./config enable-shared
make depend
make -j4

3. Copy编译结果到$QTDIR/lib, 我的目录是/opt/Qt5.7.0/5.7/gcc_64/lib/

sudo cp libcrypto.so libssl.so libcrypto.so.1.0. libssl.so.1.0. /opt/Qt5.7.0/5.7/gcc_64/lib/

4. 从新运行应用, Qt pulgin会自动从新编译的ssl libries里load符号

这时仍然会得到一些warning, 如

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method
qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method
qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method
qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method
qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto
qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiate

忽略就可以了