From f46ce0a0b819b74c4f25b5d9fcbb8a83b62dd417 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Mon, 23 Jun 2014 10:20:07 +0200 Subject: Mac networking: check system keychain for proxy auth ... and not when normal HTTP authentication is required. Also, query the system keychain for the right credentials depending on the URL scheme. Task-number: QTBUG-30434 Change-Id: Ib6f74029b2e0de9734497440e3b0e48cdf73adcb Reviewed-by: Richard J. Moore --- src/network/access/qnetworkaccessmanager.cpp | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/network/access/qnetworkaccessmanager.cpp') diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 473acc5f22..e669712147 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -99,13 +99,13 @@ bool getProxyAuth(const QString& proxyHostname, const QString &scheme, QString& bool retValue = false; SecProtocolType protocolType = kSecProtocolTypeAny; if (scheme.compare(QLatin1String("ftp"),Qt::CaseInsensitive)==0) { - protocolType = kSecProtocolTypeFTP; + protocolType = kSecProtocolTypeFTPProxy; } else if (scheme.compare(QLatin1String("http"),Qt::CaseInsensitive)==0 || scheme.compare(QLatin1String("preconnect-http"),Qt::CaseInsensitive)==0) { - protocolType = kSecProtocolTypeHTTP; + protocolType = kSecProtocolTypeHTTPProxy; } else if (scheme.compare(QLatin1String("https"),Qt::CaseInsensitive)==0 || scheme.compare(QLatin1String("preconnect-https"),Qt::CaseInsensitive)==0) { - protocolType = kSecProtocolTypeHTTPS; + protocolType = kSecProtocolTypeHTTPSProxy; } QByteArray proxyHostnameUtf8(proxyHostname.toUtf8()); err = SecKeychainFindInternetPassword(NULL, @@ -1392,21 +1392,6 @@ void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authen } } -#ifndef QT_NO_NETWORKPROXY -#if defined(Q_OS_MACX) - //now we try to get the username and password from keychain - //if not successful signal will be emitted - QString username; - QString password; - if (getProxyAuth(proxy.hostName(),reply->request().url().scheme(),username,password)) { - authenticator->setUser(username); - authenticator->setPassword(password); - authenticationManager->cacheProxyCredentials(proxy, authenticator); - return; - } -#endif -#endif //QT_NO_NETWORKPROXY - // if we emit a signal here in synchronous mode, the user might spin // an event loop, which might recurse and lead to problems if (synchronous) @@ -1419,7 +1404,8 @@ void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authen } #ifndef QT_NO_NETWORKPROXY -void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QNetworkProxy &proxy, +void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QUrl &url, + const QNetworkProxy &proxy, bool synchronous, QAuthenticator *authenticator, QNetworkProxy *lastProxyAuthentication) @@ -1435,6 +1421,21 @@ void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QNetworkPro } } +#if defined(Q_OS_OSX) + //now we try to get the username and password from keychain + //if not successful signal will be emitted + QString username; + QString password; + if (getProxyAuth(proxy.hostName(), url.scheme(), username, password)) { + authenticator->setUser(username); + authenticator->setPassword(password); + authenticationManager->cacheProxyCredentials(proxy, authenticator); + return; + } +#else + Q_UNUSED(url); +#endif + // if we emit a signal here in synchronous mode, the user might spin // an event loop, which might recurse and lead to problems if (synchronous) -- cgit v1.2.3