refactor: new static TlsUtility::certFingerprint to generate fingerprint on the fly
This commit is contained in:
@ -70,6 +70,27 @@ int TlsUtility::getCertKeyLength(const QString &certPath)
|
||||
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
|
||||
{
|
||||
qDebug(
|
||||
|
||||
@ -43,6 +43,14 @@ public:
|
||||
*/
|
||||
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:
|
||||
TlsCertificate m_certificate;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user