static void mergeSslConfigurationForSslButton(const QSslConfiguration &config, AccountPtr account) { if (config.peerCertificateChain().length() > 0) { account->_peerCertificateChain = config.peerCertificateChain(); } if (!config.sessionCipher().isNull()) { account->_sessionCipher = config.sessionCipher(); } if (config.sessionTicket().length() > 0) { account->_sessionTicket = config.sessionTicket(); } }
// // There have been problems with the finish-signal coming from the networkmanager. // To avoid that, the reply-signals were connected and the data is taken from the // sender() method. // void ownCloudInfo::slotReplyFinished() { QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); QSslConfiguration sslConfig = reply->sslConfiguration(); if (!sslConfig.isNull()) { QMutexLocker lock(&_certChainMutex); _certificateChain = sslConfig.peerCertificateChain(); } if( ! reply ) { qDebug() << "ownCloudInfo: Reply empty!"; return; } // Detect redirect url QUrl possibleRedirUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); /* We'll deduct if the redirection is valid in the redirectUrl function */ if (!possibleRedirUrl.isEmpty() && _redirectCount++ > 10) { // Are we in a redirect loop qDebug() << "Redirect loop while redirecting to" << possibleRedirUrl; possibleRedirUrl.clear(); } if(!possibleRedirUrl.isEmpty()) { QString configHandle; qDebug() << "Redirected to " << possibleRedirUrl; // We'll do another request to the redirection url. // an empty config handle is ok for the default config. if( _configHandleMap.contains(reply) ) { configHandle = _configHandleMap[reply]; qDebug() << "Redirect: Have a custom config handle: " << configHandle; } QString path = _directories[reply]; if (path.isEmpty()) { path = QLatin1String("status.php"); } else { path.prepend( QLatin1String(WEBDAV_PATH) ); } qDebug() << "This path was redirected: " << path; QString newUrl = possibleRedirUrl.toString(); if( !path.isEmpty() && newUrl.endsWith( path )) { // cut off the trailing path newUrl.chop( path.length() ); _urlRedirectedTo = newUrl; qDebug() << "Updated url to" << newUrl; getRequest( possibleRedirUrl ); } else { qDebug() << "WRN: Path is not part of the redirect URL. NO redirect."; } reply->deleteLater(); _directories.remove(reply); _configHandleMap.remove(reply); return; } // TODO: check if this is always the correct encoding const QString version = QString::fromUtf8( reply->readAll() ); const QString url = reply->url().toString(); QString plainUrl(url); plainUrl.remove( QLatin1String("/status.php")); QString info( version ); if( url.endsWith( QLatin1String("status.php")) ) { // it was a call to status.php if( reply->error() == QNetworkReply::NoError && info.isEmpty() ) { // This seems to be a bit strange behaviour of QNetworkAccessManager. // It calls the finised slot multiple times but only the first read wins. // That happend when the code connected the finished signal of the manager. // It did not happen when the code connected to the reply finish signal. qDebug() << "WRN: NetworkReply with not content but also no error! " << reply; reply->deleteLater(); return; } qDebug() << "status.php returns: " << info << " " << reply->error() << " Reply: " << reply; if( info.contains(QLatin1String("installed")) && info.contains(QLatin1String("version")) && info.contains(QLatin1String("versionstring")) ) { info.remove(0,1); // remove first char which is a "{" info.remove(-1,1); // remove the last char which is a "}" QStringList li = info.split( QLatin1Char(',') ); QString versionStr; QString version; QString edition; foreach ( const QString& infoString, li ) { QStringList touple = infoString.split( QLatin1Char(':')); QString key = touple[0]; key.remove(QLatin1Char('"')); QString val = touple[1]; val.remove(QLatin1Char('"')); if( key == QLatin1String("versionstring") ) { // get the versionstring out. versionStr = val; } else if( key == QLatin1String( "version") ) { // get version out version = val; } else if( key == QLatin1String( "edition") ) { // get version out edition = val; } else if(key == QLatin1String("installed")) { // Silently ignoring "installed = true" information } else { qDebug() << "Unknown info from ownCloud status.php: "<< key << "=" << val; } } emit ownCloudInfoFound( plainUrl, versionStr, version, edition ); } else {
void Ssu::requestFinished(QNetworkReply *reply){ QSslConfiguration sslConfiguration = reply->sslConfiguration(); SsuLog *ssuLog = SsuLog::instance(); SsuCoreConfig *settings = SsuCoreConfig::instance(); ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:") .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName)) .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName))); foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){ ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName))); } // what sucks more, this or goto? do { if (settings->contains("home-url")){ QString homeUrl = settings->value("home-url").toString().arg(""); homeUrl.remove(QRegExp("//+$")); QNetworkRequest request = reply->request(); if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)){ // we don't care about errors on download request if (reply->error() > 0) break; QByteArray data = reply->readAll(); storeAuthorizedKeys(data); break; } } if (reply->error() > 0){ pendingRequests--; setError(reply->errorString()); return; } else { QByteArray data = reply->readAll(); qDebug() << "RequestOutput" << data; QDomDocument doc; QString xmlError; if (!doc.setContent(data, &xmlError)){ pendingRequests--; setError(tr("Unable to parse server response (%1)").arg(xmlError)); return; } QString action = doc.elementsByTagName("action").at(0).toElement().text(); if (!verifyResponse(&doc)) break; if (action == "register"){ if (!registerDevice(&doc)) break; } else if (action == "credentials"){ if (!setCredentials(&doc)) break; } else { pendingRequests--; setError(tr("Response to unknown action encountered: %1").arg(action)); return; } } } while (false); pendingRequests--; ssuLog->print(LOG_DEBUG, QString("Request finished, pending requests: %1").arg(pendingRequests)); if (pendingRequests == 0) emit done(); }
void Ssu::requestFinished(QNetworkReply *reply){ QSslConfiguration sslConfiguration = reply->sslConfiguration(); SsuLog *ssuLog = SsuLog::instance(); SsuCoreConfig *settings = SsuCoreConfig::instance(); QNetworkRequest request = reply->request(); QVariant originalDomainVariant = request.attribute(SSU_NETWORK_REQUEST_DOMAIN_DATA); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:") .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName).join("")) .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName).join(""))); foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){ ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName).join(""))); } #else ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:") .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName)) .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName))); foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){ ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName))); } #endif pendingRequests--; QString action; QByteArray data; QDomDocument doc; QString xmlError; /// @TODO: indicate that the device is not registered if there's a 404 on credentials update url if (settings->contains("home-url")){ QString homeUrl = settings->value("home-url").toString().arg(""); homeUrl.remove(QRegExp("//+$")); if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)){ // we don't care about errors on download request if (reply->error() == 0) { QByteArray data = reply->readAll(); storeAuthorizedKeys(data); } goto success; } } if (reply->error() > 0){ setError(reply->errorString()); goto failure; } data = reply->readAll(); ssuLog->print(LOG_DEBUG, QString("RequestOutput %1") .arg(data.data())); if (!doc.setContent(data, &xmlError)){ setError(tr("Unable to parse server response (%1)").arg(xmlError)); goto failure; } action = doc.elementsByTagName("action").at(0).toElement().text(); if (!verifyResponse(&doc)) { goto failure; } ssuLog->print(LOG_DEBUG, QString("Handling request of type %1") .arg(action)); if (action == "register") { if (registerDevice(&doc)) { goto success; } } else if (action == "credentials") { if (setCredentials(&doc)) { goto success; } } else { setError(tr("Response to unknown action encountered: %1").arg(action)); } failure: // Restore the original domain in case of failures with the registration if (!originalDomainVariant.isNull()) { QString originalDomain = originalDomainVariant.toString(); ssuLog->print(LOG_DEBUG, QString("Restoring domain on error: '%1'").arg(originalDomain)); setDomain(originalDomain); } // Fall through to cleanup handling in success from failure label success: ssuLog->print(LOG_DEBUG, QString("Request finished, pending requests: %1").arg(pendingRequests)); if (pendingRequests == 0) { emit done(); } }