QtBase  v6.3.1
Classes | Public Member Functions | List of all members
QDtlsClientVerifier Class Reference

This class implements server-side DTLS cookie generation and verification. More...

#include <qdtls.h>

Inheritance diagram for QDtlsClientVerifier:
Inheritance graph
[legend]
Collaboration diagram for QDtlsClientVerifier:
Collaboration graph
[legend]

Classes

class  GeneratorParameters
 This class defines parameters for DTLS cookie generator. More...
 

Public Member Functions

 QDtlsClientVerifier (QObject *parent=nullptr)
 
 ~QDtlsClientVerifier ()
 
bool setCookieGeneratorParameters (const GeneratorParameters &params)
 
GeneratorParameters cookieGeneratorParameters () const
 
bool verifyClient (QUdpSocket *socket, const QByteArray &dgram, const QHostAddress &address, quint16 port)
 
QByteArray verifiedHello () const
 
QDtlsError dtlsError () const
 
QString dtlsErrorString () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Detailed Description

This class implements server-side DTLS cookie generation and verification.

Since
5.12

\inmodule QtNetwork

The QDtlsClientVerifier class implements server-side DTLS cookie generation and verification. Datagram security protocols are highly susceptible to a variety of Denial-of-Service attacks. According to \l {RFC 6347, section 4.2.1}, these are two of the more common types of attack:

\list

As a countermeasure to these attacks, \l {RFC 6347, section 4.2.1} proposes a stateless cookie technique that a server may deploy:

\list

Note
A DTLS server is not required to use DTLS cookies.

QDtlsClientVerifier is designed to work in pair with QUdpSocket, as shown in the following code-excerpt:

QDtlsClientVerifier does not impose any restrictions on how the application uses QUdpSocket. For example, it is possible to have a server with a single QUdpSocket in state QAbstractSocket::BoundState, handling multiple DTLS clients simultaneously:

\list

This implies that QDtlsClientVerifier does not read directly from a socket, instead it expects the application to read an incoming datagram, extract the sender's address, and port, and then pass this data to verifyClient(). To send a HelloVerifyRequest message, verifyClient() can write to the QUdpSocket.

Note
QDtlsClientVerifier does not take ownership of the QUdpSocket object.

By default QDtlsClientVerifier obtains its secret from a cryptographically strong pseudorandom number generator.

Note
The default secret is shared by all objects of the classes QDtlsClientVerifier and QDtls. Since this can impose security risks, RFC 6347 recommends to change the server's secret frequently. Please see \l {RFC 6347, section 4.2.1} for hints about possible server implementations. Cookie generator parameters can be set using the class QDtlsClientVerifier::GeneratorParameters and setCookieGeneratorParameters():

The \l{secureudpserver}{DTLS server} example illustrates how to use QDtlsClientVerifier in a server application.

See also
QUdpSocket, QAbstractSocket::BoundState, QDtls, verifyClient(), GeneratorParameters, setCookieGeneratorParameters(), cookieGeneratorParameters(), QDtls::setCookieGeneratorParameters(), QDtls::cookieGeneratorParameters(), QCryptographicHash::Algorithm, QDtlsError, dtlsError(), dtlsErrorString()

Definition at line 79 of file qdtls.h.

Constructor & Destructor Documentation

◆ QDtlsClientVerifier()

QDtlsClientVerifier::QDtlsClientVerifier ( QObject parent = nullptr)
explicit

Constructs a QDtlsClientVerifier object, parent is passed to QObject's constructor.

Definition at line 390 of file qdtls.cpp.

◆ ~QDtlsClientVerifier()

QDtlsClientVerifier::~QDtlsClientVerifier ( )

Destroys the QDtlsClientVerifier object.

Definition at line 408 of file qdtls.cpp.

Member Function Documentation

◆ cookieGeneratorParameters()

QDtlsClientVerifier::GeneratorParameters QDtlsClientVerifier::cookieGeneratorParameters ( ) const

Returns the current secret and hash algorithm used to generate cookies. The default hash algorithm is QCryptographicHash::Sha256 if Qt was configured to support it, QCryptographicHash::Sha1 otherwise. The default secret is obtained from the backend-specific cryptographically strong pseudorandom number generator.

See also
QCryptographicHash::Algorithm, QDtlsClientVerifier::GeneratorParameters, setCookieGeneratorParameters()

Definition at line 442 of file qdtls.cpp.

◆ dtlsError()

QDtlsError QDtlsClientVerifier::dtlsError ( ) const

Returns the last error that occurred or QDtlsError::NoError.

See also
QDtlsError, dtlsErrorString()

Definition at line 512 of file qdtls.cpp.

Here is the caller graph for this function:

◆ dtlsErrorString()

QString QDtlsClientVerifier::dtlsErrorString ( ) const

Returns a textual description of the last error, or an empty string.

See also
dtlsError()

Definition at line 527 of file qdtls.cpp.

◆ setCookieGeneratorParameters()

bool QDtlsClientVerifier::setCookieGeneratorParameters ( const GeneratorParameters params)

Sets the secret and the cryptographic hash algorithm from params. This QDtlsClientVerifier will use these to generate cookies. If the new secret has size zero, this function returns false and does not change the cookie generator parameters.

Note
The secret is supposed to be a cryptographically secure sequence of bytes.
See also
QDtlsClientVerifier::GeneratorParameters, cookieGeneratorParameters(), QCryptographicHash::Algorithm

Definition at line 423 of file qdtls.cpp.

◆ verifiedHello()

QByteArray QDtlsClientVerifier::verifiedHello ( ) const

Convenience function. Returns the last ClientHello message that was successfully verified, or an empty QByteArray if no verification has completed.

See also
verifyClient()

Definition at line 497 of file qdtls.cpp.

◆ verifyClient()

bool QDtlsClientVerifier::verifyClient ( QUdpSocket socket,
const QByteArray dgram,
const QHostAddress address,
quint16  port 
)

socket must be a valid pointer, dgram must be a non-empty datagram, address cannot be null, broadcast, or multicast. port is the remote peer's port. This function returns true if dgram contains a ClientHello message with a valid cookie. If no matching cookie is found, verifyClient() will send a HelloVerifyRequest message using socket and return false.

The following snippet shows how a server application may check for errors:

See also
QHostAddress::isNull(), QHostAddress::isBroadcast(), QHostAddress::isMulticast(), setCookieGeneratorParameters(), cookieGeneratorParameters()

Definition at line 467 of file qdtls.cpp.

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

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