7#include "signatureutils.h"
8#include <KLocalizedString>
12static QString handleEmpty(
const QString &
string, CertificateInfo::EmptyString empty)
14 if (
string.isEmpty()) {
16 case CertificateInfo::EmptyString::Empty:
18 case CertificateInfo::EmptyString::TranslatedNotAvailable:
19 return i18n(
"Not Available");
34class Okular::CertificateInfoPrivate :
public QSharedData
40 EntityInfo issuerInfo;
41 EntityInfo subjectInfo;
47 CertificateInfo::PublicKeyType publicKeyType = CertificateInfo::OtherKey;
48 int publicKeyStrength = -1;
49 bool isSelfSigned =
false;
51 CertificateInfo::Backend backend = CertificateInfo::Backend::Unknown;
52 CertificateInfo::KeyLocation keyLocation = CertificateInfo::KeyLocation::Unknown;
53 bool isQualified =
false;
54 std::function<bool(
QString)> checkPasswordFunction;
57CertificateInfo::CertificateInfo()
58 : d {new CertificateInfoPrivate()}
62Okular::CertificateInfo::CertificateInfo(
const Okular::CertificateInfo &other) =
default;
63Okular::CertificateInfo::CertificateInfo(Okular::CertificateInfo &&other)
noexcept =
default;
64Okular::CertificateInfo &Okular::CertificateInfo::operator=(
const Okular::CertificateInfo &other) =
default;
65CertificateInfo &Okular::CertificateInfo::operator=(Okular::CertificateInfo &&other)
noexcept =
default;
67CertificateInfo::~CertificateInfo() =
default;
71bool CertificateInfo::isNull()
const
76void CertificateInfo::setNull(
bool isNull)
81int CertificateInfo::version()
const
85void CertificateInfo::setVersion(
int version)
90QByteArray CertificateInfo::serialNumber()
const
92 return d->serialNumber;
94void CertificateInfo::setSerialNumber(
const QByteArray &serialNumber)
96 d->serialNumber = serialNumber;
99QString CertificateInfo::issuerInfo(EntityInfoKey key, EmptyString empty)
const
102 case EntityInfoKey::CommonName:
103 return handleEmpty(d->issuerInfo.commonName, empty);
104 case EntityInfoKey::DistinguishedName:
105 return handleEmpty(d->issuerInfo.distinguishedName, empty);
106 case EntityInfoKey::EmailAddress:
107 return handleEmpty(d->issuerInfo.emailAddress, empty);
108 case EntityInfoKey::Organization:
109 return handleEmpty(d->issuerInfo.organization, empty);
114void CertificateInfo::setIssuerInfo(EntityInfoKey key,
const QString &value)
117 case EntityInfoKey::CommonName:
118 d->issuerInfo.commonName = value;
120 case EntityInfoKey::DistinguishedName:
121 d->issuerInfo.distinguishedName = value;
123 case EntityInfoKey::EmailAddress:
124 d->issuerInfo.emailAddress = value;
126 case EntityInfoKey::Organization:
127 d->issuerInfo.organization = value;
132QString CertificateInfo::subjectInfo(EntityInfoKey key, EmptyString empty)
const
135 case EntityInfoKey::CommonName:
136 return handleEmpty(d->subjectInfo.commonName, empty);
137 case EntityInfoKey::DistinguishedName:
138 return handleEmpty(d->subjectInfo.distinguishedName, empty);
139 case EntityInfoKey::EmailAddress:
140 return handleEmpty(d->subjectInfo.emailAddress, empty);
141 case EntityInfoKey::Organization:
142 return handleEmpty(d->subjectInfo.organization, empty);
147void CertificateInfo::setSubjectInfo(EntityInfoKey key,
const QString &value)
150 case EntityInfoKey::CommonName:
151 d->subjectInfo.commonName = value;
153 case EntityInfoKey::DistinguishedName:
154 d->subjectInfo.distinguishedName = value;
156 case EntityInfoKey::EmailAddress:
157 d->subjectInfo.emailAddress = value;
159 case EntityInfoKey::Organization:
160 d->subjectInfo.organization = value;
165QString CertificateInfo::nickName()
const
170void CertificateInfo::setNickName(
const QString &nickName)
172 d->nickName = nickName;
175QDateTime CertificateInfo::validityStart()
const
177 return d->validityStart;
182 d->validityStart =
start;
185QDateTime CertificateInfo::validityEnd()
const
187 return d->validityEnd;
190void Okular::CertificateInfo::setValidityEnd(
const QDateTime &validityEnd)
192 d->validityEnd = validityEnd;
197 return d->keyUsageExtensions;
202 d->keyUsageExtensions = ext;
210void Okular::CertificateInfo::setPublicKey(
const QByteArray &publicKey)
212 d->publicKey = publicKey;
215CertificateInfo::PublicKeyType CertificateInfo::publicKeyType()
const
217 return d->publicKeyType;
220void CertificateInfo::setPublicKeyType(PublicKeyType type)
222 d->publicKeyType =
type;
225int CertificateInfo::publicKeyStrength()
const
227 return d->publicKeyStrength;
230void CertificateInfo::setPublicKeyStrength(
int strength)
232 d->publicKeyStrength = strength;
235bool CertificateInfo::isSelfSigned()
const
237 return d->isSelfSigned;
240void CertificateInfo::setSelfSigned(
bool selfSigned)
242 d->isSelfSigned = selfSigned;
245QByteArray CertificateInfo::certificateData()
const
247 return d->certificateData;
250void CertificateInfo::setCertificateData(
const QByteArray &certificateData)
252 d->certificateData = certificateData;
255CertificateInfo::KeyLocation CertificateInfo::keyLocation()
const
257 return d->keyLocation;
260void CertificateInfo::setKeyLocation(KeyLocation location)
265CertificateInfo::Backend CertificateInfo::backend()
const
270void CertificateInfo::setBackend(Backend backend)
272 d->backend = backend;
275bool CertificateInfo::checkPassword(
const QString &password)
const
277 if (d->checkPasswordFunction) {
278 return d->checkPasswordFunction(password);
283void CertificateInfo::setCheckPasswordFunction(
const std::function<
bool(
const QString &)> &passwordFunction)
285 d->checkPasswordFunction = passwordFunction;
288bool CertificateInfo::isQualified()
const
290 return d->isQualified;
293void CertificateInfo::setQualified(
bool qualified)
295 d->isQualified = qualified;
298class Okular::SignatureInfoPrivate :
public QSharedData
301 SignatureInfo::SignatureStatus signatureStatus = SignatureInfo::SignatureStatusUnknown;
302 SignatureInfo::CertificateStatus certificateStatus = SignatureInfo::CertificateStatusUnknown;
303 SignatureInfo::HashAlgorithm hashAlgorithm = SignatureInfo::HashAlgorithmUnknown;
311 bool signsTotalDocument =
false;
312 CertificateInfo certificateInfo;
315SignatureInfo::SignatureInfo()
316 : d {new SignatureInfoPrivate()}
320SignatureInfo::SignatureInfo(SignatureInfo &&other)
noexcept =
default;
321SignatureInfo::SignatureInfo(
const SignatureInfo &other) =
default;
322SignatureInfo &SignatureInfo::operator=(SignatureInfo &&other)
noexcept =
default;
323Okular::SignatureInfo &Okular::SignatureInfo::operator=(
const Okular::SignatureInfo &other) =
default;
324SignatureInfo::~SignatureInfo() =
default;
326SignatureInfo::SignatureStatus SignatureInfo::signatureStatus()
const
328 return d->signatureStatus;
331void SignatureInfo::setSignatureStatus(SignatureInfo::SignatureStatus
status)
333 d->signatureStatus =
status;
336SignatureInfo::CertificateStatus SignatureInfo::certificateStatus()
const
338 return d->certificateStatus;
341void SignatureInfo::setCertificateStatus(SignatureInfo::CertificateStatus
status)
343 d->certificateStatus =
status;
346SignatureInfo::HashAlgorithm SignatureInfo::hashAlgorithm()
const
348 return d->hashAlgorithm;
351void Okular::SignatureInfo::setHashAlgorithm(Okular::SignatureInfo::HashAlgorithm algorithm)
353 d->hashAlgorithm = algorithm;
356QString SignatureInfo::signerName()
const
358 return d->signerName;
361void SignatureInfo::setSignerName(
const QString &signerName)
363 d->signerName = signerName;
366QString SignatureInfo::signerSubjectDN()
const
368 return d->signerSubjectDN;
371void Okular::SignatureInfo::setSignerSubjectDN(
const QString &signerSubjectDN)
373 d->signerSubjectDN = signerSubjectDN;
376QString SignatureInfo::location()
const
381void SignatureInfo::setLocation(
const QString &location)
386QString SignatureInfo::reason()
const
391void Okular::SignatureInfo::setReason(
const QString &reason)
396QDateTime SignatureInfo::signingTime()
const
398 return d->signingTime;
401void Okular::SignatureInfo::setSigningTime(
const QDateTime &time)
403 d->signingTime = time;
411void SignatureInfo::setSignature(
const QByteArray &signature)
413 d->signature = signature;
418 return d->signedRangeBounds;
421void SignatureInfo::setSignedRangeBounds(
const QList<qint64> &range)
423 d->signedRangeBounds = range;
426bool SignatureInfo::signsTotalDocument()
const
428 return d->signsTotalDocument;
431void SignatureInfo::setSignsTotalDocument(
bool total)
433 d->signsTotalDocument = total;
436CertificateInfo SignatureInfo::certificateInfo()
const
438 return d->certificateInfo;
441void SignatureInfo::setCertificateInfo(
const Okular::CertificateInfo &info)
443 d->certificateInfo = info;
446CertificateStore::CertificateStore()
456 *userCancelled =
false;
464 auto it = certs.
begin();
465 *nonDateValidCerts =
false;
466 while (it != certs.
end()) {
467 if (it->validityStart() > now || now > it->validityEnd()) {
468 it = certs.
erase(it);
469 *nonDateValidCerts =
true;
QList< CertificateInfo > signingCertificatesForNow(bool *userCancelled, bool *nonDateValidCerts) const
Returns list of valid, usable signing certificates for current date and time.
virtual ~CertificateStore()
Destructor.
virtual QList< CertificateInfo > signingCertificates(bool *userCancelled) const
Returns list of valid, usable signing certificates.
Q_SCRIPTABLE CaptureState status()
Q_SCRIPTABLE Q_NOREPLY void start()
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
KCOREADDONS_EXPORT unsigned int version()
QVariant location(const QVariant &res)
QDateTime currentDateTime()
iterator erase(const_iterator begin, const_iterator end)