使用OpenSSL 1.1.1d静态编译的Qt 5.13.1产生QSslSocket :: connectToHostEncrypted:TLS初始化失败 [英] Statically compiled Qt 5.13.1 with OpenSSL 1.1.1d producing QSslSocket::connectToHostEncrypted: TLS initialization failed
问题描述
我要实现什么目标?
我需要创建一个具有SSL支持的便携式(多合一)应用程序.
I need to create a portable (all-in-one) application, with SSL support.
出了什么问题?
所以我面临的核心问题是要在我的二进制/便携式应用程序中包含SSL支持.
So the core problem I am facing is getting SSL support included into my binary/portable app.
该应用程序的 MCVE 很简单:
项目.pro
文件
QT -= gui
QT += network
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += \
main.cpp
INSTALLS += target
项目main.cpp
#include <QCoreApplication>
#include <QSslSocket>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Is SSL Enabled? " << QSslSocket::supportsSsl();
qDebug() << "SSL Library Build Version (Qt compiled against): " << QSslSocket::sslLibraryBuildVersionString();
qDebug() << "SSL Library Version String (available locally): " << QSslSocket::sslLibraryVersionString();
return a.exec();
}
-
我的 DEV计算机上的输出:
Output on my DEV machine:
Is SSL Enabled? true
SSL Library Build Version (Qt compiled against): "OpenSSL 1.1.1d 10 Sep 2019"
SSL Library Version String (available locally): "OpenSSL 1.1.1d 10 Sep 2019"
开发人员信息
C:\Users\cybex>echo %PATH%
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin
C:\Users\cybex>openssl
WARNING: can't open config file: /z/extlib/_openssl_/ssl/openssl.cnf
OpenSSL> version
OpenSSL 1.0.2g 1 Mar 2016
-
在新的Windows 10 x86计算机上运行相同的二进制文件会导致:
Running the same binary on a fresh Windows 10 x86 machine results in:
Is SSL Enabled? false
SSL Library Build Version (Qt compiled against): "OpenSSL 1.1.1d 10 Sep 2019"
SSL Library Version String (available locally): ""
测试机信息(完全全新安装-Windows 10 x86)
Info of Test Machine (Completely fresh install - Windows 10 x86)
C:\Users\cybex>echo %PATH%
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Users\cybex>openssl
'openssl' is not recognized as an internal or external command,
operable program or batch file.
-
在新的Windows 7 x64计算机上运行相同的二进制文件会导致:
Running the same binary on a fresh Windows 7 x64 machine results in:
Is SSL Enabled? false
SSL Library Build Version (Qt compiled against): "OpenSSL 1.1.1d 10 Sep 2019"
SSL Library Version String (available locally): ""
测试机信息(已安装驱动程序的Windows 7 x64笔记本电脑)
Info of Test Machine (Windows 7 x64 laptop with drivers installed)
C:\Users\Home>echo %PATH%
C:\Program Files (x86)\OpenSSL\libs;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\OpenSSL\libs;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\
C:\Users\Home>openssl
'openssl' is not recognized as an internal or external command, operable program or batch file.
通过查看以上结果,我得出结论,安装OpenSSL可解决此问题.很好,但是我想将其包含在便携式应用程序中.
By look at the above results, I conclude that installing OpenSSL solves the problem. Good, but I want need to have it included in my portable app.
要实现这一目标,我必须
In achieving this, I am required to
-
通过OpenSSL支持静态编译Qt
我已经在此脚本的帮助下完成了此操作,该脚本改编自ps1
中找到.我添加了以下内容:
I have done this with the help of this script adapted from ps1
powershell script found here on Qt's wiki. I made additions for:
-
OpenSSL主页
$OPENSSL_HOME
线程数$threads
和
要使用的体系结构类型$arch
.
architecture type $arch
to be used.
配置如下:
cmd /C "configure.bat -static -debug-and-release -platform win32-g++ -prefix $QtDir `
-qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-sqlite -ssl -openssl -I $($OPENSSL_HOME)\include -L$($OPENSSL_HOME)\lib\MinGW`
-opensource -confirm-license `
-make libs -nomake tools -nomake examples -nomake tests -v"
cmd /C "mingw32-make -k -j$($threads)"
注释1:
我正在使用-openssl
而不是-openssl-linked
.我已经尝试使用-openssl
和-openssl-linked
来构建Qt的几种变体. -openssl-linked
永远无法成功构建,请参见
I am using -openssl
and not -openssl-linked
. I have tried several variations of builing Qt with both -openssl
and -openssl-linked
. -openssl-linked
could never successfully build, see this post I made as to the reason why.
注释2:
我唯一成功完成的静态Qt编译是启用了-ssl -openssl
配置标志
The only successful static Qt compilation I had working was with -ssl -openssl
configuration flags enabled
OpenSSL安装位于
OpenSSL installation is at
`$OPENSSL_HOME = "C:\OpenSSL-Win32"`
我正在使用
`$OPENSSL_HOME = "C:\OpenSSL-Win32\lib\MinGW",`
带有文件
Directory: C:\OpenSSL-Win32\lib\MinGW
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2019/09/11 18:11 3347286 libcrypto.a
-a---- 2019/09/11 18:10 109020 libcrypto.def
-a---- 2019/09/11 18:11 385126 libssl.a
-a---- 2019/09/11 18:10 14033 libssl.def
-
将链接项目.pro添加到OpenSSL库
我将OpenSSL库添加到了.pro
文件中(使用针对OpenSSL 1.1.1d构建的预编译Qt-如上所示)
I added the OpenSSL libraries to the .pro
file (using the precompiled Qt built against OpenSSL 1.1.1d - shown above)
QT -= gui
QT += network
INCLUDEPATH += "C:\OpenSSL-Win32\include"
LIBS += -L"C:\OpenSSL-Win32\lib\MinGW\libssl.a"
LIBS += -L"C:\OpenSSL-Win32\lib\MinGW\libcrypto.a"
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += \
main.cpp
INSTALLS += target
注释3
带有和不带有上面链接的库的二进制大小保持不变
带有上面添加的库的二进制文件(在我的开发机上)的LDD输出是:
The LDD output of the binary (on my dev machine) with libraries added above is:
Start-Process -PassThru .\SSL-Test.exe | Get-Process -Module
Size(K) ModuleName FileName
------- ---------- --------
6280 SSL-Test.exe C:\Users\cybex\QtProjects\build-SSL-Test-Desktop_Qt_Op...
1512 ntdll.dll C:\Windows\SYSTEM32\ntdll.dll
596 KERNEL32.DLL C:\Windows\system32\KERNEL32.DLL
1500 KERNELBASE.dll C:\Windows\system32\KERNELBASE.dll
具有上面添加的库的二进制文件(在Windows 10 x86测试机上)的LDD输出为:
The LDD output of the binary (on my Windows 10 x86 test machine) with libraries added above is:
Start-Process -PassThru .\SSL-Test.exe | Get-Process -Module
Size(K) ModuleName FileName
------- ---------- --------
6280 SSL-Test.exe C:\Users\cybex\Desktop\SSL-Test.exe
1512 ntdll.dll C:\Windows\SYSTEM32\ntdll.dll
596 KERNEL32.DLL C:\Windows\system32\KERNEL32.DLL
1500 KERNELBASE.dll C:\Windows\system32\KERNELBASE.dll
两个 SSL信息输出都是相同的
在非Dev设备上请求SSL连接时的输出是
The output when requesting a SSL connection on Non-Dev machines are
QSslSocket :: connectToHostEncrypted:TLS初始化失败
QSslSocket::connectToHostEncrypted: TLS initialization failed
这是未包含OpenSSL库的结果.
which is the result of the OpenSSL libary not being included.
因此,基本上,将静态OpenSSL库添加到项目文件不起作用还是我做错了吗?
So basically, adding a static OpenSSL library to the project file does not work or am I doing it incorrectly?
推荐答案
我认为您需要在测试计算机上安装openSSL,可以从此处进行操作 https://code.google.com/archive/p/openssl- for-windows/下载
I think you need to install an openSSL on your test machine, can do that from here https://code.google.com/archive/p/openssl-for-windows/downloads
这篇关于使用OpenSSL 1.1.1d静态编译的Qt 5.13.1产生QSslSocket :: connectToHostEncrypted:TLS初始化失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!