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