From 9294f2a0261190bb1ae062ce147af9b5fbfb6410 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Mon, 17 Feb 2025 14:11:49 -0500 Subject: [PATCH] refactor: use a function to get the trustedFingerprintDb --- src/apps/deskflow-gui/MainWindow.cpp | 15 ++++++++++----- src/apps/deskflow-gui/MainWindow.h | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index 091226375..7e2717d29 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -734,13 +734,11 @@ void MainWindow::checkFingerprint(const QString &line) deskflow::string::fromHex(match.captured(2).toStdString()) }; - // Only Save the sha256 const bool isClient = m_coreProcess.mode() == CoreMode::Client; - const auto trustFile = isClient ? kFingerprintTrustedServersFilename : kFingerprintTrustedClientsFilename; - const auto localPath = QStringLiteral("%1/%2").arg(getTlsPath(), trustFile).toStdString(); + // Only Save the sha256 deskflow::FingerprintDatabase db; - db.read(localPath); + db.read(trustedFingerprintDb().toStdString()); if (db.isTrusted(sha256)) { return; } @@ -755,7 +753,7 @@ void MainWindow::checkFingerprint(const QString &line) ); if (fingerprintDialog.exec() == QDialog::Accepted) { db.addTrusted(sha256); - db.write(localPath); + db.write(trustedFingerprintDb().toStdString()); m_coreProcess.start(); } } @@ -1078,6 +1076,13 @@ QString MainWindow::localFingerPrintDb() return QStringLiteral("%1/%2").arg(getTlsPath(), kFingerprintLocalFilename); } +QString MainWindow::trustedFingerprintDb() +{ + const bool isClient = m_coreProcess.mode() == CoreMode::Client; + const auto trustFile = isClient ? kFingerprintTrustedServersFilename : kFingerprintTrustedClientsFilename; + return QStringLiteral("%1/%2").arg(getTlsPath(), trustFile); +} + bool MainWindow::regenerateLocalFingerprints() { if (!QFile::exists(m_appConfig.tlsCertPath()) && !m_tlsUtility.generateCertificate()) { diff --git a/src/apps/deskflow-gui/MainWindow.h b/src/apps/deskflow-gui/MainWindow.h index 174272019..b54b02845 100644 --- a/src/apps/deskflow-gui/MainWindow.h +++ b/src/apps/deskflow-gui/MainWindow.h @@ -168,6 +168,12 @@ private: QString getTlsPath(); QString localFingerPrintDb(); + /** + * @brief trustedFingerprintDb get the fingerprintDb for the trusted clients or trusted servers. + * @return The path to the trusted fingerprint file + */ + QString trustedFingerprintDb(); + // Generate prints if they are missing // Returns true if successful bool regenerateLocalFingerprints();