标签:没有 lse qt5 bin release x86 protoc tps abstract
使用Qt的https(get,post,put等)请求时报
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
错误。
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed.
void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port,
const QString &sslPeerName, OpenMode mode,
NetworkLayerProtocol protocol)
{
...
if (!supportsSsl()) {
qCWarning(lcSsl, "QSslSocket::connectToHostEncrypted: TLS initialization failed");
d->setErrorAndEmit(QAbstractSocket::SslInternalError, tr("TLS initialization failed"));
return;
}
d->init();
...
}
supportsSsl
函数返回false时打印错误(警告)信息,就不再执行后续操作了,于是继续查看supportsSsl
函数。/* 如果此平台支持SSL,则返回true;否则,返回false。
* 如果平台不支持SSL,套接字将失败在连接阶段。
*/
bool QSslSocket::supportsSsl()
{
return QSslSocketPrivate::supportsSsl();
}
bool QSslSocketPrivate::supportsSsl()
{
return ensureLibraryLoaded();
}
ensureLibraryLoaded
实现。bool QSslSocketPrivate::ensureLibraryLoaded()
{
if (!q_resolveOpenSslSymbols())
return false;
...
return true;
}
loadOpenSslWin32
加载SSL库函数。bool q_resolveOpenSslSymbols()
{
...
#ifdef Q_OS_WIN
QPair<QSystemLibrary *, QSystemLibrary *> libs = loadOpenSslWin32();
#else
QPair<QLibrary *, QLibrary *> libs = loadOpenSsl();
#endif
if (!libs.first || !libs.second)
// failed to load them
return false;
...
loadOpenSslWin32
实现。static QPair<QSystemLibrary*, QSystemLibrary*> loadOpenSslWin32()
{
...
#if QT_CONFIG(opensslv11)
// With OpenSSL 1.1 the names have changed to libssl-1_1(-x64) and libcrypto-1_1(-x64), for builds using
// MSVC and GCC, (-x64 suffix for 64-bit builds).
#ifdef Q_PROCESSOR_X86_64
#define QT_SSL_SUFFIX "-x64"
#else // !Q_PROCESSOFR_X86_64
#define QT_SSL_SUFFIX
#endif // !Q_PROCESSOR_x86_64
tryToLoadOpenSslWin32Library(QLatin1String("libssl-1_1" QT_SSL_SUFFIX),
QLatin1String("libcrypto-1_1" QT_SSL_SUFFIX), pair);
#undef QT_SSL_SUFFIX
#else // QT_CONFIG(opensslv11)
// When OpenSSL is built using MSVC then the libraries are named 'ssleay32.dll' and 'libeay32'dll'.
// When OpenSSL is built using GCC then different library names are used (depending on the OpenSSL version)
// The oldest version of a GCC-based OpenSSL which can be detected by the code below is 0.9.8g (released in 2007)
if (!tryToLoadOpenSslWin32Library(QLatin1String("ssleay32"), QLatin1String("libeay32"), pair)) {
if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-10"), QLatin1String("libcrypto-10"), pair)) {
if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-8"), QLatin1String("libcrypto-8"), pair)) {
tryToLoadOpenSslWin32Library(QLatin1String("libssl-7"), QLatin1String("libcrypto-7"), pair);
}
}
}
#endif // !QT_CONFIG(opensslv11)
return pair;
}
opensslv11
,所以加载以下的SSL库操作。依次查找ssleay32
和libeay32
,如果没有找到就查找libssl-10
和libcrypto-10
依此类推直到libssl-7
和libcrypto-7
。if (!tryToLoadOpenSslWin32Library(QLatin1String("ssleay32"), QLatin1String("libeay32"), pair)) {
if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-10"), QLatin1String("libcrypto-10"), pair)) {
if (!tryToLoadOpenSslWin32Library(QLatin1String("libssl-8"), QLatin1String("libcrypto-8"), pair)) {
tryToLoadOpenSslWin32Library(QLatin1String("libssl-7"), QLatin1String("libcrypto-7"), pair);
}
}
}
ssleay32
和libeay32
库放到运行目录下即解决了问题。ssleay32
和libeay32
路径链接,而打包程序又没有复制SSL库,导致移植到其他电脑的SSL功能不正常的问题。Dependency Walker工具也找不到依赖的库,因为它是运行时加载的库。注:Dependency Walker可以扫描任何32位或64位Windows模块exe,dll,ocx,sys等,并构建所有对象的层次结构树图。
https://slproweb.com/products/Win32OpenSSL.html
https://github.com/openssl/openssl
C:\Qt\Qt5.12.1\Tools\mingw730_64\opt\bin
标签:没有 lse qt5 bin release x86 protoc tps abstract
原文地址:https://www.cnblogs.com/qthub/p/12181347.html