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