2015-04-20 17:51:22 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-29 06:19:04 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2015 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2015-04-20 17:51:22 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
#include "TlsCertificate.h"
|
2015-04-20 17:51:22 +00:00
|
|
|
|
2024-11-01 12:59:17 +00:00
|
|
|
#include "common/constants.h"
|
2025-02-08 19:10:39 +00:00
|
|
|
#include "gui/core/CoreTool.h"
|
|
|
|
|
#include "net/FingerprintData.h"
|
|
|
|
|
#include "net/FingerprintDatabase.h"
|
2025-01-29 05:22:48 +00:00
|
|
|
#include "net/SecureUtils.h"
|
2024-11-01 12:59:17 +00:00
|
|
|
|
2015-04-20 17:51:22 +00:00
|
|
|
#include <QCoreApplication>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QProcess>
|
2015-04-20 17:51:22 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
TlsCertificate::TlsCertificate(QObject *parent) : QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
2015-04-20 17:51:22 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool TlsCertificate::generateCertificate(const QString &path, int keyLength)
|
|
|
|
|
{
|
2024-08-10 23:58:24 +00:00
|
|
|
qDebug("generating tls certificate: %s", qUtf8Printable(path));
|
2020-07-28 12:00:20 +00:00
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
QFileInfo info(path);
|
|
|
|
|
QDir dir(info.absolutePath());
|
|
|
|
|
if (!dir.exists() && !dir.mkpath(".")) {
|
|
|
|
|
qCritical("failed to create directory for tls certificate");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-04-20 17:51:22 +00:00
|
|
|
|
2025-01-29 06:19:04 +00:00
|
|
|
try {
|
|
|
|
|
deskflow::generatePemSelfSignedCert(path.toStdString(), keyLength);
|
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
qCritical() << "failed to generate self-signed pem cert: " << e.what();
|
2024-08-07 14:05:18 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2025-01-29 06:19:04 +00:00
|
|
|
qDebug("tls certificate generated");
|
|
|
|
|
return generateFingerprint(path);
|
2015-04-20 17:51:22 +00:00
|
|
|
}
|
2020-07-28 12:00:20 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool TlsCertificate::generateFingerprint(const QString &certificateFilename)
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
qDebug("generating tls fingerprint");
|
2025-01-29 05:22:48 +00:00
|
|
|
try {
|
|
|
|
|
auto fingerprint =
|
|
|
|
|
deskflow::pemFileCertFingerprint(certificateFilename.toStdString(), deskflow::FingerprintType::SHA1);
|
2025-02-08 19:10:39 +00:00
|
|
|
|
|
|
|
|
CoreTool coreTool;
|
|
|
|
|
QString profileDir = coreTool.getProfileDir();
|
|
|
|
|
|
|
|
|
|
auto localPath = QStringLiteral("%1/%2/%3").arg(profileDir, kSslDir, kFingerprintLocalFilename).toStdString();
|
|
|
|
|
|
|
|
|
|
deskflow::FingerprintDatabase db;
|
2025-02-09 01:21:36 +00:00
|
|
|
db.addTrusted(fingerprint);
|
2025-02-08 19:10:39 +00:00
|
|
|
db.write(localPath);
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
qDebug("tls fingerprint generated");
|
|
|
|
|
return true;
|
2025-01-29 05:22:48 +00:00
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
qCritical() << "failed to find tls fingerprint: " << e.what();
|
2024-08-07 14:05:18 +00:00
|
|
|
return false;
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-28 12:00:20 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
int TlsCertificate::getCertKeyLength(const QString &path)
|
|
|
|
|
{
|
2025-01-29 06:19:04 +00:00
|
|
|
return deskflow::getCertLength(path.toStdString());
|
2020-07-28 12:00:20 +00:00
|
|
|
}
|