简体   繁体   English

如何在Windows上为Qt安装OpenSSL 1.1.0?

[英]How to install OpenSSL 1.1.0 for Qt on Windows?

My goal is to get the source code (or images) from a webpage over a SSL connection using QNetworkRequest with the QNetworkAccessManager . 我的目标是使用QNetworkRequestQNetworkAccessManager通过SSL连接从网页上获取源代码(或图像)。

OpenSSL 1.1.0 doesn't work with Qt 5.8! OpenSSL 1.1.0不适用于Qt 5.8! Look in Edit 2 for the install solution! 在Edit 2中查找安装解决方案!

First Try: Get the ssleay32.lib and the libeay32.lib and copy them into the debug and the release folder. 首先尝试:获取ssleay32.lib和libeay32.lib并将它们复制到debug和release文件夹中。 Dont work. 不要工作

Second Try: (deleted because it's nonsense) But it doesnt work again. 第二次尝试:(由于废话而删除),但是它不再起作用。

Code (works fine for normal http): 代码(适用于正常的http):

QUrl url = QUrl(name);
data.clear();

QNetworkRequest *request = new QNetworkRequest(url);
request->setRawHeader("User-Agent", userAgent);

QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfiguration());
request->setSslConfiguration(sslConfiguration);

reply = webCtrl->get(*request);

connect(webCtrl, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));

Error Messages: 错误讯息:

qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
Error creating SSL context ()

Edit 1: I found this Artikel and OpenSSL 1.1.0 will be working with Qt 5.10 but not in Qt 5.8 what I am using. 编辑1:我发现 Artikel和OpenSSL 1.1.0将与Qt 5.10一起使用,但在Qt 5.8中无法使用。 And in this Artikel I found the QSslSocket::sslLibraryBuildVersionString() command and I Need OpenSSL Version: OpenSSL 1.0.2h 3 May 2016 . Artikel中,我找到了QSslSocket::sslLibraryBuildVersionString()命令,我需要OpenSSL版本: OpenSSL 1.0.2h 3 May 2016

I will checkout the other OpenSSL Version later and edit this post if it is working or not. 稍后,我将签出其他OpenSSL版本,并编辑此帖子(不管它是否有效)。

Edit 2: Download OpenSSL 1.0.2h 3 May 2016 and Install 7zip and Perl. 编辑2: OpenSSL 1.0.2h 3 May 2016下载OpenSSL 1.0.2h 3 May 2016然后安装7zip和Perl。 Extract the openSSL folder and follow INSTALL.W64 . 解压缩openSSL文件夹,然后按照INSTALL.W64 Go to the bin folder and copy libeay32-xxx.dll and ssleay32-xxx.dll to the application folder and rename the files to libeay32.dll and ssleay32.dll . 转到bin文件夹,将libeay32-xxx.dllssleay32-xxx.dll到应用程序文件夹,并将文件重命名为libeay32.dllssleay32.dll Thanks @[Max Go]. 谢谢@ [Max Go]。

Now the SSL connection finaly works, but I get an error message when I Close the application and the web connection was used at runtime. 现在,SSL连接最终完成了,但是当我关闭应用程序并且在运行时使用了Web连接时,我收到一条错误消息。

Exception at 0x000000007772D1CB (ntdll.dll) in onlineTest.exe: 0xC0000005: Access Violation reading position 0x0000000000000074. onlineTest.exe中0x000000007772D1CB(ntdll.dll)处的异常:0xC0000005:访问冲突读取位置0x0000000000000074。

VS2015 Debug Window "mem.c" line 443: VS2015调试窗口“ mem.c”行443:

  1. free_debug_func 0x0000000000000000 void(*)(void *, int)
  2. free_func 0x000007fee778b1ba {libeay32.dll!free} void(*)(void *)
  3. str 0x0000000002500cf0 void *

Edit 3: I forgot to compile the -d debug .dll's. 编辑3:我忘了编译-d调试.dll。 Simply change the compiler mode to Debug, generate the Debug .dll's, rename if needed without the -d and then copy the debug .dll's into the debug folder and the normal .dll's into the release folder. 只需将编译器模式更改为Debug,生成Debug .dll,然后在不使用-d的情况下重命名(如果需要),然后将debug .dll复制到debug文件夹,将普通.dll复制到release文件夹。

Here's the script I use to build OpenSSL automatically from a Visual Studio prompt. 这是我用来从Visual Studio提示自动构建OpenSSL的脚本。 It will build either a 32 or 64 bit library, depending on what compiler is enabled. 根据启用的编译器,它将构建32位或64位库。

Prerequisites (must be in PATH): 前提条件(必须在PATH中):

  • Active Perl 主动式Perl
  • 7zip 7zip
  • NASM 美国宇航局
  • Visual Studio 2015 or 2017 (I didn't test with anything else) Visual Studio 2015或2017(我没有进行任何其他测试)
  • jom (optional) jom(可选)
:: Configurable Options
:: If you have jom available, set it to jom - it speeds up the build.
@set JOM=nmake
:: Choose a static or dynamic build
@set LIBTYPE=dynamic
:: OpenSSL version in the 1.0.2 series
@set SRC=openssl-1.0.2k

@if "%VSCMD_ARG_TGT_ARCH%"=="x86" (
    @set BITS=32
    @set DST=OpenSSL-Win32
    @set CONFIG=VC-WIN32
    @set SETUP=ms\do_nasm
) else if "%VSCMD_ARG_TGT_ARCH%"=="x64" (
    @set BITS=64
    @set DST=OpenSSL-Win64
    @set CONFIG=VC-WIN64A
    @set SETUP=ms\do_win64a
) else goto no_vscmd

@if "%LIBTYPE%"=="static" (
    @set LIBTYPE=nt
) else if "%LIBTYPE%"=="dynamic" (
    @set LIBTYPE=ntdll
) else goto no_libtype

@echo Building %SRC% for %BITS% bits.

@echo - Downloading
@perl ^
    -e "use LWP::Simple;" ^
    -e "mirror('https://www.openssl.org/source/%SRC%.tar.gz', '%SRC%.tar.gz');"

@echo - Decompressing
@if not exist %SRC%.tar.gz goto no_archive
@rmdir /S /Q %SRC% %DST% 2>NUL
@7z x -bsp2 -y %SRC%.tar.gz >NUL && ^
7z x -bsp2 -y %SRC%.tar     >NUL && ^
del %SRC%.tar
@if errorlevel 1 goto unpack_failed
@if not exist %SRC% goto no_source

@echo - Building
@pushd %SRC%
@perl Configure %CONFIG% --prefix=%~dp0..\%DST% && ^
call %SETUP% && ^
nmake -f ms\%LIBTYPE%.mak init && ^
%JOM% -f ms\%LIBTYPE%.mak "CC=cl /FS" && ^
%JOM% -f ms\%LIBTYPE%.mak test && ^
nmake -f ms\%LIBTYPE%.mak install || goto build_failed
@popd
@rmdir /S /Q %SRC%

@echo Build has succeeded.
@goto :eof

:no_libtype
@echo Error: LIBTYPE must be either "static" or "dynamic">&2
@exit /b 1    

:no_archive
@echo Error: can't find %SRC%.tar.gz - the download has failed :(>&2
@exit /b 1

:unpack_failed
@echo Error: unpacking has failed.>&2
@exit /b %errorlevel%

:no_source
@echo Error: can't find %SRC%\>&2
@exit /b 1

:build_failed
@echo The build had failed.>&2
@popd
@exit /b 2

:no_vscmd
@echo Use vcvarsall x86 or vcvarsall x64 to set up the Visual Studio>&2
@echo build environment first.>&2
@exit /b 100

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM