refactor: move requirepeerchecking to Settings
newkey: security/checkpeerfingerprints <= General/requireClientCerts remove requireClientCerts from appconfig
This commit is contained in:
parent
4eb7ea3491
commit
5360fb3c89
11 changed files with 22 additions and 42 deletions
|
|
@ -385,7 +385,7 @@ void MainWindow::firstShown()
|
||||||
void MainWindow::settingsChanged(const QString &key)
|
void MainWindow::settingsChanged(const QString &key)
|
||||||
{
|
{
|
||||||
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
|
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
|
||||||
(key == Settings::Security::TlsEnabled)) {
|
(key == Settings::Security::TlsEnabled) || (key == Settings::Security::CheckPeers)) {
|
||||||
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
||||||
if (m_tlsUtility.isEnabled() && !QFile::exists(certificate)) {
|
if (m_tlsUtility.isEnabled() && !QFile::exists(certificate)) {
|
||||||
m_tlsUtility.generateCertificate();
|
m_tlsUtility.generateCertificate();
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ void SettingsDialog::accept()
|
||||||
m_appConfig.setEnableService(ui->cbServiceEnabled->isChecked());
|
m_appConfig.setEnableService(ui->cbServiceEnabled->isChecked());
|
||||||
Settings::setValue(Settings::Gui::CloseToTray, ui->cbCloseToTray->isChecked());
|
Settings::setValue(Settings::Gui::CloseToTray, ui->cbCloseToTray->isChecked());
|
||||||
Settings::setValue(Settings::Gui::SymbolicTrayIcon, ui->rbIconMono->isChecked());
|
Settings::setValue(Settings::Gui::SymbolicTrayIcon, ui->rbIconMono->isChecked());
|
||||||
m_appConfig.setRequireClientCerts(ui->cbRequireClientCert->isChecked());
|
Settings::setValue(Settings::Security::CheckPeers, ui->cbRequireClientCert->isChecked());
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +223,7 @@ void SettingsDialog::updateTlsControls()
|
||||||
const auto enabled = writable && tlsEnabled;
|
const auto enabled = writable && tlsEnabled;
|
||||||
|
|
||||||
ui->lineTlsCertPath->setText(certificate);
|
ui->lineTlsCertPath->setText(certificate);
|
||||||
ui->cbRequireClientCert->setChecked(m_appConfig.requireClientCerts());
|
ui->cbRequireClientCert->setChecked(Settings::value(Settings::Security::CheckPeers).toBool());
|
||||||
ui->groupSecurity->setChecked(tlsEnabled);
|
ui->groupSecurity->setChecked(tlsEnabled);
|
||||||
|
|
||||||
ui->groupSecurity->setEnabled(writable);
|
ui->groupSecurity->setEnabled(writable);
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ QVariant Settings::defaultValue(const QString &key)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((key == Gui::CloseToTray) || (key == Gui::LogExpanded) || (key == Gui::SymbolicTrayIcon) ||
|
if ((key == Gui::CloseToTray) || (key == Gui::LogExpanded) || (key == Gui::SymbolicTrayIcon)
|
||||||
(key == Gui::CloseReminder) || (key == Security::TlsEnabled)) {
|
|| (key == Gui::CloseReminder) || (key == Security::TlsEnabled) || (key == Security::CheckPeers)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ QVariant Settings::defaultValue(const QString &key)
|
||||||
if (key == Security::KeySize)
|
if (key == Security::KeySize)
|
||||||
return 2048;
|
return 2048;
|
||||||
|
|
||||||
if (key == Settings::Security::Certificate)
|
if (key == Security::Certificate)
|
||||||
return QStringLiteral("%1/%2/%3").arg(instance()->settingsPath(), kTlsDirName, kTlsCertificateFilename);
|
return QStringLiteral("%1/%2/%3").arg(instance()->settingsPath(), kTlsDirName, kTlsCertificateFilename);
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,17 @@ class Settings : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
inline const static auto UserSettingFile =
|
inline const static auto UserDir = QStringLiteral("%1/AppData/Local/%2").arg(QDir::homePath(), kAppName);
|
||||||
QStringLiteral("%1/AppData/Local/%2/%3.conf").arg(QDir::homePath(), kAppName, kAppName);
|
inline const static auto SystemDir = QStringLiteral("C:/ProgramData/%1").arg(kAppName);
|
||||||
inline const static auto SystemSettingFile = QStringLiteral("C:/ProgramData/%2/%3.conf").arg(kAppName, kAppName);
|
|
||||||
#elif defined(Q_OS_MAC)
|
#elif defined(Q_OS_MAC)
|
||||||
inline const static auto UserSettingFile =
|
inline const static auto UserDir = QStringLiteral("%1/Library/%2").arg(QDir::homePath(), kAppName);
|
||||||
QStringLiteral("%1/Library/%2/%3.conf").arg(QDir::homePath(), kAppName, kAppName);
|
inline const static auto SystemDir = QStringLiteral("/Library/%1").arg(kAppName);
|
||||||
inline const static auto SystemSettingFile = QStringLiteral("/Libaray/%2/%3.conf").arg(kAppName, kAppName);
|
|
||||||
#else
|
#else
|
||||||
inline const static auto UserSettingFile =
|
inline const static auto UserDir = QStringLiteral("%1/.config/%2").arg(QDir::homePath(), kAppName);
|
||||||
QStringLiteral("%1/.config/%2/%3.conf").arg(QDir::homePath(), kAppName, kAppName);
|
inline const static auto SystemDir = QStringLiteral("/etc/%1").arg(kAppName);
|
||||||
inline const static auto SystemSettingFile = QStringLiteral("/etc/%2/%3.conf").arg(kAppName, kAppName);
|
|
||||||
#endif
|
#endif
|
||||||
|
inline const static auto UserSettingFile = QStringLiteral("%1/%2.conf").arg(UserDir, kAppName);
|
||||||
|
inline const static auto SystemSettingFile = QStringLiteral("%1/%2.conf").arg(SystemDir, kAppName);
|
||||||
|
|
||||||
struct Core
|
struct Core
|
||||||
{
|
{
|
||||||
|
|
@ -47,6 +46,7 @@ public:
|
||||||
};
|
};
|
||||||
struct Security
|
struct Security
|
||||||
{
|
{
|
||||||
|
inline static const auto CheckPeers = QStringLiteral("security/checkpeerfingerprints");
|
||||||
inline static const auto Certificate = QStringLiteral("security/certificate");
|
inline static const auto Certificate = QStringLiteral("security/certificate");
|
||||||
inline static const auto KeySize = QStringLiteral("security/keySize");
|
inline static const auto KeySize = QStringLiteral("security/keySize");
|
||||||
inline static const auto TlsEnabled = QStringLiteral("security/tlsEnabled");
|
inline static const auto TlsEnabled = QStringLiteral("security/tlsEnabled");
|
||||||
|
|
@ -92,6 +92,7 @@ private:
|
||||||
, Gui::SymbolicTrayIcon
|
, Gui::SymbolicTrayIcon
|
||||||
, Gui::WindowGeometry
|
, Gui::WindowGeometry
|
||||||
, Security::Certificate
|
, Security::Certificate
|
||||||
|
, Security::CheckPeers
|
||||||
, Security::KeySize
|
, Security::KeySize
|
||||||
, Security::TlsEnabled
|
, Security::TlsEnabled
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ const char *const AppConfig::m_SettingsName[] = {
|
||||||
"", // 43 Moved to deskflow settings
|
"", // 43 Moved to deskflow settings
|
||||||
"", // 44, Moved to deskflow settings.
|
"", // 44, Moved to deskflow settings.
|
||||||
"", // 45 Moved to deskflow settings
|
"", // 45 Moved to deskflow settings
|
||||||
"requireClientCerts",
|
"", // 46 require peer certs, Moved to deskflow settings
|
||||||
};
|
};
|
||||||
|
|
||||||
AppConfig::AppConfig(deskflow::gui::IConfigScopes &scopes, std::shared_ptr<Deps> deps)
|
AppConfig::AppConfig(deskflow::gui::IConfigScopes &scopes, std::shared_ptr<Deps> deps)
|
||||||
|
|
@ -130,7 +130,6 @@ void AppConfig::recallFromCurrentScope()
|
||||||
m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool();
|
m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool();
|
||||||
m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool();
|
m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool();
|
||||||
m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool();
|
m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool();
|
||||||
m_RequireClientCert = getFromCurrentScope(kRequireClientCert, m_RequireClientCert).toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppConfig::recallScreenName()
|
void AppConfig::recallScreenName()
|
||||||
|
|
@ -178,7 +177,6 @@ void AppConfig::commit()
|
||||||
setInCurrentScope(kLanguageSync, m_LanguageSync);
|
setInCurrentScope(kLanguageSync, m_LanguageSync);
|
||||||
setInCurrentScope(kInvertScrollDirection, m_InvertScrollDirection);
|
setInCurrentScope(kInvertScrollDirection, m_InvertScrollDirection);
|
||||||
setInCurrentScope(kEnableService, m_EnableService);
|
setInCurrentScope(kEnableService, m_EnableService);
|
||||||
setInCurrentScope(kRequireClientCert, m_RequireClientCert);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,11 +483,6 @@ bool AppConfig::clientGroupChecked() const
|
||||||
return m_ClientGroupChecked;
|
return m_ClientGroupChecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppConfig::requireClientCerts() const
|
|
||||||
{
|
|
||||||
return m_RequireClientCert;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &AppConfig::serverHostname() const
|
const QString &AppConfig::serverHostname() const
|
||||||
{
|
{
|
||||||
return m_ServerHostname;
|
return m_ServerHostname;
|
||||||
|
|
@ -596,13 +589,6 @@ void AppConfig::setEnableService(bool enabled)
|
||||||
m_EnableService = enabled;
|
m_EnableService = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppConfig::setRequireClientCerts(bool requireClientCerts)
|
|
||||||
{
|
|
||||||
if (requireClientCerts == m_RequireClientCert)
|
|
||||||
return;
|
|
||||||
m_RequireClientCert = requireClientCerts;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// End setters
|
// End setters
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ private:
|
||||||
// 43 = Enable Update Check,
|
// 43 = Enable Update Check,
|
||||||
// 44 = LogExpanded, Moved to deskflow settings
|
// 44 = LogExpanded, Moved to deskflow settings
|
||||||
// 45 = Colorful Icon, Moved to deskflow settings
|
// 45 = Colorful Icon, Moved to deskflow settings
|
||||||
kRequireClientCert = 46
|
// kRequireClientCert = 46 Moved to deskflow settings
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -150,7 +150,6 @@ public:
|
||||||
int logLevel() const override;
|
int logLevel() const override;
|
||||||
bool enableService() const override;
|
bool enableService() const override;
|
||||||
bool clientGroupChecked() const override;
|
bool clientGroupChecked() const override;
|
||||||
bool requireClientCerts() const override;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Getters (new methods)
|
// Getters (new methods)
|
||||||
|
|
@ -176,7 +175,6 @@ public:
|
||||||
void setLanguageSync(bool b) override;
|
void setLanguageSync(bool b) override;
|
||||||
void setPreventSleep(bool b) override;
|
void setPreventSleep(bool b) override;
|
||||||
void setEnableService(bool enabled) override;
|
void setEnableService(bool enabled) override;
|
||||||
void setRequireClientCerts(bool requireClientCerts) override;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setters (new methods)
|
// Setters (new methods)
|
||||||
|
|
@ -278,7 +276,6 @@ private:
|
||||||
QString m_ServerHostname = "";
|
QString m_ServerHostname = "";
|
||||||
bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService;
|
bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService;
|
||||||
bool m_LoadFromSystemScope = false;
|
bool m_LoadFromSystemScope = false;
|
||||||
bool m_RequireClientCert = true;
|
|
||||||
|
|
||||||
deskflow::gui::IConfigScopes &m_Scopes;
|
deskflow::gui::IConfigScopes &m_Scopes;
|
||||||
std::shared_ptr<Deps> m_pDeps;
|
std::shared_ptr<Deps> m_pDeps;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ public:
|
||||||
virtual bool isActiveScopeSystem() const = 0;
|
virtual bool isActiveScopeSystem() const = 0;
|
||||||
virtual bool isActiveScopeWritable() const = 0;
|
virtual bool isActiveScopeWritable() const = 0;
|
||||||
virtual bool clientGroupChecked() const = 0;
|
virtual bool clientGroupChecked() const = 0;
|
||||||
virtual bool requireClientCerts() const = 0;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setters
|
// Setters
|
||||||
|
|
@ -72,7 +71,6 @@ public:
|
||||||
virtual void setLanguageSync(bool languageSync) = 0;
|
virtual void setLanguageSync(bool languageSync) = 0;
|
||||||
virtual void setInvertScrollDirection(bool invertScrollDirection) = 0;
|
virtual void setInvertScrollDirection(bool invertScrollDirection) = 0;
|
||||||
virtual void setEnableService(bool enableService) = 0;
|
virtual void setEnableService(bool enableService) = 0;
|
||||||
virtual void setRequireClientCerts(bool requireClientCerts) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace deskflow::gui
|
} // namespace deskflow::gui
|
||||||
|
|
|
||||||
|
|
@ -534,7 +534,7 @@ bool CoreProcess::addServerArgs(QStringList &args, QString &app)
|
||||||
args << "--log" << m_appConfig.logFilename();
|
args << "--log" << m_appConfig.logFilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_appConfig.requireClientCerts()) {
|
if (!Settings::value(Settings::Security::CheckPeers).toBool()) {
|
||||||
args << "--disable-client-cert-check";
|
args << "--disable-client-cert-check";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,8 @@ void ServerConnection::handleNewClient(const QString &clientName)
|
||||||
|
|
||||||
m_messageShowing = true;
|
m_messageShowing = true;
|
||||||
const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
|
const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
|
||||||
const auto result =
|
const bool requireCerts = Settings::value(Settings::Security::CheckPeers).toBool();
|
||||||
m_pDeps->showNewClientPrompt(m_pParent, clientName, tlsEnabled && m_appConfig.requireClientCerts());
|
const auto result = m_pDeps->showNewClientPrompt(m_pParent, clientName, tlsEnabled && requireCerts);
|
||||||
m_messageShowing = false;
|
m_messageShowing = false;
|
||||||
|
|
||||||
if (result == Add) {
|
if (result == Add) {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ public:
|
||||||
MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override));
|
MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override));
|
||||||
MOCK_METHOD(bool, isActiveScopeWritable, (), (const, override));
|
MOCK_METHOD(bool, isActiveScopeWritable, (), (const, override));
|
||||||
MOCK_METHOD(bool, clientGroupChecked, (), (const, override));
|
MOCK_METHOD(bool, clientGroupChecked, (), (const, override));
|
||||||
MOCK_METHOD(bool, requireClientCerts, (), (const, override));
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setters
|
// Setters
|
||||||
|
|
@ -73,7 +72,6 @@ public:
|
||||||
MOCK_METHOD(void, setLanguageSync, (bool languageSync), (override));
|
MOCK_METHOD(void, setLanguageSync, (bool languageSync), (override));
|
||||||
MOCK_METHOD(void, setInvertScrollDirection, (bool invertScrollDirection), (override));
|
MOCK_METHOD(void, setInvertScrollDirection, (bool invertScrollDirection), (override));
|
||||||
MOCK_METHOD(void, setEnableService, (bool enableService), (override));
|
MOCK_METHOD(void, setEnableService, (bool enableService), (override));
|
||||||
MOCK_METHOD(void, setRequireClientCerts, (bool requireClientCerts), (override));
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_stub = "stub";
|
const QString m_stub = "stub";
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt)
|
||||||
ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps);
|
ServerConnection serverConnection(nullptr, m_appConfig, m_serverConfig, m_serverConfigDialogState, m_pDeps);
|
||||||
|
|
||||||
QString clientName = "test client";
|
QString clientName = "test client";
|
||||||
EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, clientName, false));
|
EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, clientName, true));
|
||||||
|
|
||||||
serverConnection.handleLogLine(R"(unrecognised client name "test client")");
|
serverConnection.handleLogLine(R"(unrecognised client name "test client")");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue