#5627 Only generate an SSL certificate when it doesn't exist

This commit is contained in:
Andrew Nelless 2016-09-30 17:31:55 +01:00 committed by Andrew Nelless
parent 4924f2faff
commit c799041ce8
3 changed files with 51 additions and 37 deletions

View File

@ -34,6 +34,7 @@
#include "EditionType.h" #include "EditionType.h"
#include "QUtility.h" #include "QUtility.h"
#include "ProcessorArch.h" #include "ProcessorArch.h"
#include "SslCertificate.h"
#include <QtCore> #include <QtCore>
#include <QtGui> #include <QtGui>
@ -97,7 +98,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_SuppressAutoConfigWarning(false), m_SuppressAutoConfigWarning(false),
m_BonjourInstall(NULL), m_BonjourInstall(NULL),
m_SuppressEmptyServerWarning(false), m_SuppressEmptyServerWarning(false),
m_ExpectedRunningState(kStopped) m_ExpectedRunningState(kStopped),
m_pSslCertificate(NULL)
{ {
setupUi(this); setupUi(this);
@ -145,6 +147,11 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
appConfig.activationHasRun(true); appConfig.activationHasRun(true);
} }
if (appConfig.getCryptoEnabled()) {
m_pSslCertificate = new SslCertificate(this);
m_pSslCertificate->generateCertificate();
}
appConfig.saveSettings(); appConfig.saveSettings();
} }
@ -166,6 +173,8 @@ MainWindow::~MainWindow()
if (m_BonjourInstall != NULL) { if (m_BonjourInstall != NULL) {
delete m_BonjourInstall; delete m_BonjourInstall;
} }
delete m_pSslCertificate;
} }
void MainWindow::open() void MainWindow::open()

View File

@ -57,6 +57,7 @@ class SetupWizard;
class ZeroconfService; class ZeroconfService;
class DataDownloader; class DataDownloader;
class CommandProcess; class CommandProcess;
class SslCertificate;
class MainWindow : public QMainWindow, public Ui::MainWindowBase class MainWindow : public QMainWindow, public Ui::MainWindowBase
{ {
@ -207,6 +208,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool m_SuppressEmptyServerWarning; bool m_SuppressEmptyServerWarning;
qRuningState m_ExpectedRunningState; qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex; QMutex m_StopDesktopMutex;
SslCertificate* m_pSslCertificate;
private slots: private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked); void on_m_pCheckBoxAutoConfig_toggled(bool checked);

View File

@ -90,6 +90,18 @@ bool SslCertificate::runTool(const QStringList& args)
void SslCertificate::generateCertificate() 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);
QFile file(filename);
if (!file.exists()) {
QStringList arguments; QStringList arguments;
// self signed certificate // self signed certificate
@ -111,21 +123,11 @@ void SslCertificate::generateCertificate()
arguments.append("-newkey"); arguments.append("-newkey");
arguments.append("rsa:1024"); arguments.append("rsa:1024");
QString sslDirPath = QString("%1%2%3")
.arg(m_ProfileDir)
.arg(QDir::separator())
.arg(kSslDir);
QDir sslDir(sslDirPath); QDir sslDir(sslDirPath);
if (!sslDir.exists()) { if (!sslDir.exists()) {
sslDir.mkpath("."); sslDir.mkpath(".");
} }
QString filename = QString("%1%2%3")
.arg(sslDirPath)
.arg(QDir::separator())
.arg(kCertificateFilename);
// key output filename // key output filename
arguments.append("-keyout"); arguments.append("-keyout");
arguments.append(filename); arguments.append(filename);
@ -139,6 +141,7 @@ void SslCertificate::generateCertificate()
} }
emit info(tr("SSL certificate generated.")); emit info(tr("SSL certificate generated."));
}
generateFingerprint(filename); generateFingerprint(filename);