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 std::function<bool(
QString)> checkPasswordFunction;
56CertificateInfo::CertificateInfo()
57 : d {new CertificateInfoPrivate()}
61Okular::CertificateInfo::CertificateInfo(
const Okular::CertificateInfo &other) =
default;
62Okular::CertificateInfo::CertificateInfo(Okular::CertificateInfo &&other)
noexcept =
default;
63Okular::CertificateInfo &Okular::CertificateInfo::operator=(
const Okular::CertificateInfo &other) =
default;
64CertificateInfo &Okular::CertificateInfo::operator=(Okular::CertificateInfo &&other)
noexcept =
default;
66CertificateInfo::~CertificateInfo() =
default;
70bool CertificateInfo::isNull()
const
75void CertificateInfo::setNull(
bool isNull)
80int CertificateInfo::version()
const
84void CertificateInfo::setVersion(
int version)
89QByteArray CertificateInfo::serialNumber()
const
91 return d->serialNumber;
93void CertificateInfo::setSerialNumber(
const QByteArray &serialNumber)
95 d->serialNumber = serialNumber;
98QString CertificateInfo::issuerInfo(EntityInfoKey key, EmptyString empty)
const
101 case EntityInfoKey::CommonName:
102 return handleEmpty(d->issuerInfo.commonName, empty);
103 case EntityInfoKey::DistinguishedName:
104 return handleEmpty(d->issuerInfo.distinguishedName, empty);
105 case EntityInfoKey::EmailAddress:
106 return handleEmpty(d->issuerInfo.emailAddress, empty);
107 case EntityInfoKey::Organization:
108 return handleEmpty(d->issuerInfo.organization, empty);
113void CertificateInfo::setIssuerInfo(EntityInfoKey key,
const QString &value)
116 case EntityInfoKey::CommonName:
117 d->issuerInfo.commonName = value;
119 case EntityInfoKey::DistinguishedName:
120 d->issuerInfo.distinguishedName = value;
122 case EntityInfoKey::EmailAddress:
123 d->issuerInfo.emailAddress = value;
125 case EntityInfoKey::Organization:
126 d->issuerInfo.organization = value;
131QString CertificateInfo::subjectInfo(EntityInfoKey key, EmptyString empty)
const
134 case EntityInfoKey::CommonName:
135 return handleEmpty(d->subjectInfo.commonName, empty);
136 case EntityInfoKey::DistinguishedName:
137 return handleEmpty(d->subjectInfo.distinguishedName, empty);
138 case EntityInfoKey::EmailAddress:
139 return handleEmpty(d->subjectInfo.emailAddress, empty);
140 case EntityInfoKey::Organization:
141 return handleEmpty(d->subjectInfo.organization, empty);
146void CertificateInfo::setSubjectInfo(EntityInfoKey key,
const QString &value)
149 case EntityInfoKey::CommonName:
150 d->subjectInfo.commonName = value;
152 case EntityInfoKey::DistinguishedName:
153 d->subjectInfo.distinguishedName = value;
155 case EntityInfoKey::EmailAddress:
156 d->subjectInfo.emailAddress = value;
158 case EntityInfoKey::Organization:
159 d->subjectInfo.organization = value;
164QString CertificateInfo::nickName()
const
169void CertificateInfo::setNickName(
const QString &nickName)
171 d->nickName = nickName;
174QDateTime CertificateInfo::validityStart()
const
176 return d->validityStart;
181 d->validityStart =
start;
184QDateTime CertificateInfo::validityEnd()
const
186 return d->validityEnd;
189void Okular::CertificateInfo::setValidityEnd(
const QDateTime &validityEnd)
191 d->validityEnd = validityEnd;
196 return d->keyUsageExtensions;
201 d->keyUsageExtensions = ext;
209void Okular::CertificateInfo::setPublicKey(
const QByteArray &publicKey)
211 d->publicKey = publicKey;
214CertificateInfo::PublicKeyType CertificateInfo::publicKeyType()
const
216 return d->publicKeyType;
219void CertificateInfo::setPublicKeyType(PublicKeyType type)
221 d->publicKeyType =
type;
224int CertificateInfo::publicKeyStrength()
const
226 return d->publicKeyStrength;
229void CertificateInfo::setPublicKeyStrength(
int strength)
231 d->publicKeyStrength = strength;
234bool CertificateInfo::isSelfSigned()
const
236 return d->isSelfSigned;
239void CertificateInfo::setSelfSigned(
bool selfSigned)
241 d->isSelfSigned = selfSigned;
244QByteArray CertificateInfo::certificateData()
const
246 return d->certificateData;
249void CertificateInfo::setCertificateData(
const QByteArray &certificateData)
251 d->certificateData = certificateData;
254CertificateInfo::KeyLocation CertificateInfo::keyLocation()
const
256 return d->keyLocation;
259void CertificateInfo::setKeyLocation(KeyLocation location)
264CertificateInfo::Backend CertificateInfo::backend()
const
269void CertificateInfo::setBackend(Backend backend)
271 d->backend = backend;
274bool CertificateInfo::checkPassword(
const QString &password)
const
276 if (d->checkPasswordFunction) {
277 return d->checkPasswordFunction(password);
282void CertificateInfo::setCheckPasswordFunction(
const std::function<
bool(
const QString &)> &passwordFunction)
284 d->checkPasswordFunction = passwordFunction;
287class Okular::SignatureInfoPrivate :
public QSharedData
290 SignatureInfo::SignatureStatus signatureStatus = SignatureInfo::SignatureStatusUnknown;
291 SignatureInfo::CertificateStatus certificateStatus = SignatureInfo::CertificateStatusUnknown;
292 SignatureInfo::HashAlgorithm hashAlgorithm = SignatureInfo::HashAlgorithmUnknown;
300 bool signsTotalDocument =
false;
301 CertificateInfo certificateInfo;
304SignatureInfo::SignatureInfo()
305 : d {new SignatureInfoPrivate()}
309SignatureInfo::SignatureInfo(SignatureInfo &&other)
noexcept =
default;
310SignatureInfo::SignatureInfo(
const SignatureInfo &other) =
default;
311SignatureInfo &SignatureInfo::operator=(SignatureInfo &&other)
noexcept =
default;
312Okular::SignatureInfo &Okular::SignatureInfo::operator=(
const Okular::SignatureInfo &other) =
default;
313SignatureInfo::~SignatureInfo() =
default;
315SignatureInfo::SignatureStatus SignatureInfo::signatureStatus()
const
317 return d->signatureStatus;
320void SignatureInfo::setSignatureStatus(SignatureInfo::SignatureStatus
status)
322 d->signatureStatus =
status;
325SignatureInfo::CertificateStatus SignatureInfo::certificateStatus()
const
327 return d->certificateStatus;
330void SignatureInfo::setCertificateStatus(SignatureInfo::CertificateStatus
status)
332 d->certificateStatus =
status;
335SignatureInfo::HashAlgorithm SignatureInfo::hashAlgorithm()
const
337 return d->hashAlgorithm;
340void Okular::SignatureInfo::setHashAlgorithm(Okular::SignatureInfo::HashAlgorithm algorithm)
342 d->hashAlgorithm = algorithm;
345QString SignatureInfo::signerName()
const
347 return d->signerName;
350void SignatureInfo::setSignerName(
const QString &signerName)
352 d->signerName = signerName;
355QString SignatureInfo::signerSubjectDN()
const
357 return d->signerSubjectDN;
360void Okular::SignatureInfo::setSignerSubjectDN(
const QString &signerSubjectDN)
362 d->signerSubjectDN = signerSubjectDN;
365QString SignatureInfo::location()
const
370void SignatureInfo::setLocation(
const QString &location)
375QString SignatureInfo::reason()
const
380void Okular::SignatureInfo::setReason(
const QString &reason)
385QDateTime SignatureInfo::signingTime()
const
387 return d->signingTime;
390void Okular::SignatureInfo::setSigningTime(
const QDateTime &time)
392 d->signingTime = time;
400void SignatureInfo::setSignature(
const QByteArray &signature)
402 d->signature = signature;
407 return d->signedRangeBounds;
410void SignatureInfo::setSignedRangeBounds(
const QList<qint64> &range)
412 d->signedRangeBounds = range;
415bool SignatureInfo::signsTotalDocument()
const
417 return d->signsTotalDocument;
420void SignatureInfo::setSignsTotalDocument(
bool total)
422 d->signsTotalDocument = total;
425CertificateInfo SignatureInfo::certificateInfo()
const
427 return d->certificateInfo;
430void SignatureInfo::setCertificateInfo(
const Okular::CertificateInfo &info)
432 d->certificateInfo = info;
435CertificateStore::CertificateStore()
445 *userCancelled =
false;
453 auto it = certs.
begin();
454 *nonDateValidCerts =
false;
455 while (it != certs.
end()) {
456 if (it->validityStart() > now || now > it->validityEnd()) {
457 it = certs.
erase(it);
458 *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)
KDB_EXPORT KDbVersionInfo version()
QVariant location(const QVariant &res)
QDateTime currentDateTime()
iterator erase(const_iterator begin, const_iterator end)