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) void SettingsDialog::updateKeyLengthOnFile(const QString &path)
{ {
TlsCertificate ssl;
if (!QFile(path).exists()) { if (!QFile(path).exists()) {
qFatal("tls certificate file not found: %s", qUtf8Printable(path)); 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)); auto labelIcon = QPixmap(QIcon::fromTheme(QIcon::ThemeIcon::SecurityLow).pixmap(24, 24));
if (length == 2048) if (length == 2048)
labelIcon = QPixmap(QIcon::fromTheme(QStringLiteral("security-medium")).pixmap(24, 24)); 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)); db.addTrusted(deskflow::pemFileCertFingerprint(certPath, Fingerprint::Type::SHA256));
return db.write(Settings::tlsLocalDb()); 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 generateCertificate(const QString &path, int keyLength) const;
bool generateFingerprint(const QString &certificateFilename) const; bool generateFingerprint(const QString &certificateFilename) const;
int getCertKeyLength(const QString &path) const;
}; };

View file

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

View file

@ -36,6 +36,13 @@ public:
*/ */
static bool isCertValid(const QString &certPath = Settings::value(Settings::Security::Certificate).toString()); 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: private:
TlsCertificate m_certificate; TlsCertificate m_certificate;
}; };