diff --git a/src/gui/src/SslCertificate.cpp b/src/gui/src/SslCertificate.cpp index be46a48c..dc52c6f3 100644 --- a/src/gui/src/SslCertificate.cpp +++ b/src/gui/src/SslCertificate.cpp @@ -37,8 +37,8 @@ static const char kConfigFile[] = "barrier.conf"; SslCertificate::SslCertificate(QObject *parent) : QObject(parent) { - m_ProfileDir = QString::fromStdString(DataDirectories::profile()); - if (m_ProfileDir.isEmpty()) { + m_ProfileDir = DataDirectories::profile(); + if (m_ProfileDir.empty()) { emit error(tr("Failed to get profile directory.")); } } @@ -91,15 +91,7 @@ std::pair SslCertificate::runTool(const QStringList& args) void SslCertificate::generateCertificate() { - QString sslDirPath = QString("%1%2%3") - .arg(m_ProfileDir) - .arg(QDir::separator()) - .arg(kSslDir); - - QString filename = QString("%1%2%3") - .arg(sslDirPath) - .arg(QDir::separator()) - .arg(kCertificateFilename); + auto filename = QString::fromStdString(getCertificatePath()); QFile file(filename); if (!file.exists()) { @@ -124,7 +116,7 @@ void SslCertificate::generateCertificate() arguments.append("-newkey"); arguments.append("rsa:2048"); - QDir sslDir(sslDirPath); + QDir sslDir(QString::fromStdString(getCertificateDirectory())); if (!sslDir.exists()) { sslDir.mkpath("."); } @@ -182,3 +174,12 @@ void SslCertificate::generateFingerprint(const QString& certificateFilename) } } +std::string SslCertificate::getCertificatePath() +{ + return getCertificateDirectory() + QDir::separator().toLatin1() + kCertificateFilename; +} + +std::string SslCertificate::getCertificateDirectory() +{ + return m_ProfileDir + QDir::separator().toLatin1() + kSslDir; +} diff --git a/src/gui/src/SslCertificate.h b/src/gui/src/SslCertificate.h index 04ced49d..5ff5368d 100644 --- a/src/gui/src/SslCertificate.h +++ b/src/gui/src/SslCertificate.h @@ -39,6 +39,9 @@ private: std::pair runTool(const QStringList& args); void generateFingerprint(const QString& certificateFilename); + std::string getCertificatePath(); + std::string getCertificateDirectory(); + private: - QString m_ProfileDir; + std::string m_ProfileDir; };