diff --git a/src/gui/src/Fingerprint.cpp b/src/gui/src/Fingerprint.cpp index 6eefdcd5..502a4a06 100644 --- a/src/gui/src/Fingerprint.cpp +++ b/src/gui/src/Fingerprint.cpp @@ -34,20 +34,9 @@ Fingerprint::Fingerprint(const QString& filename) void Fingerprint::trust(const QString& fingerprintText) { - CoreInterface coreInterface; - QString profileDir = coreInterface.getProfileDir(); + Fingerprint::persistDirectory(); - QString dirName = QString("%1/%2") - .arg(profileDir) - .arg(kDirName); - - QDir dir(dirName); - if (!dir.exists()) { - dir.mkpath("."); - } - - QString path = QString("%1/%2").arg(dirName).arg(m_Filename); - QFile file(path); + QFile file(filePath()); if (file.open(QIODevice::Append)) { QTextStream out(&file); @@ -58,19 +47,12 @@ void Fingerprint::trust(const QString& fingerprintText) bool Fingerprint::exists(const QString& fingerprintText) { - CoreInterface coreInterface; - QString profileDir = coreInterface.getProfileDir(); - - QString dirName = QString("%1/%2") - .arg(profileDir) - .arg(kDirName); - + QString dirName = Fingerprint::directoryPath(); if (!QDir(dirName).exists()) { return false; } - QString path = QString("%1/%2").arg(dirName).arg(m_Filename); - QFile file(path); + QFile file(filePath()); if (file.open(QIODevice::ReadOnly)) { @@ -88,6 +70,30 @@ bool Fingerprint::exists(const QString& fingerprintText) return false; } +QString Fingerprint::filePath() const +{ + QString dir = Fingerprint::directoryPath(); + return QString("%1/%2").arg(dir).arg(m_Filename); +} + +void Fingerprint::persistDirectory() +{ + QDir dir(Fingerprint::directoryPath()); + if (!dir.exists()) { + dir.mkpath("."); + } +} + +QString Fingerprint::directoryPath() +{ + CoreInterface coreInterface; + QString profileDir = coreInterface.getProfileDir(); + + return QString("%1/%2") + .arg(profileDir) + .arg(kDirName); +} + bool Fingerprint::localFingerprintExists() { CoreInterface coreInterface; diff --git a/src/gui/src/Fingerprint.h b/src/gui/src/Fingerprint.h index 179afef9..0da2a7fc 100644 --- a/src/gui/src/Fingerprint.h +++ b/src/gui/src/Fingerprint.h @@ -27,14 +27,16 @@ private: public: void trust(const QString& fingerprintText); bool exists(const QString& fingerprintText); + QString filePath() const; public: static Fingerprint local(); static Fingerprint trustedServers(); static Fingerprint trustedClients(); - + static QString directoryPath(); static QString localFingerprint(); static bool localFingerprintExists(); + static void persistDirectory(); private: QString m_Filename; diff --git a/src/gui/src/PluginManager.cpp b/src/gui/src/PluginManager.cpp index 3c548a15..d62432be 100644 --- a/src/gui/src/PluginManager.cpp +++ b/src/gui/src/PluginManager.cpp @@ -22,6 +22,7 @@ #include "DataDownloader.h" #include "QUtility.h" #include "ProcessorArch.h" +#include "Fingerprint.h" #include #include @@ -40,8 +41,6 @@ static QString kCertificateLifetime = "365"; static QString kCertificateSubjectInfo = "/CN=Synergy"; static QString kCertificateFilename = "Synergy.pem"; static QString kUnixOpenSslCommand = "openssl"; -static const char kFingerprintDir[] = "ssl/fingerprints"; -static const char kFingerprintLocalFilename[] = "local.txt"; #if defined(Q_OS_WIN) static const char kWinPluginExt[] = ".dll"; @@ -233,13 +232,7 @@ void PluginManager::generateCertificate() // write the standard output into file filename.clear(); - filename.append(m_ProfileDir); - filename.append(QDir::separator()).append(kFingerprintDir); - QDir dir(filename); - if (!dir.exists()) { - dir.mkpath("."); - } - filename.append(QDir::separator()).append(kFingerprintLocalFilename); + filename.append(Fingerprint::local().filePath()); // only write the fingerprint part int i = m_standardOutput.indexOf("=");