QSslPreSharedKeyAuthenticator Class▲
-
Header: QSslPreSharedKeyAuthenticator
-
Since: Qt 5.5
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
-
qmake: QT += network
-
Group: QSslPreSharedKeyAuthenticator is part of Network Programming API, ssl, shared
Detailed Description▲
The QSslPreSharedKeyAuthenticator class is used by an SSL socket to provide the required authentication data in a pre shared key (PSK) ciphersuite.
In a PSK handshake, the client must derive a key, which must match the key set on the server. The exact algorithm of deriving the key depends on the application; however, for this purpose, the server may send an identity hint to the client. This hint, combined with other information (for instance a passphrase), is then used by the client to construct the shared key.
The QSslPreSharedKeyAuthenticator provides means to client applications for completing the PSK handshake. The client application needs to connect a slot to the QSslSocket::preSharedKeyAuthenticationRequired() signal:
connect(socket, &
amp;QSslSocket::
preSharedKeyAuthenticationRequired,
this
, &
amp;AuthManager::
handlePreSharedKeyAuthentication);
The signal carries a QSslPreSharedKeyAuthenticator object containing the identity hint the server sent to the client, and which must be filled with the corresponding client identity and the derived key:
void
AuthManager::
handlePreSharedKeyAuthentication(QSslPreSharedKeyAuthenticator *
authenticator)
{
authenticator-&
gt;setIdentity("My Qt App"
);
const
QByteArray key =
deriveKey(authenticator-&
gt;identityHint(), passphrase);
authenticator-&
gt;setPreSharedKey(key);
}
PSK ciphersuites are supported only when using OpenSSL 1.0.1 (or greater) as the SSL backend.
PSK is currently only supported in OpenSSL.
See Also▲
See also QSslSocket
Member Function Documentation▲
QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator()▲
The identity hint, the identity and the key will be initialized to empty byte arrays; the maximum length for both the identity and the key will be initialized to 0.
QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator)▲
QSslPreSharedKeyAuthenticator::~QSslPreSharedKeyAuthenticator()▲
QByteArray QSslPreSharedKeyAuthenticator::identity() const▲
QByteArray QSslPreSharedKeyAuthenticator::identityHint() const▲
Returns the PSK identity hint as provided by the server. The interpretation of this hint is left to the application.
int QSslPreSharedKeyAuthenticator::maximumIdentityLength() const▲
Returns the maximum length, in bytes, of the PSK client identity.
it is possible to set an identity whose length is greater than maximumIdentityLength(); in this case, only the first maximumIdentityLength() bytes will be actually sent to the server.
See Also▲
See also setIdentity()
int QSslPreSharedKeyAuthenticator::maximumPreSharedKeyLength() const▲
it is possible to set a key whose length is greater than the maximumPreSharedKeyLength(); in this case, only the first maximumPreSharedKeyLength() bytes will be actually sent to the server.
See Also▲
See also setPreSharedKey()
QByteArray QSslPreSharedKeyAuthenticator::preSharedKey() const▲
See Also▲
See also setPreSharedKey()
void QSslPreSharedKeyAuthenticator::setIdentity(const QByteArray &identity)▲
Sets the PSK client identity (to be advised to the server) to identity.
it is possible to set an identity whose length is greater than maximumIdentityLength(); in this case, only the first maximumIdentityLength() bytes will be actually sent to the server.
See Also▲
See also identity(), maximumIdentityLength()
void QSslPreSharedKeyAuthenticator::setPreSharedKey(const QByteArray &preSharedKey)▲
it is possible to set a key whose length is greater than the maximumPreSharedKeyLength(); in this case, only the first maximumPreSharedKeyLength() bytes will be actually sent to the server.
See Also▲
See also preSharedKey(), maximumPreSharedKeyLength(), QByteArray::fromHex()
void QSslPreSharedKeyAuthenticator::swap(QSslPreSharedKeyAuthenticator &authenticator)▲
Swaps the QSslPreSharedKeyAuthenticator object authenticator with this object. This operation is very fast and never fails.
QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(const QSslPreSharedKeyAuthenticator &authenticator)▲
Assigns the QSslPreSharedKeyAuthenticator object authenticator to this object, and returns a reference to the copy.
QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(QSslPreSharedKeyAuthenticator &&authenticator)▲
Move-assigns the QSslPreSharedKeyAuthenticator object authenticator to this object, and returns a reference to the moved instance.
Related Non-Members▲
[since 5.5] bool operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)▲
Returns true if the authenticator object lhs is not equal to rhs; false otherwise.
This function was introduced in Qt 5.5.
[since 5.5] bool operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)▲
Returns true if the authenticator object lhs is equal to rhs; false otherwise.
Two authenticator objects are equal if and only if they have the same identity hint, identity, pre shared key, maximum length for the identity and maximum length for the pre shared key.
This function was introduced in Qt 5.5.