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"
|
2025-03-06 23:08:08 +00:00
|
|
|
#include "common/Settings.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
|
|
|
|
2025-03-07 00:27:29 +00:00
|
|
|
TlsUtility::TlsUtility(QObject *parent) : QObject(parent)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-05-20 14:39:18 +00:00
|
|
|
// do nothing
|
2024-10-17 18:04:35 +00:00
|
|
|
}
|
2024-07-26 22:53:52 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool TlsUtility::isEnabled() const
|
|
|
|
|
{
|
2025-03-06 23:08:08 +00:00
|
|
|
return Settings::value(Settings::Security::TlsEnabled).toBool();
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-19 21:06:51 +00:00
|
|
|
bool TlsUtility::generateCertificate() const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-03-11 00:21:57 +00:00
|
|
|
qDebug(
|
|
|
|
|
"generating tls certificate, "
|
|
|
|
|
"all clients must trust the new fingerprint"
|
|
|
|
|
);
|
2024-08-03 00:17:29 +00:00
|
|
|
|
2025-03-06 23:32:14 +00:00
|
|
|
auto length = Settings::value(Settings::Security::KeySize).toInt();
|
2025-06-16 01:21:16 +00:00
|
|
|
|
|
|
|
|
if (length < 2048) {
|
|
|
|
|
length = 2048;
|
|
|
|
|
qDebug("selected size too small setting certificate size to 2048");
|
|
|
|
|
Settings::setValue(Settings::Security::KeySize, 2048);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-07 00:04:55 +00:00
|
|
|
const auto certificate = Settings::value(Settings::Security::Certificate).toString();
|
|
|
|
|
return m_certificate.generateCertificate(certificate, length);
|
2024-08-10 23:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-19 21:06:51 +00:00
|
|
|
bool TlsUtility::persistCertificate() const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-08-10 23:58:24 +00:00
|
|
|
qDebug("persisting tls certificate");
|
|
|
|
|
|
2025-03-07 00:04:55 +00:00
|
|
|
if (QFile::exists(Settings::value(Settings::Security::Certificate).toString())) {
|
2024-08-10 23:58:24 +00:00
|
|
|
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
|