Files
deskflow/src/lib/gui/tls/TlsUtility.cpp
sithlord48 2721de220a refactor: move tlsEnabled to Settings
newkey: security/tlsEnabled <= General/cryptoEnabled
remove tlsEnabled from appconfig
2025-03-13 13:58:25 +00:00

58 lines
1.2 KiB
C++

/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "TlsUtility.h"
#include "TlsCertificate.h"
#include "common/Settings.h"
#include <QFile>
#include <QString>
namespace deskflow::gui {
TlsUtility::TlsUtility(const IAppConfig &appConfig) : m_appConfig(appConfig)
{
}
bool TlsUtility::isEnabled() const
{
return Settings::value(Settings::Security::TlsEnabled).toBool();
}
bool TlsUtility::generateCertificate()
{
qDebug(
"generating tls certificate, "
"all clients must trust the new fingerprint"
);
if (!isEnabled()) {
qCritical(
"unable to generate tls certificate, "
"tls is either not available or not enabled"
);
return false;
}
auto length = m_appConfig.tlsKeyLength();
return m_certificate.generateCertificate(m_appConfig.tlsCertPath(), length);
}
bool TlsUtility::persistCertificate()
{
qDebug("persisting tls certificate");
if (QFile::exists(m_appConfig.tlsCertPath())) {
qDebug("tls certificate already exists");
return true;
}
return generateCertificate();
}
} // namespace deskflow::gui