QSslPreSharedKeyAuthenticator Class
QSslPreSharedKeyAuthenticator 类为预共享密钥(PSK)密码套件提供验证数据。更多
头文件: | #include <QSslPreSharedKeyAuthenticator> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
- 所有成员(包括继承成员)的列表
- QSslPreSharedKeyAuthenticator 属于网络编程 API和隐式共享类。
注意:该类中的所有函数都是可重入的。
公共函数
QSslPreSharedKeyAuthenticator() | |
QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator) | |
~QSslPreSharedKeyAuthenticator() | |
QByteArray | identity() const |
QByteArray | identityHint() const |
int | maximumIdentityLength() const |
int | maximumPreSharedKeyLength() const |
QByteArray | preSharedKey() const |
void | setIdentity(const QByteArray &identity) |
void | setPreSharedKey(const QByteArray &preSharedKey) |
void | swap(QSslPreSharedKeyAuthenticator &other) |
QSslPreSharedKeyAuthenticator & | operator=(QSslPreSharedKeyAuthenticator &&authenticator) |
QSslPreSharedKeyAuthenticator & | operator=(const QSslPreSharedKeyAuthenticator &authenticator) |
相关非成员
bool | operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs) |
bool | operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs) |
详细说明
SSL 套接字使用 QSslPreSharedKeyAuthenticator 类在预共享密钥(PSK)密码套件中提供所需的验证数据。
在 PSK 握手过程中,客户端必须导出一个密钥,该密钥必须与服务器上设置的密钥相匹配。获取密钥的具体算法取决于应用;不过,为此目的,服务器可向客户端发送一个身份提示。然后,客户端使用该提示和其他信息(如口令)来构建共享密钥。
QSslPreSharedKeyAuthenticator 为客户端应用程序提供了完成 PSK 握手的方法。客户端应用程序需要将一个插槽连接到QSslSocket::preSharedKeyAuthenticationRequired() 信号:
connect(socket, &QSslSocket::preSharedKeyAuthenticationRequired, this, &AuthManager::handlePreSharedKeyAuthentication);
该信号携带一个 QSslPreSharedKeyAuthenticator 对象,其中包含服务器发送给客户端的身份提示,而且必须填写相应的客户端身份和派生密钥:
void AuthManager::handlePreSharedKeyAuthentication(QSslPreSharedKeyAuthenticator *authenticator) { authenticator->setIdentity("My Qt App"); const QByteArray key = deriveKey(authenticator->identityHint(), passphrase); authenticator->setPreSharedKey(key); }
注: 只有在使用 OpenSSL 1.0.1(或更高版本)作为 SSL 后端时,才支持 PSK 密码套件。
注: 目前只有 OpenSSL 支持 PSK。
另请参阅 QSslSocket 。
成员函数文档
QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator()
构造默认的 QSslPreSharedKeyAuthenticator 对象。
身份提示、身份和密钥将被初始化为空字节数组;身份和密钥的最大长度将被初始化为 0。
QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator)
构造一个 QSslPreSharedKeyAuthenticator 对象,作为authenticator 的副本。
另请参阅 operator=().
[noexcept]
QSslPreSharedKeyAuthenticator::~QSslPreSharedKeyAuthenticator()
销毁QSslPreSharedKeyAuthenticator 对象。
QByteArray QSslPreSharedKeyAuthenticator::identity() const
返回 PSK 客户身份。
另请参阅 setIdentity()。
QByteArray QSslPreSharedKeyAuthenticator::identityHint() const
返回服务器提供的 PSK 身份提示。该提示的解释权归应用程序所有。
int QSslPreSharedKeyAuthenticator::maximumIdentityLength() const
返回 PSK 客户端标识的最大长度(以字节为单位)。
注意: 可以设置一个长度大于 maximumIdentityLength() 的标识;在这种情况下,只有第一个 maximumIdentityLength() 字节会实际发送到服务器。
另请参阅 setIdentity()。
int QSslPreSharedKeyAuthenticator::maximumPreSharedKeyLength() const
返回预共享密钥的最大长度(以字节为单位)。
注意: 可以设置一个长度大于 maximumPreSharedKeyLength() 的密钥;在这种情况下,只有第一个 maximumPreSharedKeyLength() 字节会被发送到服务器。
另请参阅 setPreSharedKey()。
QByteArray QSslPreSharedKeyAuthenticator::preSharedKey() const
返回预共享密钥。
另请参见 setPreSharedKey()。
void QSslPreSharedKeyAuthenticator::setIdentity(const QByteArray &identity)
将 PSK 客户身份(将告知服务器)设置为identity 。
注意: 可以设置一个长度大于maximumIdentityLength() 的身份;在这种情况下,只有第一个maximumIdentityLength() 字节会实际发送到服务器。
另请参阅 identity() 和maximumIdentityLength()。
void QSslPreSharedKeyAuthenticator::setPreSharedKey(const QByteArray &preSharedKey)
将预共享密钥设置为preSharedKey 。
注意: 可以设置一个长度大于maximumPreSharedKeyLength() 的密钥;在这种情况下,只有第一个maximumPreSharedKeyLength() 字节会实际发送到服务器。
另请参阅 preSharedKey()、maximumPreSharedKeyLength() 和QByteArray::fromHex()。
[noexcept]
void QSslPreSharedKeyAuthenticator::swap(QSslPreSharedKeyAuthenticator &other)
将该验证器与other 互换。这一操作非常快速,从未出现过故障。
[noexcept]
QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(QSslPreSharedKeyAuthenticator &&authenticator)
移动 - 将QSslPreSharedKeyAuthenticator 对象authenticator 分配给此对象,并返回移动实例的引用。
QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(const QSslPreSharedKeyAuthenticator &authenticator)
将QSslPreSharedKeyAuthenticator 对象authenticator 指派给此对象,并返回该副本的引用。
相关非成员
bool operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)
如果验证器对象lhs 不等于rhs ,则返回true
;否则返回false
。
bool operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)
如果身份验证器对象lhs 等于rhs ,则返回true
;否则返回false
。
当且仅当两个身份验证器对象具有相同的身份提示、身份、预共享密钥、身份的最大长度和预共享密钥的最大长度时,它们才是相等的。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.