From 2721de220a9eb22ea7f74311c70c15bf751f9a46 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 6 Mar 2025 18:08:08 -0500 Subject: [PATCH] refactor: move tlsEnabled to Settings newkey: security/tlsEnabled <= General/cryptoEnabled remove tlsEnabled from appconfig --- src/apps/deskflow-gui/MainWindow.cpp | 7 +++--- .../deskflow-gui/dialogs/SettingsDialog.cpp | 4 ++-- src/lib/common/Settings.cpp | 2 +- src/lib/common/Settings.h | 5 ++++ src/lib/gui/config/AppConfig.cpp | 24 ++++--------------- src/lib/gui/config/AppConfig.h | 5 +--- src/lib/gui/config/IAppConfig.h | 2 -- src/lib/gui/core/CoreProcess.cpp | 6 ++--- src/lib/gui/core/ServerConnection.cpp | 4 +++- src/lib/gui/tls/TlsUtility.cpp | 5 ++-- src/test/shared/gui/mocks/AppConfigMock.h | 2 -- 11 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index 422b2b39a..092c4a733 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -157,7 +157,7 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) updateSize(); // Force generation of SHA256 for the localhost - if (m_appConfig.tlsEnabled()) { + if (Settings::value(Settings::Security::TlsEnabled).toBool()) { if (!QFile::exists(localFingerprintDb())) { regenerateLocalFingerprints(); return; @@ -591,7 +591,7 @@ void MainWindow::updateSecurityIcon(bool visible) if (!visible) return; - bool secureSocket = m_appConfig.tlsEnabled(); + bool secureSocket = Settings::value(Settings::Security::TlsEnabled).toBool(); const auto txt = secureSocket ? tr("%1 Encryption Enabled").arg(m_coreProcess.secureSocketVersion()) : tr("Encryption Disabled"); @@ -1018,7 +1018,8 @@ QString MainWindow::getIPAddresses() const void MainWindow::updateLocalFingerprint() { - m_btnFingerprint->setVisible(m_appConfig.tlsEnabled() && QFile::exists(localFingerprintDb())); + const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool(); + m_btnFingerprint->setVisible(tlsEnabled && QFile::exists(localFingerprintDb())); } void MainWindow::autoAddScreen(const QString name) diff --git a/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp b/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp index fd18f9def..a8b4ac652 100644 --- a/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp +++ b/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp @@ -154,7 +154,7 @@ void SettingsDialog::accept() m_appConfig.setPreventSleep(ui->cbPreventSleep->isChecked()); m_appConfig.setTlsCertPath(ui->lineTlsCertPath->text()); m_appConfig.setTlsKeyLength(ui->comboTlsKeyLength->currentText().toInt()); - m_appConfig.setTlsEnabled(ui->groupSecurity->isChecked()); + Settings::setValue(Settings::Security::TlsEnabled, ui->groupSecurity->isChecked()); m_appConfig.setLanguageSync(ui->cbLanguageSync->isChecked()); m_appConfig.setInvertScrollDirection(ui->cbScrollDirection->isChecked()); m_appConfig.setEnableService(ui->cbServiceEnabled->isChecked()); @@ -218,7 +218,7 @@ void SettingsDialog::updateTlsControls() ui->comboTlsKeyLength->setCurrentIndex(ui->comboTlsKeyLength->findText(keyLengthText)); } - const auto tlsEnabled = m_tlsUtility.isEnabled(); + const auto tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool(); const auto writable = m_appConfig.isActiveScopeWritable(); const auto enabled = writable && tlsEnabled; diff --git a/src/lib/common/Settings.cpp b/src/lib/common/Settings.cpp index 7cd34dbda..c420ff06a 100644 --- a/src/lib/common/Settings.cpp +++ b/src/lib/common/Settings.cpp @@ -75,7 +75,7 @@ QVariant Settings::defaultValue(const QString &key) } if ((key == Gui::CloseToTray) || (key == Gui::LogExpanded) || (key == Gui::SymbolicTrayIcon) - || (key == Gui::CloseReminder)) { + || (key == Gui::CloseReminder) || (key == Security::TlsEnabled)) { return true; } diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index 53cde87a2..c508a7775 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -45,6 +45,10 @@ public: inline static const auto SymbolicTrayIcon = QStringLiteral("gui/symbolicTrayIcon"); inline static const auto WindowGeometry = QStringLiteral("gui/windowGeometry"); }; + struct Security + { + inline static const auto TlsEnabled = QStringLiteral("security/tlsEnabled"); + }; static Settings *instance(); static void setSettingFile(const QString &settingsFile = QString()); @@ -85,6 +89,7 @@ private: , Gui::LogExpanded , Gui::SymbolicTrayIcon , Gui::WindowGeometry + , Security::TlsEnabled }; // clang-format on }; diff --git a/src/lib/gui/config/AppConfig.cpp b/src/lib/gui/config/AppConfig.cpp index ed91b4eeb..e8454efd9 100644 --- a/src/lib/gui/config/AppConfig.cpp +++ b/src/lib/gui/config/AppConfig.cpp @@ -43,10 +43,10 @@ const char *const AppConfig::m_SettingsName[] = { "", // 7 statedBefore moved to deskflow settings "elevateMode", "elevateModeEnum", - "", // 10 = edition, obsolete (using serial key instead) - "cryptoEnabled", // 11 = kTlsEnabled (retain legacy string value) - "", // 12 AutoHide, moved to Settings - "", // 13 = serialKey, obsolete + "", // 10 = edition, obsolete (using serial key instead) + "", // 11 = kTlsEnabled (retain legacy string value) Moved to Settings + "", // 12 AutoHide, moved to Settings + "", // 13 = serialKey, obsolete "lastVersion", "", // 15 = lastExpiringWarningTime, obsolete "", // 16 = activationHasRun, obsolete @@ -131,7 +131,6 @@ void AppConfig::recallFromCurrentScope() m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool(); m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool(); m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool(); - m_TlsEnabled = getFromCurrentScope(kTlsEnabled, m_TlsEnabled).toBool(); m_TlsCertPath = getFromCurrentScope(kTlsCertPath, m_TlsCertPath).toString(); m_TlsKeyLength = getFromCurrentScope(kTlsKeyLength, m_TlsKeyLength).toInt(); m_RequireClientCert = getFromCurrentScope(kRequireClientCert, m_RequireClientCert).toBool(); @@ -173,7 +172,6 @@ void AppConfig::commit() setInCurrentScope(kLogFilename, m_LogFilename); setInCurrentScope(kElevateMode, static_cast(m_ElevateMode)); setInCurrentScope(kElevateModeLegacy, m_ElevateMode == ElevateMode::kAlways); - setInCurrentScope(kTlsEnabled, m_TlsEnabled); setInCurrentScope(kLastVersion, m_LastVersion); setInCurrentScope(kUseExternalConfig, m_UseExternalConfig); setInCurrentScope(kConfigFile, m_ConfigFile); @@ -450,11 +448,6 @@ ElevateMode AppConfig::elevateMode() const return m_ElevateMode; } -bool AppConfig::tlsEnabled() const -{ - return m_TlsEnabled; -} - bool AppConfig::invertScrollDirection() const { return m_InvertScrollDirection; @@ -528,15 +521,6 @@ const QString &AppConfig::serverHostname() const // Begin setters /////////////////////////////////////////////////////////////////////////////// -void AppConfig::setTlsEnabled(bool value) -{ - // we purposefully do not set the 'tls changed' flag when enabling/disabling - // tls, since that would cause the certificate to regenerate, which could get - // pretty annoying. - - m_TlsEnabled = value; -} - void AppConfig::setTlsCertPath(const QString &value) { if (m_TlsCertPath != value) { diff --git a/src/lib/gui/config/AppConfig.h b/src/lib/gui/config/AppConfig.h index c38fd6df0..dfcb16cd3 100644 --- a/src/lib/gui/config/AppConfig.h +++ b/src/lib/gui/config/AppConfig.h @@ -66,7 +66,7 @@ private: kElevateModeLegacy = 8, kElevateMode = 9, // 10 = edition, obsolete (related to obsolete licensing) - kTlsEnabled = 11, + // 11 = tlsEnagled moved to Settigns // 12 = auto hide, Moved to Settings // 13 = serial key, obsolete kLastVersion = 14, @@ -135,7 +135,6 @@ public: IConfigScopes &scopes() const override; ProcessMode processMode() const override; ElevateMode elevateMode() const override; - bool tlsEnabled() const override; QString tlsCertPath() const override; int tlsKeyLength() const override; QString logLevelText() const override; @@ -180,7 +179,6 @@ public: void setLogToFile(bool b) override; void setLogFilename(const QString &s) override; void setElevateMode(ElevateMode em) override; - void setTlsEnabled(bool e) override; void setInvertScrollDirection(bool b) override; void setLanguageSync(bool b) override; void setPreventSleep(bool b) override; @@ -282,7 +280,6 @@ private: bool m_LogToFile = false; QString m_LogFilename = logDir() + deskflow::gui::kDefaultLogFile; ElevateMode m_ElevateMode = deskflow::gui::kDefaultElevateMode; - bool m_TlsEnabled = true; QString m_LastVersion = ""; bool m_InvertScrollDirection = false; bool m_LanguageSync = true; diff --git a/src/lib/gui/config/IAppConfig.h b/src/lib/gui/config/IAppConfig.h index 25a6b4fbd..8502c9048 100644 --- a/src/lib/gui/config/IAppConfig.h +++ b/src/lib/gui/config/IAppConfig.h @@ -34,7 +34,6 @@ public: virtual IConfigScopes &scopes() const = 0; virtual QString tlsCertPath() const = 0; virtual int tlsKeyLength() const = 0; - virtual bool tlsEnabled() const = 0; virtual ProcessMode processMode() const = 0; virtual ElevateMode elevateMode() const = 0; virtual QString logLevelText() const = 0; @@ -74,7 +73,6 @@ public: virtual void setPreventSleep(bool preventSleep) = 0; virtual void setTlsCertPath(const QString &tlsCertPath) = 0; virtual void setTlsKeyLength(int tlsKeyLength) = 0; - virtual void setTlsEnabled(bool tlsEnabled) = 0; virtual void setLanguageSync(bool languageSync) = 0; virtual void setInvertScrollDirection(bool invertScrollDirection) = 0; virtual void setEnableService(bool enableService) = 0; diff --git a/src/lib/gui/core/CoreProcess.cpp b/src/lib/gui/core/CoreProcess.cpp index 34204d15f..cd18fe03b 100644 --- a/src/lib/gui/core/CoreProcess.cpp +++ b/src/lib/gui/core/CoreProcess.cpp @@ -6,7 +6,7 @@ #include "CoreProcess.h" -#include "common/constants.h" +#include "common/Settings.h" #include "gui/config/IAppConfig.h" #include "gui/core/CoreTool.h" #include "gui/ipc/DaemonIpcClient.h" @@ -500,7 +500,7 @@ bool CoreProcess::addGenericArgs(QStringList &args, const ProcessMode processMod #endif - if (m_appConfig.tlsEnabled()) { + if (Settings::value(Settings::Security::TlsEnabled).toBool()) { args << "--enable-crypto"; } @@ -555,7 +555,7 @@ bool CoreProcess::addServerArgs(QStringList &args, QString &app) // bizarrely, the tls cert path arg was being given to the core client. // since it's not clear why (it is only needed for the server), this has now // been moved to server args. - if (m_appConfig.tlsEnabled()) { + if (Settings::value(Settings::Security::TlsEnabled).toBool()) { TlsUtility tlsUtility(m_appConfig); if (!tlsUtility.persistCertificate()) { qCritical("failed to persist tls certificate"); diff --git a/src/lib/gui/core/ServerConnection.cpp b/src/lib/gui/core/ServerConnection.cpp index 9077fd20c..e09758b7e 100644 --- a/src/lib/gui/core/ServerConnection.cpp +++ b/src/lib/gui/core/ServerConnection.cpp @@ -7,6 +7,7 @@ #include "ServerConnection.h" #include "ServerMessage.h" +#include "common/Settings.h" #include "gui/config/ServerConfigDialogState.h" #include "messages.h" @@ -94,8 +95,9 @@ void ServerConnection::handleNewClient(const QString &clientName) Q_EMIT messageShowing(); m_messageShowing = true; + const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool(); const auto result = - m_pDeps->showNewClientPrompt(m_pParent, clientName, m_appConfig.tlsEnabled() && m_appConfig.requireClientCerts()); + m_pDeps->showNewClientPrompt(m_pParent, clientName, tlsEnabled && m_appConfig.requireClientCerts()); m_messageShowing = false; if (result == Add) { diff --git a/src/lib/gui/tls/TlsUtility.cpp b/src/lib/gui/tls/TlsUtility.cpp index c4ad35e01..34693e5ca 100644 --- a/src/lib/gui/tls/TlsUtility.cpp +++ b/src/lib/gui/tls/TlsUtility.cpp @@ -7,7 +7,7 @@ #include "TlsUtility.h" #include "TlsCertificate.h" - +#include "common/Settings.h" #include #include @@ -19,8 +19,7 @@ TlsUtility::TlsUtility(const IAppConfig &appConfig) : m_appConfig(appConfig) bool TlsUtility::isEnabled() const { - const auto &config = m_appConfig; - return config.tlsEnabled(); + return Settings::value(Settings::Security::TlsEnabled).toBool(); } bool TlsUtility::generateCertificate() diff --git a/src/test/shared/gui/mocks/AppConfigMock.h b/src/test/shared/gui/mocks/AppConfigMock.h index 62aee845e..56e3b56cb 100644 --- a/src/test/shared/gui/mocks/AppConfigMock.h +++ b/src/test/shared/gui/mocks/AppConfigMock.h @@ -35,7 +35,6 @@ public: MOCK_METHOD(deskflow::gui::IConfigScopes &, scopes, (), (const, override)); MOCK_METHOD(QString, tlsCertPath, (), (const, override)); MOCK_METHOD(int, tlsKeyLength, (), (const, override)); - MOCK_METHOD(bool, tlsEnabled, (), (const, override)); MOCK_METHOD(ProcessMode, processMode, (), (const, override)); MOCK_METHOD(ElevateMode, elevateMode, (), (const, override)); MOCK_METHOD(QString, logLevelText, (), (const, override)); @@ -75,7 +74,6 @@ public: MOCK_METHOD(void, setPreventSleep, (bool preventSleep), (override)); MOCK_METHOD(void, setTlsCertPath, (const QString &tlsCertPath), (override)); MOCK_METHOD(void, setTlsKeyLength, (int tlsKeyLength), (override)); - MOCK_METHOD(void, setTlsEnabled, (bool tlsEnabled), (override)); MOCK_METHOD(void, setLanguageSync, (bool languageSync), (override)); MOCK_METHOD(void, setInvertScrollDirection, (bool invertScrollDirection), (override)); MOCK_METHOD(void, setEnableService, (bool enableService), (override));