Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QSslPreSharedKeyAuthenticator Class Reference

The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) ciphersuites. More...

#include <qsslpresharedkeyauthenticator.h>

+ Collaboration diagram for QSslPreSharedKeyAuthenticator:

Public Member Functions

Q_NETWORK_EXPORT QSslPreSharedKeyAuthenticator ()
 Constructs a default QSslPreSharedKeyAuthenticator object.
 
Q_NETWORK_EXPORT ~QSslPreSharedKeyAuthenticator ()
 Destroys the QSslPreSharedKeyAuthenticator object.
 
Q_NETWORK_EXPORT QSslPreSharedKeyAuthenticator (const QSslPreSharedKeyAuthenticator &authenticator)
 Constructs a QSslPreSharedKeyAuthenticator object as a copy of authenticator.
 
Q_NETWORK_EXPORT QSslPreSharedKeyAuthenticatoroperator= (const QSslPreSharedKeyAuthenticator &authenticator)
 Assigns the QSslPreSharedKeyAuthenticator object authenticator to this object, and returns a reference to the copy.
 
QSslPreSharedKeyAuthenticatoroperator= (QSslPreSharedKeyAuthenticator &&other) noexcept
 Move-assigns the QSslPreSharedKeyAuthenticator object authenticator to this object, and returns a reference to the moved instance.
 
void swap (QSslPreSharedKeyAuthenticator &other) noexcept
 Swaps the QSslPreSharedKeyAuthenticator object authenticator with this object.
 
Q_NETWORK_EXPORT QByteArray identityHint () const
 Returns the PSK identity hint as provided by the server.
 
Q_NETWORK_EXPORT void setIdentity (const QByteArray &identity)
 Sets the PSK client identity (to be advised to the server) to identity.
 
Q_NETWORK_EXPORT QByteArray identity () const
 Returns the PSK client identity.
 
Q_NETWORK_EXPORT int maximumIdentityLength () const
 Returns the maximum length, in bytes, of the PSK client identity.
 
Q_NETWORK_EXPORT void setPreSharedKey (const QByteArray &preSharedKey)
 Sets the pre shared key to preSharedKey.
 
Q_NETWORK_EXPORT QByteArray preSharedKey () const
 Returns the pre shared key.
 
Q_NETWORK_EXPORT int maximumPreSharedKeyLength () const
 Returns the maximum length, in bytes, of the pre shared key.
 

Friends

class QTlsBackend
 
bool operator== (const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)
 
bool operator!= (const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)
 

Detailed Description

The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) ciphersuites.

\inmodule QtNetwork

\reentrant

Since
5.5

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:

this, &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->setIdentity("My Qt App");
const QByteArray key = deriveKey(authenticator->identityHint(), passphrase);
authenticator->setPreSharedKey(key);
}
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
Q_NETWORK_EXPORT void setIdentity(const QByteArray &identity)
Sets the PSK client identity (to be advised to the server) to identity.
Q_NETWORK_EXPORT QByteArray identityHint() const
Returns the PSK identity hint as provided by the server.
Q_NETWORK_EXPORT void setPreSharedKey(const QByteArray &preSharedKey)
Sets the pre shared key to preSharedKey.
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
connect(socket, &QSslSocket::preSharedKeyAuthenticationRequired, this, &AuthManager::handlePreSharedKeyAuthentication)
[0]
Note
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
QSslSocket

Definition at line 17 of file qsslpresharedkeyauthenticator.h.

Constructor & Destructor Documentation

◆ QSslPreSharedKeyAuthenticator() [1/2]

QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator ( )

Constructs a default QSslPreSharedKeyAuthenticator object.

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.

Definition at line 76 of file qsslpresharedkeyauthenticator.cpp.

◆ ~QSslPreSharedKeyAuthenticator()

QSslPreSharedKeyAuthenticator::~QSslPreSharedKeyAuthenticator ( )

Destroys the QSslPreSharedKeyAuthenticator object.

Definition at line 84 of file qsslpresharedkeyauthenticator.cpp.

◆ QSslPreSharedKeyAuthenticator() [2/2]

QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator ( const QSslPreSharedKeyAuthenticator & authenticator)

Constructs a QSslPreSharedKeyAuthenticator object as a copy of authenticator.

See also
operator=()

Definition at line 93 of file qsslpresharedkeyauthenticator.cpp.

Member Function Documentation

◆ identity()

QByteArray QSslPreSharedKeyAuthenticator::identity ( ) const

Returns the PSK client identity.

See also
setIdentity()

Definition at line 150 of file qsslpresharedkeyauthenticator.cpp.

References QSslPreSharedKeyAuthenticatorPrivate::identity.

Referenced by QDtlsPrivateOpenSSL::pskClientCallback(), QTlsPrivate::TlsCryptographOpenSSL::pskClientTlsCallback(), and setIdentity().

+ Here is the caller graph for this function:

◆ identityHint()

QByteArray QSslPreSharedKeyAuthenticator::identityHint ( ) const

Returns the PSK identity hint as provided by the server.

The interpretation of this hint is left to the application.

Definition at line 126 of file qsslpresharedkeyauthenticator.cpp.

References QSslPreSharedKeyAuthenticatorPrivate::identityHint.

◆ maximumIdentityLength()

int QSslPreSharedKeyAuthenticator::maximumIdentityLength ( ) const

Returns the maximum length, in bytes, of the PSK client identity.

Note
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
setIdentity()

Definition at line 165 of file qsslpresharedkeyauthenticator.cpp.

References QSslPreSharedKeyAuthenticatorPrivate::maximumIdentityLength.

Referenced by QDtlsPrivateOpenSSL::pskClientCallback(), and QTlsPrivate::TlsCryptographOpenSSL::pskClientTlsCallback().

+ Here is the caller graph for this function:

◆ maximumPreSharedKeyLength()

int QSslPreSharedKeyAuthenticator::maximumPreSharedKeyLength ( ) const

Returns the maximum length, in bytes, of the pre shared key.

Note
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
setPreSharedKey()

Definition at line 204 of file qsslpresharedkeyauthenticator.cpp.

References QSslPreSharedKeyAuthenticatorPrivate::maximumPreSharedKeyLength.

Referenced by QDtlsPrivateOpenSSL::pskClientCallback(), QTlsPrivate::TlsCryptographOpenSSL::pskClientTlsCallback(), QDtlsPrivateOpenSSL::pskServerCallback(), and QTlsPrivate::TlsCryptographOpenSSL::pskServerTlsCallback().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

QSslPreSharedKeyAuthenticator & QSslPreSharedKeyAuthenticator::operator= ( const QSslPreSharedKeyAuthenticator & authenticator)

Assigns the QSslPreSharedKeyAuthenticator object authenticator to this object, and returns a reference to the copy.

Definition at line 102 of file qsslpresharedkeyauthenticator.cpp.

◆ operator=() [2/2]

QSslPreSharedKeyAuthenticator & QSslPreSharedKeyAuthenticator::operator= ( QSslPreSharedKeyAuthenticator && other)
inlinenoexcept

Move-assigns the QSslPreSharedKeyAuthenticator object authenticator to this object, and returns a reference to the moved instance.

Definition at line 26 of file qsslpresharedkeyauthenticator.h.

References other(), and swap().

+ Here is the call graph for this function:

◆ preSharedKey()

QByteArray QSslPreSharedKeyAuthenticator::preSharedKey ( ) const

Returns the pre shared key.

See also
setPreSharedKey()

Definition at line 190 of file qsslpresharedkeyauthenticator.cpp.

References QSslPreSharedKeyAuthenticatorPrivate::preSharedKey.

Referenced by QDtlsPrivateOpenSSL::pskClientCallback(), QTlsPrivate::TlsCryptographOpenSSL::pskClientTlsCallback(), QDtlsPrivateOpenSSL::pskServerCallback(), QTlsPrivate::TlsCryptographOpenSSL::pskServerTlsCallback(), and setPreSharedKey().

+ Here is the caller graph for this function:

◆ setIdentity()

void QSslPreSharedKeyAuthenticator::setIdentity ( const QByteArray & identity)

Sets the PSK client identity (to be advised to the server) to identity.

Note
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
identity(), maximumIdentityLength()

Definition at line 140 of file qsslpresharedkeyauthenticator.cpp.

References identity(), and QSslPreSharedKeyAuthenticatorPrivate::identity.

+ Here is the call graph for this function:

◆ setPreSharedKey()

void QSslPreSharedKeyAuthenticator::setPreSharedKey ( const QByteArray & preSharedKey)

Sets the pre shared key to preSharedKey.

Note
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
preSharedKey(), maximumPreSharedKeyLength(), QByteArray::fromHex()

Definition at line 180 of file qsslpresharedkeyauthenticator.cpp.

References preSharedKey(), and QSslPreSharedKeyAuthenticatorPrivate::preSharedKey.

+ Here is the call graph for this function:

◆ swap()

void QSslPreSharedKeyAuthenticator::swap ( QSslPreSharedKeyAuthenticator & authenticator)
inlinenoexcept

Swaps the QSslPreSharedKeyAuthenticator object authenticator with this object.

This operation is very fast and never fails.

Definition at line 28 of file qsslpresharedkeyauthenticator.h.

References other(), and QSharedDataPointer< T >::swap().

Referenced by operator=(), QDtlsPrivateOpenSSL::pskClientCallback(), and QDtlsPrivateOpenSSL::pskServerCallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

bool QSslPreSharedKeyAuthenticator::operator!= ( const QSslPreSharedKeyAuthenticator & lhs,
const QSslPreSharedKeyAuthenticator & rhs )
friend
Since
5.5

Returns true if the authenticator object lhs is not equal to rhs; false otherwise.

Definition at line 47 of file qsslpresharedkeyauthenticator.h.

◆ operator==

bool QSslPreSharedKeyAuthenticator::operator== ( const QSslPreSharedKeyAuthenticator & lhs,
const QSslPreSharedKeyAuthenticator & rhs )
friend
Since
5.5

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.

Definition at line 45 of file qsslpresharedkeyauthenticator.h.

◆ QTlsBackend

friend class QTlsBackend
friend

Definition at line 43 of file qsslpresharedkeyauthenticator.h.


The documentation for this class was generated from the following files: