refactor: new static TlsUtility::certFingerprint to generate fingerprint on the fly
This commit is contained in:
parent
94eaa79768
commit
2087097415
2 changed files with 29 additions and 0 deletions
|
|
@ -70,6 +70,27 @@ int TlsUtility::getCertKeyLength(const QString &certPath)
|
||||||
return deskflow::getCertLength(certPath.toStdString());
|
return deskflow::getCertLength(certPath.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray TlsUtility::certFingerprint(const QString &certPath)
|
||||||
|
{
|
||||||
|
QByteArray fingerprint;
|
||||||
|
|
||||||
|
const auto certs = QSslCertificate::fromPath(certPath);
|
||||||
|
if (certs.isEmpty()) {
|
||||||
|
//: %1 will be replaced by the certificate path
|
||||||
|
qDebug() << tr("failed to read key from certificate file: %1").arg(certPath);
|
||||||
|
return fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto cert = certs.first();
|
||||||
|
if (cert.isNull()) {
|
||||||
|
//: %1 will be replaced by the certificate path
|
||||||
|
qWarning() << tr("failed to parse certificate file: %1").arg(certPath);
|
||||||
|
return fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cert.digest(QCryptographicHash::Sha256);
|
||||||
|
}
|
||||||
|
|
||||||
bool TlsUtility::generateCertificate() const
|
bool TlsUtility::generateCertificate() const
|
||||||
{
|
{
|
||||||
qDebug(
|
qDebug(
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,14 @@ public:
|
||||||
*/
|
*/
|
||||||
static int getCertKeyLength(const QString &certPath = Settings::value(Settings::Security::Certificate).toString());
|
static int getCertKeyLength(const QString &certPath = Settings::value(Settings::Security::Certificate).toString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get the SHA256 fingerprint of a certificatefile.
|
||||||
|
* @param certPath path of the file to fingerprint, when not set uses the vaule of Settings::Security::Certificate
|
||||||
|
* @return A QByteArray of the SHA256 fingerprint of the file or empty array if invalid file is passed
|
||||||
|
*/
|
||||||
|
// clang-format off
|
||||||
|
static QByteArray certFingerprint(const QString &certPath = Settings::value(Settings::Security::Certificate).toString());
|
||||||
|
// clang-format on
|
||||||
private:
|
private:
|
||||||
TlsCertificate m_certificate;
|
TlsCertificate m_certificate;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue