Wizard: Ensure client cert doesn't get lost #6911
authorChristian Kamm <mail@ckamm.de>
Fri, 11 Jan 2019 12:14:30 +0000 (13:14 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:32 +0000 (10:58 +0100)
src/gui/owncloudsetupwizard.cpp
src/gui/wizard/owncloudsetuppage.cpp

index 519fcaef0b2b2210029b9a71c39bce088d43f3b9..cb401cd56925c699f7b737455cbad874e8d35f3a 100644 (file)
@@ -150,11 +150,27 @@ void OwncloudSetupWizard::slotCheckServer(const QString &urlString)
     }
     AccountPtr account = _ocWizard->account();
     account->setUrl(url);
+
     // Reset the proxy which might had been determined previously in ConnectionValidator::checkServerAndAuth()
     // when there was a previous account.
     account->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::NoProxy));
+
     // And also reset the QSslConfiguration, for the same reason (#6832)
-    account->setSslConfiguration({});
+    // Here the client certificate is added, if any. Later it'll be in HttpCredentials
+    account->setSslConfiguration(QSslConfiguration());
+    auto sslConfiguration = account->getOrCreateSslConfig(); // let Account set defaults
+    if (!_ocWizard->_clientSslCertificate.isNull()) {
+        sslConfiguration.setLocalCertificate(_ocWizard->_clientSslCertificate);
+        sslConfiguration.setPrivateKey(_ocWizard->_clientSslKey);
+    }
+    // Be sure to merge the CAs
+    auto ca = sslConfiguration.systemCaCertificates();
+    ca.append(_ocWizard->_clientSslCaCertificates);
+    sslConfiguration.setCaCertificates(ca);
+    account->setSslConfiguration(sslConfiguration);
+
+    // Make sure TCP connections get re-established
+    account->networkAccessManager()->clearAccessCache();
 
     // Lookup system proxy in a thread https://github.com/owncloud/client/issues/2993
     if (ClientProxy::isUsingSystemDefault()) {
index db9289992f8cd633927d7743915218c1317aaa37..c024c19d56d93054341cbef7b7c313a4bdd63f6c 100644 (file)
@@ -371,27 +371,7 @@ void OwncloudSetupPage::slotCertificateAccepted()
             &_ocWizard->_clientSslCertificate,
             &_ocWizard->_clientSslCaCertificates,
             addCertDial->getCertificatePasswd().toLocal8Bit())) {
-        AccountPtr acc = _ocWizard->account();
-
-        // to re-create the session ticket because we added a key/cert
-        acc->setSslConfiguration(QSslConfiguration());
-        QSslConfiguration sslConfiguration = acc->getOrCreateSslConfig();
-
-        // We're stuffing the certificate into the configuration form here. Later the
-        // cert will come via the HttpCredentials
-        sslConfiguration.setLocalCertificate(_ocWizard->_clientSslCertificate);
-        sslConfiguration.setPrivateKey(_ocWizard->_clientSslKey);
-
-        // Be sure to merge the CAs
-        auto ca = sslConfiguration.systemCaCertificates();
-        ca.append(_ocWizard->_clientSslCaCertificates);
-        sslConfiguration.setCaCertificates(ca);
-
-        acc->setSslConfiguration(sslConfiguration);
-
-        // Make sure TCP connections get re-established
-        acc->networkAccessManager()->clearAccessCache();
-
+        // The SSL cert gets added to the QSslConfiguration in checkServer()
         addCertDial->reinit(); // FIXME: Why not just have this only created on use?
         validatePage();
     } else {