Load WebUI certificate & key from file path

This allow users to update certificate & key more easily, i.e. without the need to import them
into qbt.

Closes #6675, #7547, #8315, #8564.
This commit is contained in:
Chocobo1 2019-01-17 09:42:01 +08:00
commit 5cdb3b6a2d
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
12 changed files with 212 additions and 277 deletions

View file

@ -28,11 +28,14 @@
#include "webui.h"
#include <QFile>
#include "base/http/server.h"
#include "base/logger.h"
#include "base/net/dnsupdater.h"
#include "base/net/portforwarder.h"
#include "base/preferences.h"
#include "base/utils/net.h"
#include "webapplication.h"
WebUI::WebUI()
@ -77,11 +80,18 @@ void WebUI::configure()
m_httpServer->close();
}
#ifndef QT_NO_OPENSSL
if (pref->isWebUiHttpsEnabled()) {
const QByteArray certs = pref->getWebUiHttpsCertificate();
const QByteArray key = pref->getWebUiHttpsKey();
bool success = m_httpServer->setupHttps(certs, key);
const auto readData = [](const QString &path) -> QByteArray
{
QFile file(path);
if (!file.open(QIODevice::ReadOnly))
return {};
return file.read(Utils::Net::MAX_SSL_FILE_SIZE);
};
const QByteArray cert = readData(pref->getWebUIHttpsCertificatePath());
const QByteArray key = readData(pref->getWebUIHttpsKeyPath());
const bool success = m_httpServer->setupHttps(cert, key);
if (success)
logger->addMessage(tr("Web UI: HTTPS setup successful"));
else
@ -90,7 +100,6 @@ void WebUI::configure()
else {
m_httpServer->disableHttps();
}
#endif
if (!m_httpServer->isListening()) {
const auto address = (serverAddressString == "*" || serverAddressString.isEmpty())