2024-07-26 22:53:52 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2024-07-26 22:53:52 +00:00
|
|
|
* 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-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-01 13:30:24 +00:00
|
|
|
TlsUtility::TlsUtility(const IAppConfig &appConfig) : m_appConfig(appConfig) {}
|
2024-07-26 22:53:52 +00:00
|
|
|
|
2024-10-01 13:30:24 +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-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-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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow::gui
|