AusweisApp2/src/core/CertificateChecker.cpp

58 lines
1.6 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2014-2018 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
#include "CertificateChecker.h"
2017-12-20 14:54:05 +01:00
#include "AppSettings.h"
#include "paos/retrieve/DidAuthenticateEac1.h"
#include "TlsChecker.h"
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
#include <QCryptographicHash>
#include <QDate>
#include <QLoggingCategory>
2017-07-03 09:30:10 +02:00
using namespace governikus;
2017-07-03 09:33:28 +02:00
2017-07-03 09:30:10 +02:00
Q_DECLARE_LOGGING_CATEGORY(developermode)
2017-12-20 14:54:05 +01:00
CertificateChecker::CertificateStatus CertificateChecker::checkAndSaveCertificate(const QSslCertificate& pCertificate,
const QUrl& pUrl,
const QSharedPointer<DIDAuthenticateEAC1>& pEAC1,
const QSharedPointer<const CVCertificate>& pDvCvc,
const std::function<void(const QUrl& pUrl, const QSslCertificate& pCert)>& pSaveCertificateFunc)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (!TlsChecker::hasValidCertificateKeyLength(pCertificate))
2017-07-03 09:30:10 +02:00
{
2017-07-03 09:33:28 +02:00
return CertificateStatus::Unsupported_Algorithm_Or_Length;
}
2017-12-20 14:54:05 +01:00
if (pEAC1 && pDvCvc)
2017-07-03 09:33:28 +02:00
{
2017-12-20 14:54:05 +01:00
if (auto certificateDescription = pEAC1->getCertificateDescription())
2017-07-03 09:30:10 +02:00
{
2017-07-03 09:33:28 +02:00
const QSet<QString> certHashes = certificateDescription->getCommCertificates();
2017-12-20 14:54:05 +01:00
QCryptographicHash::Algorithm hashAlgo = pDvCvc->getBody().getHashAlgorithm();
if (!TlsChecker::checkCertificate(pCertificate, hashAlgo, certHashes))
2017-07-03 09:30:10 +02:00
{
2017-07-03 09:33:28 +02:00
auto hashError = QStringLiteral("hash of certificate not in certificate description");
2017-07-03 09:30:10 +02:00
if (AppSettings::getInstance().getGeneralSettings().isDeveloperMode())
{
2017-07-03 09:33:28 +02:00
qCCritical(developermode) << hashError;
2017-07-03 09:30:10 +02:00
}
else
{
2017-07-03 09:33:28 +02:00
qCritical() << hashError;
return CertificateStatus::Hash_Not_In_Description;
2017-07-03 09:30:10 +02:00
}
}
}
2017-07-03 09:33:28 +02:00
}
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
pSaveCertificateFunc(pUrl, pCertificate);
2017-07-03 09:33:28 +02:00
return CertificateStatus::Good;
}