2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
2018-03-28 15:10:51 +02:00
|
|
|
* \copyright Copyright (c) 2016-2018 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "asn1/CertificateDescription.h"
|
2017-09-15 10:23:30 +02:00
|
|
|
#include "AppSettings.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
#include "context/AuthContext.h"
|
2017-12-20 14:54:05 +01:00
|
|
|
#include "context/SelfAuthContext.h"
|
2017-09-15 10:23:30 +02:00
|
|
|
#include "CertificateDescriptionModel.h"
|
2017-12-20 14:54:05 +01:00
|
|
|
#include "Env.h"
|
|
|
|
#include "SecureStorage.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QSharedPointer<const CertificateDescription> CertificateDescriptionModel::getCertificateDescription() const
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
if (mContext && mContext->getDidAuthenticateEac1())
|
|
|
|
{
|
|
|
|
return mContext->getDidAuthenticateEac1()->getCertificateDescription();
|
|
|
|
}
|
|
|
|
|
2018-03-28 15:10:51 +02:00
|
|
|
return QSharedPointer<const CertificateDescription>();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CertificateDescriptionModel::onDidAuthenticateEac1Changed()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
mData.clear();
|
2017-07-03 09:33:28 +02:00
|
|
|
if (const auto& certDescr = getCertificateDescription())
|
|
|
|
{
|
|
|
|
initModelData(certDescr);
|
|
|
|
}
|
|
|
|
endResetModel();
|
|
|
|
|
|
|
|
Q_EMIT fireChanged();
|
|
|
|
}
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
void CertificateDescriptionModel::initModelData(const QSharedPointer<const CertificateDescription>& pCertDescription)
|
2017-07-03 09:33:28 +02:00
|
|
|
{
|
|
|
|
const QString& serviceProviderAddress = pCertDescription->getServiceProviderAddress();
|
|
|
|
const QString& purpose = getPurpose();
|
|
|
|
const QString& dataSecurityOfficer = pCertDescription->getDataSecurityOfficer();
|
|
|
|
const QString& termsOfUsage = pCertDescription->getTermsOfUsage();
|
2017-07-03 09:30:10 +02:00
|
|
|
const bool showDetailedProviderInfo = !(serviceProviderAddress.isEmpty() || purpose.isEmpty() || dataSecurityOfficer.isEmpty());
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
mData += QPair<QString, QString>(tr("Service provider"), getSubjectName() + QLatin1Char('\n') + getSubjectUrl());
|
|
|
|
mData += QPair<QString, QString>(tr("Certificate issuer"), pCertDescription->getIssuerName() + QLatin1Char('\n') + pCertDescription->getIssuerUrl());
|
2017-07-03 09:30:10 +02:00
|
|
|
if (showDetailedProviderInfo)
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
mData += QPair<QString, QString>(tr("Name, address and mail address of the service provider"), serviceProviderAddress);
|
|
|
|
mData += QPair<QString, QString>(tr("Purpose"), purpose);
|
|
|
|
mData += QPair<QString, QString>(tr("Indication of the bodies responsible for the service provider, "
|
|
|
|
"that verify the compliance with data security regulations"), dataSecurityOfficer);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
else if (!termsOfUsage.isEmpty())
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
mData += QPair<QString, QString>(tr("Service provider information"), termsOfUsage);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
if (!getValidity().isEmpty())
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
mData += QPair<QString, QString>(tr("Validity"), getValidity());
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CertificateDescriptionModel::CertificateDescriptionModel(QObject* pParent)
|
|
|
|
: QAbstractListModel(pParent)
|
|
|
|
, mData()
|
|
|
|
, mContext()
|
|
|
|
{
|
|
|
|
resetContext();
|
|
|
|
connect(&AppSettings::getInstance(), &AppSettings::fireSettingsChanged, this, &CertificateDescriptionModel::onDidAuthenticateEac1Changed);
|
2017-12-20 14:54:05 +01:00
|
|
|
connect(&AppSettings::getInstance().getGeneralSettings(), &GeneralSettings::fireSettingsChanged, this, [this]()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
onDidAuthenticateEac1Changed();
|
|
|
|
endResetModel();
|
|
|
|
});
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
void CertificateDescriptionModel::resetContext(const QSharedPointer<AuthContext>& pContext)
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
mContext = pContext;
|
|
|
|
if (mContext)
|
|
|
|
{
|
|
|
|
connect(mContext.data(), &AuthContext::fireDidAuthenticateEac1Changed, this, &CertificateDescriptionModel::onDidAuthenticateEac1Changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDidAuthenticateEac1Changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CertificateDescriptionModel::getSubjectName() const
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto& certificateDescription = getCertificateDescription();
|
|
|
|
return certificateDescription ? getCertificateDescription()->getSubjectName() : QString();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CertificateDescriptionModel::getSubjectUrl() const
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto& certificateDescription = getCertificateDescription();
|
|
|
|
return certificateDescription ? getCertificateDescription()->getSubjectUrl() : QString();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CertificateDescriptionModel::getPurpose() const
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto& certificateDescription = getCertificateDescription();
|
|
|
|
return certificateDescription ? getCertificateDescription()->getPurpose() : QString();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CertificateDescriptionModel::getValidity() const
|
|
|
|
{
|
|
|
|
if (mContext && mContext->getDidAuthenticateEac1() && !mContext->getDidAuthenticateEac1()->getCvCertificates().isEmpty())
|
|
|
|
{
|
|
|
|
const CVCertificateBody body = mContext->getDidAuthenticateEac1()->getCvCertificates().at(0)->getBody();
|
|
|
|
const QString effectiveDate = body.getCertificateEffectiveDate().toString(Qt::DefaultLocaleShortDate);
|
|
|
|
const QString expirationDate = body.getCertificateExpirationDate().toString(Qt::DefaultLocaleShortDate);
|
|
|
|
|
|
|
|
return QStringLiteral("%1 - %2").arg(effectiveDate, expirationDate);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CertificateDescriptionModel::rowCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return mData.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant CertificateDescriptionModel::data(const QModelIndex& pIndex, int pRole) const
|
|
|
|
{
|
|
|
|
if (pIndex.isValid() && pIndex.row() < rowCount())
|
|
|
|
{
|
|
|
|
auto entry = mData[pIndex.row()];
|
|
|
|
if (pRole == LABEL)
|
|
|
|
{
|
|
|
|
return entry.first;
|
|
|
|
}
|
|
|
|
if (pRole == TEXT)
|
|
|
|
{
|
|
|
|
return entry.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QHash<int, QByteArray> CertificateDescriptionModel::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
|
|
|
|
roles.insert(LABEL, "label");
|
|
|
|
roles.insert(TEXT, "text");
|
|
|
|
return roles;
|
|
|
|
}
|