refactor: move TlsCertificate::getCertKeyLength -> static TlsUtility::getCertKeyLength

This commit is contained in:
sithlord48
2025-11-22 10:29:47 -05:00
committed by Nick Bolton
parent c4a2dfd300
commit 6f10cd269e
5 changed files with 14 additions and 8 deletions

View File

@ -264,12 +264,11 @@ bool SettingsDialog::isClientMode() const
void SettingsDialog::updateKeyLengthOnFile(const QString &path)
{
TlsCertificate ssl;
if (!QFile(path).exists()) {
qFatal("tls certificate file not found: %s", qUtf8Printable(path));
}
auto length = ssl.getCertKeyLength(path);
auto length = TlsUtility::getCertKeyLength(path);
auto labelIcon = QPixmap(QIcon::fromTheme(QIcon::ThemeIcon::SecurityLow).pixmap(24, 24));
if (length == 2048)
labelIcon = QPixmap(QIcon::fromTheme(QStringLiteral("security-medium")).pixmap(24, 24));

View File

@ -47,8 +47,3 @@ bool TlsCertificate::generateFingerprint(const QString &certificateFilename) con
db.addTrusted(deskflow::pemFileCertFingerprint(certPath, Fingerprint::Type::SHA256));
return db.write(Settings::tlsLocalDb());
}
int TlsCertificate::getCertKeyLength(const QString &path) const
{
return deskflow::getCertLength(path.toStdString());
}

View File

@ -18,5 +18,4 @@ public:
bool generateCertificate(const QString &path, int keyLength) const;
bool generateFingerprint(const QString &certificateFilename) const;
int getCertKeyLength(const QString &path) const;
};

View File

@ -9,6 +9,7 @@
#include "TlsCertificate.h"
#include "common/Settings.h"
#include "net/SecureUtils.h"
#include <QFile>
#include <QSslCertificate>
@ -64,6 +65,11 @@ bool TlsUtility::isCertValid(const QString &certPath)
return true;
}
int TlsUtility::getCertKeyLength(const QString &certPath)
{
return deskflow::getCertLength(certPath.toStdString());
}
bool TlsUtility::generateCertificate() const
{
qDebug(

View File

@ -36,6 +36,13 @@ public:
*/
static bool isCertValid(const QString &certPath = Settings::value(Settings::Security::Certificate).toString());
/**
* @brief Get the lenght of a key
* @param certPath path of the file to check, when unset will use the value of Settings::Security::Certificate
* @return the bitsize of the key
*/
static int getCertKeyLength(const QString &certPath = Settings::value(Settings::Security::Certificate).toString());
private:
TlsCertificate m_certificate;
};