Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.7.4
-
None
-
Mac OsX 10.7 10.6.x
-
-
Ic7952afab4d16a65a87bb2f97a928c1c91167fe7
Description
When proxy requires authentication then Qt should try to get the username and password from OsX keychain. Something like this:
int getProxyAuth(const QString& url,QString& username, QString& password)
{
OSStatus err;
SecKeychainItemRef itemRef;
err = SecKeychainFindInternetPassword(NULL,
url.length(), qPrintable(url),
0,NULL,
0, NULL,
0, NULL,
0,
kSecProtocolTypeAny,
kSecAuthenticationTypeAny,
0, NULL,
&itemRef);
if (err == noErr) {
SecKeychainAttribute attr;
SecKeychainAttributeList attrList;
UInt32 length;
void *outData;
attr.tag = kSecAccountItemAttr;
attr.length = 0;
attr.data = NULL;
attrList.count = 1;
attrList.attr = &attr;
if (SecKeychainItemCopyContent(itemRef, NULL, &attrList, &length, &outData) == noErr) {
CFStringRef usernameosx = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)attr.data, attr.length, kCFStringEncodingUTF8, false);
CFStringRef passwordosx = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)outData, length, kCFStringEncodingUTF8, false);
username = QString(CFStringGetCStringPtr(usernameosx, kCFStringEncodingMacRoman));
password = QString(CFStringGetCStringPtr(passwordosx, kCFStringEncodingMacRoman));
CFRelease(usernameosx);
CFRelease(passwordosx);
}
CFRelease(itemRef);
return 0;
}
return -1;
}
void MainWindow::proxyAuthenticationRequired ( const QNetworkProxy & proxy, QAuthenticator * authenticator ) {
QString username;
QString password;
if( getProxyAuth(proxy.hostName(),username,password) == 0 ) {
authenticator->setUser(username);
authenticator->setPassword(password);
}
}
Attachments
Issue Links
- relates to
-
QTBUG-5316 Proxy returned by QNetworkProxyFactory::systemProxyForQuery authentication problem
-
- Open
-