qauthenticator.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qauthenticator.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include <qauthenticator.h>-
35#include <qauthenticator_p.h>-
36#include <qdebug.h>-
37#include <qhash.h>-
38#include <qbytearray.h>-
39#include <qcryptographichash.h>-
40#include <qiodevice.h>-
41#include <qdatastream.h>-
42#include <qendian.h>-
43#include <qstring.h>-
44#include <qdatetime.h>-
45-
46#ifdef Q_OS_WIN-
47#include <qmutex.h>-
48#include <private/qmutexpool_p.h>-
49#include <rpc.h>-
50#ifndef Q_OS_WINRT-
51#define SECURITY_WIN32 1-
52#include <security.h>-
53#endif-
54#endif-
55-
56QT_BEGIN_NAMESPACE-
57-
58static QByteArray qNtlmPhase1();-
59static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phase2data);-
60#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
61static QByteArray qNtlmPhase1_SSPI(QAuthenticatorPrivate *ctx);-
62static QByteArray qNtlmPhase3_SSPI(QAuthenticatorPrivate *ctx, const QByteArray& phase2data);-
63#endif-
64-
65/*!-
66 \class QAuthenticator-
67 \brief The QAuthenticator class provides an authentication object.-
68 \since 4.3-
69-
70 \reentrant-
71 \ingroup network-
72 \inmodule QtNetwork-
73-
74 The QAuthenticator class is usually used in the-
75 \l{QNetworkAccessManager::}{authenticationRequired()} and-
76 \l{QNetworkAccessManager::}{proxyAuthenticationRequired()} signals of QNetworkAccessManager and-
77 QAbstractSocket. The class provides a way to pass back the required-
78 authentication information to the socket when accessing services that-
79 require authentication.-
80-
81 QAuthenticator supports the following authentication methods:-
82 \list-
83 \li Basic-
84 \li NTLM version 2-
85 \li Digest-MD5-
86 \endlist-
87-
88 \target qauthenticator-options-
89 \section1 Options-
90-
91 In addition to the username and password required for authentication, a-
92 QAuthenticator object can also contain additional options. The-
93 options() function can be used to query incoming options sent by-
94 the server; the setOption() function can-
95 be used to set outgoing options, to be processed by the authenticator-
96 calculation. The options accepted and provided depend on the authentication-
97 type (see method()).-
98-
99 The following tables list known incoming options as well as accepted-
100 outgoing options. The list of incoming options is not exhaustive, since-
101 servers may include additional information at any time. The list of-
102 outgoing options is exhaustive, however, and no unknown options will be-
103 treated or sent back to the server.-
104-
105 \section2 Basic-
106-
107 \table-
108 \header \li Option \li Direction \li Type \li Description-
109 \row \li \tt{realm} \li Incoming \li QString \li Contains the realm of the authentication, the same as realm()-
110 \endtable-
111-
112 The Basic authentication mechanism supports no outgoing options.-
113-
114 \section2 NTLM version 2-
115-
116 The NTLM authentication mechanism currently supports no incoming or outgoing options.-
117 On Windows, if no \a user has been set, domain\\user credentials will be searched for on the-
118 local system to enable Single-Sign-On functionality.-
119-
120 \section2 Digest-MD5-
121-
122 \table-
123 \header \li Option \li Direction \li Type \li Description-
124 \row \li \tt{realm} \li Incoming \li QString \li Contains the realm of the authentication, the same as realm()-
125 \endtable-
126-
127 The Digest-MD5 authentication mechanism supports no outgoing options.-
128-
129 \sa QSslSocket-
130*/-
131-
132-
133/*!-
134 Constructs an empty authentication object.-
135*/-
136QAuthenticator::QAuthenticator()-
137 : d(0)-
138{-
139}
executed 7351 times by 15 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
7351
140-
141/*!-
142 Destructs the object.-
143*/-
144QAuthenticator::~QAuthenticator()-
145{-
146 if (d)
dDescription
TRUEevaluated 2546 times by 16 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_spdy - unknown status
FALSEevaluated 4793 times by 13 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qtcpsocket - unknown status
2546-4793
147 delete d;
executed 2546 times by 16 tests: delete d;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_spdy - unknown status
2546
148}
executed 7339 times by 16 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
  • tst_spdy - unknown status
7339
149-
150/*!-
151 Constructs a copy of \a other.-
152*/-
153QAuthenticator::QAuthenticator(const QAuthenticator &other)-
154 : d(0)-
155{-
156 if (other.d)
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
157 *this = other;
never executed: *this = other;
0
158}
never executed: end of block
0
159-
160/*!-
161 Assigns the contents of \a other to this authenticator.-
162*/-
163QAuthenticator &QAuthenticator::operator=(const QAuthenticator &other)-
164{-
165 if (d == other.d)
d == other.dDescription
TRUEnever evaluated
FALSEevaluated 43 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
0-43
166 return *this;
never executed: return *this;
0
167-
168 // Do not share the d since challange reponse/based changes-
169 // could corrupt the internal store and different network requests-
170 // can utilize different types of proxies.-
171 detach();-
172 if (other.d) {
other.dDescription
TRUEnever evaluated
FALSEevaluated 43 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
0-43
173 d->user = other.d->user;-
174 d->userDomain = other.d->userDomain;-
175 d->workstation = other.d->workstation;-
176 d->extractedUser = other.d->extractedUser;-
177 d->password = other.d->password;-
178 d->realm = other.d->realm;-
179 d->method = other.d->method;-
180 d->options = other.d->options;-
181 } else if (d->phase == QAuthenticatorPrivate::Start) {
never executed: end of block
d->phase == QA...Private::StartDescription
TRUEevaluated 43 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
FALSEnever evaluated
0-43
182 delete d;-
183 d = 0;-
184 }
executed 43 times by 3 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
43
185 return *this;
executed 43 times by 3 tests: return *this;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
43
186}-
187-
188/*!-
189 Returns \c true if this authenticator is identical to \a other; otherwise-
190 returns \c false.-
191*/-
192bool QAuthenticator::operator==(const QAuthenticator &other) const-
193{-
194 if (d == other.d)
d == other.dDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
4
195 return true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_qauthenticator - unknown status
4
196 if (!d || !other.d)
!dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
!other.dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-2
197 return false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_qauthenticator - unknown status
4
198 return d->user == other.d->user
never executed: return d->user == other.d->user && d->password == other.d->password && d->realm == other.d->realm && d->method == other.d->method && d->options == other.d->options;
d->user == other.d->userDescription
TRUEnever evaluated
FALSEnever evaluated
0
199 && d->password == other.d->password
never executed: return d->user == other.d->user && d->password == other.d->password && d->realm == other.d->realm && d->method == other.d->method && d->options == other.d->options;
d->password ==...er.d->passwordDescription
TRUEnever evaluated
FALSEnever evaluated
0
200 && d->realm == other.d->realm
never executed: return d->user == other.d->user && d->password == other.d->password && d->realm == other.d->realm && d->method == other.d->method && d->options == other.d->options;
d->realm == other.d->realmDescription
TRUEnever evaluated
FALSEnever evaluated
0
201 && d->method == other.d->method
never executed: return d->user == other.d->user && d->password == other.d->password && d->realm == other.d->realm && d->method == other.d->method && d->options == other.d->options;
d->method == other.d->methodDescription
TRUEnever evaluated
FALSEnever evaluated
0
202 && d->options == other.d->options;
never executed: return d->user == other.d->user && d->password == other.d->password && d->realm == other.d->realm && d->method == other.d->method && d->options == other.d->options;
d->options == other.d->optionsDescription
TRUEnever evaluated
FALSEnever evaluated
0
203}-
204-
205/*!-
206 \fn bool QAuthenticator::operator!=(const QAuthenticator &other) const-
207-
208 Returns \c true if this authenticator is different from \a other; otherwise-
209 returns \c false.-
210*/-
211-
212/*!-
213 Returns the user used for authentication.-
214*/-
215QString QAuthenticator::user() const-
216{-
217 return d ? d->user : QString();
executed 4341 times by 8 tests: return d ? d->user : QString();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
dDescription
TRUEevaluated 3626 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 715 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qsocks5socketengine - unknown status
715-4341
218}-
219-
220/*!-
221 Sets the \a user used for authentication.-
222-
223 \sa QNetworkAccessManager::authenticationRequired()-
224*/-
225void QAuthenticator::setUser(const QString &user)-
226{-
227 detach();-
228 d->user = user;-
229 d->updateCredentials();-
230}
executed 1155 times by 10 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
1155
231-
232/*!-
233 Returns the password used for authentication.-
234*/-
235QString QAuthenticator::password() const-
236{-
237 return d ? d->password : QString();
executed 3977 times by 8 tests: return d ? d->password : QString();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
dDescription
TRUEevaluated 3896 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 81 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsocks5socketengine - unknown status
81-3977
238}-
239-
240/*!-
241 Sets the \a password used for authentication.-
242-
243 \sa QNetworkAccessManager::authenticationRequired()-
244*/-
245void QAuthenticator::setPassword(const QString &password)-
246{-
247 detach();-
248 d->password = password;-
249}
executed 1164 times by 10 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
1164
250-
251/*!-
252 \internal-
253*/-
254void QAuthenticator::detach()-
255{-
256 if (!d) {
!dDescription
TRUEevaluated 2593 times by 15 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 2156 times by 11 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qnetworkreply - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
2156-2593
257 d = new QAuthenticatorPrivate;-
258 return;
executed 2593 times by 15 tests: return;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
2593
259 }-
260-
261 if (d->phase == QAuthenticatorPrivate::Done)
d->phase == QA...rPrivate::DoneDescription
TRUEevaluated 577 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 1579 times by 11 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qnetworkreply - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
577-1579
262 d->phase = QAuthenticatorPrivate::Start;
executed 577 times by 9 tests: d->phase = QAuthenticatorPrivate::Start;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
577
263}
executed 2156 times by 11 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qnetworkreply - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
2156
264-
265/*!-
266 Returns the realm requiring authentication.-
267*/-
268QString QAuthenticator::realm() const-
269{-
270 return d ? d->realm : QString();
executed 430 times by 3 tests: return d ? d->realm : QString();
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
dDescription
TRUEevaluated 425 times by 3 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QNetworkReply
5-430
271}-
272-
273/*!-
274 \internal-
275*/-
276void QAuthenticator::setRealm(const QString &realm)-
277{-
278 detach();-
279 d->realm = realm;-
280}
never executed: end of block
0
281-
282/*!-
283 \since 4.7-
284 Returns the value related to option \a opt if it was set by the server.-
285 See the \l{QAuthenticator#qauthenticator-options}{Options section} for-
286 more information on incoming options.-
287 If option \a opt isn't found, an invalid QVariant will be returned.-
288-
289 \sa options(), {QAuthenticator#qauthenticator-options}{QAuthenticator options}-
290*/-
291QVariant QAuthenticator::option(const QString &opt) const-
292{-
293 return d ? d->options.value(opt) : QVariant();
executed 3 times by 1 test: return d ? d->options.value(opt) : QVariant();
Executed by:
  • tst_qauthenticator - unknown status
dDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-3
294}-
295-
296/*!-
297 \since 4.7-
298 Returns all incoming options set in this QAuthenticator object by parsing-
299 the server reply. See the \l{QAuthenticator#qauthenticator-options}{Options section}-
300 for more information on incoming options.-
301-
302 \sa option(), {QAuthenticator#qauthenticator-options}{QAuthenticator options}-
303*/-
304QVariantHash QAuthenticator::options() const-
305{-
306 return d ? d->options : QVariantHash();
never executed: return d ? d->options : QVariantHash();
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
307}-
308-
309/*!-
310 \since 4.7-
311-
312 Sets the outgoing option \a opt to value \a value.-
313 See the \l{QAuthenticator#qauthenticator-options}{Options section} for more information on outgoing options.-
314-
315 \sa options(), option(), {QAuthenticator#qauthenticator-options}{QAuthenticator options}-
316*/-
317void QAuthenticator::setOption(const QString &opt, const QVariant &value)-
318{-
319 detach();-
320 d->options.insert(opt, value);-
321}
never executed: end of block
0
322-
323-
324/*!-
325 Returns \c true if the object has not been initialized. Returns-
326 \c false if non-const member functions have been called, or-
327 the content was constructed or copied from another initialized-
328 QAuthenticator object.-
329*/-
330bool QAuthenticator::isNull() const-
331{-
332 return !d;
executed 1227 times by 8 tests: return !d;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
1227
333}-
334-
335#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
336class QNtlmWindowsHandles-
337{-
338public:-
339 CredHandle credHandle;-
340 CtxtHandle ctxHandle;-
341};-
342#endif-
343-
344-
345QAuthenticatorPrivate::QAuthenticatorPrivate()-
346 : method(None)-
347 #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
348 , ntlmWindowsHandles(0)-
349 #endif-
350 , hasFailed(false)-
351 , phase(Start)-
352 , nonceCount(0)-
353{-
354 cnonce = QCryptographicHash::hash(QByteArray::number(qrand(), 16) + QByteArray::number(qrand(), 16),-
355 QCryptographicHash::Md5).toHex();-
356 nonceCount = 0;-
357}
executed 2593 times by 15 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
2593
358-
359QAuthenticatorPrivate::~QAuthenticatorPrivate()-
360{-
361#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
362 if (ntlmWindowsHandles)-
363 delete ntlmWindowsHandles;-
364#endif-
365}-
366-
367void QAuthenticatorPrivate::updateCredentials()-
368{-
369 int separatorPosn = 0;-
370-
371 switch (method) {-
372 case QAuthenticatorPrivate::Ntlm:
executed 8 times by 1 test: case QAuthenticatorPrivate::Ntlm:
Executed by:
  • tst_qauthenticator - unknown status
8
373 if ((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1) {
(separatorPosn...("\\"))) != -1Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-8
374 //domain name is present-
375 realm.clear();-
376 userDomain = user.left(separatorPosn);-
377 extractedUser = user.mid(separatorPosn + 1);-
378 } else {
never executed: end of block
0
379 extractedUser = user;-
380 realm.clear();-
381 userDomain.clear();-
382 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
8
383 break;
executed 8 times by 1 test: break;
Executed by:
  • tst_qauthenticator - unknown status
8
384 default:
executed 1686 times by 10 tests: default:
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
1686
385 userDomain.clear();-
386 break;
executed 1686 times by 10 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
1686
387 }-
388}-
389-
390void QAuthenticatorPrivate::parseHttpResponse(const QList<QPair<QByteArray, QByteArray> > &values, bool isProxy)-
391{-
392 const char *search = isProxy ? "proxy-authenticate" : "www-authenticate";
isProxyDescription
TRUEevaluated 228 times by 7 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 311 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
228-311
393-
394 method = None;-
395 /*-
396 Fun from the HTTP 1.1 specs, that we currently ignore:-
397-
398 User agents are advised to take special care in parsing the WWW--
399 Authenticate field value as it might contain more than one challenge,-
400 or if more than one WWW-Authenticate header field is provided, the-
401 contents of a challenge itself can contain a comma-separated list of-
402 authentication parameters.-
403 */-
404-
405 QByteArray headerVal;-
406 for (int i = 0; i < values.size(); ++i) {
i < values.size()Description
TRUEevaluated 4602 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 539 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
539-4602
407 const QPair<QByteArray, QByteArray> &current = values.at(i);-
408 if (current.first.toLower() != search)
current.first....er() != searchDescription
TRUEevaluated 4064 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 538 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
538-4064
409 continue;
executed 4064 times by 8 tests: continue;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
4064
410 QByteArray str = current.second.toLower();-
411 if (method < Basic && str.startsWith("basic")) {
method < BasicDescription
TRUEevaluated 538 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEnever evaluated
str.startsWith("basic")Description
TRUEevaluated 462 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 76 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
0-538
412 method = Basic;-
413 headerVal = current.second.mid(6);-
414 } else if (method < Ntlm && str.startsWith("ntlm")) {
executed 462 times by 9 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
method < NtlmDescription
TRUEevaluated 76 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
FALSEnever evaluated
str.startsWith("ntlm")Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 68 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
0-462
415 method = Ntlm;-
416 headerVal = current.second.mid(5);-
417 } else if (method < DigestMd5 && str.startsWith("digest")) {
executed 8 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
method < DigestMd5Description
TRUEevaluated 68 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
FALSEnever evaluated
str.startsWith("digest")Description
TRUEevaluated 67 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_qhttpsocketengine - unknown status
0-68
418 method = DigestMd5;-
419 headerVal = current.second.mid(7);-
420 }
executed 67 times by 2 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
67
421 }
executed 538 times by 9 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
538
422-
423 // Reparse credentials since we know the method now-
424 updateCredentials();-
425 challenge = headerVal.trimmed();-
426 QHash<QByteArray, QByteArray> options = parseDigestAuthenticationChallenge(challenge);-
427-
428 switch(method) {-
429 case Basic:
executed 462 times by 9 tests: case Basic:
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
462
430 this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));-
431 if (user.isEmpty() && password.isEmpty())
user.isEmpty()Description
TRUEevaluated 290 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 172 times by 3 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qhttpsocketengine - unknown status
password.isEmpty()Description
TRUEevaluated 290 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEnever evaluated
0-290
432 phase = Done;
executed 290 times by 9 tests: phase = Done;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
290
433 break;
executed 462 times by 9 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
462
434 case Ntlm:
executed 8 times by 1 test: case Ntlm:
Executed by:
  • tst_qauthenticator - unknown status
8
435 // work is done in calculateResponse()-
436 break;
executed 8 times by 1 test: break;
Executed by:
  • tst_qauthenticator - unknown status
8
437 case DigestMd5: {
executed 67 times by 2 tests: case DigestMd5:
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
67
438 this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));-
439 if (options.value("stale").toLower() == "true")
options.value(...er() == "true"Description
TRUEnever evaluated
FALSEevaluated 67 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
0-67
440 phase = Start;
never executed: phase = Start;
0
441 if (user.isEmpty() && password.isEmpty())
user.isEmpty()Description
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEevaluated 59 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
password.isEmpty()Description
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEnever evaluated
0-59
442 phase = Done;
executed 8 times by 2 tests: phase = Done;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
8
443 break;
executed 67 times by 2 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
67
444 }-
445 default:
executed 2 times by 1 test: default:
Executed by:
  • tst_qhttpsocketengine - unknown status
2
446 realm.clear();-
447 challenge = QByteArray();-
448 phase = Invalid;-
449 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qhttpsocketengine - unknown status
2
450}-
451-
452QByteArray QAuthenticatorPrivate::calculateResponse(const QByteArray &requestMethod, const QByteArray &path)-
453{-
454 QByteArray response;-
455 const char *methodString = 0;-
456 switch(method) {-
457 case QAuthenticatorPrivate::None:
never executed: case QAuthenticatorPrivate::None:
0
458 methodString = "";-
459 phase = Done;-
460 break;
never executed: break;
0
461 case QAuthenticatorPrivate::Plain:
never executed: case QAuthenticatorPrivate::Plain:
0
462 response = '\0' + user.toUtf8() + '\0' + password.toUtf8();-
463 phase = Done;-
464 break;
never executed: break;
0
465 case QAuthenticatorPrivate::Basic:
executed 325 times by 9 tests: case QAuthenticatorPrivate::Basic:
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
325
466 methodString = "Basic ";-
467 response = user.toLatin1() + ':' + password.toLatin1();-
468 response = response.toBase64();-
469 phase = Done;-
470 break;
executed 325 times by 9 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
325
471 case QAuthenticatorPrivate::Login:
never executed: case QAuthenticatorPrivate::Login:
0
472 if (challenge.contains("VXNlciBOYW1lAA==")) {
challenge.cont...ciBOYW1lAA==")Description
TRUEnever evaluated
FALSEnever evaluated
0
473 response = user.toUtf8().toBase64();-
474 phase = Phase2;-
475 } else if (challenge.contains("UGFzc3dvcmQA")) {
never executed: end of block
challenge.cont...UGFzc3dvcmQA")Description
TRUEnever evaluated
FALSEnever evaluated
0
476 response = password.toUtf8().toBase64();-
477 phase = Done;-
478 }
never executed: end of block
0
479 break;
never executed: break;
0
480 case QAuthenticatorPrivate::CramMd5:
never executed: case QAuthenticatorPrivate::CramMd5:
0
481 break;
never executed: break;
0
482 case QAuthenticatorPrivate::DigestMd5:
executed 35 times by 2 tests: case QAuthenticatorPrivate::DigestMd5:
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
483 methodString = "Digest ";-
484 response = digestMd5Response(challenge, requestMethod, path);-
485 phase = Done;-
486 break;
executed 35 times by 2 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
487 case QAuthenticatorPrivate::Ntlm:
executed 8 times by 1 test: case QAuthenticatorPrivate::Ntlm:
Executed by:
  • tst_qauthenticator - unknown status
8
488 methodString = "NTLM ";-
489 if (challenge.isEmpty()) {
challenge.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
4
490#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
491 QByteArray phase1Token;-
492 if (user.isEmpty()) // Only pull from system if no user was specified in authenticator-
493 phase1Token = qNtlmPhase1_SSPI(this);-
494 if (!phase1Token.isEmpty()) {-
495 response = phase1Token.toBase64();-
496 phase = Phase2;-
497 } else-
498#endif-
499 {-
500 response = qNtlmPhase1().toBase64();-
501 if (user.isEmpty())
user.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
2
502 phase = Done;
executed 2 times by 1 test: phase = Done;
Executed by:
  • tst_qauthenticator - unknown status
2
503 else-
504 phase = Phase2;
executed 2 times by 1 test: phase = Phase2;
Executed by:
  • tst_qauthenticator - unknown status
2
505 }-
506 } else {-
507#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
508 QByteArray phase3Token;-
509 if (ntlmWindowsHandles)-
510 phase3Token = qNtlmPhase3_SSPI(this, QByteArray::fromBase64(challenge));-
511 if (!phase3Token.isEmpty()) {-
512 response = phase3Token.toBase64();-
513 phase = Done;-
514 } else-
515#endif-
516 {-
517 response = qNtlmPhase3(this, QByteArray::fromBase64(challenge)).toBase64();-
518 phase = Done;-
519 }-
520 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
521-
522 break;
executed 8 times by 1 test: break;
Executed by:
  • tst_qauthenticator - unknown status
8
523 }-
524 return QByteArray(methodString) + response;
executed 368 times by 9 tests: return QByteArray(methodString) + response;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
368
525}-
526-
527-
528// ---------------------------- Digest Md5 code -----------------------------------------
529-
530QHash<QByteArray, QByteArray> QAuthenticatorPrivate::parseDigestAuthenticationChallenge(const QByteArray &challenge)-
531{-
532 QHash<QByteArray, QByteArray> options;-
533 // parse the challenge-
534 const char *d = challenge.constData();-
535 const char *end = d + challenge.length();-
536 while (d < end) {
d < endDescription
TRUEevaluated 870 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 572 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
572-870
537 while (d < end && (*d == ' ' || *d == '\n' || *d == '\r'))
d < endDescription
TRUEevaluated 1176 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEnever evaluated
*d == ' 'Description
TRUEevaluated 306 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEevaluated 870 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
*d == '\n'Description
TRUEnever evaluated
FALSEevaluated 870 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
*d == '\r'Description
TRUEnever evaluated
FALSEevaluated 870 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
0-1176
538 ++d;
executed 306 times by 2 tests: ++d;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
306
539 const char *start = d;-
540 while (d < end && *d != '=')
d < endDescription
TRUEevaluated 6694 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
*d != '='Description
TRUEevaluated 5826 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 868 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
2-6694
541 ++d;
executed 5826 times by 9 tests: ++d;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
5826
542 QByteArray key = QByteArray(start, d - start);-
543 ++d;-
544 if (d >= end)
d >= endDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 868 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
2-868
545 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_qauthenticator - unknown status
2
546 bool quote = (*d == '"');-
547 if (quote)
quoteDescription
TRUEevaluated 760 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 108 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
108-760
548 ++d;
executed 760 times by 8 tests: ++d;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
760
549 if (d >= end)
d >= endDescription
TRUEnever evaluated
FALSEevaluated 868 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
0-868
550 break;
never executed: break;
0
551 start = d;-
552 QByteArray value;-
553 while (d < end) {
d < endDescription
TRUEevaluated 19245 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
6-19245
554 bool backslash = false;-
555 if (*d == '\\' && d < end - 1) {
*d == '\\'Description
TRUEnever evaluated
FALSEevaluated 19245 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
d < end - 1Description
TRUEnever evaluated
FALSEnever evaluated
0-19245
556 ++d;-
557 backslash = true;-
558 }
never executed: end of block
0
559 if (!backslash) {
!backslashDescription
TRUEevaluated 19245 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEnever evaluated
0-19245
560 if (quote) {
quoteDescription
TRUEevaluated 18795 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 450 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
450-18795
561 if (*d == '"')
*d == '"'Description
TRUEevaluated 760 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 18035 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
760-18035
562 break;
executed 760 times by 8 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
760
563 } else {
executed 18035 times by 8 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
18035
564 if (*d == ',')
*d == ','Description
TRUEevaluated 102 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEevaluated 348 times by 4 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
102-348
565 break;
executed 102 times by 2 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
102
566 }
executed 348 times by 4 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
348
567 }-
568 value += *d;-
569 ++d;-
570 }
executed 18383 times by 9 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
18383
571 while (d < end && *d != ',')
d < endDescription
TRUEevaluated 1066 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 562 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
*d != ','Description
TRUEevaluated 760 times by 8 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
FALSEevaluated 306 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
306-1066
572 ++d;
executed 760 times by 8 tests: ++d;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
760
573 ++d;-
574 options[key] = value;-
575 }
executed 868 times by 9 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
868
576-
577 QByteArray qop = options.value("qop");-
578 if (!qop.isEmpty()) {
!qop.isEmpty()Description
TRUEevaluated 102 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEevaluated 472 times by 9 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
102-472
579 QList<QByteArray> qopoptions = qop.split(',');-
580 if (!qopoptions.contains("auth"))
!qopoptions.contains("auth")Description
TRUEnever evaluated
FALSEevaluated 102 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
0-102
581 return QHash<QByteArray, QByteArray>();
never executed: return QHash<QByteArray, QByteArray>();
0
582 // #### can't do auth-int currently-
583// if (qop.contains("auth-int"))-
584// qop = "auth-int";-
585// else if (qop.contains("auth"))-
586// qop = "auth";-
587// else-
588// qop = QByteArray();-
589 options["qop"] = "auth";-
590 }
executed 102 times by 2 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
102
591-
592 return options;
executed 574 times by 9 tests: return options;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qauthenticator - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
  • tst_qtcpsocket - unknown status
574
593}-
594-
595/*-
596 Digest MD5 implementation-
597-
598 Code taken from RFC 2617-
599-
600 Currently we don't support the full SASL authentication mechanism (which includes cyphers)-
601*/-
602-
603-
604/* calculate request-digest/response-digest as per HTTP Digest spec */-
605static QByteArray digestMd5ResponseHelper(-
606 const QByteArray &alg,-
607 const QByteArray &userName,-
608 const QByteArray &realm,-
609 const QByteArray &password,-
610 const QByteArray &nonce, /* nonce from server */-
611 const QByteArray &nonceCount, /* 8 hex digits */-
612 const QByteArray &cNonce, /* client nonce */-
613 const QByteArray &qop, /* qop-value: "", "auth", "auth-int" */-
614 const QByteArray &method, /* method from the request */-
615 const QByteArray &digestUri, /* requested URL */-
616 const QByteArray &hEntity /* H(entity body) if qop="auth-int" */-
617 )-
618{-
619 QCryptographicHash hash(QCryptographicHash::Md5);-
620 hash.addData(userName);-
621 hash.addData(":", 1);-
622 hash.addData(realm);-
623 hash.addData(":", 1);-
624 hash.addData(password);-
625 QByteArray ha1 = hash.result();-
626 if (alg.toLower() == "md5-sess") {
alg.toLower() == "md5-sess"Description
TRUEnever evaluated
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
0-35
627 hash.reset();-
628 // RFC 2617 contains an error, it was:-
629 // hash.addData(ha1);-
630 // but according to the errata page at http://www.rfc-editor.org/errata_list.php, ID 1649, it-
631 // must be the following line:-
632 hash.addData(ha1.toHex());-
633 hash.addData(":", 1);-
634 hash.addData(nonce);-
635 hash.addData(":", 1);-
636 hash.addData(cNonce);-
637 ha1 = hash.result();-
638 };
never executed: end of block
0
639 ha1 = ha1.toHex();-
640-
641 // calculate H(A2)-
642 hash.reset();-
643 hash.addData(method);-
644 hash.addData(":", 1);-
645 hash.addData(digestUri);-
646 if (qop.toLower() == "auth-int") {
qop.toLower() == "auth-int"Description
TRUEnever evaluated
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
0-35
647 hash.addData(":", 1);-
648 hash.addData(hEntity);-
649 }
never executed: end of block
0
650 QByteArray ha2hex = hash.result().toHex();-
651-
652 // calculate response-
653 hash.reset();-
654 hash.addData(ha1);-
655 hash.addData(":", 1);-
656 hash.addData(nonce);-
657 hash.addData(":", 1);-
658 if (!qop.isNull()) {
!qop.isNull()Description
TRUEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEnever evaluated
0-35
659 hash.addData(nonceCount);-
660 hash.addData(":", 1);-
661 hash.addData(cNonce);-
662 hash.addData(":", 1);-
663 hash.addData(qop);-
664 hash.addData(":", 1);-
665 }
executed 35 times by 2 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
666 hash.addData(ha2hex);-
667 return hash.result().toHex();
executed 35 times by 2 tests: return hash.result().toHex();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
668}-
669-
670QByteArray QAuthenticatorPrivate::digestMd5Response(const QByteArray &challenge, const QByteArray &method, const QByteArray &path)-
671{-
672 QHash<QByteArray,QByteArray> options = parseDigestAuthenticationChallenge(challenge);-
673-
674 ++nonceCount;-
675 QByteArray nonceCountString = QByteArray::number(nonceCount, 16);-
676 while (nonceCountString.length() < 8)
nonceCountString.length() < 8Description
TRUEevaluated 245 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35-245
677 nonceCountString.prepend('0');
executed 245 times by 2 tests: nonceCountString.prepend('0');
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
245
678-
679 QByteArray nonce = options.value("nonce");-
680 QByteArray opaque = options.value("opaque");-
681 QByteArray qop = options.value("qop");-
682-
683// qDebug() << "calculating digest: method=" << method << "path=" << path;-
684 QByteArray response = digestMd5ResponseHelper(options.value("algorithm"), user.toLatin1(),-
685 realm.toLatin1(), password.toLatin1(),-
686 nonce, nonceCountString,-
687 cnonce, qop, method,-
688 path, QByteArray());-
689-
690-
691 QByteArray credentials;-
692 credentials += "username=\"" + user.toLatin1() + "\", ";-
693 credentials += "realm=\"" + realm.toLatin1() + "\", ";-
694 credentials += "nonce=\"" + nonce + "\", ";-
695 credentials += "uri=\"" + path + "\", ";-
696 if (!opaque.isEmpty())
!opaque.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
0-35
697 credentials += "opaque=\"" + opaque + "\", ";
never executed: credentials += "opaque=\"" + opaque + "\", ";
0
698 credentials += "response=\"" + response + '"';-
699 if (!options.value("algorithm").isEmpty())
!options.value...hm").isEmpty()Description
TRUEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEnever evaluated
0-35
700 credentials += ", algorithm=" + options.value("algorithm");
executed 35 times by 2 tests: credentials += ", algorithm=" + options.value("algorithm");
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
701 if (!options.value("qop").isEmpty()) {
!options.value...op").isEmpty()Description
TRUEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
FALSEnever evaluated
0-35
702 credentials += ", qop=" + qop + ", ";-
703 credentials += "nc=" + nonceCountString + ", ";-
704 credentials += "cnonce=\"" + cnonce + '"';-
705 }
executed 35 times by 2 tests: end of block
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
706-
707 return credentials;
executed 35 times by 2 tests: return credentials;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
35
708}-
709-
710// ---------------------------- Digest Md5 code -----------------------------------------
711-
712-
713-
714/*-
715 * NTLM message flags.-
716 *-
717 * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>-
718 *-
719 * This software is released under the MIT license.-
720 */-
721-
722/*-
723 * Indicates that Unicode strings are supported for use in security-
724 * buffer data.-
725 */-
726#define NTLMSSP_NEGOTIATE_UNICODE 0x00000001-
727-
728/*-
729 * Indicates that OEM strings are supported for use in security buffer data.-
730 */-
731#define NTLMSSP_NEGOTIATE_OEM 0x00000002-
732-
733/*-
734 * Requests that the server's authentication realm be included in the-
735 * Type 2 message.-
736 */-
737#define NTLMSSP_REQUEST_TARGET 0x00000004-
738-
739/*-
740 * Specifies that authenticated communication between the client and server-
741 * should carry a digital signature (message integrity).-
742 */-
743#define NTLMSSP_NEGOTIATE_SIGN 0x00000010-
744-
745/*-
746 * Specifies that authenticated communication between the client and server-
747 * should be encrypted (message confidentiality).-
748 */-
749#define NTLMSSP_NEGOTIATE_SEAL 0x00000020-
750-
751/*-
752 * Indicates that datagram authentication is being used.-
753 */-
754#define NTLMSSP_NEGOTIATE_DATAGRAM 0x00000040-
755-
756/*-
757 * Indicates that the LAN Manager session key should be-
758 * used for signing and sealing authenticated communications.-
759 */-
760#define NTLMSSP_NEGOTIATE_LM_KEY 0x00000080-
761-
762/*-
763 * Indicates that NTLM authentication is being used.-
764 */-
765#define NTLMSSP_NEGOTIATE_NTLM 0x00000200-
766-
767/*-
768 * Sent by the client in the Type 1 message to indicate that the name of the-
769 * domain in which the client workstation has membership is included in the-
770 * message. This is used by the server to determine whether the client is-
771 * eligible for local authentication.-
772 */-
773#define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x00001000-
774-
775/*-
776 * Sent by the client in the Type 1 message to indicate that the client-
777 * workstation's name is included in the message. This is used by the server-
778 * to determine whether the client is eligible for local authentication.-
779 */-
780#define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x00002000-
781-
782/*-
783 * Sent by the server to indicate that the server and client are on the same-
784 * machine. Implies that the client may use the established local credentials-
785 * for authentication instead of calculating a response to the challenge.-
786 */-
787#define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x00004000-
788-
789/*-
790 * Indicates that authenticated communication between the client and server-
791 * should be signed with a "dummy" signature.-
792 */-
793#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x00008000-
794-
795/*-
796 * Sent by the server in the Type 2 message to indicate that the target-
797 * authentication realm is a domain.-
798 */-
799#define NTLMSSP_TARGET_TYPE_DOMAIN 0x00010000-
800-
801/*-
802 * Sent by the server in the Type 2 message to indicate that the target-
803 * authentication realm is a server.-
804 */-
805#define NTLMSSP_TARGET_TYPE_SERVER 0x00020000-
806-
807/*-
808 * Sent by the server in the Type 2 message to indicate that the target-
809 * authentication realm is a share. Presumably, this is for share-level-
810 * authentication. Usage is unclear.-
811 */-
812#define NTLMSSP_TARGET_TYPE_SHARE 0x00040000-
813-
814/*-
815 * Indicates that the NTLM2 signing and sealing scheme should be used for-
816 * protecting authenticated communications. Note that this refers to a-
817 * particular session security scheme, and is not related to the use of-
818 * NTLMv2 authentication.-
819 */-
820#define NTLMSSP_NEGOTIATE_NTLM2 0x00080000-
821-
822/*-
823 * Sent by the server in the Type 2 message to indicate that it is including-
824 * a Target Information block in the message. The Target Information block-
825 * is used in the calculation of the NTLMv2 response.-
826 */-
827#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x00800000-
828-
829/*-
830 * Indicates that 128-bit encryption is supported.-
831 */-
832#define NTLMSSP_NEGOTIATE_128 0x20000000-
833-
834/*-
835 * Indicates that the client will provide an encrypted master session key in-
836 * the "Session Key" field of the Type 3 message. This is used in signing and-
837 * sealing, and is RC4-encrypted using the previous session key as the-
838 * encryption key.-
839 */-
840#define NTLMSSP_NEGOTIATE_KEY_EXCHANGE 0x40000000-
841-
842/*-
843 * Indicates that 56-bit encryption is supported.-
844 */-
845#define NTLMSSP_NEGOTIATE_56 0x80000000-
846-
847/*-
848 * AvId values-
849 */-
850#define AVTIMESTAMP 7-
851-
852-
853//************************Global variables***************************-
854-
855const int blockSize = 64; //As per RFC2104 Block-size is 512 bits-
856const quint8 respversion = 1;-
857const quint8 hirespversion = 1;-
858-
859/* usage:-
860 // fill up ctx with what we know.-
861 QByteArray response = qNtlmPhase1(ctx);-
862 // send response (b64 encoded??)-
863 // get response from server (b64 decode?)-
864 Phase2Block pb;-
865 qNtlmDecodePhase2(response, pb);-
866 response = qNtlmPhase3(ctx, pb);-
867 // send response (b64 encoded??)-
868*/-
869-
870/*-
871 TODO:-
872 - Fix unicode handling-
873 - add v2 handling-
874*/-
875-
876class QNtlmBuffer {-
877public:-
878 QNtlmBuffer() : len(0), maxLen(0), offset(0) {}
executed 40 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
40
879 quint16 len;-
880 quint16 maxLen;-
881 quint32 offset;-
882 enum { Size = 8 };-
883};-
884-
885class QNtlmPhase1BlockBase-
886{-
887public:-
888 char magic[8];-
889 quint32 type;-
890 quint32 flags;-
891 QNtlmBuffer domain;-
892 QNtlmBuffer workstation;-
893 enum { Size = 32 };-
894};-
895-
896// ################# check paddings-
897class QNtlmPhase2BlockBase-
898{-
899public:-
900 char magic[8];-
901 quint32 type;-
902 QNtlmBuffer targetName;-
903 quint32 flags;-
904 unsigned char challenge[8];-
905 quint32 context[2];-
906 QNtlmBuffer targetInfo;-
907 enum { Size = 48 };-
908};-
909-
910class QNtlmPhase3BlockBase {-
911public:-
912 char magic[8];-
913 quint32 type;-
914 QNtlmBuffer lmResponse;-
915 QNtlmBuffer ntlmResponse;-
916 QNtlmBuffer domain;-
917 QNtlmBuffer user;-
918 QNtlmBuffer workstation;-
919 QNtlmBuffer sessionKey;-
920 quint32 flags;-
921 enum { Size = 64 };-
922};-
923-
924static void qStreamNtlmBuffer(QDataStream& ds, const QByteArray& s)-
925{-
926 ds.writeRawData(s.constData(), s.size());-
927}
executed 8 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
8
928-
929-
930static void qStreamNtlmString(QDataStream& ds, const QString& s, bool unicode)-
931{-
932 if (!unicode) {
!unicodeDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-8
933 qStreamNtlmBuffer(ds, s.toLatin1());-
934 return;
never executed: return;
0
935 }-
936 const ushort *d = s.utf16();-
937 for (int i = 0; i < s.length(); ++i)
i < s.length()Description
TRUEevaluated 62 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
8-62
938 ds << d[i];
executed 62 times by 1 test: ds << d[i];
Executed by:
  • tst_qauthenticator - unknown status
62
939}
executed 8 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
8
940-
941-
942-
943static int qEncodeNtlmBuffer(QNtlmBuffer& buf, int offset, const QByteArray& s)-
944{-
945 buf.len = s.size();-
946 buf.maxLen = buf.len;-
947 buf.offset = (offset + 1) & ~1;-
948 return buf.offset + buf.len;
executed 8 times by 1 test: return buf.offset + buf.len;
Executed by:
  • tst_qauthenticator - unknown status
8
949}-
950-
951-
952static int qEncodeNtlmString(QNtlmBuffer& buf, int offset, const QString& s, bool unicode)-
953{-
954 if (!unicode)
!unicodeDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-12
955 return qEncodeNtlmBuffer(buf, offset, s.toLatin1());
never executed: return qEncodeNtlmBuffer(buf, offset, s.toLatin1());
0
956 buf.len = 2 * s.length();-
957 buf.maxLen = buf.len;-
958 buf.offset = (offset + 1) & ~1;-
959 return buf.offset + buf.len;
executed 12 times by 1 test: return buf.offset + buf.len;
Executed by:
  • tst_qauthenticator - unknown status
12
960}-
961-
962-
963static QDataStream& operator<<(QDataStream& s, const QNtlmBuffer& b)-
964{-
965 s << b.len << b.maxLen << b.offset;-
966 return s;
executed 32 times by 1 test: return s;
Executed by:
  • tst_qauthenticator - unknown status
32
967}-
968-
969static QDataStream& operator>>(QDataStream& s, QNtlmBuffer& b)-
970{-
971 s >> b.len >> b.maxLen >> b.offset;-
972 return s;
executed 8 times by 1 test: return s;
Executed by:
  • tst_qauthenticator - unknown status
8
973}-
974-
975-
976class QNtlmPhase1Block : public QNtlmPhase1BlockBase-
977{ // request-
978public:-
979 QNtlmPhase1Block() {-
980 qstrncpy(magic, "NTLMSSP", 8);-
981 type = 1;-
982 flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NTLMSSP_NEGOTIATE_NTLM2;-
983 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
984-
985 // extracted-
986 QString domainStr, workstationStr;-
987};-
988-
989-
990class QNtlmPhase2Block : public QNtlmPhase2BlockBase-
991{ // challenge-
992public:-
993 QNtlmPhase2Block() {-
994 magic[0] = 0;-
995 type = 0xffffffff;-
996 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
997-
998 // extracted-
999 QString targetNameStr, targetInfoStr;-
1000 QByteArray targetInfoBuff;-
1001};-
1002-
1003-
1004-
1005class QNtlmPhase3Block : public QNtlmPhase3BlockBase { // response-
1006public:-
1007 QNtlmPhase3Block() {-
1008 qstrncpy(magic, "NTLMSSP", 8);-
1009 type = 3;-
1010 flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO;-
1011 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1012-
1013 // extracted-
1014 QByteArray lmResponseBuf, ntlmResponseBuf;-
1015 QString domainStr, userStr, workstationStr, sessionKeyStr;-
1016 QByteArray v2Hash;-
1017};-
1018-
1019-
1020static QDataStream& operator<<(QDataStream& s, const QNtlmPhase1Block& b) {-
1021 bool unicode = (b.flags & NTLMSSP_NEGOTIATE_UNICODE);-
1022-
1023 s.writeRawData(b.magic, sizeof(b.magic));-
1024 s << b.type;-
1025 s << b.flags;-
1026 s << b.domain;-
1027 s << b.workstation;-
1028 if (!b.domainStr.isEmpty())
!b.domainStr.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1029 qStreamNtlmString(s, b.domainStr, unicode);
never executed: qStreamNtlmString(s, b.domainStr, unicode);
0
1030 if (!b.workstationStr.isEmpty())
!b.workstationStr.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1031 qStreamNtlmString(s, b.workstationStr, unicode);
never executed: qStreamNtlmString(s, b.workstationStr, unicode);
0
1032 return s;
executed 4 times by 1 test: return s;
Executed by:
  • tst_qauthenticator - unknown status
4
1033}-
1034-
1035-
1036static QDataStream& operator<<(QDataStream& s, const QNtlmPhase3Block& b) {-
1037 bool unicode = (b.flags & NTLMSSP_NEGOTIATE_UNICODE);-
1038 s.writeRawData(b.magic, sizeof(b.magic));-
1039 s << b.type;-
1040 s << b.lmResponse;-
1041 s << b.ntlmResponse;-
1042 s << b.domain;-
1043 s << b.user;-
1044 s << b.workstation;-
1045 s << b.sessionKey;-
1046 s << b.flags;-
1047-
1048 if (!b.domainStr.isEmpty())
!b.domainStr.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1049 qStreamNtlmString(s, b.domainStr, unicode);
executed 4 times by 1 test: qStreamNtlmString(s, b.domainStr, unicode);
Executed by:
  • tst_qauthenticator - unknown status
4
1050-
1051 qStreamNtlmString(s, b.userStr, unicode);-
1052-
1053 if (!b.workstationStr.isEmpty())
!b.workstationStr.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1054 qStreamNtlmString(s, b.workstationStr, unicode);
never executed: qStreamNtlmString(s, b.workstationStr, unicode);
0
1055-
1056 // Send auth info-
1057 qStreamNtlmBuffer(s, b.lmResponseBuf);-
1058 qStreamNtlmBuffer(s, b.ntlmResponseBuf);-
1059-
1060-
1061 return s;
executed 4 times by 1 test: return s;
Executed by:
  • tst_qauthenticator - unknown status
4
1062}-
1063-
1064-
1065static QByteArray qNtlmPhase1()-
1066{-
1067 QByteArray rc;-
1068 QDataStream ds(&rc, QIODevice::WriteOnly);-
1069 ds.setByteOrder(QDataStream::LittleEndian);-
1070 QNtlmPhase1Block pb;-
1071 ds << pb;-
1072 return rc;
executed 4 times by 1 test: return rc;
Executed by:
  • tst_qauthenticator - unknown status
4
1073}-
1074-
1075-
1076static QByteArray qStringAsUcs2Le(const QString& src)-
1077{-
1078 QByteArray rc(2*src.length(), 0);-
1079 const unsigned short *s = src.utf16();-
1080 unsigned short *d = (unsigned short*)rc.data();-
1081 for (int i = 0; i < src.length(); ++i) {
i < src.length()Description
TRUEevaluated 84 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
12-84
1082 d[i] = qToLittleEndian(s[i]);-
1083 }
executed 84 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
84
1084 return rc;
executed 12 times by 1 test: return rc;
Executed by:
  • tst_qauthenticator - unknown status
12
1085}-
1086-
1087-
1088static QString qStringFromUcs2Le(QByteArray src)-
1089{-
1090 Q_ASSERT(src.size() % 2 == 0);-
1091 unsigned short *d = (unsigned short*)src.data();-
1092 for (int i = 0; i < src.length() / 2; ++i) {
i < src.length() / 2Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
4-40
1093 d[i] = qFromLittleEndian(d[i]);-
1094 }
executed 40 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
40
1095 return QString((const QChar *)src.data(), src.size()/2);
executed 4 times by 1 test: return QString((const QChar *)src.data(), src.size()/2);
Executed by:
  • tst_qauthenticator - unknown status
4
1096}-
1097-
1098-
1099/*********************************************************************-
1100* Function Name: qEncodeHmacMd5-
1101* Params:-
1102* key: Type - QByteArray-
1103* - It is the Authentication key-
1104* message: Type - QByteArray-
1105* - This is the actual message which will be encoded-
1106* using HMacMd5 hash algorithm-
1107*-
1108* Return Value:-
1109* hmacDigest: Type - QByteArray-
1110*-
1111* Description:-
1112* This function will be used to encode the input message using-
1113* HMacMd5 hash algorithm.-
1114*-
1115* As per the RFC2104 the HMacMd5 algorithm can be specified-
1116* ----------------------------------------
1117* MD5(K XOR opad, MD5(K XOR ipad, text))-
1118* ----------------------------------------
1119*-
1120*********************************************************************/-
1121QByteArray qEncodeHmacMd5(QByteArray &key, const QByteArray &message)-
1122{-
1123 Q_ASSERT_X(!(message.isEmpty()),"qEncodeHmacMd5", "Empty message check");-
1124 Q_ASSERT_X(!(key.isEmpty()),"qEncodeHmacMd5", "Empty key check");-
1125-
1126 QCryptographicHash hash(QCryptographicHash::Md5);-
1127 QByteArray hMsg;-
1128-
1129 QByteArray iKeyPad(blockSize, 0x36);-
1130 QByteArray oKeyPad(blockSize, 0x5c);-
1131-
1132 hash.reset();-
1133 // Adjust the key length to blockSize-
1134-
1135 if(blockSize < key.length()) {
blockSize < key.length()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-8
1136 hash.addData(key);-
1137 key = hash.result(); //MD5 will always return 16 bytes length output-
1138 }
never executed: end of block
0
1139-
1140 //Key will be <= 16 or 20 bytes as hash function (MD5 or SHA hash algorithms)-
1141 //key size can be max of Block size only-
1142 key = key.leftJustified(blockSize,0,true);-
1143-
1144 //iKeyPad, oKeyPad and key are all of same size "blockSize"-
1145-
1146 //xor of iKeyPad with Key and store the result into iKeyPad-
1147 for(int i = 0; i<key.size();i++) {
i<key.size()Description
TRUEevaluated 512 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
8-512
1148 iKeyPad[i] = key[i]^iKeyPad[i];-
1149 }
executed 512 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
512
1150-
1151 //xor of oKeyPad with Key and store the result into oKeyPad-
1152 for(int i = 0; i<key.size();i++) {
i<key.size()Description
TRUEevaluated 512 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
8-512
1153 oKeyPad[i] = key[i]^oKeyPad[i];-
1154 }
executed 512 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
512
1155-
1156 iKeyPad.append(message); // (K0 xor ipad) || text-
1157-
1158 hash.reset();-
1159 hash.addData(iKeyPad);-
1160 hMsg = hash.result();-
1161 //Digest gen after pass-1: H((K0 xor ipad)||text)-
1162-
1163 QByteArray hmacDigest;-
1164 oKeyPad.append(hMsg);-
1165 hash.reset();-
1166 hash.addData(oKeyPad);-
1167 hmacDigest = hash.result();-
1168 // H((K0 xor opad )|| H((K0 xor ipad) || text))-
1169-
1170 /*hmacDigest should not be less than half the length of the HMAC output-
1171 (to match the birthday attack bound) and not less than 80 bits-
1172 (a suitable lower bound on the number of bits that need to be-
1173 predicted by an attacker).-
1174 Refer RFC 2104 for more details on truncation part */-
1175-
1176 /*MD5 hash always returns 16 byte digest only and HMAC-MD5 spec-
1177 (RFC 2104) also says digest length should be 16 bytes*/-
1178 return hmacDigest;
executed 8 times by 1 test: return hmacDigest;
Executed by:
  • tst_qauthenticator - unknown status
8
1179}-
1180-
1181static QByteArray qCreatev2Hash(const QAuthenticatorPrivate *ctx,-
1182 QNtlmPhase3Block *phase3)-
1183{-
1184 Q_ASSERT(phase3 != 0);-
1185 // since v2 Hash is need for both NTLMv2 and LMv2 it is calculated-
1186 // only once and stored and reused-
1187 if(phase3->v2Hash.size() == 0) {
phase3->v2Hash.size() == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1188 QCryptographicHash md4(QCryptographicHash::Md4);-
1189 QByteArray passUnicode = qStringAsUcs2Le(ctx->password);-
1190 md4.addData(passUnicode.data(), passUnicode.size());-
1191-
1192 QByteArray hashKey = md4.result();-
1193 Q_ASSERT(hashKey.size() == 16);-
1194 // Assuming the user and domain is always unicode in challenge-
1195 QByteArray message =-
1196 qStringAsUcs2Le(ctx->extractedUser.toUpper()) +-
1197 qStringAsUcs2Le(phase3->domainStr);-
1198-
1199 phase3->v2Hash = qEncodeHmacMd5(hashKey, message);-
1200 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1201 return phase3->v2Hash;
executed 4 times by 1 test: return phase3->v2Hash;
Executed by:
  • tst_qauthenticator - unknown status
4
1202}-
1203-
1204static QByteArray clientChallenge(const QAuthenticatorPrivate *ctx)-
1205{-
1206 Q_ASSERT(ctx->cnonce.size() >= 8);-
1207 QByteArray clientCh = ctx->cnonce.right(8);-
1208 return clientCh;
executed 4 times by 1 test: return clientCh;
Executed by:
  • tst_qauthenticator - unknown status
4
1209}-
1210-
1211// caller has to ensure a valid targetInfoBuff-
1212static QByteArray qExtractServerTime(const QByteArray& targetInfoBuff)-
1213{-
1214 QByteArray timeArray;-
1215 QDataStream ds(targetInfoBuff);-
1216 ds.setByteOrder(QDataStream::LittleEndian);-
1217-
1218 quint16 avId;-
1219 quint16 avLen;-
1220-
1221 ds >> avId;-
1222 ds >> avLen;-
1223 while(avId != 0) {
avId != 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
4-18
1224 if(avId == AVTIMESTAMP) {
avId == 7Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-18
1225 timeArray.resize(avLen);-
1226 //avLen size of QByteArray is allocated-
1227 ds.readRawData(timeArray.data(), avLen);-
1228 break;
never executed: break;
0
1229 }-
1230 ds.skipRawData(avLen);-
1231 ds >> avId;-
1232 ds >> avLen;-
1233 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
18
1234 return timeArray;
executed 4 times by 1 test: return timeArray;
Executed by:
  • tst_qauthenticator - unknown status
4
1235}-
1236-
1237static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx,-
1238 const QNtlmPhase2Block& ch,-
1239 QNtlmPhase3Block *phase3)-
1240{-
1241 Q_ASSERT(phase3 != 0);-
1242 // return value stored in phase3-
1243 qCreatev2Hash(ctx, phase3);-
1244-
1245 QByteArray temp;-
1246 QDataStream ds(&temp, QIODevice::WriteOnly);-
1247 ds.setByteOrder(QDataStream::LittleEndian);-
1248-
1249 ds << respversion;-
1250 ds << hirespversion;-
1251-
1252 //Reserved-
1253 QByteArray reserved1(6, 0);-
1254 ds.writeRawData(reserved1.constData(), reserved1.size());-
1255-
1256 quint64 time = 0;-
1257 QByteArray timeArray;-
1258-
1259 if(ch.targetInfo.len)
ch.targetInfo.lenDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1260 {-
1261 timeArray = qExtractServerTime(ch.targetInfoBuff);-
1262 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1263-
1264 //if server sends time, use it instead of current time-
1265 if(timeArray.size()) {
timeArray.size()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1266 ds.writeRawData(timeArray.constData(), timeArray.size());-
1267 } else {
never executed: end of block
0
1268 QDateTime currentTime(QDate::currentDate(),-
1269 QTime::currentTime(), Qt::UTC);-
1270-
1271 // number of seconds between 1601 and epoc(1970)-
1272 // 369 years, 89 leap years-
1273 // ((369 * 365) + 89) * 24 * 3600 = 11644473600-
1274-
1275 time = currentTime.toTime_t() + Q_UINT64_C(11644473600);-
1276-
1277 // represented as 100 nano seconds-
1278 time = time * Q_UINT64_C(10000000);-
1279 ds << time;-
1280 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1281-
1282 //8 byte client challenge-
1283 QByteArray clientCh = clientChallenge(ctx);-
1284 ds.writeRawData(clientCh.constData(), clientCh.size());-
1285-
1286 //Reserved-
1287 QByteArray reserved2(4, 0);-
1288 ds.writeRawData(reserved2.constData(), reserved2.size());-
1289-
1290 if (ch.targetInfo.len > 0) {
ch.targetInfo.len > 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1291 ds.writeRawData(ch.targetInfoBuff.constData(),-
1292 ch.targetInfoBuff.size());-
1293 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1294-
1295 //Reserved-
1296 QByteArray reserved3(4, 0);-
1297 ds.writeRawData(reserved3.constData(), reserved3.size());-
1298-
1299 QByteArray message((const char*)ch.challenge, sizeof(ch.challenge));-
1300 message.append(temp);-
1301-
1302 QByteArray ntChallengeResp = qEncodeHmacMd5(phase3->v2Hash, message);-
1303 ntChallengeResp.append(temp);-
1304-
1305 return ntChallengeResp;
executed 4 times by 1 test: return ntChallengeResp;
Executed by:
  • tst_qauthenticator - unknown status
4
1306}-
1307-
1308static QByteArray qEncodeLmv2Response(const QAuthenticatorPrivate *ctx,-
1309 const QNtlmPhase2Block& ch,-
1310 QNtlmPhase3Block *phase3)-
1311{-
1312 Q_ASSERT(phase3 != 0);-
1313 // return value stored in phase3-
1314 qCreatev2Hash(ctx, phase3);-
1315-
1316 QByteArray message((const char*)ch.challenge, sizeof(ch.challenge));-
1317 QByteArray clientCh = clientChallenge(ctx);-
1318-
1319 message.append(clientCh);-
1320-
1321 QByteArray lmChallengeResp = qEncodeHmacMd5(phase3->v2Hash, message);-
1322 lmChallengeResp.append(clientCh);-
1323-
1324 return lmChallengeResp;
never executed: return lmChallengeResp;
0
1325}-
1326-
1327static bool qNtlmDecodePhase2(const QByteArray& data, QNtlmPhase2Block& ch)-
1328{-
1329 Q_ASSERT(QNtlmPhase2BlockBase::Size == sizeof(QNtlmPhase2BlockBase));-
1330 if (data.size() < QNtlmPhase2BlockBase::Size)
data.size() < ...lockBase::SizeDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1331 return false;
never executed: return false;
0
1332-
1333-
1334 QDataStream ds(data);-
1335 ds.setByteOrder(QDataStream::LittleEndian);-
1336 if (ds.readRawData(ch.magic, 8) < 8)
ds.readRawData....magic, 8) < 8Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1337 return false;
never executed: return false;
0
1338 if (strncmp(ch.magic, "NTLMSSP", 8) != 0)
strncmp(ch.mag...MSSP", 8) != 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1339 return false;
never executed: return false;
0
1340-
1341 ds >> ch.type;-
1342 if (ch.type != 2)
ch.type != 2Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1343 return false;
never executed: return false;
0
1344-
1345 ds >> ch.targetName;-
1346 ds >> ch.flags;-
1347 if (ds.readRawData((char *)ch.challenge, 8) < 8)
ds.readRawData...llenge, 8) < 8Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1348 return false;
never executed: return false;
0
1349 ds >> ch.context[0] >> ch.context[1];-
1350 ds >> ch.targetInfo;-
1351-
1352 if (ch.targetName.len > 0) {
ch.targetName.len > 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1353 if (ch.targetName.len + ch.targetName.offset > (unsigned)data.size())
ch.targetName....ed)data.size()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1354 return false;
never executed: return false;
0
1355-
1356 ch.targetNameStr = qStringFromUcs2Le(data.mid(ch.targetName.offset, ch.targetName.len));-
1357 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1358-
1359 if (ch.targetInfo.len > 0) {
ch.targetInfo.len > 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1360 if (ch.targetInfo.len + ch.targetInfo.offset > (unsigned)data.size())
ch.targetInfo....ed)data.size()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1361 return false;
never executed: return false;
0
1362-
1363 ch.targetInfoBuff = data.mid(ch.targetInfo.offset, ch.targetInfo.len);-
1364 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1365-
1366 return true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_qauthenticator - unknown status
4
1367}-
1368-
1369-
1370static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phase2data)-
1371{-
1372 QNtlmPhase2Block ch;-
1373 if (!qNtlmDecodePhase2(phase2data, ch))
!qNtlmDecodePh...hase2data, ch)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1374 return QByteArray();
never executed: return QByteArray();
0
1375-
1376 QByteArray rc;-
1377 QDataStream ds(&rc, QIODevice::WriteOnly);-
1378 ds.setByteOrder(QDataStream::LittleEndian);-
1379 QNtlmPhase3Block pb;-
1380-
1381 // set NTLMv2-
1382 if (ch.flags & NTLMSSP_NEGOTIATE_NTLM2)
ch.flags & 0x00080000Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1383 pb.flags |= NTLMSSP_NEGOTIATE_NTLM2;
never executed: pb.flags |= 0x00080000;
0
1384-
1385 // set Always Sign-
1386 if (ch.flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)
ch.flags & 0x00008000Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
0-4
1387 pb.flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
never executed: pb.flags |= 0x00008000;
0
1388-
1389 bool unicode = ch.flags & NTLMSSP_NEGOTIATE_UNICODE;-
1390-
1391 if (unicode)
unicodeDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1392 pb.flags |= NTLMSSP_NEGOTIATE_UNICODE;
executed 4 times by 1 test: pb.flags |= 0x00000001;
Executed by:
  • tst_qauthenticator - unknown status
4
1393 else-
1394 pb.flags |= NTLMSSP_NEGOTIATE_OEM;
never executed: pb.flags |= 0x00000002;
0
1395-
1396-
1397 int offset = QNtlmPhase3BlockBase::Size;-
1398 Q_ASSERT(QNtlmPhase3BlockBase::Size == sizeof(QNtlmPhase3BlockBase));-
1399-
1400 // for kerberos style user@domain logins, NTLM domain string should be left empty-
1401 if (ctx->userDomain.isEmpty() && !ctx->extractedUser.contains(QLatin1Char('@'))) {
ctx->userDomain.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
!ctx->extracte...tin1Char('@'))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1402 offset = qEncodeNtlmString(pb.domain, offset, ch.targetNameStr, unicode);-
1403 pb.domainStr = ch.targetNameStr;-
1404 } else {
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1405 offset = qEncodeNtlmString(pb.domain, offset, ctx->userDomain, unicode);-
1406 pb.domainStr = ctx->userDomain;-
1407 }
never executed: end of block
0
1408-
1409 offset = qEncodeNtlmString(pb.user, offset, ctx->extractedUser, unicode);-
1410 pb.userStr = ctx->extractedUser;-
1411-
1412 offset = qEncodeNtlmString(pb.workstation, offset, ctx->workstation, unicode);-
1413 pb.workstationStr = ctx->workstation;-
1414-
1415 // Get LM response-
1416 if (ch.targetInfo.len > 0) {
ch.targetInfo.len > 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qauthenticator - unknown status
FALSEnever evaluated
0-4
1417 pb.lmResponseBuf = QByteArray();-
1418 } else {
executed 4 times by 1 test: end of block
Executed by:
  • tst_qauthenticator - unknown status
4
1419 pb.lmResponseBuf = qEncodeLmv2Response(ctx, ch, &pb);-
1420 }
never executed: end of block
0
1421 offset = qEncodeNtlmBuffer(pb.lmResponse, offset, pb.lmResponseBuf);-
1422-
1423 // Get NTLM response-
1424 pb.ntlmResponseBuf = qEncodeNtlmv2Response(ctx, ch, &pb);-
1425 offset = qEncodeNtlmBuffer(pb.ntlmResponse, offset, pb.ntlmResponseBuf);-
1426-
1427-
1428 // Encode and send-
1429 ds << pb;-
1430-
1431 return rc;
executed 4 times by 1 test: return rc;
Executed by:
  • tst_qauthenticator - unknown status
4
1432}-
1433-
1434#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)-
1435// See http://davenport.sourceforge.net/ntlm.html-
1436// and libcurl http_ntlm.c-
1437-
1438// Handle of secur32.dll-
1439static HMODULE securityDLLHandle = NULL;-
1440// Pointer to SSPI dispatch table-
1441static PSecurityFunctionTable pSecurityFunctionTable = NULL;-
1442-
1443-
1444static bool q_NTLM_SSPI_library_load()-
1445{-
1446 QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&pSecurityFunctionTable));-
1447-
1448 // Initialize security interface-
1449 if (pSecurityFunctionTable == NULL) {-
1450 securityDLLHandle = LoadLibrary(L"secur32.dll");-
1451 if (securityDLLHandle != NULL) {-
1452#if defined(Q_OS_WINCE)-
1453 INIT_SECURITY_INTERFACE pInitSecurityInterface =-
1454 (INIT_SECURITY_INTERFACE)GetProcAddress(securityDLLHandle,-
1455 L"InitSecurityInterfaceW");-
1456#else-
1457 INIT_SECURITY_INTERFACE pInitSecurityInterface =-
1458 (INIT_SECURITY_INTERFACE)GetProcAddress(securityDLLHandle,-
1459 "InitSecurityInterfaceW");-
1460#endif-
1461 if (pInitSecurityInterface != NULL)-
1462 pSecurityFunctionTable = pInitSecurityInterface();-
1463 }-
1464 }-
1465-
1466 if (pSecurityFunctionTable == NULL)-
1467 return false;-
1468-
1469 return true;-
1470}-
1471-
1472// Phase 1:-
1473static QByteArray qNtlmPhase1_SSPI(QAuthenticatorPrivate *ctx)-
1474{-
1475 QByteArray result;-
1476-
1477 if (!q_NTLM_SSPI_library_load())-
1478 return result;-
1479-
1480 // 1. The client obtains a representation of the credential set-
1481 // for the user via the SSPI AcquireCredentialsHandle function.-
1482 if (!ctx->ntlmWindowsHandles)-
1483 ctx->ntlmWindowsHandles = new QNtlmWindowsHandles;-
1484 memset(&ctx->ntlmWindowsHandles->credHandle, 0, sizeof(CredHandle));-
1485 TimeStamp tsDummy;-
1486 SECURITY_STATUS secStatus = pSecurityFunctionTable->AcquireCredentialsHandle(-
1487 NULL, (SEC_WCHAR*)L"NTLM", SECPKG_CRED_OUTBOUND, NULL, NULL,-
1488 NULL, NULL, &ctx->ntlmWindowsHandles->credHandle, &tsDummy);-
1489 if (secStatus != SEC_E_OK) {-
1490 delete ctx->ntlmWindowsHandles;-
1491 ctx->ntlmWindowsHandles = 0;-
1492 return result;-
1493 }-
1494-
1495 // 2. The client calls the SSPI InitializeSecurityContext function-
1496 // to obtain an authentication request token (in our case, a Type 1 message).-
1497 // The client sends this token to the server.-
1498 SecBufferDesc desc;-
1499 SecBuffer buf;-
1500 desc.ulVersion = SECBUFFER_VERSION;-
1501 desc.cBuffers = 1;-
1502 desc.pBuffers = &buf;-
1503 buf.cbBuffer = 0;-
1504 buf.BufferType = SECBUFFER_TOKEN;-
1505 buf.pvBuffer = NULL;-
1506 ULONG attrs;-
1507-
1508 secStatus = pSecurityFunctionTable->InitializeSecurityContext(&ctx->ntlmWindowsHandles->credHandle, NULL,-
1509 const_cast<SEC_WCHAR*>(L"") /* host */,-
1510 ISC_REQ_ALLOCATE_MEMORY,-
1511 0, SECURITY_NETWORK_DREP,-
1512 NULL, 0,-
1513 &ctx->ntlmWindowsHandles->ctxHandle, &desc,-
1514 &attrs, &tsDummy);-
1515 if (secStatus == SEC_I_COMPLETE_AND_CONTINUE ||-
1516 secStatus == SEC_I_CONTINUE_NEEDED) {-
1517 pSecurityFunctionTable->CompleteAuthToken(&ctx->ntlmWindowsHandles->ctxHandle, &desc);-
1518 } else if (secStatus != SEC_E_OK) {-
1519 if ((const char*)buf.pvBuffer)-
1520 pSecurityFunctionTable->FreeContextBuffer(buf.pvBuffer);-
1521 pSecurityFunctionTable->FreeCredentialsHandle(&ctx->ntlmWindowsHandles->credHandle);-
1522 delete ctx->ntlmWindowsHandles;-
1523 ctx->ntlmWindowsHandles = 0;-
1524 return result;-
1525 }-
1526-
1527 result = QByteArray((const char*)buf.pvBuffer, buf.cbBuffer);-
1528 pSecurityFunctionTable->FreeContextBuffer(buf.pvBuffer);-
1529 return result;-
1530}-
1531-
1532// Phase 2:-
1533// 3. The server receives the token from the client, and uses it as input to the-
1534// AcceptSecurityContext SSPI function. This creates a local security context on-
1535// the server to represent the client, and yields an authentication response token-
1536// (the Type 2 message), which is sent to the client.-
1537-
1538// Phase 3:-
1539static QByteArray qNtlmPhase3_SSPI(QAuthenticatorPrivate *ctx, const QByteArray& phase2data)-
1540{-
1541 // 4. The client receives the response token from the server and calls-
1542 // InitializeSecurityContext again, passing the server's token as input.-
1543 // This provides us with another authentication request token (the Type 3 message).-
1544 // The return value indicates that the security context was successfully initialized;-
1545 // the token is sent to the server.-
1546-
1547 QByteArray result;-
1548-
1549 if (pSecurityFunctionTable == NULL)-
1550 return result;-
1551-
1552 SecBuffer type_2, type_3;-
1553 SecBufferDesc type_2_desc, type_3_desc;-
1554 ULONG attrs;-
1555 TimeStamp tsDummy; // For Windows 9x compatibility of SPPI calls-
1556-
1557 type_2_desc.ulVersion = type_3_desc.ulVersion = SECBUFFER_VERSION;-
1558 type_2_desc.cBuffers = type_3_desc.cBuffers = 1;-
1559 type_2_desc.pBuffers = &type_2;-
1560 type_3_desc.pBuffers = &type_3;-
1561-
1562 type_2.BufferType = SECBUFFER_TOKEN;-
1563 type_2.pvBuffer = (PVOID)phase2data.data();-
1564 type_2.cbBuffer = phase2data.length();-
1565 type_3.BufferType = SECBUFFER_TOKEN;-
1566 type_3.pvBuffer = 0;-
1567 type_3.cbBuffer = 0;-
1568-
1569 SECURITY_STATUS secStatus = pSecurityFunctionTable->InitializeSecurityContext(&ctx->ntlmWindowsHandles->credHandle,-
1570 &ctx->ntlmWindowsHandles->ctxHandle,-
1571 const_cast<SEC_WCHAR*>(L"") /* host */,-
1572 ISC_REQ_ALLOCATE_MEMORY,-
1573 0, SECURITY_NETWORK_DREP, &type_2_desc,-
1574 0, &ctx->ntlmWindowsHandles->ctxHandle, &type_3_desc,-
1575 &attrs, &tsDummy);-
1576-
1577 if (secStatus == SEC_E_OK && ((const char*)type_3.pvBuffer)) {-
1578 result = QByteArray((const char*)type_3.pvBuffer, type_3.cbBuffer);-
1579 pSecurityFunctionTable->FreeContextBuffer(type_3.pvBuffer);-
1580 }-
1581-
1582 pSecurityFunctionTable->FreeCredentialsHandle(&ctx->ntlmWindowsHandles->credHandle);-
1583 pSecurityFunctionTable->DeleteSecurityContext(&ctx->ntlmWindowsHandles->ctxHandle);-
1584 delete ctx->ntlmWindowsHandles;-
1585 ctx->ntlmWindowsHandles = 0;-
1586-
1587 return result;-
1588}-
1589#endif // Q_OS_WIN && !Q_OS_WINRT-
1590-
1591QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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