QtBase  v6.3.1
qdtls.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QDTLS_H
41 #define QDTLS_H
42 
43 #include <QtNetwork/qtnetworkglobal.h>
44 
45 #include <QtNetwork/qsslsocket.h>
46 #include <QtNetwork/qssl.h>
47 
48 #include <QtCore/qcryptographichash.h>
49 #include <QtCore/qobject.h>
50 #include <QtCore/qcontainerfwd.h>
51 
53 
54 #ifndef Q_CLANG_QDOC
56 #endif
57 
59 
60 enum class QDtlsError : unsigned char
61 {
62  NoError,
71 };
72 
73 class QHostAddress;
74 class QUdpSocket;
75 class QByteArray;
76 class QString;
77 
79 class Q_NETWORK_EXPORT QDtlsClientVerifier : public QObject
80 {
81  Q_OBJECT
82 
83 public:
84 
85  explicit QDtlsClientVerifier(QObject *parent = nullptr);
87 
88  struct Q_NETWORK_EXPORT GeneratorParameters
89  {
94  };
95 
96  bool setCookieGeneratorParameters(const GeneratorParameters &params);
97  GeneratorParameters cookieGeneratorParameters() const;
98 
99  bool verifyClient(QUdpSocket *socket, const QByteArray &dgram,
100  const QHostAddress &address, quint16 port);
101  QByteArray verifiedHello() const;
102 
103  QDtlsError dtlsError() const;
104  QString dtlsErrorString() const;
105 
106 private:
107 
108  Q_DECLARE_PRIVATE(QDtlsClientVerifier)
110 };
111 
113 class QSslConfiguration;
114 class QSslCipher;
115 class QSslError;
116 
117 class QDtlsPrivate;
118 class Q_NETWORK_EXPORT QDtls : public QObject
119 {
120  Q_OBJECT
121 
122 public:
123 
125  {
129  HandshakeComplete
130  };
131 
132  explicit QDtls(QSslSocket::SslMode mode, QObject *parent = nullptr);
133  ~QDtls();
134 
135  bool setPeer(const QHostAddress &address, quint16 port,
136  const QString &verificationName = {});
137  bool setPeerVerificationName(const QString &name);
138  QHostAddress peerAddress() const;
139  quint16 peerPort() const;
140  QString peerVerificationName() const;
141  QSslSocket::SslMode sslMode() const;
142 
143  void setMtuHint(quint16 mtuHint);
144  quint16 mtuHint() const;
145 
147  bool setCookieGeneratorParameters(const GeneratorParameters &params);
148  GeneratorParameters cookieGeneratorParameters() const;
149 
150  bool setDtlsConfiguration(const QSslConfiguration &configuration);
151  QSslConfiguration dtlsConfiguration() const;
152 
153  HandshakeState handshakeState() const;
154 
155  bool doHandshake(QUdpSocket *socket, const QByteArray &dgram = {});
156  bool handleTimeout(QUdpSocket *socket);
157  bool resumeHandshake(QUdpSocket *socket);
158  bool abortHandshake(QUdpSocket *socket);
159  bool shutdown(QUdpSocket *socket);
160 
161  bool isConnectionEncrypted() const;
162  QSslCipher sessionCipher() const;
163  QSsl::SslProtocol sessionProtocol() const;
164 
165  qint64 writeDatagramEncrypted(QUdpSocket *socket, const QByteArray &dgram);
166  QByteArray decryptDatagram(QUdpSocket *socket, const QByteArray &dgram);
167 
168  QDtlsError dtlsError() const;
169  QString dtlsErrorString() const;
170 
171  QList<QSslError> peerVerificationErrors() const;
172  void ignoreVerificationErrors(const QList<QSslError> &errorsToIgnore);
173 
174 Q_SIGNALS:
175 
178 
179 private:
180 
181  bool startHandshake(QUdpSocket *socket, const QByteArray &dgram);
182  bool continueHandshake(QUdpSocket *socket, const QByteArray &dgram);
183 
184  Q_DECLARE_PRIVATE(QDtls)
186 };
187 
189 
190 #endif // QDTLS_H
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
This class implements server-side DTLS cookie generation and verification.
Definition: qdtls.h:80
This class provides encryption for UDP sockets.
Definition: qdtls.h:119
HandshakeState
Describes the current state of DTLS handshake.
Definition: qdtls.h:125
@ PeerVerificationFailed
Definition: qdtls.h:128
@ HandshakeNotStarted
Definition: qdtls.h:126
@ HandshakeInProgress
Definition: qdtls.h:127
void handshakeTimeout()
void pskRequired(QSslPreSharedKeyAuthenticator *authenticator)
The QHostAddress class provides an IP address.\inmodule QtNetwork.
Definition: qhostaddress.h:74
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QSslCipher class represents an SSL cryptographic cipher.
Definition: qsslcipher.h:58
The QSslConfiguration class holds the configuration and state of an SSL connection.
The QSslError class provides an SSL error.
Definition: qsslerror.h:57
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QUdpSocket class provides a UDP socket.
Definition: qudpsocket.h:57
QHash< int, QWidget * > hash
[35multi]
SslProtocol
Definition: qssl.h:75
QT_REQUIRE_CONFIG(dtls)
QDtlsError
Definition: qdtls.h:61
@ TlsInitializationError
@ UnderlyingSocketError
@ InvalidInputParameters
@ PeerVerificationError
@ RemoteClosedConnectionError
EGLOutputPortEXT port
#define Q_DISABLE_COPY_MOVE(Class)
Definition: qglobal.h:519
unsigned short quint16
Definition: qglobal.h:286
long long qint64
Definition: qglobal.h:298
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
GLenum mode
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint name
void ** params
GLuint GLuint64EXT address
Definition: qopenglext.h:11428
GLdouble s
[6]
Definition: qopenglext.h:235
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_MOC_INCLUDE(...)
Definition: qtmetamacros.h:115
#define Q_SIGNALS
Definition: qtmetamacros.h:81
QTcpSocket * socket
[1]
QDtls dtls
clientDtls setPeer(address, port, peerName)
dtlsConnection setDtlsConfiguration(config)
dtls doHandshake(udpSocket)
dtls ignoreVerificationErrors(expectedSslErrors)
This class defines parameters for DTLS cookie generator.
Definition: qdtls.h:89
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent