refactor: move TlsCertPath to Settings
newkey: security/certPath <= General/tlsCertPath remove tlsCertPath from appConfig
This commit is contained in:
@ -388,7 +388,8 @@ void MainWindow::configScopesSaving()
|
||||
|
||||
void MainWindow::appConfigTlsChanged()
|
||||
{
|
||||
if (m_tlsUtility.isEnabled() && !QFile::exists(m_appConfig.tlsCertPath())) {
|
||||
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
||||
if (m_tlsUtility.isEnabled() && !QFile::exists(certificate)) {
|
||||
m_tlsUtility.generateCertificate();
|
||||
}
|
||||
updateSecurityIcon(m_lblSecurityStatus->isVisible());
|
||||
@ -1149,12 +1150,13 @@ QString MainWindow::trustedFingerprintDb()
|
||||
|
||||
bool MainWindow::regenerateLocalFingerprints()
|
||||
{
|
||||
if (!QFile::exists(m_appConfig.tlsCertPath()) && !m_tlsUtility.generateCertificate()) {
|
||||
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
||||
if (!QFile::exists(certificate) && !m_tlsUtility.generateCertificate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TlsCertificate tls;
|
||||
if (!tls.generateFingerprint(m_appConfig.tlsCertPath())) {
|
||||
if (!tls.generateFingerprint(certificate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -152,7 +152,7 @@ void SettingsDialog::accept()
|
||||
Settings::setValue(Settings::Gui::Autohide, ui->cbAutoHide->isChecked());
|
||||
Settings::setValue(Settings::Gui::AutoUpdateCheck, ui->cbAutoUpdate->isChecked());
|
||||
m_appConfig.setPreventSleep(ui->cbPreventSleep->isChecked());
|
||||
m_appConfig.setTlsCertPath(ui->lineTlsCertPath->text());
|
||||
Settings::setValue(Settings::Security::Certificate, ui->lineTlsCertPath->text());
|
||||
Settings::setValue(Settings::Security::KeySize, ui->comboTlsKeyLength->currentText().toInt());
|
||||
Settings::setValue(Settings::Security::TlsEnabled, ui->groupSecurity->isChecked());
|
||||
m_appConfig.setLanguageSync(ui->cbLanguageSync->isChecked());
|
||||
@ -210,8 +210,9 @@ void SettingsDialog::loadFromConfig()
|
||||
|
||||
void SettingsDialog::updateTlsControls()
|
||||
{
|
||||
if (QFile(m_appConfig.tlsCertPath()).exists()) {
|
||||
updateKeyLengthOnFile(m_appConfig.tlsCertPath());
|
||||
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
||||
if (QFile(certificate).exists()) {
|
||||
updateKeyLengthOnFile(certificate);
|
||||
} else {
|
||||
const auto keyLengthText = Settings::value(Settings::Security::KeySize).toString();
|
||||
ui->comboTlsKeyLength->setCurrentText(keyLengthText);
|
||||
@ -221,7 +222,7 @@ void SettingsDialog::updateTlsControls()
|
||||
const auto writable = m_appConfig.isActiveScopeWritable();
|
||||
const auto enabled = writable && tlsEnabled;
|
||||
|
||||
ui->lineTlsCertPath->setText(m_appConfig.tlsCertPath());
|
||||
ui->lineTlsCertPath->setText(certificate);
|
||||
ui->cbRequireClientCert->setChecked(m_appConfig.requireClientCerts());
|
||||
ui->groupSecurity->setChecked(tlsEnabled);
|
||||
|
||||
|
||||
@ -74,8 +74,8 @@ QVariant Settings::defaultValue(const QString &key)
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((key == Gui::CloseToTray) || (key == Gui::LogExpanded) || (key == Gui::SymbolicTrayIcon)
|
||||
|| (key == Gui::CloseReminder) || (key == Security::TlsEnabled)) {
|
||||
if ((key == Gui::CloseToTray) || (key == Gui::LogExpanded) || (key == Gui::SymbolicTrayIcon) ||
|
||||
(key == Gui::CloseReminder) || (key == Security::TlsEnabled)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -85,6 +85,9 @@ QVariant Settings::defaultValue(const QString &key)
|
||||
if (key == Security::KeySize)
|
||||
return 2048;
|
||||
|
||||
if (key == Settings::Security::Certificate)
|
||||
return QStringLiteral("%1/%2/%3").arg(instance()->settingsPath(), kTlsDirName, kTlsCertificateFilename);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ public:
|
||||
};
|
||||
struct Security
|
||||
{
|
||||
inline static const auto Certificate = QStringLiteral("security/certificate");
|
||||
inline static const auto KeySize = QStringLiteral("security/keySize");
|
||||
inline static const auto TlsEnabled = QStringLiteral("security/tlsEnabled");
|
||||
};
|
||||
@ -90,6 +91,7 @@ private:
|
||||
, Gui::LogExpanded
|
||||
, Gui::SymbolicTrayIcon
|
||||
, Gui::WindowGeometry
|
||||
, Security::Certificate
|
||||
, Security::KeySize
|
||||
, Security::TlsEnabled
|
||||
};
|
||||
|
||||
@ -59,7 +59,7 @@ const char *const AppConfig::m_SettingsName[] = {
|
||||
"useInternalConfig",
|
||||
"groupClientChecked",
|
||||
"serverHostname",
|
||||
"tlsCertPath",
|
||||
"", // 26 cert path moved to deskflow settings
|
||||
"", // 27 key length Moved to Deskflow settings
|
||||
"preventSleep",
|
||||
"languageSync",
|
||||
@ -85,8 +85,7 @@ const char *const AppConfig::m_SettingsName[] = {
|
||||
AppConfig::AppConfig(deskflow::gui::IConfigScopes &scopes, std::shared_ptr<Deps> deps)
|
||||
: m_Scopes(scopes),
|
||||
m_pDeps(deps),
|
||||
m_ScreenName(deps->hostname()),
|
||||
m_TlsCertPath(deps->defaultTlsCertPath())
|
||||
m_ScreenName(deps->hostname())
|
||||
{
|
||||
determineScope();
|
||||
recall();
|
||||
@ -131,7 +130,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_TlsCertPath = getFromCurrentScope(kTlsCertPath, m_TlsCertPath).toString();
|
||||
m_RequireClientCert = getFromCurrentScope(kRequireClientCert, m_RequireClientCert).toBool();
|
||||
}
|
||||
|
||||
@ -182,11 +180,6 @@ void AppConfig::commit()
|
||||
setInCurrentScope(kEnableService, m_EnableService);
|
||||
setInCurrentScope(kRequireClientCert, m_RequireClientCert);
|
||||
}
|
||||
|
||||
if (m_TlsChanged) {
|
||||
m_TlsChanged = false;
|
||||
Q_EMIT tlsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void AppConfig::determineScope()
|
||||
@ -462,11 +455,6 @@ bool AppConfig::preventSleep() const
|
||||
return m_PreventSleep;
|
||||
}
|
||||
|
||||
QString AppConfig::tlsCertPath() const
|
||||
{
|
||||
return m_TlsCertPath;
|
||||
}
|
||||
|
||||
bool AppConfig::enableService() const
|
||||
{
|
||||
return m_EnableService;
|
||||
@ -515,16 +503,6 @@ const QString &AppConfig::serverHostname() const
|
||||
// Begin setters
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void AppConfig::setTlsCertPath(const QString &value)
|
||||
{
|
||||
if (m_TlsCertPath != 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_TlsCertPath = value;
|
||||
}
|
||||
|
||||
void AppConfig::setServerGroupChecked(bool newValue)
|
||||
{
|
||||
m_ServerGroupChecked = newValue;
|
||||
|
||||
@ -80,7 +80,7 @@ private:
|
||||
kUseInternalConfig = 23,
|
||||
kClientGroupChecked = 24,
|
||||
kServerHostname = 25,
|
||||
kTlsCertPath = 26,
|
||||
// 26 = kTlsCertPath moved to deskflow settings
|
||||
// 27 = tlsKeyLength Moved to deskflow settings
|
||||
kPreventSleep = 28,
|
||||
kLanguageSync = 29,
|
||||
@ -107,10 +107,6 @@ public:
|
||||
struct Deps
|
||||
{
|
||||
virtual ~Deps() = default;
|
||||
virtual QString defaultTlsCertPath() const
|
||||
{
|
||||
return deskflow::gui::paths::defaultTlsCertPath();
|
||||
}
|
||||
virtual QString hostname() const
|
||||
{
|
||||
return QHostInfo::localHostName();
|
||||
@ -134,7 +130,6 @@ public:
|
||||
IConfigScopes &scopes() const override;
|
||||
ProcessMode processMode() const override;
|
||||
ElevateMode elevateMode() const override;
|
||||
QString tlsCertPath() const override;
|
||||
QString logLevelText() const override;
|
||||
const QString &screenName() const override;
|
||||
bool logToFile() const override;
|
||||
@ -181,7 +176,6 @@ public:
|
||||
void setLanguageSync(bool b) override;
|
||||
void setPreventSleep(bool b) override;
|
||||
void setEnableService(bool enabled) override;
|
||||
void setTlsCertPath(const QString &path) override;
|
||||
void setRequireClientCerts(bool requireClientCerts) override;
|
||||
|
||||
//
|
||||
@ -248,11 +242,6 @@ private:
|
||||
/// @param [in] scope which should be loaded.
|
||||
void loadScope(IConfigScopes::Scope scope);
|
||||
|
||||
/**
|
||||
* @brief Gets a TLS certificate path based on the user's profile dir.
|
||||
*/
|
||||
QString defaultTlsCertPath() const;
|
||||
|
||||
// Used to make the server and client names on windows.
|
||||
#ifdef Q_OS_WIN
|
||||
inline static const auto s_winExeTemplate = QStringLiteral("%1.exe");
|
||||
@ -300,7 +289,6 @@ private:
|
||||
deskflow::gui::IConfigScopes &m_Scopes;
|
||||
std::shared_ptr<Deps> m_pDeps;
|
||||
QString m_ScreenName;
|
||||
QString m_TlsCertPath;
|
||||
|
||||
signals:
|
||||
void tlsChanged();
|
||||
|
||||
@ -32,7 +32,6 @@ public:
|
||||
//
|
||||
|
||||
virtual IConfigScopes &scopes() const = 0;
|
||||
virtual QString tlsCertPath() const = 0;
|
||||
virtual ProcessMode processMode() const = 0;
|
||||
virtual ElevateMode elevateMode() const = 0;
|
||||
virtual QString logLevelText() const = 0;
|
||||
@ -70,7 +69,6 @@ public:
|
||||
virtual void setLogFilename(const QString &logFilename) = 0;
|
||||
virtual void setElevateMode(ElevateMode elevateMode) = 0;
|
||||
virtual void setPreventSleep(bool preventSleep) = 0;
|
||||
virtual void setTlsCertPath(const QString &tlsCertPath) = 0;
|
||||
virtual void setLanguageSync(bool languageSync) = 0;
|
||||
virtual void setInvertScrollDirection(bool invertScrollDirection) = 0;
|
||||
virtual void setEnableService(bool enableService) = 0;
|
||||
|
||||
@ -561,7 +561,7 @@ bool CoreProcess::addServerArgs(QStringList &args, QString &app)
|
||||
qCritical("failed to persist tls certificate");
|
||||
return false;
|
||||
}
|
||||
args << "--tls-cert" << m_appConfig.tlsCertPath();
|
||||
args << "--tls-cert" << Settings::value(Settings::Security::Certificate).toString();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#include "config/ConfigScopes.h"
|
||||
#include "paths.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
|
||||
@ -27,7 +27,7 @@ void restart()
|
||||
QProcess::startDetached(program, arguments);
|
||||
|
||||
qDebug("exiting current process");
|
||||
QApplication::exit();
|
||||
QCoreApplication::exit();
|
||||
}
|
||||
|
||||
void clearSettings(ConfigScopes &scopes, bool enableRestart)
|
||||
|
||||
@ -46,11 +46,4 @@ inline QDir coreProfileDir()
|
||||
return QDir(coreTool.getProfileDir());
|
||||
}
|
||||
|
||||
inline QString defaultTlsCertPath()
|
||||
{
|
||||
const auto root = coreProfileDir();
|
||||
const auto sslDirPath = QDir(root.filePath(kTlsDirName));
|
||||
return sslDirPath.filePath(kTlsCertificateFilename);
|
||||
}
|
||||
|
||||
} // namespace deskflow::gui::paths
|
||||
|
||||
@ -38,15 +38,15 @@ bool TlsUtility::generateCertificate()
|
||||
}
|
||||
|
||||
auto length = Settings::value(Settings::Security::KeySize).toInt();
|
||||
|
||||
return m_certificate.generateCertificate(m_appConfig.tlsCertPath(), length);
|
||||
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
||||
return m_certificate.generateCertificate(certificate, length);
|
||||
}
|
||||
|
||||
bool TlsUtility::persistCertificate()
|
||||
{
|
||||
qDebug("persisting tls certificate");
|
||||
|
||||
if (QFile::exists(m_appConfig.tlsCertPath())) {
|
||||
if (QFile::exists(Settings::value(Settings::Security::Certificate).toString())) {
|
||||
qDebug("tls certificate already exists");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -33,7 +33,6 @@ public:
|
||||
//
|
||||
|
||||
MOCK_METHOD(deskflow::gui::IConfigScopes &, scopes, (), (const, override));
|
||||
MOCK_METHOD(QString, tlsCertPath, (), (const, override));
|
||||
MOCK_METHOD(ProcessMode, processMode, (), (const, override));
|
||||
MOCK_METHOD(ElevateMode, elevateMode, (), (const, override));
|
||||
MOCK_METHOD(QString, logLevelText, (), (const, override));
|
||||
@ -71,7 +70,6 @@ public:
|
||||
MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override));
|
||||
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, setLanguageSync, (bool languageSync), (override));
|
||||
MOCK_METHOD(void, setInvertScrollDirection, (bool invertScrollDirection), (override));
|
||||
MOCK_METHOD(void, setEnableService, (bool enableService), (override));
|
||||
|
||||
@ -41,7 +41,6 @@ struct DepsMock : public AppConfig::Deps
|
||||
{
|
||||
DepsMock()
|
||||
{
|
||||
ON_CALL(*this, defaultTlsCertPath()).WillByDefault(Return("stub"));
|
||||
ON_CALL(*this, hostname()).WillByDefault(Return("stub"));
|
||||
}
|
||||
|
||||
@ -50,7 +49,6 @@ struct DepsMock : public AppConfig::Deps
|
||||
return std::make_shared<NiceMock<DepsMock>>();
|
||||
}
|
||||
|
||||
MOCK_METHOD(QString, defaultTlsCertPath, (), (const, override));
|
||||
MOCK_METHOD(QString, hostname, (), (const, override));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user