Changeset View
Changeset View
Standalone View
Standalone View
generators/poppler/pdfsignatureutils.cpp
- 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 | #include "pdfsignatureutils.h" | ||||
11 | | ||||
12 | #include <KLocalizedString> | ||||
13 | #include <QDebug> | ||||
14 | | ||||
15 | PopplerCertificateInfo::PopplerCertificateInfo( const Poppler::CertificateInfo &info ) | ||||
16 | : m_info( new Poppler::CertificateInfo( nullptr ) ) | ||||
17 | { | ||||
18 | *m_info = info; | ||||
19 | } | ||||
20 | | ||||
21 | PopplerCertificateInfo::~PopplerCertificateInfo() | ||||
22 | { | ||||
23 | delete m_info; | ||||
24 | } | ||||
25 | | ||||
26 | bool PopplerCertificateInfo::isNull() const | ||||
27 | { | ||||
28 | return m_info->isNull(); | ||||
29 | } | ||||
30 | | ||||
31 | int PopplerCertificateInfo::version() const | ||||
32 | { | ||||
33 | return m_info->version(); | ||||
34 | } | ||||
35 | | ||||
36 | QByteArray PopplerCertificateInfo::serialNumber() const | ||||
37 | { | ||||
38 | return m_info->serialNumber(); | ||||
39 | } | ||||
40 | | ||||
41 | QString PopplerCertificateInfo::issuerInfo( PopplerCertificateInfo::EntityInfoKey key ) const | ||||
42 | { | ||||
43 | QString str = m_info->issuerInfo(static_cast<Poppler::CertificateInfo::EntityInfoKey>( key )); | ||||
44 | return !str.isEmpty() ? str : i18n("Not Available"); | ||||
45 | } | ||||
46 | | ||||
47 | QString PopplerCertificateInfo::subjectInfo( PopplerCertificateInfo::EntityInfoKey key ) const | ||||
48 | { | ||||
49 | QString str = m_info->subjectInfo(static_cast<Poppler::CertificateInfo::EntityInfoKey>( key )); | ||||
50 | return !str.isEmpty() ? str : i18n("Not Available"); | ||||
51 | } | ||||
52 | | ||||
53 | QDateTime PopplerCertificateInfo::validityStart() const | ||||
54 | { | ||||
55 | return m_info->validityStart(); | ||||
56 | } | ||||
57 | | ||||
58 | QDateTime PopplerCertificateInfo::validityEnd() const | ||||
59 | { | ||||
60 | return m_info->validityEnd(); | ||||
61 | } | ||||
62 | | ||||
63 | PopplerCertificateInfo::KeyUsageExtensions PopplerCertificateInfo::keyUsageExtensions() const | ||||
64 | { | ||||
65 | Poppler::CertificateInfo::KeyUsageExtensions popplerKu = m_info->keyUsageExtensions(); | ||||
66 | KeyUsageExtensions ku = KuNone; | ||||
67 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuDigitalSignature ) ) | ||||
68 | ku |= KuDigitalSignature; | ||||
69 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuNonRepudiation ) ) | ||||
70 | ku |= KuNonRepudiation; | ||||
71 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuKeyEncipherment ) ) | ||||
72 | ku |= KuKeyEncipherment; | ||||
73 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuDataEncipherment ) ) | ||||
74 | ku |= KuDataEncipherment; | ||||
75 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuKeyAgreement ) ) | ||||
76 | ku |= KuKeyAgreement; | ||||
77 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuKeyCertSign ) ) | ||||
78 | ku |= KuKeyCertSign; | ||||
79 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuClrSign ) ) | ||||
80 | ku |= KuClrSign; | ||||
81 | if ( popplerKu.testFlag( Poppler::CertificateInfo::KuEncipherOnly ) ) | ||||
82 | ku |= KuEncipherOnly; | ||||
83 | return ku; | ||||
84 | } | ||||
85 | | ||||
86 | QByteArray PopplerCertificateInfo::publicKey() const | ||||
87 | { | ||||
88 | return m_info->publicKey(); | ||||
89 | } | ||||
90 | | ||||
91 | PopplerCertificateInfo::PublicKeyType PopplerCertificateInfo::publicKeyType() const | ||||
92 | { | ||||
93 | switch ( m_info->publicKeyType() ) | ||||
94 | { | ||||
95 | case Poppler::CertificateInfo::RsaKey: | ||||
96 | return RsaKey; | ||||
97 | case Poppler::CertificateInfo::DsaKey: | ||||
98 | return DsaKey; | ||||
99 | case Poppler::CertificateInfo::EcKey: | ||||
100 | return EcKey; | ||||
101 | case Poppler::CertificateInfo::OtherKey: | ||||
102 | return OtherKey; | ||||
103 | } | ||||
104 | } | ||||
105 | | ||||
106 | int PopplerCertificateInfo::publicKeyStrength() const | ||||
107 | { | ||||
108 | return m_info->publicKeyStrength(); | ||||
109 | } | ||||
110 | | ||||
111 | bool PopplerCertificateInfo::isSelfSigned() const | ||||
112 | { | ||||
113 | return m_info->isSelfSigned(); | ||||
114 | } | ||||
115 | | ||||
116 | QByteArray PopplerCertificateInfo::certificateData() const | ||||
117 | { | ||||
118 | return m_info->certificateData(); | ||||
119 | } | ||||
120 | | ||||
121 | | ||||
122 | PopplerSignatureInfo::PopplerSignatureInfo( const Poppler::SignatureValidationInfo &info ) | ||||
123 | : m_info( new Poppler::SignatureValidationInfo( nullptr ) ) | ||||
124 | { | ||||
125 | *m_info = info; | ||||
126 | } | ||||
127 | | ||||
128 | PopplerSignatureInfo::~PopplerSignatureInfo() | ||||
129 | { | ||||
130 | delete m_info; | ||||
131 | } | ||||
132 | | ||||
133 | PopplerSignatureInfo::SignatureStatus PopplerSignatureInfo::signatureStatus() const | ||||
134 | { | ||||
135 | switch ( m_info->signatureStatus() ) | ||||
136 | { | ||||
137 | case Poppler::SignatureValidationInfo::SignatureValid: | ||||
138 | return SignatureValid; | ||||
139 | case Poppler::SignatureValidationInfo::SignatureInvalid: | ||||
140 | return SignatureInvalid; | ||||
141 | case Poppler::SignatureValidationInfo::SignatureDigestMismatch: | ||||
142 | return SignatureDigestMismatch; | ||||
143 | case Poppler::SignatureValidationInfo::SignatureDecodingError: | ||||
144 | return SignatureDecodingError; | ||||
145 | case Poppler::SignatureValidationInfo::SignatureGenericError: | ||||
146 | return SignatureGenericError; | ||||
147 | case Poppler::SignatureValidationInfo::SignatureNotFound: | ||||
148 | return SignatureNotFound; | ||||
149 | case Poppler::SignatureValidationInfo::SignatureNotVerified: | ||||
150 | return SignatureNotVerified; | ||||
151 | default: | ||||
152 | return SignatureStatusUnknown; | ||||
153 | } | ||||
154 | } | ||||
155 | | ||||
156 | PopplerSignatureInfo::CertificateStatus PopplerSignatureInfo::certificateStatus() const | ||||
157 | { | ||||
158 | switch ( m_info->certificateStatus() ) | ||||
159 | { | ||||
160 | case Poppler::SignatureValidationInfo::CertificateTrusted: | ||||
161 | return CertificateTrusted; | ||||
162 | case Poppler::SignatureValidationInfo::CertificateUntrustedIssuer: | ||||
163 | return CertificateUntrustedIssuer; | ||||
164 | case Poppler::SignatureValidationInfo::CertificateUnknownIssuer: | ||||
165 | return CertificateUnknownIssuer; | ||||
166 | case Poppler::SignatureValidationInfo::CertificateRevoked: | ||||
167 | return CertificateRevoked; | ||||
168 | case Poppler::SignatureValidationInfo::CertificateExpired: | ||||
169 | return CertificateExpired; | ||||
170 | case Poppler::SignatureValidationInfo::CertificateGenericError: | ||||
171 | return CertificateGenericError; | ||||
172 | case Poppler::SignatureValidationInfo::CertificateNotVerified: | ||||
173 | return CertificateNotVerified; | ||||
174 | default: | ||||
175 | return CertificateStatusUnknown; | ||||
176 | } | ||||
177 | } | ||||
178 | | ||||
179 | PopplerSignatureInfo::HashAlgorithm PopplerSignatureInfo::hashAlgorithm() const | ||||
180 | { | ||||
181 | switch ( m_info->hashAlgorithm() ) | ||||
182 | { | ||||
183 | case Poppler::SignatureValidationInfo::HashAlgorithmMd2: | ||||
184 | return HashAlgorithmMd2; | ||||
185 | case Poppler::SignatureValidationInfo::HashAlgorithmMd5: | ||||
186 | return HashAlgorithmMd5; | ||||
187 | case Poppler::SignatureValidationInfo::HashAlgorithmSha1: | ||||
188 | return HashAlgorithmSha1; | ||||
189 | case Poppler::SignatureValidationInfo::HashAlgorithmSha256: | ||||
190 | return HashAlgorithmSha256; | ||||
191 | case Poppler::SignatureValidationInfo::HashAlgorithmSha384: | ||||
192 | return HashAlgorithmSha384; | ||||
193 | case Poppler::SignatureValidationInfo::HashAlgorithmSha512: | ||||
194 | return HashAlgorithmSha512; | ||||
195 | case Poppler::SignatureValidationInfo::HashAlgorithmSha224: | ||||
196 | return HashAlgorithmSha224; | ||||
197 | default: | ||||
198 | return HashAlgorithmUnknown; | ||||
199 | } | ||||
200 | } | ||||
201 | | ||||
202 | QString PopplerSignatureInfo::signerName() const | ||||
203 | { | ||||
204 | return m_info->signerName(); | ||||
205 | } | ||||
206 | | ||||
207 | QString PopplerSignatureInfo::signerSubjectDN() const | ||||
208 | { | ||||
209 | return m_info->signerSubjectDN(); | ||||
210 | } | ||||
211 | | ||||
212 | QString PopplerSignatureInfo::location() const | ||||
213 | { | ||||
214 | return m_info->location(); | ||||
215 | } | ||||
216 | | ||||
217 | QString PopplerSignatureInfo::reason() const | ||||
218 | { | ||||
219 | return m_info->reason(); | ||||
220 | } | ||||
221 | | ||||
222 | QDateTime PopplerSignatureInfo::signingTime() const | ||||
223 | { | ||||
224 | return QDateTime::fromTime_t( m_info->signingTime() ); | ||||
225 | } | ||||
226 | | ||||
227 | QByteArray PopplerSignatureInfo::signature() const | ||||
228 | { | ||||
229 | return m_info->signature(); | ||||
230 | } | ||||
231 | | ||||
232 | QList<qint64> PopplerSignatureInfo::signedRangeBounds() const | ||||
233 | { | ||||
234 | return m_info->signedRangeBounds(); | ||||
235 | } | ||||
236 | | ||||
237 | bool PopplerSignatureInfo::signsTotalDocument() const | ||||
238 | { | ||||
239 | return m_info->signsTotalDocument(); | ||||
240 | } | ||||
241 | | ||||
242 | Okular::CertificateInfo *PopplerSignatureInfo::certificateInfo() const | ||||
243 | { | ||||
244 | return ( new PopplerCertificateInfo( m_info->certificateInfo() ) ); | ||||
245 | } |