QGpgME 10.3.4.0000000
Qt API for GpgME
protocol_p.h
1/*
2 protocol_p.h
3
4 This file is part of qgpgme, the Qt API binding for gpgme
5 Copyright (c) 2004,2005 Klarälvdalens Datakonsult AB
6 Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
7 Software engineering by Intevation GmbH
8
9 QGpgME is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 QGpgME is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
23 In addition, as a special exception, the copyright holders give
24 permission to link the code of this program with any edition of
25 the Qt library by Trolltech AS, Norway (or with modified versions
26 of Qt that use the same license as Qt), and distribute linked
27 combinations including the two. You must obey the GNU General
28 Public License in all respects for all of the code used other than
29 Qt. If you modify this file, you may extend this exception to
30 your version of the file, but you are not obligated to do so. If
31 you do not wish to do so, delete this exception statement from
32 your version.
33*/
34#ifndef __QGPGME_PROTOCOL_P_H__
35#define __QGPGME_PROTOCOL_P_H__
36#include "qgpgmenewcryptoconfig.h"
37
38#include "qgpgmekeygenerationjob.h"
39#include "qgpgmekeylistjob.h"
40#include "qgpgmelistallkeysjob.h"
41#include "qgpgmedecryptjob.h"
42#include "qgpgmedecryptverifyjob.h"
43#include "qgpgmerefreshkeysjob.h"
44#include "qgpgmedeletejob.h"
45#include "qgpgmesecretkeyexportjob.h"
46#include "qgpgmedownloadjob.h"
47#include "qgpgmesignencryptjob.h"
48#include "qgpgmeencryptjob.h"
49#include "qgpgmesignjob.h"
50#include "qgpgmesignkeyjob.h"
51#include "qgpgmeexportjob.h"
52#include "qgpgmeverifydetachedjob.h"
53#include "qgpgmeimportjob.h"
54#include "qgpgmeimportfromkeyserverjob.h"
55#include "qgpgmeverifyopaquejob.h"
56#include "qgpgmechangeexpiryjob.h"
57#include "qgpgmechangeownertrustjob.h"
58#include "qgpgmechangepasswdjob.h"
59#include "qgpgmeadduseridjob.h"
60#include "qgpgmekeyformailboxjob.h"
61#include "qgpgmewkspublishjob.h"
62#include "qgpgmetofupolicyjob.h"
63#include "qgpgmequickjob.h"
64
65namespace
66{
67
68class Protocol : public QGpgME::Protocol
69{
70 GpgME::Protocol mProtocol;
71public:
72 explicit Protocol(GpgME::Protocol proto) : mProtocol(proto) {}
73
74 QString name() const Q_DECL_OVERRIDE
75 {
76 switch (mProtocol) {
77 case GpgME::OpenPGP: return QStringLiteral("OpenPGP");
78 case GpgME::CMS: return QStringLiteral("SMIME");
79 default: return QString();
80 }
81 }
82
83 QString displayName() const Q_DECL_OVERRIDE
84 {
85 // ah (2.4.16): Where is this used and isn't this inverted
86 // with name
87 switch (mProtocol) {
88 case GpgME::OpenPGP: return QStringLiteral("gpg");
89 case GpgME::CMS: return QStringLiteral("gpgsm");
90 default: return QStringLiteral("unknown");
91 }
92 }
93
94 QGpgME::SpecialJob *specialJob(const char *, const QMap<QString, QVariant> &) const Q_DECL_OVERRIDE
95 {
96 return nullptr;
97 }
98
99 QGpgME::KeyListJob *keyListJob(bool remote, bool includeSigs, bool validate) const Q_DECL_OVERRIDE
100 {
101 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
102 if (!context) {
103 return nullptr;
104 }
105
106 unsigned int mode = context->keyListMode();
107 if (remote) {
108 mode |= GpgME::Extern;
109 mode &= ~GpgME::Local;
110 } else {
111 mode |= GpgME::Local;
112 mode &= ~GpgME::Extern;
113 }
114 if (includeSigs) {
115 mode |= GpgME::Signatures;
116 }
117 if (validate) {
118 mode |= GpgME::Validate;
119 }
120 context->setKeyListMode(mode);
121 return new QGpgME::QGpgMEKeyListJob(context);
122 }
123
124 QGpgME::ListAllKeysJob *listAllKeysJob(bool includeSigs, bool validate) const Q_DECL_OVERRIDE
125 {
126 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
127 if (!context) {
128 return nullptr;
129 }
130
131 unsigned int mode = context->keyListMode();
132 mode |= GpgME::Local;
133 mode &= ~GpgME::Extern;
134 if (includeSigs) {
135 mode |= GpgME::Signatures;
136 }
137 if (validate) {
138 mode |= GpgME::Validate;
139 /* Setting the context to offline mode disables CRL / OCSP checks in
140 this Job. Otherwise we would try to fetch the CRL's for all CMS
141 keys in the users keyring because GpgME::Validate includes remote
142 resources by default in the validity check.
143 This setting only has any effect if gpgsm >= 2.1.6 is used.
144 */
145 context->setOffline(true);
146 }
147 context->setKeyListMode(mode);
148 return new QGpgME::QGpgMEListAllKeysJob(context);
149 }
150
151 QGpgME::EncryptJob *encryptJob(bool armor, bool textmode) const Q_DECL_OVERRIDE
152 {
153 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
154 if (!context) {
155 return nullptr;
156 }
157
158 context->setArmor(armor);
159 context->setTextMode(textmode);
160 return new QGpgME::QGpgMEEncryptJob(context);
161 }
162
163 QGpgME::DecryptJob *decryptJob() const Q_DECL_OVERRIDE
164 {
165 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
166 if (!context) {
167 return nullptr;
168 }
169 return new QGpgME::QGpgMEDecryptJob(context);
170 }
171
172 QGpgME::SignJob *signJob(bool armor, bool textMode) const Q_DECL_OVERRIDE
173 {
174 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
175 if (!context) {
176 return nullptr;
177 }
178
179 context->setArmor(armor);
180 context->setTextMode(textMode);
181 return new QGpgME::QGpgMESignJob(context);
182 }
183
184 QGpgME::VerifyDetachedJob *verifyDetachedJob(bool textMode) const Q_DECL_OVERRIDE
185 {
186 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
187 if (!context) {
188 return nullptr;
189 }
190
191 context->setTextMode(textMode);
192 return new QGpgME::QGpgMEVerifyDetachedJob(context);
193 }
194
195 QGpgME::VerifyOpaqueJob *verifyOpaqueJob(bool textMode) const Q_DECL_OVERRIDE
196 {
197 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
198 if (!context) {
199 return nullptr;
200 }
201
202 context->setTextMode(textMode);
203 return new QGpgME::QGpgMEVerifyOpaqueJob(context);
204 }
205
206 QGpgME::KeyGenerationJob *keyGenerationJob() const Q_DECL_OVERRIDE
207 {
208 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
209 if (!context) {
210 return nullptr;
211 }
212 return new QGpgME::QGpgMEKeyGenerationJob(context);
213 }
214
215 QGpgME::ImportJob *importJob() const Q_DECL_OVERRIDE
216 {
217 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
218 if (!context) {
219 return nullptr;
220 }
221 return new QGpgME::QGpgMEImportJob(context);
222 }
223
224 QGpgME::ImportFromKeyserverJob *importFromKeyserverJob() const Q_DECL_OVERRIDE
225 {
226 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
227 if (!context) {
228 return nullptr;
229 }
230 return new QGpgME::QGpgMEImportFromKeyserverJob(context);
231 }
232
233 QGpgME::ExportJob *publicKeyExportJob(bool armor) const Q_DECL_OVERRIDE
234 {
235 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
236 if (!context) {
237 return nullptr;
238 }
239
240 context->setArmor(armor);
241 return new QGpgME::QGpgMEExportJob(context);
242 }
243
244 QGpgME::ExportJob *secretKeyExportJob(bool armor, const QString &charset) const Q_DECL_OVERRIDE
245 {
246 if (mProtocol != GpgME::CMS) { // fixme: add support for gpg, too
247 return nullptr;
248 }
249
250 // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
251 return new QGpgME::QGpgMESecretKeyExportJob(armor, charset);
252 }
253
254 QGpgME::RefreshKeysJob *refreshKeysJob() const Q_DECL_OVERRIDE
255 {
256 if (mProtocol != GpgME::CMS) { // fixme: add support for gpg, too
257 return nullptr;
258 }
259
260 // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
261 return new QGpgME::QGpgMERefreshKeysJob();
262 }
263
264 QGpgME::DownloadJob *downloadJob(bool armor) const Q_DECL_OVERRIDE
265 {
266 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
267 if (!context) {
268 return nullptr;
269 }
270
271 context->setArmor(armor);
272 // this is the hackish interface for downloading from keyserers currently:
273 context->setKeyListMode(GpgME::Extern);
274 return new QGpgME::QGpgMEDownloadJob(context);
275 }
276
277 QGpgME::DeleteJob *deleteJob() const Q_DECL_OVERRIDE
278 {
279 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
280 if (!context) {
281 return nullptr;
282 }
283 return new QGpgME::QGpgMEDeleteJob(context);
284 }
285
286 QGpgME::SignEncryptJob *signEncryptJob(bool armor, bool textMode) const Q_DECL_OVERRIDE
287 {
288 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
289 if (!context) {
290 return nullptr;
291 }
292
293 context->setArmor(armor);
294 context->setTextMode(textMode);
295 return new QGpgME::QGpgMESignEncryptJob(context);
296 }
297
298 QGpgME::DecryptVerifyJob *decryptVerifyJob(bool textMode) const Q_DECL_OVERRIDE
299 {
300 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
301 if (!context) {
302 return nullptr;
303 }
304
305 context->setTextMode(textMode);
306 return new QGpgME::QGpgMEDecryptVerifyJob(context);
307 }
308
309 QGpgME::ChangeExpiryJob *changeExpiryJob() const Q_DECL_OVERRIDE
310 {
311 if (mProtocol != GpgME::OpenPGP) {
312 return nullptr; // only supported by gpg
313 }
314
315 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
316 if (!context) {
317 return nullptr;
318 }
319 return new QGpgME::QGpgMEChangeExpiryJob(context);
320 }
321
322 QGpgME::ChangePasswdJob *changePasswdJob() const Q_DECL_OVERRIDE
323 {
324 if (!GpgME::hasFeature(GpgME::PasswdFeature, 0)) {
325 return nullptr;
326 }
327 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
328 if (!context) {
329 return nullptr;
330 }
331 return new QGpgME::QGpgMEChangePasswdJob(context);
332 }
333
334 QGpgME::SignKeyJob *signKeyJob() const Q_DECL_OVERRIDE
335 {
336 if (mProtocol != GpgME::OpenPGP) {
337 return nullptr; // only supported by gpg
338 }
339
340 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
341 if (!context) {
342 return nullptr;
343 }
344 return new QGpgME::QGpgMESignKeyJob(context);
345 }
346
347 QGpgME::ChangeOwnerTrustJob *changeOwnerTrustJob() const Q_DECL_OVERRIDE
348 {
349 if (mProtocol != GpgME::OpenPGP) {
350 return nullptr; // only supported by gpg
351 }
352
353 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
354 if (!context) {
355 return nullptr;
356 }
357 return new QGpgME::QGpgMEChangeOwnerTrustJob(context);
358 }
359
360 QGpgME::AddUserIDJob *addUserIDJob() const Q_DECL_OVERRIDE
361 {
362 if (mProtocol != GpgME::OpenPGP) {
363 return nullptr; // only supported by gpg
364 }
365
366 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
367 if (!context) {
368 return nullptr;
369 }
370 return new QGpgME::QGpgMEAddUserIDJob(context);
371 }
372
373 QGpgME::KeyListJob *locateKeysJob() const Q_DECL_OVERRIDE
374 {
375 if (mProtocol != GpgME::OpenPGP) {
376 return nullptr;
377 }
378 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
379 if (!context) {
380 return nullptr;
381 }
382 context->setKeyListMode(GpgME::Extern | GpgME::Local | GpgME::Signatures | GpgME::Validate);
383 return new QGpgME::QGpgMEKeyListJob(context);
384 }
385
386 QGpgME::KeyForMailboxJob *keyForMailboxJob() const Q_DECL_OVERRIDE
387 {
388 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
389 if (!context) {
390 return nullptr;
391 }
392 return new QGpgME::QGpgMEKeyForMailboxJob(context);
393 }
394
395 QGpgME::WKSPublishJob *wksPublishJob() const Q_DECL_OVERRIDE
396 {
397 if (mProtocol != GpgME::OpenPGP) {
398 return nullptr;
399 }
400 auto context = GpgME::Context::createForEngine(GpgME::SpawnEngine);
401 if (!context) {
402 return nullptr;
403 }
404 return new QGpgME::QGpgMEWKSPublishJob(context.release());
405 }
406
407 QGpgME::TofuPolicyJob *tofuPolicyJob() const Q_DECL_OVERRIDE
408 {
409 if (mProtocol != GpgME::OpenPGP) {
410 return nullptr;
411 }
412 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
413 if (!context) {
414 return nullptr;
415 }
416 return new QGpgME::QGpgMETofuPolicyJob(context);
417 }
418
419 QGpgME::QuickJob *quickJob() const Q_DECL_OVERRIDE
420 {
421 if (mProtocol != GpgME::OpenPGP) {
422 return nullptr;
423 }
424 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
425 if (!context) {
426 return nullptr;
427 }
428 return new QGpgME::QGpgMEQuickJob(context);
429 }
430};
431
432}
433#endif
An abstract base class to asynchronously add UIDs to OpenPGP keys.
Definition: adduseridjob.h:65
An abstract base class to change expiry asynchronously.
Definition: changeexpiryjob.h:65
An abstract base class to change owner trust asynchronously.
Definition: changeownertrustjob.h:63
An abstract base class to change a key's passphrase asynchronously.
Definition: changepasswdjob.h:63
An abstract base class for asynchronous decrypters.
Definition: decryptjob.h:68
An abstract base class for asynchronous combined decrypters and verifiers.
Definition: decryptverifyjob.h:69
An abstract base class for asynchronous deleters.
Definition: deletejob.h:64
An abstract base class for asynchronous downloaders.
Definition: downloadjob.h:70
An abstract base class for asynchronous encrypters.
Definition: encryptjob.h:76
An abstract base class for asynchronous exporters.
Definition: exportjob.h:67
An abstract base class for asynchronous keyserver-importers.
Definition: importfromkeyserverjob.h:67
An abstract base class for asynchronous importers.
Definition: importjob.h:66
Get the best key to use for a Mailbox.
Definition: keyformailboxjob.h:74
An abstract base class for asynchronous key generation.
Definition: keygenerationjob.h:66
An abstract base class for asynchronous key listers.
Definition: keylistjob.h:76
An abstract base class for asynchronously listing all keys.
Definition: listallkeysjob.h:75
Definition: protocol.h:107
virtual KeyListJob * locateKeysJob() const =0
virtual WKSPublishJob * wksPublishJob() const =0
virtual QuickJob * quickJob() const =0
virtual KeyForMailboxJob * keyForMailboxJob() const =0
virtual TofuPolicyJob * tofuPolicyJob() const =0
Definition: qgpgmeadduseridjob.h:51
Definition: qgpgmechangeexpiryjob.h:51
Definition: qgpgmechangeownertrustjob.h:51
Definition: qgpgmechangepasswdjob.h:51
Definition: qgpgmedecryptjob.h:57
Definition: qgpgmedecryptverifyjob.h:62
Definition: qgpgmedeletejob.h:56
Definition: qgpgmedownloadjob.h:51
Definition: qgpgmeencryptjob.h:62
Definition: qgpgmeexportjob.h:51
Definition: qgpgmeimportfromkeyserverjob.h:57
Definition: qgpgmeimportjob.h:57
Definition: qgpgmekeyformailboxjob.h:59
Definition: qgpgmekeygenerationjob.h:57
Definition: qgpgmekeylistjob.h:62
Definition: qgpgmelistallkeysjob.h:62
Definition: qgpgmequickjob.h:55
Definition: qgpgmerefreshkeysjob.h:52
Definition: qgpgmesecretkeyexportjob.h:55
Definition: qgpgmesignencryptjob.h:69
Definition: qgpgmesignjob.h:62
Definition: qgpgmesignkeyjob.h:57
Definition: qgpgmetofupolicyjob.h:50
Definition: qgpgmeverifydetachedjob.h:57
Definition: qgpgmeverifyopaquejob.h:57
Definition: qgpgmewkspublishjob.h:54
Definition: quickjob.h:53
An abstract base class for asynchronous key refreshers.
Definition: refreshkeysjob.h:68
An abstract base class for asynchronous combined signing and encrypting.
Definition: signencryptjob.h:81
An abstract base class for asynchronous signing.
Definition: signjob.h:77
An abstract base class to sign keys asynchronously.
Definition: signkeyjob.h:65
An abstract base class for protocol-specific jobs.
Definition: specialjob.h:71
Definition: tofupolicyjob.h:55
An abstract base class for asynchronous verification of detached signatures.
Definition: verifydetachedjob.h:69
An abstract base class for asynchronous verification of opaque signatures.
Definition: verifyopaquejob.h:68
Definition: wkspublishjob.h:62
Definition: qgpgmebackend.h:43