qsslpresharedkeyauthenticator.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslpresharedkeyauthenticator.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2014 Governikus GmbH & Co. KG.-
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#include "qsslpresharedkeyauthenticator.h"-
41#include "qsslpresharedkeyauthenticator_p.h"-
42-
43#include <QSharedData>-
44-
45QT_BEGIN_NAMESPACE-
46-
47/*!-
48 \internal-
49*/-
50QSslPreSharedKeyAuthenticatorPrivate::QSslPreSharedKeyAuthenticatorPrivate()-
51 : maximumIdentityLength(0),-
52 maximumPreSharedKeyLength(0)-
53{-
54}
never executed: end of block
0
55-
56/*!-
57 \class QSslPreSharedKeyAuthenticator-
58-
59 \brief The QSslPreSharedKeyAuthenticator class provides authentication data for pre-
60 shared keys (PSK) ciphersuites.-
61-
62 \inmodule QtNetwork-
63-
64 \reentrant-
65-
66 \ingroup network-
67 \ingroup ssl-
68 \ingroup shared-
69-
70 \since 5.5-
71-
72 The QSslPreSharedKeyAuthenticator class is used by an SSL socket to provide-
73 the required authentication data in a pre shared key (PSK) ciphersuite.-
74-
75 In a PSK handshake, the client must derive a key, which must match the key-
76 set on the server. The exact algorithm of deriving the key depends on the-
77 application; however, for this purpose, the server may send an \e{identity-
78 hint} to the client. This hint, combined with other information (for-
79 instance a passphrase), is then used by the client to construct the shared-
80 key.-
81-
82 The QSslPreSharedKeyAuthenticator provides means to client applications for-
83 completing the PSK handshake. The client application needs to connect a-
84 slot to the QSslSocket::preSharedKeyAuthenticationRequired() signal:-
85-
86 \code-
87-
88 connect(socket, &QSslSocket::preSharedKeyAuthenticationRequired,-
89 this, &AuthManager::handlePreSharedKeyAuthentication);-
90-
91 \endcode-
92-
93 The signal carries a QSslPreSharedKeyAuthenticator object containing the-
94 identity hint the server sent to the client, and which must be filled with the-
95 corresponding client identity and the derived key:-
96-
97 \code-
98-
99 void AuthManager::handlePreSharedKeyAuthentication(QSslPreSharedKeyAuthenticator *authenticator)-
100 {-
101 authenticator->setIdentity("My Qt App");-
102-
103 const QByteArray key = deriveKey(authenticator->identityHint(), passphrase);-
104 authenticator->setPreSharedKey(key);-
105 }-
106-
107 \endcode-
108-
109 \note PSK ciphersuites are supported only when using OpenSSL 1.0.1 (or-
110 greater) as the SSL backend.-
111-
112 \sa QSslSocket-
113*/-
114-
115/*!-
116 Constructs a default QSslPreSharedKeyAuthenticator object.-
117-
118 The identity hint, the identity and the key will be initialized to empty-
119 byte arrays; the maximum length for both the identity and the key will be-
120 initialized to 0.-
121*/-
122QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator()-
123 : d(new QSslPreSharedKeyAuthenticatorPrivate)-
124{-
125}
never executed: end of block
0
126-
127/*!-
128 Destroys the QSslPreSharedKeyAuthenticator object.-
129*/-
130QSslPreSharedKeyAuthenticator::~QSslPreSharedKeyAuthenticator()-
131{-
132}-
133-
134/*!-
135 Constructs a QSslPreSharedKeyAuthenticator object as a copy of \a authenticator.-
136-
137 \sa operator=()-
138*/-
139QSslPreSharedKeyAuthenticator::QSslPreSharedKeyAuthenticator(const QSslPreSharedKeyAuthenticator &authenticator)-
140 : d(authenticator.d)-
141{-
142}
never executed: end of block
0
143-
144/*!-
145 Assigns the QSslPreSharedKeyAuthenticator object \a authenticator to this object,-
146 and returns a reference to the copy.-
147*/-
148QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(const QSslPreSharedKeyAuthenticator &authenticator)-
149{-
150 d = authenticator.d;-
151 return *this;
never executed: return *this;
0
152}-
153-
154/*!-
155 \fn QSslPreSharedKeyAuthenticator &QSslPreSharedKeyAuthenticator::operator=(QSslPreSharedKeyAuthenticator &&authenticator)-
156-
157 Move-assigns the the QSslPreSharedKeyAuthenticator object \a authenticator to this-
158 object, and returns a reference to the moved instance.-
159*/-
160-
161/*!-
162 \fn void QSslPreSharedKeyAuthenticator::swap(QSslPreSharedKeyAuthenticator &authenticator)-
163-
164 Swaps the QSslPreSharedKeyAuthenticator object \a authenticator with this object.-
165 This operation is very fast and never fails.-
166*/-
167-
168/*!-
169 Returns the PSK identity hint as provided by the server. The interpretation-
170 of this hint is left to the application.-
171*/-
172QByteArray QSslPreSharedKeyAuthenticator::identityHint() const-
173{-
174 return d->identityHint;
never executed: return d->identityHint;
0
175}-
176-
177/*!-
178 Sets the PSK client identity (to be advised to the server) to \a identity.-
179-
180 \note it is possible to set an identity whose length is greater than-
181 maximumIdentityLength(); in this case, only the first maximumIdentityLength()-
182 bytes will be actually sent to the server.-
183-
184 \sa identity(), maximumIdentityLength()-
185*/-
186void QSslPreSharedKeyAuthenticator::setIdentity(const QByteArray &identity)-
187{-
188 d->identity = identity;-
189}
never executed: end of block
0
190-
191/*!-
192 Returns the PSK client identity.-
193-
194 \sa setIdentity()-
195*/-
196QByteArray QSslPreSharedKeyAuthenticator::identity() const-
197{-
198 return d->identity;
never executed: return d->identity;
0
199}-
200-
201-
202/*!-
203 Returns the maximum length, in bytes, of the PSK client identity.-
204-
205 \note it is possible to set an identity whose length is greater than-
206 maximumIdentityLength(); in this case, only the first maximumIdentityLength()-
207 bytes will be actually sent to the server.-
208-
209 \sa setIdentity()-
210*/-
211int QSslPreSharedKeyAuthenticator::maximumIdentityLength() const-
212{-
213 return d->maximumIdentityLength;
never executed: return d->maximumIdentityLength;
0
214}-
215-
216-
217/*!-
218 Sets the pre shared key to \a preSharedKey.-
219-
220 \note it is possible to set a key whose length is greater than the-
221 maximumPreSharedKeyLength(); in this case, only the first-
222 maximumPreSharedKeyLength() bytes will be actually sent to the server.-
223-
224 \sa preSharedKey(), maximumPreSharedKeyLength(), QByteArray::fromHex()-
225*/-
226void QSslPreSharedKeyAuthenticator::setPreSharedKey(const QByteArray &preSharedKey)-
227{-
228 d->preSharedKey = preSharedKey;-
229}
never executed: end of block
0
230-
231/*!-
232 Returns the pre shared key.-
233-
234 \sa setPreSharedKey()-
235*/-
236QByteArray QSslPreSharedKeyAuthenticator::preSharedKey() const-
237{-
238 return d->preSharedKey;
never executed: return d->preSharedKey;
0
239}-
240-
241/*!-
242 Returns the maximum length, in bytes, of the pre shared key.-
243-
244 \note it is possible to set a key whose length is greater than the-
245 maximumPreSharedKeyLength(); in this case, only the first-
246 maximumPreSharedKeyLength() bytes will be actually sent to the server.-
247-
248 \sa setPreSharedKey()-
249*/-
250int QSslPreSharedKeyAuthenticator::maximumPreSharedKeyLength() const-
251{-
252 return d->maximumPreSharedKeyLength;
never executed: return d->maximumPreSharedKeyLength;
0
253}-
254-
255/*!-
256 \relates QSslPreSharedKeyAuthenticator-
257 \since 5.5-
258-
259 Returns true if the authenticator object \a lhs is equal to \a rhs; false-
260 otherwise.-
261-
262 Two authenticator objects are equal if and only if they have the same-
263 identity hint, identity, pre shared key, maximum length for the identity-
264 and maximum length for the pre shared key.-
265-
266*/-
267bool operator==(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)-
268{-
269 return ((lhs.d == rhs.d) ||
never executed: return ((lhs.d == rhs.d) || (lhs.d->identityHint == rhs.d->identityHint && lhs.d->identity == rhs.d->identity && lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength && lhs.d->preSharedKey == rhs.d->preSharedKey && lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
0
270 (lhs.d->identityHint == rhs.d->identityHint &&
never executed: return ((lhs.d == rhs.d) || (lhs.d->identityHint == rhs.d->identityHint && lhs.d->identity == rhs.d->identity && lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength && lhs.d->preSharedKey == rhs.d->preSharedKey && lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
0
271 lhs.d->identity == rhs.d->identity &&
never executed: return ((lhs.d == rhs.d) || (lhs.d->identityHint == rhs.d->identityHint && lhs.d->identity == rhs.d->identity && lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength && lhs.d->preSharedKey == rhs.d->preSharedKey && lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
0
272 lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength &&
never executed: return ((lhs.d == rhs.d) || (lhs.d->identityHint == rhs.d->identityHint && lhs.d->identity == rhs.d->identity && lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength && lhs.d->preSharedKey == rhs.d->preSharedKey && lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
0
273 lhs.d->preSharedKey == rhs.d->preSharedKey &&
never executed: return ((lhs.d == rhs.d) || (lhs.d->identityHint == rhs.d->identityHint && lhs.d->identity == rhs.d->identity && lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength && lhs.d->preSharedKey == rhs.d->preSharedKey && lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
0
274 lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
never executed: return ((lhs.d == rhs.d) || (lhs.d->identityHint == rhs.d->identityHint && lhs.d->identity == rhs.d->identity && lhs.d->maximumIdentityLength == rhs.d->maximumIdentityLength && lhs.d->preSharedKey == rhs.d->preSharedKey && lhs.d->maximumPreSharedKeyLength == rhs.d->maximumPreSharedKeyLength));
0
275}-
276-
277/*!-
278 \fn bool operator!=(const QSslPreSharedKeyAuthenticator &lhs, const QSslPreSharedKeyAuthenticator &rhs)-
279 \relates QSslPreSharedKeyAuthenticator-
280 \since 5.5-
281-
282 Returns true if the authenticator object \a lhs is different than \a rhs;-
283 false otherwise.-
284-
285*/-
286-
287QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9