summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-08-31 14:00:21 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-08-31 18:57:27 (GMT)
commitbba97ff5e7faecfaf9b3d0cbb0e2d788bdfd5ab9 (patch)
tree86accc6a03c988fb769926ea09baf9c4133eac0e /src/network
parentb5bfe694814ff4dccc82cc5ae5c5bee0f7254a47 (diff)
downloadQt-bba97ff5e7faecfaf9b3d0cbb0e2d788bdfd5ab9.zip
Qt-bba97ff5e7faecfaf9b3d0cbb0e2d788bdfd5ab9.tar.gz
Qt-bba97ff5e7faecfaf9b3d0cbb0e2d788bdfd5ab9.tar.bz2
Update to the NTLM code.
Fixes extraction of time from the server, and saves the domain information properly. Patch by subcontractor Reviewed-by: Thiago Macieira
Diffstat (limited to 'src/network')
-rw-r--r--src/network/kernel/qauthenticator.cpp56
1 files changed, 37 insertions, 19 deletions
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
index d61c686..18cc14e 100644
--- a/src/network/kernel/qauthenticator.cpp
+++ b/src/network/kernel/qauthenticator.cpp
@@ -52,10 +52,13 @@
#include <qstring.h>
#include <qdatetime.h>
+//#define NTLMV1_CLIENT
QT_BEGIN_NAMESPACE
+#ifdef NTLMV1_CLIENT
#include "../../3rdparty/des/des.cpp"
+#endif
static QByteArray qNtlmPhase1();
static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phase2data);
@@ -203,17 +206,29 @@ QString QAuthenticator::user() const
void QAuthenticator::setUser(const QString &user)
{
detach();
-
int separatorPosn = 0;
- separatorPosn = user.indexOf(QLatin1String("\\"));
- if (separatorPosn == -1) {
- //No domain name present
+ switch(d->method) {
+ case QAuthenticatorPrivate::DigestMd5:
+ case QAuthenticatorPrivate::Ntlm:
+ if((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1)
+ {
+ //domain name is present
+ d->realm = user.left(separatorPosn);
+ d->user = user.mid(separatorPosn + 1);
+ } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) {
+ //domain name is present
+ d->realm = user.mid(separatorPosn + 1);
+ d->user = user.left(separatorPosn);
+ } else {
+ d->user = user;
+ d->realm.clear();
+ }
+ break;
+ // For other auth mechanisms, domain name will be part of username
+ default:
d->user = user;
- } else {
- //domain name is present
- d->realm = user.left(separatorPosn);
- d->user = user.mid(separatorPosn+1);
+ break;
}
}
@@ -1178,11 +1193,9 @@ static QByteArray clientChallenge(const QAuthenticatorPrivate *ctx)
}
// caller has to ensure a valid targetInfoBuff
-static bool qExtractServerTime(const QByteArray& targetInfoBuff,
- quint64 *serverTime)
+static QByteArray qExtractServerTime(const QByteArray& targetInfoBuff)
{
- Q_ASSERT(serverTime != 0);
- bool retValue = false;
+ QByteArray timeArray;
QDataStream ds(targetInfoBuff);
ds.setByteOrder(QDataStream::LittleEndian);
@@ -1193,19 +1206,16 @@ static bool qExtractServerTime(const QByteArray& targetInfoBuff,
ds >> avLen;
while(avId != 0) {
if(avId == AVTIMESTAMP) {
- QByteArray timeArray(avLen, 0);
+ timeArray.resize(avLen);
//avLen size of QByteArray is allocated
ds.readRawData(timeArray.data(), avLen);
- bool ok;
- *serverTime = timeArray.toHex().toLongLong(&ok, 16);
- retValue = true;
break;
}
ds.skipRawData(avLen);
ds >> avId;
ds >> avLen;
}
- return retValue;
+ return timeArray;
}
static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx,
@@ -1228,9 +1238,17 @@ static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx,
ds.writeRawData(reserved1.constData(), reserved1.size());
quint64 time = 0;
+ QByteArray timeArray;
+
+ if(ch.targetInfo.len)
+ {
+ timeArray = qExtractServerTime(ch.targetInfoBuff);
+ }
//if server sends time, use it instead of current time
- if(!(ch.targetInfo.len && qExtractServerTime(ch.targetInfoBuff, &time))) {
+ if(timeArray.size()) {
+ ds.writeRawData(timeArray.constData(), timeArray.size());
+ } else {
QDateTime currentTime(QDate::currentDate(),
QTime::currentTime(), Qt::UTC);
@@ -1242,8 +1260,8 @@ static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx,
// represented as 100 nano seconds
time = Q_UINT64_C(time * 10000000);
+ ds << time;
}
- ds << time;
//8 byte client challenge
QByteArray clientCh = clientChallenge(ctx);