refactor: new static TlsUtiliy::isCertValid
This commit is contained in:
@ -147,8 +147,13 @@ MainWindow::MainWindow()
|
||||
this, kAppName,
|
||||
tr("Your current TLS key is smaller than the minimum allowed size, A new key 2048-bit key will be generated.")
|
||||
);
|
||||
regenerateLocalFingerprints();
|
||||
Settings::setValue(Settings::Security::KeySize, 2048);
|
||||
}
|
||||
if (!TlsUtility::isCertValid()) {
|
||||
regenerateLocalFingerprints();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QFile::exists(Settings::tlsLocalDb())) {
|
||||
regenerateLocalFingerprints();
|
||||
return;
|
||||
@ -371,7 +376,8 @@ void MainWindow::settingsChanged(const QString &key)
|
||||
|
||||
if ((key == Settings::Security::Certificate) || (key == Settings::Security::KeySize) ||
|
||||
(key == Settings::Security::TlsEnabled) || (key == Settings::Security::CheckPeers)) {
|
||||
if (TlsUtility::isEnabled() && !QFile::exists(Settings::value(Settings::Security::Certificate).toString())) {
|
||||
if (TlsUtility::isEnabled() && !TlsUtility::isCertValid()) {
|
||||
qWarning() << tr("invalid certificate, generating a new one");
|
||||
m_tlsUtility.generateCertificate();
|
||||
}
|
||||
updateSecurityIcon(m_lblSecurityStatus->isVisible());
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
@ -8,7 +9,10 @@
|
||||
|
||||
#include "TlsCertificate.h"
|
||||
#include "common/Settings.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QSslCertificate>
|
||||
#include <QSslKey>
|
||||
#include <QString>
|
||||
|
||||
namespace deskflow::gui {
|
||||
@ -23,6 +27,43 @@ bool TlsUtility::isEnabled()
|
||||
return Settings::value(Settings::Security::TlsEnabled).toBool();
|
||||
}
|
||||
|
||||
bool TlsUtility::isCertValid(const QString &certPath)
|
||||
{
|
||||
const auto certs = QSslCertificate::fromPath(certPath);
|
||||
if (certs.isEmpty()) {
|
||||
//: %1 will be replaced by the certificate path
|
||||
qDebug() << tr("failed to read key from certificate file: %1").arg(certPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto cert = certs.first();
|
||||
if (cert.isNull()) {
|
||||
//: %1 will be replaced by the certificate path
|
||||
qDebug() << tr("failed to parse certificate file: %1").arg(certPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto key = cert.publicKey();
|
||||
if (key.isNull()) {
|
||||
//: %1 will be replaced by the certificate path
|
||||
qDebug() << tr("failed to read key from certificate file: %1").arg(certPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key.length() != Settings::value(Settings::Security::KeySize).toInt()) {
|
||||
qDebug() << tr("key detected is the incorrect size");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (const auto type = key.algorithm(); (type != QSsl::Dsa || type != QSsl::Rsa)) {
|
||||
//: %1 will be replaced by the certificate path
|
||||
qDebug() << tr("failed to read RSA or DSA key from certificate file: %1").arg(certPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TlsUtility::generateCertificate() const
|
||||
{
|
||||
qDebug(
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
@ -7,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "TlsCertificate.h"
|
||||
#include <common/Settings.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@ -28,6 +30,13 @@ public:
|
||||
*/
|
||||
static bool isEnabled();
|
||||
|
||||
/**
|
||||
* @brief isCertValid
|
||||
* @param certPath the path of the file to check, when not set uses Settings::Security::Certificate value
|
||||
* @return true if the certificate is valid
|
||||
*/
|
||||
static bool isCertValid(const QString &certPath = Settings::value(Settings::Security::Certificate).toString());
|
||||
|
||||
private:
|
||||
TlsCertificate m_certificate;
|
||||
};
|
||||
|
||||
@ -455,6 +455,10 @@ Do you want to connect to the server?
|
||||
<source>%1 is starting...</source>
|
||||
<translation type="unfinished">%1 está iniciando...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">certificado no válido, generando uno nuevo</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 will retry in a moment...</source>
|
||||
<translation type="unfinished">%1 lo intentará nuevamente en un momento...</translation>
|
||||
@ -1284,6 +1288,28 @@ Al habilitar esta opción, se deshabilitará la interfaz gráfica de usuario (GU
|
||||
<translation type="unfinished">La clave pública en el archivo de clave del certificado predeterminado es demasiado pequeña</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>deskflow::gui::TlsUtility</name>
|
||||
<message>
|
||||
<source>failed to parse certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">Error al analizar el archivo de certificado: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">No se pudo leer la clave del archivo de certificado: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>key detected is the incorrect size</source>
|
||||
<translation type="unfinished">La clave detectada es de tamaño incorrecto</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read RSA or DSA key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">No se pudo leer la clave RSA o DSA del archivo de certificado: %1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>i18n</name>
|
||||
<message>
|
||||
|
||||
@ -463,6 +463,10 @@ Nomi validi:
|
||||
<source>%1 is starting...</source>
|
||||
<translation>%1 si sta avviando...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">certificato non valido, ne viene generato uno nuovo</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 will retry in a moment...</source>
|
||||
<translation>%1 riproverà tra un momento...</translation>
|
||||
@ -1284,6 +1288,28 @@ L'abilitazione di questa impostazione disabiliterà l'interfaccia graf
|
||||
<translation>La chiave pubblica nel file della chiave del certificato predefinito è troppo piccola</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>deskflow::gui::TlsUtility</name>
|
||||
<message>
|
||||
<source>failed to parse certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">impossibile analizzare il file del certificato: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">impossibile leggere la chiave dal file del certificato: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>key detected is the incorrect size</source>
|
||||
<translation type="unfinished">la chiave rilevata ha una dimensione errata</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read RSA or DSA key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">impossibile leggere la chiave RSA o DSA dal file del certificato: %1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>i18n</name>
|
||||
<message>
|
||||
|
||||
@ -307,6 +307,10 @@ Do you want to connect to the server?
|
||||
<source>Your current TLS key is smaller than the minimum allowed size, A new key 2048-bit key will be generated.</source>
|
||||
<translation>現在のTLS鍵長が許容される長さより小さいため、新しい2048ビット長の鍵を生成します。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">無効な証明書、新しい証明書を生成しています</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>A new version v%1 is available</source>
|
||||
<translation>新しいバージョン(v%1)が利用できます</translation>
|
||||
@ -1285,6 +1289,28 @@ Enabling this setting will disable the server config GUI.</source>
|
||||
<translation>既定の証明書鍵ファイル内の公開鍵が小さすぎます</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>deskflow::gui::TlsUtility</name>
|
||||
<message>
|
||||
<source>failed to parse certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">証明書ファイルの解析に失敗しました: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">証明書ファイルからキーを読み取ることができませんでした: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>key detected is the incorrect size</source>
|
||||
<translation type="unfinished">検出されたキーのサイズが正しくありません</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read RSA or DSA key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">証明書ファイルから RSA または DSA キーを読み取ることができませんでした: %1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>i18n</name>
|
||||
<message>
|
||||
|
||||
@ -309,6 +309,10 @@ Do you want to connect to the server?
|
||||
<source>Your current TLS key is smaller than the minimum allowed size, A new key 2048-bit key will be generated.</source>
|
||||
<translation>Ваш нынешний TLS ключ меньше чем минимальный разрешимый размер , Новый ключ 2048-бит ключ будет сгенерирован.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">недействительный сертификат, генерация нового</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>A new version v%1 is available</source>
|
||||
<translation>Новая версия %1 доступна</translation>
|
||||
@ -1289,6 +1293,28 @@ Enabling this setting will disable the server config GUI.</source>
|
||||
<translation>Публичный ключ в стандартном файле сертификата слишком мал</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>deskflow::gui::TlsUtility</name>
|
||||
<message>
|
||||
<source>failed to parse certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">не удалось проанализировать файл сертификата: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">не удалось прочитать ключ из файла сертификата: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>key detected is the incorrect size</source>
|
||||
<translation type="unfinished">обнаружен ключ неправильного размера</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read RSA or DSA key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">не удалось прочитать ключ RSA или DSA из файла сертификата: %1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>i18n</name>
|
||||
<message>
|
||||
|
||||
@ -307,6 +307,10 @@ Do you want to connect to the server?
|
||||
<source>Your current TLS key is smaller than the minimum allowed size, A new key 2048-bit key will be generated.</source>
|
||||
<translation>您当前的 TLS 密钥长度小于允许的最小值,将生成一个新的 2048 位密钥。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">证书无效,正在生成新证书</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>A new version v%1 is available</source>
|
||||
<translation>新版本 v%1 可用</translation>
|
||||
@ -1285,6 +1289,28 @@ Enabling this setting will disable the server config GUI.</source>
|
||||
<translation>默认证书密钥文件中的公钥太短</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>deskflow::gui::TlsUtility</name>
|
||||
<message>
|
||||
<source>failed to parse certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">解析证书文件失败:%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">无法从证书文件中读取密钥:%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>key detected is the incorrect size</source>
|
||||
<translation type="unfinished">检测到的密钥大小不正确。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>failed to read RSA or DSA key from certificate file: %1</source>
|
||||
<extracomment>%1 will be replaced by the certificate path</extracomment>
|
||||
<translation type="unfinished">无法从证书文件中读取 RSA 或 DSA 密钥:%1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>i18n</name>
|
||||
<message>
|
||||
|
||||
Reference in New Issue
Block a user