当我试图加载cer文件时,QSslCertificate崩溃了

QSslCertificate crashes when i try to load a cer file

本文关键字:QSslCertificate 崩溃 文件 cer 加载      更新时间:2023-10-16

我在Qt中有这个代码

QFile file(address);
file.open(QIODevice::ReadOnly);
const QByteArray bytes = file.readAll();
qDebug()<<"Length : " + QString::number(bytes.length());
const QSslCertificate cert(bytes,QSsl::Der);

当我在windows 7 64位中尝试这段代码时,它工作得很好,但是当我为linux编译它时,它每次到达最后一行时都会崩溃,即使它给了我正确的长度,但它在终端中崩溃了。

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_negotiated
qt.network.ssl: QSslSocket: cannot resolve EC_KEY_new_by_curve_name
qt.network.ssl: QSslSocket: cannot resolve EC_KEY_free
Segmentation fault (core dumped)

我没有在我的代码中使用任何QSslSocket,我现在被困在这个问题上好几天了。
qt 5.4.2版本在Ubuntu 13.10 64位和CentOS 6.4 64位测试


我在Windows和Linux上都使用了openssl-1.0.2d

我找到了一个解决方案,我所做的是:

OpenSSL 1.1.0与QT不兼容,所以我克隆了1.0.1的稳定版本:下面是bug: https://bugreports.qt.io/browse/QTBUG-52905
git clone https://github.com/openssl/openssl -b OpenSSL_1_0_1-stable

然后安装到自定义位置:

./config --prefix=/opt/openssl-stable
make
make test
sudo make install

获取QT源代码,然后当你想要构建它们时,你必须链接已安装的OpenSSL:

OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked

见:http://doc.qt.io/qt-5/ssl.html

这是我的配置:

OPENSSL_LIBS='-L/opt/openssl-stable/lib -lssl -lcrypto' ./configure -prefix /opt/qt5.7_linux_staticssl -opensource -confirm-license -release -openssl-linked -I /opt/openssl-stable/include/openssl -L /opt/openssl-stable/lib

,如果qt构建给你一个错误,它没有找到一些SSL结构,只是复制/opt/openssl-stable/include/openssl头到/usr/include/openssl或qt正在寻找他们的地方(你可以看到,当qt构建失败时)

就这样了