SSL (安全套接字层) 类

The classes below provide support for secure network communication using the Secure Sockets Layer (SSL) protocol, using a native TLS backend, the OpenSSL 工具包 ,或任何适当 TLS 插件以履行加密和协议处理。

从 Qt 5.15 起,OpenSSL 官方支持版是 1.1.1 或更高版本。

Qt version 5.15.1 onward is also compatible with OpenSSL 3.

QDtls

此类为 UDP (用户数据报协议) 套接字提供加密

QDtlsClientVerifier

此类实现服务器侧 DTLS Cookie 的生成和验证

QDtlsClientVerifier::GeneratorParameters

此类定义用于 DTLS Cookie 生成器的参数

QOcspResponse

此类表示在线证书状态协议响应

QSsl

声明 Qt Network 中所有 SSL 类公用的枚举

QSslCertificate

用于 X509 证书的便捷 API

QSslCertificateExtension

用于访问 X509 证书扩展名的 API

QSslCipher

表示 SSL 加密密码

QSslConfiguration

保持 SSL 连接的配置和状态

QSslDiffieHellmanParameters

用于服务器的 Diffie-Hellman 参数的接口

QSslEllipticCurve

表示供椭圆曲线密码算法使用的椭圆曲线

QSslError

SSL 错误

QSslKey

用于私钥和公钥的接口

QSslPreSharedKeyAuthenticator

用于 PSK (预共享密钥) 密码套件的身份验证数据

QSslServer

通过 TLS (传输层安全) 实现加密的、安全 TCP 服务器

QSslSocket

用于客户端和服务器两者的 SSL 加密套接字

QSslSocket::AlertLevel

描述警报消息的级别

QSslSocket::AlertType

枚举警报消息可以拥有的可能代码

QDtls::HandshakeState

描述 DTLS 握手的当前状态

QSslSocket::ImplementedClass

枚举 TLS (传输层安全) 后端实现的类

QDtls::QDtlsError

描述通过 QDtls 和 QDtlsClientVerifier 发现的错误

QOcspResponse::QOcspCertificateStatus

描述在线证书状态

QOcspResponse::QOcspRevocationReason

描述撤销的原因

QSslSocket::SupportedFeature

枚举 TLS (传输层安全) 后端支持的可能特征

For Android applications see 为 Android 添加 OpenSSL 支持 .

从源代码构建 Qt 时启用/禁用 SSL 支持

When building Qt from source, Qt builds plugins for native TLS libraries that are supported for the operating system you are building for. For Windows this means Schannel ,而对于 macOS 这是 Secure Transport .

在所有平台,配置系统校验是否存在 openssl/opensslv.h header provided by source or developer packages of OpenSSL. If found, it will enable and build the OpenSSL backend for Qt.

默认情况下,启用 OpenSSL 的 Qt 库在运行时会动态加载任何安装的 OpenSSL 库。不管怎样,在编译时链接到库是可能的通过配置 Qt 采用 -openssl-linked 选项。

When building a version of Qt linked against OpenSSL, Qt's build system will use CMake's FindOpenSSL command to find OpenSSL in several standard locations. You can set the CMake variable OPENSSL_ROOT_DIR to force a specific location.

例如:

configure -openssl-linked -- -D OPENSSL_ROOT_DIR=<openssl_dir>
					

要禁用 SSL 支持在 Qt 构建中,配置 Qt 采用 -no-openssl 选项。

打包应用程序时的注意事项

When you package your application, you may run a tool like windeployqt 。这将要使用的所有库插件拷贝到 plugins/ folder. However, for TLS you only need one backend, and you may delete the other plugins before packaging your application. For example, if you're on Windows and don't require any of the extra features the OpenSSL backend provides, you can choose to forego shipping the qopensslbackend plugin as well as the OpenSSL library, and simply ship the qschannelbackend 插件。

不管怎样,随附多个后端不是问题。Qt 将试图按次序加载后端 (首先尝试 OpenSSL),直到成功加载一个后端为止。就不再使用其它后端。

安全数据报传输层

DTLS (安全数据报传输层) 是为基于数据报的应用程序,提供防窃听、防篡改或防消息伪造保护的一种安全协议。DTLS 协议基于面向流的 TLS (传输层安全) 协议。 QtNetwork 使能够使用采用 UDP (用户数据报协议) 的 DTLS,作为定义通过 RFC 6347 .

进出口限定

Qt 二进制安装程序包括的 OpenSSL 库,使用要通过 QtNetwork 。不管怎样,这些不会自动部署到采用 Qt 构建的应用程序中。进出口限定适用于某些类型的软件,也适用于世界某些地区。希望在部署应用程序中使用 SSL 通信的开发者应确保其用户有安装合适的库,或者,他们应咨询具备适当资格的法律专业人士,以确保使用 OpenSSL 工程代码的应用程序在世界相关地区得到正确进出口认证。