mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 22:47:21 -06:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user