Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-22033

Qt should detect username and password from OsX keychain if the proxy requires it

    XMLWordPrintable

    Details

    • Platform/s:
      macOS
    • Commits:
      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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              shkearns Shane Kearns
              Reporter:
              qtcomsupport Qt Support
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes