2024-07-26 22:53:52 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
|
* Copyright (C) 2024 Symless Ltd.
|
|
|
|
|
*
|
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
|
|
|
|
*
|
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "TlsUtility.h"
|
|
|
|
|
|
|
|
|
|
#include "TlsCertificate.h"
|
2024-08-13 23:13:17 +00:00
|
|
|
#include "gui/license/license_utils.h"
|
2024-07-26 22:53:52 +00:00
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
#include <QFile>
|
2024-08-07 14:05:18 +00:00
|
|
|
#include <QString>
|
|
|
|
|
|
2024-08-11 21:34:48 +00:00
|
|
|
using namespace synergy::license;
|
|
|
|
|
using namespace synergy::gui::license;
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
namespace synergy::gui {
|
|
|
|
|
|
2024-08-11 21:34:48 +00:00
|
|
|
TlsUtility::TlsUtility(const IAppConfig &appConfig, const ILicense &license)
|
2024-08-07 14:05:18 +00:00
|
|
|
: m_appConfig(appConfig),
|
|
|
|
|
m_license(license) {}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool TlsUtility::isAvailable() const {
|
2024-08-11 21:34:48 +00:00
|
|
|
return !isActivationEnabled() || m_license.isTlsAvailable();
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TlsUtility::isAvailableAndEnabled() const {
|
|
|
|
|
const auto &config = m_appConfig;
|
|
|
|
|
return isAvailable() && config.tlsEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 14:05:18 +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-07-26 22:53:52 +00:00
|
|
|
if (!isAvailableAndEnabled()) {
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TlsUtility::persistCertificate() {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace synergy::gui
|