QSslPreSharedKeyAuthenticator Class

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

头: #include <QSslPreSharedKeyAuthenticator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network

注意: 此类的所有函数 可重入 .

公共函数

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 & authenticator )
QSslPreSharedKeyAuthenticator & operator= (const QSslPreSharedKeyAuthenticator & authenticator )
QSslPreSharedKeyAuthenticator & operator= (QSslPreSharedKeyAuthenticator && authenticator )
bool operator!= (const QSslPreSharedKeyAuthenticator & lhs , const QSslPreSharedKeyAuthenticator & rhs )
bool operator== (const QSslPreSharedKeyAuthenticator & lhs , const QSslPreSharedKeyAuthenticator & rhs )

详细描述

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, &QSslSocket::preSharedKeyAuthenticationRequired,
            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);
    }
					

注意: PSK ciphersuites are supported only when using OpenSSL 1.0.1 (or greater) as the SSL backend.

注意: PSK is currently only supported in OpenSSL.

另请参阅 QSslSocket .

成员函数文档编制

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.

QSslPreSharedKeyAuthenticator:: QSslPreSharedKeyAuthenticator (const QSslPreSharedKeyAuthenticator & authenticator )

Constructs a QSslPreSharedKeyAuthenticator object as a copy of authenticator .

另请参阅 operator= ().

QSslPreSharedKeyAuthenticator:: ~QSslPreSharedKeyAuthenticator ()

销毁 QSslPreSharedKeyAuthenticator 对象。

QByteArray QSslPreSharedKeyAuthenticator:: identity () const

Returns the PSK client identity.

另请参阅 setIdentity ().

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.

另请参阅 setIdentity ().

int QSslPreSharedKeyAuthenticator:: maximumPreSharedKeyLength () const

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

注意: 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.

另请参阅 setPreSharedKey ().

QByteArray QSslPreSharedKeyAuthenticator:: preSharedKey () const

Returns the pre shared key.

另请参阅 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.

另请参阅 identity () 和 maximumIdentityLength ().

void QSslPreSharedKeyAuthenticator:: setPreSharedKey (const QByteArray & preSharedKey )

Sets the pre shared key to 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.

另请参阅 preSharedKey (), maximumPreSharedKeyLength (),和 QByteArray::fromHex ().

void QSslPreSharedKeyAuthenticator:: swap ( QSslPreSharedKeyAuthenticator & authenticator )

Swaps the QSslPreSharedKeyAuthenticator 对象 authenticator 与此对象。此操作非常快且从不失败。

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

赋值 QSslPreSharedKeyAuthenticator 对象 authenticator to this object, and returns a reference to the copy.

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

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

相关非成员

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

返回 true if the authenticator object lhs 不等于 rhs ; false 否则。

bool operator== (const QSslPreSharedKeyAuthenticator & lhs , const QSslPreSharedKeyAuthenticator & rhs )

返回 true if the authenticator object lhs 等于 rhs ; false 否则。

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.