一、问题
在Qt中使用https,运行时报错:
qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method
二、原因分析
SSLv2由于某些漏洞导致的不安全原因, 在某些linux发行版里的openssl库禁用掉了SSLv2
三、解决办法
重新编译openssl
1、下载openssl
git clone https://github.com/openssl/openssl.git
2、编译
./config enable-shared
make -j4
3、部署
将ssl和crypto库拷贝到Qt目录lib下:
cp libssl.so* libcrypto.so* ~/Qt5.6.3/5.6.3/gcc_64/lib/ -a
4、新的错误
重新运行时,报错
qt.network.ssl: QSslSocket: cannot call unresolved function *
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: QSslSocket: cannot call unresolved function CRYPTO_num_locks
qt.network.ssl: QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
qt.network.ssl: QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function sk_num
qt.network.ssl: QSslSocket: cannot call unresolved function SSLeay
qt.network.ssl: QSslSocket: cannot call unresolved function SSLeay
qt.network.ssl: QSslSocket: cannot call unresolved function SSLeay
qt.network.ssl: QSslSocket: cannot call unresolved function SSLeay
四、解决新错误
参考博客:https://www.cnblogs.com/btian/p/6130560.html
Qt5.6对openssl版本的要求1.0,而从git上下载的最新版本是1.1的;
其它Qt的版本对openssl的要求未测试。
1、查看版本信息
git branch -r
origin/HEAD -> origin/master
origin/OpenSSL-engine-0_9_6-stable
origin/OpenSSL-fips-0_9_7-stable
origin/OpenSSL-fips-0_9_8-stable
origin/OpenSSL-fips-1_2-stable
origin/OpenSSL-fips-2_0-dev
origin/OpenSSL-fips-2_0-stable
origin/OpenSSL-fips2-0_9_7-stable
origin/OpenSSL_0_9_6-stable
origin/OpenSSL_0_9_7-stable
origin/OpenSSL_0_9_8-stable
origin/OpenSSL_0_9_8fg-stable
origin/OpenSSL_1_0_0-stable
origin/OpenSSL_1_0_1-stable
origin/OpenSSL_1_0_2-stable
origin/OpenSSL_1_1_0-stable
origin/OpenSSL_1_1_1-stable
origin/SSLeay
origin/master
origin/tls1.3-draft-18
origin/tls1.3-draft-19
2、导出1.0.2版本
git checkout -b openssl-1.0.2 origin/OpenSSL_1_0_2-stable
3、编译
./config enable-shared
make -j4
4、部署
cp libssl.so* libcrypto.so* ~/Qt5.6.3/5.6.3/gcc_64/lib/ -a
重新运行不再报错