This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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

  • Loading branch information...
nlyan committed Sep 30, 2016
1 parent 4924f2f commit c799041ce8a7e2a0fecfc970f394f87a91dc57d1
Showing with 51 additions and 37 deletions.
  1. +10 −1 src/gui/src/MainWindow.cpp
  2. +2 −0 src/gui/src/MainWindow.h
  3. +39 −36 src/gui/src/SslCertificate.cpp
View
@@ -34,6 +34,7 @@
#include "EditionType.h"
#include "QUtility.h"
#include "ProcessorArch.h"
+#include "SslCertificate.h"
#include <QtCore>
#include <QtGui>
@@ -97,7 +98,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_SuppressAutoConfigWarning(false),
m_BonjourInstall(NULL),
m_SuppressEmptyServerWarning(false),
- m_ExpectedRunningState(kStopped)
+ m_ExpectedRunningState(kStopped),
+ m_pSslCertificate(NULL)
{
setupUi(this);
@@ -145,6 +147,11 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
appConfig.activationHasRun(true);
}
+ if (appConfig.getCryptoEnabled()) {
+ m_pSslCertificate = new SslCertificate(this);
+ m_pSslCertificate->generateCertificate();
+ }
+
appConfig.saveSettings();
}
@@ -166,6 +173,8 @@ MainWindow::~MainWindow()
if (m_BonjourInstall != NULL) {
delete m_BonjourInstall;
}
+
+ delete m_pSslCertificate;
}
void MainWindow::open()
View
@@ -57,6 +57,7 @@ class SetupWizard;
class ZeroconfService;
class DataDownloader;
class CommandProcess;
+class SslCertificate;
class MainWindow : public QMainWindow, public Ui::MainWindowBase
{
@@ -207,6 +208,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool m_SuppressEmptyServerWarning;
qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
+ SslCertificate* m_pSslCertificate;
private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
@@ -90,55 +90,58 @@ bool SslCertificate::runTool(const QStringList& args)
void SslCertificate::generateCertificate()
{
- QStringList arguments;
-
- // self signed certificate
- arguments.append("req");
- arguments.append("-x509");
- arguments.append("-nodes");
-
- // valide duration
- arguments.append("-days");
- arguments.append(kCertificateLifetime);
-
- // subject information
- arguments.append("-subj");
-
- QString subInfo(kCertificateSubjectInfo);
- arguments.append(subInfo);
-
- // private key
- arguments.append("-newkey");
- arguments.append("rsa:1024");
-
QString sslDirPath = QString("%1%2%3")
.arg(m_ProfileDir)
.arg(QDir::separator())
.arg(kSslDir);
- QDir sslDir(sslDirPath);
- if (!sslDir.exists()) {
- sslDir.mkpath(".");
- }
-
QString filename = QString("%1%2%3")
.arg(sslDirPath)
.arg(QDir::separator())
.arg(kCertificateFilename);
- // key output filename
- arguments.append("-keyout");
- arguments.append(filename);
+ QFile file(filename);
+ if (!file.exists()) {
+ QStringList arguments;
- // certificate output filename
- arguments.append("-out");
- arguments.append(filename);
+ // self signed certificate
+ arguments.append("req");
+ arguments.append("-x509");
+ arguments.append("-nodes");
- if (!runTool(arguments)) {
- return;
- }
+ // valide duration
+ arguments.append("-days");
+ arguments.append(kCertificateLifetime);
+
+ // subject information
+ arguments.append("-subj");
+
+ QString subInfo(kCertificateSubjectInfo);
+ arguments.append(subInfo);
+
+ // private key
+ arguments.append("-newkey");
+ arguments.append("rsa:1024");
- emit info(tr("SSL certificate generated."));
+ QDir sslDir(sslDirPath);
+ if (!sslDir.exists()) {
+ sslDir.mkpath(".");
+ }
+
+ // key output filename
+ arguments.append("-keyout");
+ arguments.append(filename);
+
+ // certificate output filename
+ arguments.append("-out");
+ arguments.append(filename);
+
+ if (!runTool(arguments)) {
+ return;
+ }
+
+ emit info(tr("SSL certificate generated."));
+ }
generateFingerprint(filename);

0 comments on commit c799041

Please sign in to comment.