307 return QDtls::tr(
"Multicast and broadcast addresses are not supported");
332 :
hash(algorithm), secret(secret)
340 qCWarning(lcSsl,
"No TLS backend is available, cannot verify DTLS client");
343 backend.reset(tlsBackend->createDtlsCookieVerifier());
345 qCWarning(lcSsl) <<
"The backend" << tlsBackend->backendName() <<
"does not support DTLS cookies";
359 if (
auto *backend =
d->backend.get()) {
363 auto conf = QSslConfiguration::defaultDtlsConfiguration();
365 backend->setConfiguration(conf);
390 if (
auto *backend =
d->backend.get())
391 return backend->setCookieGeneratorParameters(
params);
410 if (
const auto *backend =
d->backend.get())
411 return backend->cookieGeneratorParameters();
436 auto *backend =
d->backend.get();
442 tr(
"A valid UDP socket, non-empty datagram, and valid address/port were expected"));
465 if (
const auto *backend =
d->backend.get())
466 return backend->verifiedHello();
480 if (
const auto *backend =
d->backend.get())
481 return backend->error();
495 if (
const auto *backend =
d->backend.get())
496 return backend->errorString();
498 return QStringLiteral(
"No TLS backend is available, no client verification");
517 qCWarning(lcSsl,
"No TLS backend found, QDtls is unsupported");
520 d->backend.reset(tlsBackend->createDtlsCryptograph(
this,
mode));
521 if (!
d->backend.get()) {
522 qCWarning(lcSsl) <<
"TLS backend" << tlsBackend->backendName()
523 <<
"does not support the protocol DTLS";
543 const QString &verificationName)
547 auto *backend =
d->backend.get();
553 tr(
"Cannot set peer after handshake started"));
559 tr(
"Invalid address"));
569 backend->clearDtlsError();
587 auto *backend =
d->backend.get();
593 tr(
"Cannot set verification name after handshake started"));
597 backend->clearDtlsError();
598 backend->setPeerVerificationName(
name);
612 if (
const auto *backend =
d->backend.get())
613 return backend->peerAddress();
627 if (
const auto *backend =
d->backend.get())
628 return backend->peerPort();
643 if (
const auto *backend =
d->backend.get())
644 return backend->peerVerificationName();
659 if (
const auto *backend =
d->backend.get())
660 return backend->cryptographMode();
675 if (
auto *backend =
d->backend.get())
676 backend->setDtlsMtuHint(
mtuHint);
688 if (
const auto *backend =
d->backend.get())
689 return backend->dtlsMtuHint();
708 if (
auto *backend =
d->backend.get())
709 backend->setCookieGeneratorParameters(
params);
729 if (
const auto *backend =
d->backend.get())
730 return backend->cookieGeneratorParameters();
747 auto *backend =
d->backend.get();
753 tr(
"Cannot set configuration after handshake started"));
757 backend->setConfiguration(configuration);
770 if (
const auto *backend =
d->backend.get())
771 return backend->configuration();
785 if (
const auto *backend =
d->backend.get())
786 return backend->state();
814 auto *backend =
d->backend.get();
819 return startHandshake(
socket, dgram);
821 return continueHandshake(
socket, dgram);
824 tr(
"Cannot start/continue handshake, invalid handshake state"));
835 auto *backend =
d->backend.get();
844 if (backend->peerAddress().isNull()) {
846 tr(
"To start a handshake you must set peer's address and port first"));
852 tr(
"To start a handshake, DTLS server requires non-empty datagram (client hello)"));
858 tr(
"Cannot start handshake, already done/in progress"));
862 return backend->startHandshake(
socket, datagram);
877 auto *backend =
d->backend.get();
886 return backend->handleTimeout(
socket);
896 auto *backend =
d->backend.get();
902 tr(
"A valid QUdpSocket and non-empty datagram are needed to continue the handshake"));
908 tr(
"Cannot continue handshake, not in InProgress state"));
912 return backend->continueHandshake(
socket, datagram);
927 auto *backend =
d->backend.get();
938 tr(
"Cannot resume, not in VerificationError state"));
942 return backend->resumeHandshake(
socket);
955 auto *backend =
d->backend.get();
966 tr(
"No handshake in progress, nothing to abort"));
970 backend->abortHandshake(
socket);
985 auto *backend =
d->backend.get();
991 tr(
"Invalid (nullptr) socket"));
995 if (!backend->isConnectionEncrypted()) {
997 tr(
"Cannot send shutdown alert, not encrypted"));
1001 backend->sendShutdownAlert(
socket);
1015 if (
const auto *backend =
d->backend.get())
1016 return backend->isConnectionEncrypted();
1037 if (
const auto *backend =
d->backend.get())
1038 return backend->dtlsSessionCipher();
1057 if (
const auto *backend =
d->backend.get())
1058 return backend->dtlsSessionProtocol();
1075 auto *backend =
d->backend.get();
1086 tr(
"Cannot write a datagram, not in encrypted state"));
1090 return backend->writeDatagramEncrypted(
socket, dgram);
1103 auto *backend =
d->backend.get();
1114 tr(
"Cannot read a datagram, not in encrypted state"));
1121 return backend->decryptDatagram(
socket, dgram);
1133 if (
const auto *backend =
d->backend.get())
1134 return backend->error();
1149 if (
const auto *backend =
d->backend.get())
1150 return backend->errorString();
1165 if (
const auto *backend =
d->backend.get())
1166 return backend->peerVerificationErrors();
1194 if (
auto *backend =
d->backend.get())
1195 backend->ignoreVerificationErrors(errorsToIgnore);
1200#include "moc_qdtls.cpp"
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
QDtlsClientVerifierPrivate()
~QDtlsClientVerifierPrivate()
This class implements server-side DTLS cookie generation and verification.
~QDtlsClientVerifier()
Destroys the QDtlsClientVerifier object.
QString dtlsErrorString() const
Returns a textual description of the last error, or an empty string.
GeneratorParameters cookieGeneratorParameters() const
Returns the current secret and hash algorithm used to generate cookies.
QByteArray verifiedHello() const
Convenience function.
bool 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,...
QDtlsError dtlsError() const
Returns the last error that occurred or QDtlsError::NoError.
bool setCookieGeneratorParameters(const GeneratorParameters ¶ms)
Sets the secret and the cryptographic hash algorithm from params.
QDtlsClientVerifier(QObject *parent=nullptr)
Constructs a QDtlsClientVerifier object, parent is passed to QObject's constructor.
This class provides encryption for UDP sockets.
bool setPeer(const QHostAddress &address, quint16 port, const QString &verificationName={})
Sets the peer's address, port, and host name and returns true if successful.
bool handleTimeout(QUdpSocket *socket)
If a timeout occurs during the handshake, the handshakeTimeout() signal is emitted.
QSslConfiguration dtlsConfiguration() const
Returns either the default DTLS configuration or the configuration set by an earlier call to setDtlsC...
qint64 writeDatagramEncrypted(QUdpSocket *socket, const QByteArray &dgram)
Encrypts dgram and writes the encrypted data into socket.
bool setDtlsConfiguration(const QSslConfiguration &configuration)
Sets the connection's TLS configuration from configuration and returns true if successful.
bool doHandshake(QUdpSocket *socket, const QByteArray &dgram={})
Starts or continues a DTLS handshake.
QString peerVerificationName() const
Returns the host name set by setPeer() or setPeerVerificationName().
bool shutdown(QUdpSocket *socket)
Sends an encrypted shutdown alert message and closes the DTLS connection.
bool resumeHandshake(QUdpSocket *socket)
If peer verification errors were ignored during the handshake, resumeHandshake() resumes and complete...
quint16 peerPort() const
Returns the peer's port number, set by setPeer(), or 0.
void ignoreVerificationErrors(const QList< QSslError > &errorsToIgnore)
This method tells QDtls to ignore only the errors given in errorsToIgnore.
QString dtlsErrorString() const
Returns a textual description for the last error encountered by the connection or empty string.
~QDtls()
Destroys the QDtls object.
QDtls(QSslSocket::SslMode mode, QObject *parent=nullptr)
Creates a QDtls object, parent is passed to the QObject constructor.
QByteArray decryptDatagram(QUdpSocket *socket, const QByteArray &dgram)
Decrypts dgram and returns its contents as plain text.
bool setCookieGeneratorParameters(const GeneratorParameters ¶ms)
Sets the cryptographic hash algorithm and the secret from params.
bool isConnectionEncrypted() const
Returns true if DTLS handshake completed successfully.
QList< QSslError > peerVerificationErrors() const
Returns errors found while establishing the identity of the peer.
void setMtuHint(quint16 mtuHint)
mtuHint is the maximum transmission unit (MTU), either discovered or guessed by the application.
QSslSocket::SslMode sslMode() const
Returns QSslSocket::SslServerMode for a server-side connection and QSslSocket::SslClientMode for a cl...
HandshakeState handshakeState() const
Returns the current handshake state for this QDtls.
QDtlsError dtlsError() const
Returns the last error encountered by the connection or QDtlsError::NoError.
quint16 mtuHint() const
Returns the value previously set by setMtuHint().
QHostAddress peerAddress() const
Returns the peer's address, set by setPeer(), or QHostAddress::Null.
QSslCipher sessionCipher() const
Returns the cryptographic \l {QSslCipher} {cipher} used by this connection, or a null cipher if the c...
bool abortHandshake(QUdpSocket *socket)
Aborts the ongoing handshake.
GeneratorParameters cookieGeneratorParameters() const
Returns the current hash algorithm and secret, either default ones or previously set by a call to set...
QSsl::SslProtocol sessionProtocol() const
Returns the DTLS protocol version used by this connection, or UnknownProtocol if the connection isn't...
bool setPeerVerificationName(const QString &name)
Sets the host name that will be used for the certificate validation and returns true if successful.
The QHostAddress class provides an IP address.
QObject * parent() const
Returns a pointer to the parent object.
The QSslCipher class represents an SSL cryptographic cipher.
The QSslConfiguration class holds the configuration and state of an SSL connection.
static QTlsBackend * tlsBackendInUse()
SslMode
Describes the connection modes available for QSslSocket.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QHash< int, QWidget * > hash
[35multi]
SslProtocol
Describes the protocol of the cipher.
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE QString msgUnsupportedMulticastAddress()
#define qCWarning(category,...)
GLuint GLuint64EXT address
#define QStringLiteral(str)
This class defines parameters for DTLS cookie generator.
GeneratorParameters()
Default constructs GeneratorParameters object with QCryptographicHash::Sha1 as its algorithm and an e...
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent