refactor: move tlsKeyLength to Settings

newkey: security/keySize <= General/tlsKeyLength
removed tlsKeyLength from appconfig
This commit is contained in:
sithlord48
2025-03-06 18:32:14 -05:00
committed by Nick Bolton
parent 2721de220a
commit bee0f84556
8 changed files with 13 additions and 34 deletions

View File

@ -153,7 +153,7 @@ void SettingsDialog::accept()
Settings::setValue(Settings::Gui::AutoUpdateCheck, ui->cbAutoUpdate->isChecked());
m_appConfig.setPreventSleep(ui->cbPreventSleep->isChecked());
m_appConfig.setTlsCertPath(ui->lineTlsCertPath->text());
m_appConfig.setTlsKeyLength(ui->comboTlsKeyLength->currentText().toInt());
Settings::setValue(Settings::Security::KeySize, ui->comboTlsKeyLength->currentText().toInt());
Settings::setValue(Settings::Security::TlsEnabled, ui->groupSecurity->isChecked());
m_appConfig.setLanguageSync(ui->cbLanguageSync->isChecked());
m_appConfig.setInvertScrollDirection(ui->cbScrollDirection->isChecked());
@ -210,12 +210,11 @@ void SettingsDialog::loadFromConfig()
void SettingsDialog::updateTlsControls()
{
if (QFile(m_appConfig.tlsCertPath()).exists()) {
updateKeyLengthOnFile(m_appConfig.tlsCertPath());
} else {
const auto keyLengthText = QString::number(m_appConfig.tlsKeyLength());
ui->comboTlsKeyLength->setCurrentIndex(ui->comboTlsKeyLength->findText(keyLengthText));
const auto keyLengthText = Settings::value(Settings::Security::KeySize).toString();
ui->comboTlsKeyLength->setCurrentText(keyLengthText);
}
const auto tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
@ -262,9 +261,8 @@ void SettingsDialog::updateKeyLengthOnFile(const QString &path)
}
auto length = ssl.getCertKeyLength(path);
auto index = ui->comboTlsKeyLength->findText(QString::number(length));
ui->comboTlsKeyLength->setCurrentIndex(index);
m_appConfig.setTlsKeyLength(length);
ui->comboTlsKeyLength->setCurrentText(QString::number(length));
Settings::setValue(Settings::Security::KeySize, length);
}
void SettingsDialog::updateControls()

View File

@ -82,6 +82,9 @@ QVariant Settings::defaultValue(const QString &key)
if (key == Gui::WindowGeometry)
return QRect();
if (key == Security::KeySize)
return 2048;
return QVariant();
}

View File

@ -47,6 +47,7 @@ public:
};
struct Security
{
inline static const auto KeySize = QStringLiteral("security/keySize");
inline static const auto TlsEnabled = QStringLiteral("security/tlsEnabled");
};
@ -89,6 +90,7 @@ private:
, Gui::LogExpanded
, Gui::SymbolicTrayIcon
, Gui::WindowGeometry
, Security::KeySize
, Security::TlsEnabled
};
// clang-format on

View File

@ -60,7 +60,7 @@ const char *const AppConfig::m_SettingsName[] = {
"groupClientChecked",
"serverHostname",
"tlsCertPath",
"tlsKeyLength",
"", // 27 key length Moved to Deskflow settings
"preventSleep",
"languageSync",
"invertScrollDirection",
@ -132,7 +132,6 @@ void AppConfig::recallFromCurrentScope()
m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool();
m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool();
m_TlsCertPath = getFromCurrentScope(kTlsCertPath, m_TlsCertPath).toString();
m_TlsKeyLength = getFromCurrentScope(kTlsKeyLength, m_TlsKeyLength).toInt();
m_RequireClientCert = getFromCurrentScope(kRequireClientCert, m_RequireClientCert).toBool();
}
@ -468,11 +467,6 @@ QString AppConfig::tlsCertPath() const
return m_TlsCertPath;
}
int AppConfig::tlsKeyLength() const
{
return m_TlsKeyLength;
}
bool AppConfig::enableService() const
{
return m_EnableService;
@ -531,16 +525,6 @@ void AppConfig::setTlsCertPath(const QString &value)
m_TlsCertPath = value;
}
void AppConfig::setTlsKeyLength(int value)
{
if (m_TlsKeyLength != value) {
// deliberately only set the changed flag if there was a change.
// it's important not to set this flag to false here.
m_TlsChanged = true;
}
m_TlsKeyLength = value;
}
void AppConfig::setServerGroupChecked(bool newValue)
{
m_ServerGroupChecked = newValue;

View File

@ -27,7 +27,6 @@ namespace deskflow::gui {
const ElevateMode kDefaultElevateMode = ElevateMode::kAutomatic;
const QString kDefaultLogFile = QStringLiteral("%1.log").arg(kAppId);
const int kDefaultTlsKeyLength = 2048;
#if defined(Q_OS_WIN)
const ProcessMode kDefaultProcessMode = ProcessMode::kService;
@ -82,7 +81,7 @@ private:
kClientGroupChecked = 24,
kServerHostname = 25,
kTlsCertPath = 26,
kTlsKeyLength = 27,
// 27 = tlsKeyLength Moved to deskflow settings
kPreventSleep = 28,
kLanguageSync = 29,
kInvertScrollDirection = 30,
@ -136,7 +135,6 @@ public:
ProcessMode processMode() const override;
ElevateMode elevateMode() const override;
QString tlsCertPath() const override;
int tlsKeyLength() const override;
QString logLevelText() const override;
const QString &screenName() const override;
bool logToFile() const override;
@ -184,7 +182,6 @@ public:
void setPreventSleep(bool b) override;
void setEnableService(bool enabled) override;
void setTlsCertPath(const QString &path) override;
void setTlsKeyLength(int length) override;
void setRequireClientCerts(bool requireClientCerts) override;
//
@ -291,7 +288,6 @@ private:
bool m_ClientGroupChecked = false;
QString m_ServerHostname = "";
bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService;
int m_TlsKeyLength = deskflow::gui::kDefaultTlsKeyLength;
bool m_LoadFromSystemScope = false;
bool m_RequireClientCert = true;

View File

@ -33,7 +33,6 @@ public:
virtual IConfigScopes &scopes() const = 0;
virtual QString tlsCertPath() const = 0;
virtual int tlsKeyLength() const = 0;
virtual ProcessMode processMode() const = 0;
virtual ElevateMode elevateMode() const = 0;
virtual QString logLevelText() const = 0;
@ -72,7 +71,6 @@ public:
virtual void setElevateMode(ElevateMode elevateMode) = 0;
virtual void setPreventSleep(bool preventSleep) = 0;
virtual void setTlsCertPath(const QString &tlsCertPath) = 0;
virtual void setTlsKeyLength(int tlsKeyLength) = 0;
virtual void setLanguageSync(bool languageSync) = 0;
virtual void setInvertScrollDirection(bool invertScrollDirection) = 0;
virtual void setEnableService(bool enableService) = 0;

View File

@ -37,7 +37,7 @@ bool TlsUtility::generateCertificate()
return false;
}
auto length = m_appConfig.tlsKeyLength();
auto length = Settings::value(Settings::Security::KeySize).toInt();
return m_certificate.generateCertificate(m_appConfig.tlsCertPath(), length);
}

View File

@ -34,7 +34,6 @@ public:
MOCK_METHOD(deskflow::gui::IConfigScopes &, scopes, (), (const, override));
MOCK_METHOD(QString, tlsCertPath, (), (const, override));
MOCK_METHOD(int, tlsKeyLength, (), (const, override));
MOCK_METHOD(ProcessMode, processMode, (), (const, override));
MOCK_METHOD(ElevateMode, elevateMode, (), (const, override));
MOCK_METHOD(QString, logLevelText, (), (const, override));
@ -73,7 +72,6 @@ public:
MOCK_METHOD(void, setElevateMode, (ElevateMode elevateMode), (override));
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, setLanguageSync, (bool languageSync), (override));
MOCK_METHOD(void, setInvertScrollDirection, (bool invertScrollDirection), (override));
MOCK_METHOD(void, setEnableService, (bool enableService), (override));