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
parent 48d358872f
commit 5cdb3b6a2d
12 changed files with 212 additions and 277 deletions

View File

@@ -28,6 +28,8 @@
#include "net.h"
#include <QSslCertificate>
#include <QSslKey>
#include <QString>
namespace Utils
@@ -88,5 +90,32 @@ namespace Utils
{
return subnet.first.toString() + '/' + QString::number(subnet.second);
}
QList<QSslCertificate> loadSSLCertificate(const QByteArray &data)
{
const QList<QSslCertificate> certs {QSslCertificate::fromData(data)};
if (std::any_of(certs.cbegin(), certs.cend(), [](const QSslCertificate &c) { return c.isNull(); }))
return {};
return certs;
}
bool isSSLCertificatesValid(const QByteArray &data)
{
return !loadSSLCertificate(data).isEmpty();
}
QSslKey loadSSLKey(const QByteArray &data)
{
// try different formats
QSslKey key {data, QSsl::Rsa};
if (!key.isNull())
return key;
return QSslKey(data, QSsl::Ec);
}
bool isSSLKeyValid(const QByteArray &data)
{
return !loadSSLKey(data).isNull();
}
}
}