refactor: use new Setting::tlsDir() method to return current tlsdir where needed

This commit is contained in:
sithlord48
2025-03-17 21:18:37 -04:00
committed by Nick Bolton
parent 55601debe0
commit b7f29d76c3
7 changed files with 15 additions and 22 deletions

View File

@ -1143,21 +1143,16 @@ void MainWindow::setHostName()
applyConfig();
}
QString MainWindow::getTlsPath()
{
return QStringLiteral("%1/%2").arg(Settings::settingsPath(), kTlsDirName);
}
QString MainWindow::localFingerprintDb()
{
return QStringLiteral("%1/%2").arg(getTlsPath(), kTlsFingerprintLocalFilename);
return QStringLiteral("%1/%2").arg(Settings::tlsDir(), kTlsFingerprintLocalFilename);
}
QString MainWindow::trustedFingerprintDb()
{
const bool isClient = m_coreProcess.mode() == CoreMode::Client;
const auto trustFile = isClient ? kTlsFingerprintTrustedServersFilename : kTlsFingerprintTrustedClientsFilename;
return QStringLiteral("%1/%2").arg(getTlsPath(), trustFile);
return QStringLiteral("%1/%2").arg(Settings::tlsDir(), trustFile);
}
bool MainWindow::regenerateLocalFingerprints()

View File

@ -161,8 +161,6 @@ private:
void showHostNameEditor();
void setHostName();
QString getTlsPath();
/**
* @brief localFingerprintDb
* @return The path to the local fingerprint file

View File

@ -90,7 +90,7 @@ QVariant Settings::defaultValue(const QString &key)
return QRect();
if (key == Security::Certificate)
return QStringLiteral("%1/%2/%3").arg(instance()->settingsPath(), kTlsDirName, kTlsCertificateFilename);
return QStringLiteral("%1/%2").arg(instance()->tlsDir(), kTlsCertificateFilename);
if (key == Security::KeySize)
return 2048;
@ -161,6 +161,11 @@ const QString Settings::settingsPath()
return QFileInfo(instance()->m_settings->fileName()).absolutePath();
}
const QString Settings::tlsDir()
{
return QStringLiteral("%1/%2").arg(instance()->settingsPath(), kTlsDirName);
}
void Settings::setValue(const QString &key, const QVariant &value)
{
if (instance()->m_settings->value(key) == value)

View File

@ -141,6 +141,7 @@ public:
static bool isWritable();
static const QString settingsFile();
static const QString settingsPath();
static const QString tlsDir();
static const QString logLevelText();
static QSettingsProxy &proxy();
static void save(bool emitSaving = true);

View File

@ -55,7 +55,7 @@ bool TlsCertificate::generateFingerprint(const QString &certificateFilename)
deskflow::FingerprintDatabase db;
db.addTrusted(deskflow::pemFileCertFingerprint(certPath, deskflow::FingerprintType::SHA1));
db.addTrusted(deskflow::pemFileCertFingerprint(certPath, deskflow::FingerprintType::SHA256));
db.write(QStringLiteral("%1/%2").arg(getTlsDir(), kTlsFingerprintLocalFilename).toStdString());
db.write(QStringLiteral("%1/%2").arg(Settings::tlsDir(), kTlsFingerprintLocalFilename).toStdString());
qDebug("tls fingerprint generated");
return true;
@ -72,12 +72,7 @@ int TlsCertificate::getCertKeyLength(const QString &path)
QString TlsCertificate::getCertificatePath() const
{
return QStringLiteral("%1/%2/%3").arg(Settings::settingsPath(), kTlsDirName, kTlsCertificateFilename);
}
QString TlsCertificate::getTlsDir() const
{
return QStringLiteral("%1/%2").arg(Settings::settingsPath(), kTlsDirName);
return QStringLiteral("%1/%2").arg(Settings::tlsDir(), kTlsCertificateFilename);
}
bool TlsCertificate::isCertificateValid(const QString &path)

View File

@ -21,5 +21,4 @@ public:
bool generateFingerprint(const QString &certificateFilename);
int getCertKeyLength(const QString &path);
QString getCertificatePath() const;
QString getTlsDir() const;
};

View File

@ -13,7 +13,7 @@
#include "base/Path.h"
#include "base/String.h"
#include "base/TMethodEventJob.h"
#include "common/constants.h"
#include "common/Settings.h"
#include "mt/Lock.h"
#include "net/FingerprintDatabase.h"
#include "net/TCPSocket.h"
@ -449,7 +449,7 @@ int SecureSocket::secureAccept(int socket)
if (retry == 0) {
if (m_securityLevel == SecurityLevel::PeerAuth) {
std::string dbDir = deskflow::string::sprintf(
"%s/%s/%s", ARCH->getProfileDirectory().c_str(), kTlsDirName, kTlsFingerprintTrustedClientsFilename
"%s/%s", Settings::tlsDir().toStdString().c_str(), kTlsFingerprintTrustedClientsFilename
);
if (!verifyCertFingerprint(dbDir)) {
retry = 0;
@ -481,7 +481,7 @@ int SecureSocket::secureConnect(int socket)
{
std::string certDir =
deskflow::string::sprintf("%s/%s/%s", ARCH->getProfileDirectory().c_str(), kTlsDirName, kTlsCertificateFilename);
deskflow::string::sprintf("%s/%s", Settings::tlsDir().toStdString().c_str(), kTlsCertificateFilename);
if (!loadCertificates(certDir)) {
LOG((CLOG_ERR "could not load client certificates"));
@ -525,7 +525,7 @@ int SecureSocket::secureConnect(int socket)
// No error, set ready, process and return ok
m_secureReady = true;
std::string dbDir = deskflow::string::sprintf(
"%s/%s/%s", ARCH->getProfileDirectory().c_str(), kTlsDirName, kTlsFingerprintTrustedServersFilename
"%s/%s", Settings::tlsDir().toStdString().c_str(), kTlsFingerprintTrustedServersFilename
);
if (verifyCertFingerprint(dbDir)) {
LOG((CLOG_INFO "connected to secure socket"));