From 4c29a590cbdd68006906cb8ce3250f8d19caa3d6 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 18 Oct 2010 16:21:47 +0200 Subject: QAuthenticator: Fix NTLMv2 credential caching of QNAM QNetworkAccessManager used the user() function for caching the credentials when doing HTTP authentication with NTLMv2. For that to work it needs to return the same value as was put in with setUser(). Reviewed-by: Peter Hartmann Reviewed-by: Prasanth Task-Number: QTBUG-13234 --- src/network/kernel/qauthenticator.cpp | 14 ++++++++------ src/network/kernel/qauthenticator_p.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index f97d833..220f7da 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -232,19 +232,21 @@ void QAuthenticator::setUser(const QString &user) //domain name is present d->realm.clear(); d->userDomain = user.left(separatorPosn); - d->user = user.mid(separatorPosn + 1); + d->extractedUser = user.mid(separatorPosn + 1); + d->user = user; } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) { //domain name is present d->realm.clear(); d->userDomain = user.left(separatorPosn); - d->user = user.left(separatorPosn); + d->extractedUser = user.left(separatorPosn); + d->user = user; } else { + d->extractedUser = user; d->user = user; d->realm.clear(); d->userDomain.clear(); } break; - // For other auth mechanisms, domain name will be part of username default: d->user = user; break; @@ -1196,7 +1198,7 @@ static QByteArray qCreatev2Hash(const QAuthenticatorPrivate *ctx, Q_ASSERT(hashKey.size() == 16); // Assuming the user and domain is always unicode in challenge QByteArray message = - qStringAsUcs2Le(ctx->user.toUpper()) + + qStringAsUcs2Le(ctx->extractedUser.toUpper()) + qStringAsUcs2Le(phase3->domainStr); phase3->v2Hash = qEncodeHmacMd5(hashKey, message); @@ -1401,8 +1403,8 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas pb.domainStr = ctx->userDomain; } - offset = qEncodeNtlmString(pb.user, offset, ctx->user, unicode); - pb.userStr = ctx->user; + offset = qEncodeNtlmString(pb.user, offset, ctx->extractedUser, unicode); + pb.userStr = ctx->extractedUser; offset = qEncodeNtlmString(pb.workstation, offset, ctx->workstation, unicode); pb.workstationStr = ctx->workstation; diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h index 4e09360..9f2e607 100644 --- a/src/network/kernel/qauthenticator_p.h +++ b/src/network/kernel/qauthenticator_p.h @@ -71,6 +71,7 @@ public: QAtomicInt ref; QString user; + QString extractedUser; QString password; QVariantHash options; Method method; -- cgit v0.12