简体   繁体   English

如何使用OpenSSL安装使QSslSocket支持SSL?

[英]How to make QSslSocket support SSL using an OpenSSL installation?

I'm trying to run a simple client/server to implement a communication using QSslSocket. 我正在尝试运行一个简单的客户端/服务器以使用QSslSocket实现通信。 I work on Windows (unfortunately) and I use QtCreator for more convenience. 我在Windows上工作(不幸的是),我使用QtCreator以获得更多的便利。

When I try, from the client side, to connect to the server using MyQSslSocket->connectToHostEncrypted(ip, port) , I get the following message: 当我尝试从客户端使用MyQSslSocket->connectToHostEncrypted(ip, port)连接到服务器时,收到以下消息:

qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed qt.network.ssl:QSslSocket :: connectToHostEncrypted:TLS初始化失败

When I print the raised error, I get the following one: 当我打印引发的错误时,得到以下错误:

QAbstractSocket::SocketError(20) QAbstractSocket :: SocketError(20)

In the documentation we can find that this error code corresponds to QAbstractSocket::SslInternalError whose the description is: 在文档中,我们可以发现此错误代码对应于QAbstractSocket::SslInternalError ,其描述为:

"The SSL library being used reported an internal error. This is probably the result of a bad installation or misconfiguration of the library." “正在使用的SSL库报告内部错误。这可能是由于库安装错误或配置错误造成的。”

After some investigations I found that Qt does not provide OpenSSL by itself so I installed it (the binaries, for both 32 and 64 bits versions to be sure) from here https://slproweb.com/products/Win32OpenSSL.html . 经过一番调查后,我发现Qt本身并不提供OpenSSL,因此我从https://slproweb.com/products/Win32OpenSSL.html安装了它(二进制文件,以确保32位和64位版本)。
During the installation, the dll was copied to C:\\Windows\\System32 (for the 64 bits). 在安装过程中,该dll被复制到C:\\ Windows \\ System32(64位)。 Then I checked that the PATH environment variable does well contain this folder. 然后,我检查了PATH环境变量是否很好地包含了该文件夹。

At this point I tried again, but I still had the same problem, as if the OpenSSL installation was still not found. 此时,我再次尝试,但是仍然遇到相同的问题,好像仍然找不到OpenSSL安装。

When I print the output of the following calls (in the main function of my client): 当我打印以下调用的输出时(在客户端的主要功能中):

qDebug() << QSslSocket::supportsSsl();
qDebug() << QSslSocket::sslLibraryVersionString();

I get the following outputs: 我得到以下输出:

false
""

My question is, how to make QSslSocket::supportsSsl() return true ? 我的问题是,如何使QSslSocket::supportsSsl()返回true?

If anyone could teach me what I missed, what I am doing wrong and tell me what I should do to be able to make this SSL connection run properly, I would be very grateful. 如果有人能教给我我所错过的东西,我做错了什么并告诉我应该如何做才能使此SSL连接正常运行,我将不胜感激。

Fareanor. 法雷诺。

PS: Sorry for the long question but I think it is important to clearly expose the problem and the context to help you to easily understand the problem and give me more relevant answers. PS:对很长的问题很抱歉,但我认为重要的是要清楚地揭示问题和背景,以帮助您轻松理解问题并为我提供更多相关的答案。

Ok, Thanks to @AlienPenguin and @Macias advices, it was that my version of OpenSSL was too recent. 好的,感谢@AlienPenguin和@Macias的建议,这是因为我的OpenSSL版本太新了。

Finally I have installed the closest available version of the one used for the Qt build (which does make sense, I should have thought of it) which can be found by running the following call: 最后,我安装了用于Qt构建的版本的最接近的可用版本(这确实有意义,我应该考虑过),可以通过运行以下调用找到该版本:

qDebug() << QSslSocket::sslLibraryBuildVersionString();

Problem solved. 问题解决了。

Thanks again. 再次感谢。

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

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