diff options
Diffstat (limited to 'src/server/net/certmanager.cpp')
-rw-r--r-- | src/server/net/certmanager.cpp | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/server/net/certmanager.cpp b/src/server/net/certmanager.cpp index a503088..5f0980b 100644 --- a/src/server/net/certmanager.cpp +++ b/src/server/net/certmanager.cpp @@ -18,19 +18,22 @@ #define CERTSTORAGE ".config/openslx/pvs2/" #include "certmanager.h" -#include <QMap> +#include "../../shared/util.h" +// Remove in future - see comment in util.h +#undef errorOccurred + +#include <QHash> #include <QDir> #include <QDebug> #include <QFileInfo> -#include <QSettings> #include <QMessageBox> -#include <QApplication> -#include <cstdlib> +#include <QProcess> +#include <QCoreApplication> namespace CertManager { -static QMap<QString, QSslCertificate> _certs; -static QMap<QString, QSslKey> _keys; +static QHash<QString, QSslCertificate> _certs; +static QHash<QString, QSslKey> _keys; static void generateFiles(QString& key, QString& cert); static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCertificate &cert); @@ -44,7 +47,7 @@ bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &ce } QString certDir = QDir::homePath().append("/").append(CERTSTORAGE); if (!QDir::root().mkpath(certDir)) { - certDir = QString("/tmp/") + QString::number(qrand()) + "-" + QString::number(qrand()) + "/"; + certDir = QString("/tmp/") + QString::number(slxrand()) + "-" + QString::number(slxrand()) + "/"; QDir::root().mkpath(certDir); } QString certFile = certDir.append(name); @@ -66,11 +69,11 @@ bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &ce void fatal() { - QMessageBox::critical(nullptr, QCoreApplication::trUtf8("OpenSSL error", "CertManager"), - QCoreApplication::trUtf8("Could not generate certificates for secure connections.\n" + QMessageBox::critical(nullptr, QObject::tr("OpenSSL error", "CertManager"), + QObject::tr("Could not generate certificates for secure connections.\n" "PVS will not work.\n\n" "Press OK to quit.", "CertManager")); - qApp->exit(1); + QCoreApplication::exit(1); } static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCertificate &cert) @@ -95,14 +98,18 @@ static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCer static void generateFiles(QString& key, QString& cert) { - char tmp[1000]; - remove(key.toLocal8Bit().data()); - remove(cert.toLocal8Bit().data()); - snprintf(tmp, 1000, - "openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -subj '/C=DE/ST=BaWue/L=Freiburg/CN=openslx.org' -keyout \"%s\" -out \"%s\"", - key.toLocal8Bit().data(), cert.toLocal8Bit().data()); - system(tmp); - snprintf(tmp, 1000, "chmod 0600 \"%s\" \"%s\"", key.toLocal8Bit().data(), cert.toLocal8Bit().data()); - system(tmp); + QProcess p; + QFile::remove(key); + QFile::remove(cert); + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(QStringLiteral("openssl"), { + "req", "-x509", "-nodes", "-days", "5000", "-newkey", "rsa:4096", + "-subj", "/C=DE/ST=BaWue/L=Freiburg/CN=openslx.org", + "-keyout", key, "-out", cert + }); + p.waitForFinished(); + p.start(QStringLiteral("chmod"), { "0600", key, cert }); + p.waitForFinished(500); } + } |