refactor: use a function to get the trustedFingerprintDb

This commit is contained in:
sithlord48
2025-02-17 14:11:49 -05:00
committed by Nick Bolton
parent bfb64f0653
commit 9294f2a026
2 changed files with 16 additions and 5 deletions

View File

@ -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()) {

View File

@ -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();