From fd679589e5769b2a0e507633eca44094b065c51b Mon Sep 17 00:00:00 2001 From: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Date: Tue, 10 Nov 2020 14:26:37 +0300 Subject: [PATCH] SYNEGRY-549 Create TLS certificate during upgrade (#6835) * SYNEGRY-549 Create TLS certificate during upgrade * Update ChangeLog --- ChangeLog | 1 + src/gui/src/ActivationDialog.cpp | 3 ++- src/gui/src/AppConfig.cpp | 17 +++++++++++++++-- src/gui/src/AppConfig.h | 5 ++++- src/gui/src/MainWindow.cpp | 12 +++--------- src/gui/src/MainWindow.h | 3 +-- src/gui/src/SettingsDialog.cpp | 23 +---------------------- src/gui/src/SettingsDialog.h | 3 --- 8 files changed, 27 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86a51f529..7406a4413 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,7 @@ Bug fixes: - #6821 Blocker bugs found by sonar in synergy and in tests - #6825 The system requires google test even when tests are disabled with BUILD_TESTS=OFF - #6832 TLS certificate error on macOS system +- #6835 Create TLS certificate during upgrade Enhancements: - #6750 Integrate SonarCloud for static analysis and test coverage diff --git a/src/gui/src/ActivationDialog.cpp b/src/gui/src/ActivationDialog.cpp index 0569449e1..50aba661d 100644 --- a/src/gui/src/ActivationDialog.cpp +++ b/src/gui/src/ActivationDialog.cpp @@ -92,7 +92,8 @@ void ActivationDialog::accept() arg ((daysLeft == 1) ? "" : "s"). arg ((daysLeft == 1) ? "s" : ""); - if (edition == kPro) { + if (edition == kPro || edition == kBusiness) { + m_appConfig->generateCertificate(); thanksMessage = thanksMessage.arg("If you're using SSL, " "remember to activate all of your devices."); } else { diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 30bfee49c..bf646aa7c 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -26,6 +26,7 @@ #include #include "ConfigWriter.h" +#include "SslCertificate.h" #if defined(Q_OS_WIN) const char AppConfig::m_SynergysName[] = "synergys.exe"; @@ -414,8 +415,10 @@ ElevateMode AppConfig::elevateMode() } void AppConfig::setCryptoEnabled(bool newValue) { + if (m_CryptoEnabled != newValue && newValue){ + generateCertificate(); + } setSettingModified(m_CryptoEnabled, newValue); - emit sslToggled(m_CryptoEnabled); } bool AppConfig::isCryptoAvailable() const { @@ -564,6 +567,16 @@ QString AppConfig::getTLSKeyLength() const { } void AppConfig::setTLSKeyLength(const QString& length) { - m_TLSKeyLength = length; + if (m_TLSKeyLength != length) { + m_TLSKeyLength = length; + generateCertificate(true); + } } +void AppConfig::generateCertificate(bool forceGeneration) const { + SslCertificate sslCertificate; + sslCertificate.generateCertificate(getTLSCertPath(), getTLSKeyLength(), forceGeneration); + emit sslToggled(); +} + + diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index 5c7f71dbc..35a0a852c 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -160,6 +160,9 @@ class AppConfig: public QObject, public GUI::Config::ConfigBase void saveSettings() override; void setLastVersion(const QString& version); + /// @brief Generates TLS certificate + /// @param [in] bool forceGeneration Generate certificate even if it's exists. + void generateCertificate(bool forceGeneration=false) const; protected: /// @brief The enumeration to easily access the names of the setting inside m_SynergySettingsName @@ -288,7 +291,7 @@ protected: void setSettingModified(T& variable,const T& newValue); signals: - void sslToggled(bool enabled); + void sslToggled() const; void zeroConfToggled(); }; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 00028b8fe..843974ae7 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -163,7 +163,7 @@ MainWindow::MainWindow (AppConfig& appConfig, // hide padlock icon secureSocket(false); - sslToggled(appConfig.getCryptoEnabled()); + updateLocalFingerprint(); connect (this, SIGNAL(windowShown()), this, SLOT(on_windowShown()), Qt::QueuedConnection); @@ -178,8 +178,8 @@ MainWindow::MainWindow (AppConfig& appConfig, this, SLOT(InvalidLicense()), Qt::QueuedConnection); #endif - connect (m_AppConfig, SIGNAL(sslToggled(bool)), - this, SLOT(sslToggled(bool)), Qt::QueuedConnection); + connect (m_AppConfig, SIGNAL(sslToggled()), + this, SLOT(updateLocalFingerprint()), Qt::QueuedConnection); connect (m_AppConfig, SIGNAL(zeroConfToggled()), this, SLOT(zeroConfToggled()), Qt::QueuedConnection); @@ -744,12 +744,6 @@ void MainWindow::retryStart() } } -void -MainWindow::sslToggled (bool enabled) -{ - updateLocalFingerprint(); -} - bool MainWindow::clientArgs(QStringList& args, QString& app) { app = appPath(appConfig().synergycName()); diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 639e117ef..b75a7b6d2 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -120,7 +120,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void showConfigureServer() { showConfigureServer(""); } void autoAddScreen(const QString name); void addZeroconfServer(const QString name); - void updateLocalFingerprint(); Zeroconf& zeroconf() { return *m_pZeroconf; } #ifndef SYNERGY_ENTERPRISE LicenseManager& licenseManager() const; @@ -143,7 +142,7 @@ public slots: void retryStart(); // If the connection failed this will retry a startSynergy protected slots: - void sslToggled(bool enabled); + void updateLocalFingerprint(); void on_m_pGroupClient_toggled(bool on); void on_m_pGroupServer_toggled(bool on); bool on_m_pButtonBrowseConfigFile_clicked(); diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index a4f19c973..8adc714a9 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -66,19 +66,10 @@ void SettingsDialog::accept() appConfig().setAutoConfig(m_pCheckBoxAutoConfig->isChecked()); appConfig().setMinimizeToTray(m_pCheckBoxMinimizeToTray->isChecked()); appConfig().setTLSCertPath(m_pLineEditCertificatePath->text()); - - bool keyLengthChanged = appConfig().getTLSKeyLength() != m_pComboBoxKeyLength->currentText(); appConfig().setTLSKeyLength(m_pComboBoxKeyLength->currentText()); //We only need to test the System scoped Radio as they are connected appConfig().setLoadFromSystemScope(m_pRadioSystemScope->isChecked()); - - if(m_pCheckBoxEnableCrypto->isChecked()) { - SslCertificate sslCertificate; - sslCertificate.generateCertificate(appConfig().getTLSCertPath(), - m_pComboBoxKeyLength->currentText(), - keyLengthChanged); - } m_appConfig.setCryptoEnabled(m_pCheckBoxEnableCrypto->isChecked()); QDialog::accept(); @@ -224,9 +215,6 @@ void SettingsDialog::on_m_pCheckBoxEnableCrypto_toggled(bool checked) { m_appConfig.setCryptoEnabled(checked); if (checked) { - SslCertificate sslCertificate; - sslCertificate.generateCertificate(m_pLineEditCertificatePath->text(), m_pComboBoxKeyLength->currentText()); - m_pMainWindow->updateLocalFingerprint(); verticalSpacer_4->changeSize(10, 10, QSizePolicy::Minimum); } else { verticalSpacer_4->changeSize(10, 0, QSizePolicy::Ignored); @@ -265,15 +253,6 @@ void SettingsDialog::on_m_pPushButtonBrowseCert_clicked() { updateRegenButton(); } -void SettingsDialog::regenerateSSLCert() { - SslCertificate sslCertificate; - sslCertificate.generateCertificate(appConfig().getTLSCertPath(), - appConfig().getTLSKeyLength(), - true); - - m_pMainWindow->updateLocalFingerprint(); -} - void SettingsDialog::on_m_pComboBoxKeyLength_currentIndexChanged(int index) { updateRegenButton(); } @@ -289,7 +268,7 @@ void SettingsDialog::updateRegenButton() { } void SettingsDialog::on_m_pPushButtonRegenCert_clicked() { - regenerateSSLCert(); + appConfig().generateCertificate(true); } void SettingsDialog::updateKeyLengthOnFile(const QString &path) { diff --git a/src/gui/src/SettingsDialog.h b/src/gui/src/SettingsDialog.h index 1b03dcd9b..5c8a0e85e 100644 --- a/src/gui/src/SettingsDialog.h +++ b/src/gui/src/SettingsDialog.h @@ -48,9 +48,6 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase /// @brief Causes the dialog to load all the settings from m_appConfig void loadFromConfig(); - /// @brief Forces the regeneration of the TLS cert from the saved settings - void regenerateSSLCert(); - /// @brief Check if the regenerate button should be enabled or disabled and sets it void updateRegenButton();