From 679ac0d26a6607a1d98024d829c0f71cc715d480 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 23 Nov 2016 11:43:15 +0100 Subject: [PATCH] Wizard: Show if server asks for client certificate #2799 #69 (#5261) This also nicely displays the 'Untrusted domain' message of oC. The link to add a trusted domain (via web browser) is clickable. --- src/gui/owncloudsetupwizard.cpp | 32 ++++++++++++++++++++++++---- src/gui/wizard/owncloudsetuppage.cpp | 1 + src/libsync/networkjobs.cpp | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index b33e96bd9..cc32ef3bb 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -203,10 +203,34 @@ void OwncloudSetupWizard::slotOwnCloudFoundAuth(const QUrl& url, const QVariantM void OwncloudSetupWizard::slotNoOwnCloudFoundAuth(QNetworkReply *reply) { - _ocWizard->displayError(tr("Failed to connect to %1 at %2:
%3") - .arg(Theme::instance()->appNameGUI(), - reply->url().toString(), - reply->errorString()), checkDowngradeAdvised(reply)); + int resultCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + + // Do this early because reply might be deleted in message box event loop + QString msg = tr("Failed to connect to %1 at %2:
%3") + .arg(Theme::instance()->appNameGUI(), + reply->url().toString(), + reply->errorString()); + bool isDowngradeAdvised = checkDowngradeAdvised(reply); + + // If a client cert is needed, nginx sends: + // 400 "\r\n400 No required SSL certificate was sent\r\n\r\n

400 Bad Request

\r\n
No required SSL certificate was sent
\r\n
nginx/1.10.0
\r\n\r\n\r\n" + // If the IP needs to be added as "trusted domain" in oC, oC sends: + // https://gist.github.com/guruz/ab6d11df1873c2ad3932180de92e7d82 + if (resultCode != 200 && contentType.startsWith("text/")) { + // FIXME: Synchronous dialogs are not so nice because of event loop recursion + // (we already create a dialog further below) + QString serverError = reply->peek(1024*20); + qDebug() << serverError; + QMessageBox messageBox(_ocWizard); + messageBox.setText(serverError); + messageBox.addButton(QMessageBox::Ok); + messageBox.setTextFormat(Qt::RichText); + messageBox.exec(); + } + + // Displays message inside wizard and possibly also another message box + _ocWizard->displayError(msg, isDowngradeAdvised); // Allow the credentials dialog to pop up again for the same URL. // Maybe the user just clicked 'Cancel' by accident or changed his mind. diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp index 95ea565e2..7700e7cf5 100644 --- a/src/gui/wizard/owncloudsetuppage.cpp +++ b/src/gui/wizard/owncloudsetuppage.cpp @@ -256,6 +256,7 @@ void OwncloudSetupPage::setErrorString( const QString& err, bool retryHTTPonly ) OwncloudConnectionMethodDialog dialog; dialog.setUrl(url); + // FIXME: Synchronous dialogs are not so nice because of event loop recursion int retVal = dialog.exec(); switch (retVal) { diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index 10fd3d545..974264045 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -463,7 +463,7 @@ bool CheckServerJob::finished() } bool success = false; - QByteArray body = reply()->readAll(); + QByteArray body = reply()->peek(4*1024); int httpStatus = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if( body.isEmpty() || httpStatus != 200) { qDebug() << "error: status.php replied " << httpStatus << body; -- 2.30.2