refactor: use new Setting::tlsDir() method to return current tlsdir where needed
This commit is contained in:
parent
55601debe0
commit
b7f29d76c3
7 changed files with 15 additions and 22 deletions
|
|
@ -1143,21 +1143,16 @@ void MainWindow::setHostName()
|
||||||
applyConfig();
|
applyConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getTlsPath()
|
|
||||||
{
|
|
||||||
return QStringLiteral("%1/%2").arg(Settings::settingsPath(), kTlsDirName);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MainWindow::localFingerprintDb()
|
QString MainWindow::localFingerprintDb()
|
||||||
{
|
{
|
||||||
return QStringLiteral("%1/%2").arg(getTlsPath(), kTlsFingerprintLocalFilename);
|
return QStringLiteral("%1/%2").arg(Settings::tlsDir(), kTlsFingerprintLocalFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::trustedFingerprintDb()
|
QString MainWindow::trustedFingerprintDb()
|
||||||
{
|
{
|
||||||
const bool isClient = m_coreProcess.mode() == CoreMode::Client;
|
const bool isClient = m_coreProcess.mode() == CoreMode::Client;
|
||||||
const auto trustFile = isClient ? kTlsFingerprintTrustedServersFilename : kTlsFingerprintTrustedClientsFilename;
|
const auto trustFile = isClient ? kTlsFingerprintTrustedServersFilename : kTlsFingerprintTrustedClientsFilename;
|
||||||
return QStringLiteral("%1/%2").arg(getTlsPath(), trustFile);
|
return QStringLiteral("%1/%2").arg(Settings::tlsDir(), trustFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::regenerateLocalFingerprints()
|
bool MainWindow::regenerateLocalFingerprints()
|
||||||
|
|
|
||||||
|
|
@ -161,8 +161,6 @@ private:
|
||||||
void showHostNameEditor();
|
void showHostNameEditor();
|
||||||
void setHostName();
|
void setHostName();
|
||||||
|
|
||||||
QString getTlsPath();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief localFingerprintDb
|
* @brief localFingerprintDb
|
||||||
* @return The path to the local fingerprint file
|
* @return The path to the local fingerprint file
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ QVariant Settings::defaultValue(const QString &key)
|
||||||
return QRect();
|
return QRect();
|
||||||
|
|
||||||
if (key == Security::Certificate)
|
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)
|
if (key == Security::KeySize)
|
||||||
return 2048;
|
return 2048;
|
||||||
|
|
@ -161,6 +161,11 @@ const QString Settings::settingsPath()
|
||||||
return QFileInfo(instance()->m_settings->fileName()).absolutePath();
|
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)
|
void Settings::setValue(const QString &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
if (instance()->m_settings->value(key) == value)
|
if (instance()->m_settings->value(key) == value)
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ public:
|
||||||
static bool isWritable();
|
static bool isWritable();
|
||||||
static const QString settingsFile();
|
static const QString settingsFile();
|
||||||
static const QString settingsPath();
|
static const QString settingsPath();
|
||||||
|
static const QString tlsDir();
|
||||||
static const QString logLevelText();
|
static const QString logLevelText();
|
||||||
static QSettingsProxy &proxy();
|
static QSettingsProxy &proxy();
|
||||||
static void save(bool emitSaving = true);
|
static void save(bool emitSaving = true);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ bool TlsCertificate::generateFingerprint(const QString &certificateFilename)
|
||||||
deskflow::FingerprintDatabase db;
|
deskflow::FingerprintDatabase db;
|
||||||
db.addTrusted(deskflow::pemFileCertFingerprint(certPath, deskflow::FingerprintType::SHA1));
|
db.addTrusted(deskflow::pemFileCertFingerprint(certPath, deskflow::FingerprintType::SHA1));
|
||||||
db.addTrusted(deskflow::pemFileCertFingerprint(certPath, deskflow::FingerprintType::SHA256));
|
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");
|
qDebug("tls fingerprint generated");
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -72,12 +72,7 @@ int TlsCertificate::getCertKeyLength(const QString &path)
|
||||||
|
|
||||||
QString TlsCertificate::getCertificatePath() const
|
QString TlsCertificate::getCertificatePath() const
|
||||||
{
|
{
|
||||||
return QStringLiteral("%1/%2/%3").arg(Settings::settingsPath(), kTlsDirName, kTlsCertificateFilename);
|
return QStringLiteral("%1/%2").arg(Settings::tlsDir(), kTlsCertificateFilename);
|
||||||
}
|
|
||||||
|
|
||||||
QString TlsCertificate::getTlsDir() const
|
|
||||||
{
|
|
||||||
return QStringLiteral("%1/%2").arg(Settings::settingsPath(), kTlsDirName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TlsCertificate::isCertificateValid(const QString &path)
|
bool TlsCertificate::isCertificateValid(const QString &path)
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,4 @@ public:
|
||||||
bool generateFingerprint(const QString &certificateFilename);
|
bool generateFingerprint(const QString &certificateFilename);
|
||||||
int getCertKeyLength(const QString &path);
|
int getCertKeyLength(const QString &path);
|
||||||
QString getCertificatePath() const;
|
QString getCertificatePath() const;
|
||||||
QString getTlsDir() const;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
#include "base/Path.h"
|
#include "base/Path.h"
|
||||||
#include "base/String.h"
|
#include "base/String.h"
|
||||||
#include "base/TMethodEventJob.h"
|
#include "base/TMethodEventJob.h"
|
||||||
#include "common/constants.h"
|
#include "common/Settings.h"
|
||||||
#include "mt/Lock.h"
|
#include "mt/Lock.h"
|
||||||
#include "net/FingerprintDatabase.h"
|
#include "net/FingerprintDatabase.h"
|
||||||
#include "net/TCPSocket.h"
|
#include "net/TCPSocket.h"
|
||||||
|
|
@ -449,7 +449,7 @@ int SecureSocket::secureAccept(int socket)
|
||||||
if (retry == 0) {
|
if (retry == 0) {
|
||||||
if (m_securityLevel == SecurityLevel::PeerAuth) {
|
if (m_securityLevel == SecurityLevel::PeerAuth) {
|
||||||
std::string dbDir = deskflow::string::sprintf(
|
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)) {
|
if (!verifyCertFingerprint(dbDir)) {
|
||||||
retry = 0;
|
retry = 0;
|
||||||
|
|
@ -481,7 +481,7 @@ int SecureSocket::secureConnect(int socket)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string certDir =
|
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)) {
|
if (!loadCertificates(certDir)) {
|
||||||
LOG((CLOG_ERR "could not load client certificates"));
|
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
|
// No error, set ready, process and return ok
|
||||||
m_secureReady = true;
|
m_secureReady = true;
|
||||||
std::string dbDir = deskflow::string::sprintf(
|
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)) {
|
if (verifyCertFingerprint(dbDir)) {
|
||||||
LOG((CLOG_INFO "connected to secure socket"));
|
LOG((CLOG_INFO "connected to secure socket"));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue