Okular

signatureutils.h
1 /***************************************************************************
2  * Copyright (C) 2018 by Chinmoy Ranjan Pradhan <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  ***************************************************************************/
9 
10 #ifndef OKULAR_SIGNATUREUTILS_H
11 #define OKULAR_SIGNATUREUTILS_H
12 
13 #include "okularcore_export.h"
14 
15 #include <QDateTime>
16 #include <QFlag>
17 #include <QList>
18 #include <QSharedPointer>
19 #include <QString>
20 
21 namespace Okular
22 {
23 class SignatureInfoPrivate;
24 
25 /**
26  * @short A helper class to store information about x509 certificate
27  */
28 class OKULARCORE_EXPORT CertificateInfo
29 {
30 public:
31  /**
32  * The algorithm of public key.
33  */
34  enum PublicKeyType { RsaKey, DsaKey, EcKey, OtherKey };
35 
36  /**
37  * Certificate key usage extensions.
38  */
39  enum KeyUsageExtension { KuDigitalSignature = 0x80, KuNonRepudiation = 0x40, KuKeyEncipherment = 0x20, KuDataEncipherment = 0x10, KuKeyAgreement = 0x08, KuKeyCertSign = 0x04, KuClrSign = 0x02, KuEncipherOnly = 0x01, KuNone = 0x00 };
40  Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
41 
42  /**
43  * Predefined keys for elements in an entity's distinguished name.
44  */
46  CommonName,
47  DistinguishedName,
48  EmailAddress,
50  };
51 
52  /**
53  * Destructor
54  */
55  virtual ~CertificateInfo();
56 
57  /**
58  * Returns true if certificate has no contents; otherwise returns false.
59  */
60  virtual bool isNull() const;
61 
62  /**
63  * The certificate version string.
64  */
65  virtual int version() const;
66 
67  /**
68  * The certificate serial number.
69  */
70  virtual QByteArray serialNumber() const;
71 
72  /**
73  * Information about the issuer.
74  */
75  virtual QString issuerInfo(EntityInfoKey key) const;
76 
77  /**
78  * Information about the subject
79  */
80  virtual QString subjectInfo(EntityInfoKey key) const;
81 
82  /**
83  * The certificate internal database nickname
84  */
85  virtual QString nickName() const;
86 
87  /**
88  * The date-time when certificate becomes valid.
89  */
90  virtual QDateTime validityStart() const;
91 
92  /**
93  * The date-time when certificate expires.
94  */
95  virtual QDateTime validityEnd() const;
96 
97  /**
98  * The uses allowed for the certificate.
99  */
100  virtual KeyUsageExtensions keyUsageExtensions() const;
101 
102  /**
103  * The public key value.
104  */
105  virtual QByteArray publicKey() const;
106 
107  /**
108  * The public key type.
109  */
110  virtual PublicKeyType publicKeyType() const;
111 
112  /**
113  * The strength of public key in bits.
114  */
115  virtual int publicKeyStrength() const;
116 
117  /**
118  * Returns true if certificate is self-signed otherwise returns false.
119  */
120  virtual bool isSelfSigned() const;
121 
122  /**
123  * The DER encoded certificate.
124  */
125  virtual QByteArray certificateData() const;
126 
127  /**
128  * Checks if the given password is the correct one for this certificate
129  *
130  * @since 21.04
131  */
132  virtual bool checkPassword(const QString &password) const;
133 
134 protected:
135  friend class SignatureInfo;
136  CertificateInfo();
137 
138 private:
139  Q_DISABLE_COPY(CertificateInfo)
140 };
141 
142 /**
143  * @short A helper class to store information about digital signature
144  */
145 class OKULARCORE_EXPORT SignatureInfo
146 {
147 public:
148  /**
149  * The verification result of the signature.
150  */
152  SignatureStatusUnknown, ///< The signature status is unknown for some reason.
153  SignatureValid, ///< The signature is cryptographically valid.
154  SignatureInvalid, ///< The signature is cryptographically invalid.
155  SignatureDigestMismatch, ///< The document content was changed after the signature was applied.
156  SignatureDecodingError, ///< The signature CMS/PKCS7 structure is malformed.
157  SignatureGenericError, ///< The signature could not be verified.
158  SignatureNotFound, ///< The requested signature is not present in the document.
159  SignatureNotVerified ///< The signature is not yet verified.
160  };
161 
162  /**
163  * The verification result of the certificate.
164  */
166  CertificateStatusUnknown, ///< The certificate status is unknown for some reason.
167  CertificateTrusted, ///< The certificate is considered trusted.
168  CertificateUntrustedIssuer, ///< The issuer of this certificate has been marked as untrusted by the user.
169  CertificateUnknownIssuer, ///< The certificate trust chain has not finished in a trusted root certificate.
170  CertificateRevoked, ///< The certificate was revoked by the issuing certificate authority.
171  CertificateExpired, ///< The signing time is outside the validity bounds of this certificate.
172  CertificateGenericError, ///< The certificate could not be verified.
173  CertificateNotVerified ///< The certificate is not yet verified.
174  };
175 
176  /**
177  * The hash algorithm of the signature
178  */
179  enum HashAlgorithm { HashAlgorithmUnknown, HashAlgorithmMd2, HashAlgorithmMd5, HashAlgorithmSha1, HashAlgorithmSha256, HashAlgorithmSha384, HashAlgorithmSha512, HashAlgorithmSha224 };
180 
181  /**
182  * Destructor.
183  */
184  virtual ~SignatureInfo();
185 
186  /**
187  * The signature status of the signature.
188  */
189  virtual SignatureStatus signatureStatus() const;
190 
191  /**
192  * The certificate status of the signature.
193  */
194  virtual CertificateStatus certificateStatus() const;
195 
196  /**
197  * The signer subject common name associated with the signature.
198  */
199  virtual QString signerName() const;
200 
201  /**
202  * The signer subject distinguished name associated with the signature.
203  */
204  virtual QString signerSubjectDN() const;
205 
206  /**
207  * Get signing location.
208  */
209  virtual QString location() const;
210 
211  /**
212  * Get signing reason.
213  */
214  virtual QString reason() const;
215 
216  /**
217  * The hash algorithm used for the signature.
218  */
219  virtual HashAlgorithm hashAlgorithm() const;
220 
221  /**
222  * The signing time associated with the signature.
223  */
224  virtual QDateTime signingTime() const;
225 
226  /**
227  * Get the signature binary data.
228  */
229  virtual QByteArray signature() const;
230 
231  /**
232  * Get the bounds of the ranges of the document which are signed.
233  */
234  virtual QList<qint64> signedRangeBounds() const;
235 
236  /**
237  * Checks whether the signature authenticates the total document
238  * except for the signature itself.
239  */
240  virtual bool signsTotalDocument() const;
241 
242  /**
243  * Get certificate details.
244  */
245  virtual const CertificateInfo &certificateInfo() const;
246 
247 protected:
248  SignatureInfo();
249 
250 private:
251  Q_DISABLE_COPY(SignatureInfo)
252 };
253 
254 /**
255  * @short A helper class to store information about x509 certificate
256  */
257 class OKULARCORE_EXPORT CertificateStore
258 {
259 public:
260  /**
261  * Destructor
262  */
263  virtual ~CertificateStore();
264 
265  /**
266  * Returns list of valid, usable signing certificates.
267  *
268  * This can ask the user for a password, userCancelled will be true if the user decided not to enter it.
269  */
270  virtual QList<CertificateInfo *> signingCertificates(bool *userCancelled) const;
271 
272 protected:
274 
275 private:
276  Q_DISABLE_COPY(CertificateStore)
277 };
278 
279 }
280 
281 #endif
PublicKeyType
The algorithm of public key.
Organization
The signature CMS/PKCS7 structure is malformed.
global.h
Definition: action.h:19
The signing time is outside the validity bounds of this certificate.
The certificate was revoked by the issuing certificate authority.
The signature is cryptographically valid.
SignatureStatus
The verification result of the signature.
The certificate is considered trusted.
HashAlgorithm
The hash algorithm of the signature.
A helper class to store information about digital signature.
The issuer of this certificate has been marked as untrusted by the user.
The requested signature is not present in the document.
The certificate status is unknown for some reason.
A helper class to store information about x509 certificate.
The signature is cryptographically invalid.
CertificateStatus
The verification result of the certificate.
EntityInfoKey
Predefined keys for elements in an entity&#39;s distinguished name.
A helper class to store information about x509 certificate.
The signature status is unknown for some reason.
The document content was changed after the signature was applied.
The certificate trust chain has not finished in a trusted root certificate.
CommonName
KeyUsageExtension
Certificate key usage extensions.
The signature could not be verified.
The certificate could not be verified.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue May 11 2021 22:35:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.