mirror of https://github.com/debauchee/barrier.git
Refactored fingerprint file path logic #4525
This commit is contained in:
parent
36a6bb9218
commit
80fd3cc01b
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "DataDownloader.h"
|
||||
#include "QUtility.h"
|
||||
#include "ProcessorArch.h"
|
||||
#include "Fingerprint.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
|
@ -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("=");
|
||||
|
|
Loading…
Reference in New Issue