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