2024-07-26 22:53:52 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2024-07-26 22:53:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "TlsUtility.h"
|
|
|
|
|
|
|
|
|
|
#include "TlsCertificate.h"
|
|
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
#include <QFile>
|
2024-08-07 14:05:18 +00:00
|
|
|
#include <QString>
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow::gui {
|
2024-07-26 22:53:52 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
TlsUtility::TlsUtility(const IAppConfig &appConfig) : m_appConfig(appConfig)
|
|
|
|
|
{
|
|
|
|
|
}
|
2024-07-26 22:53:52 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool TlsUtility::isEnabled() const
|
|
|
|
|
{
|
2024-07-26 22:53:52 +00:00
|
|
|
const auto &config = m_appConfig;
|
2024-10-01 13:30:24 +00:00
|
|
|
return config.tlsEnabled();
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool TlsUtility::generateCertificate()
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
qDebug("generating tls certificate, "
|
|
|
|
|
"all clients must trust the new fingerprint");
|
|
|
|
|
|
2024-10-01 13:30:24 +00:00
|
|
|
if (!isEnabled()) {
|
2024-08-07 14:05:18 +00:00
|
|
|
qCritical("unable to generate tls certificate, "
|
|
|
|
|
"tls is either not available or not enabled");
|
|
|
|
|
return false;
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto length = m_appConfig.tlsKeyLength();
|
|
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
return m_certificate.generateCertificate(m_appConfig.tlsCertPath(), length);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool TlsUtility::persistCertificate()
|
|
|
|
|
{
|
2024-08-10 23:58:24 +00:00
|
|
|
qDebug("persisting tls certificate");
|
|
|
|
|
|
|
|
|
|
if (QFile::exists(m_appConfig.tlsCertPath())) {
|
|
|
|
|
qDebug("tls certificate already exists");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return generateCertificate();
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow::gui
|