QGpgME  19.4.0.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  Copyright (c) 2022 by g10 Code GmbH
9  Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
10 
11  QGpgME is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15 
16  QGpgME is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 
25  In addition, as a special exception, the copyright holders give
26  permission to link the code of this program with any edition of
27  the Qt library by Trolltech AS, Norway (or with modified versions
28  of Qt that use the same license as Qt), and distribute linked
29  combinations including the two. You must obey the GNU General
30  Public License in all respects for all of the code used other than
31  Qt. If you modify this file, you may extend this exception to
32  your version of the file, but you are not obligated to do so. If
33  you do not wish to do so, delete this exception statement from
34  your version.
35 */
36 #ifndef __QGPGME_PROTOCOL_P_H__
37 #define __QGPGME_PROTOCOL_P_H__
38 #include "qgpgmenewcryptoconfig.h"
39 
40 #include "qgpgmekeygenerationjob.h"
41 #include "qgpgmekeylistjob.h"
42 #include "qgpgmelistallkeysjob.h"
43 #include "qgpgmedecryptjob.h"
44 #include "qgpgmedecryptverifyarchivejob.h"
45 #include "qgpgmedecryptverifyjob.h"
46 #include "qgpgmerefreshsmimekeysjob.h"
47 #include "qgpgmedeletejob.h"
48 #include "qgpgmedownloadjob.h"
49 #include "qgpgmesignencryptjob.h"
50 #include "qgpgmeencryptarchivejob.h"
51 #include "qgpgmeencryptjob.h"
52 #include "qgpgmesignarchivejob.h"
53 #include "qgpgmesignencryptarchivejob.h"
54 #include "qgpgmesignjob.h"
55 #include "qgpgmesignkeyjob.h"
56 #include "qgpgmeexportjob.h"
57 #include "qgpgmeverifydetachedjob.h"
58 #include "qgpgmeimportjob.h"
59 #include "qgpgmeimportfromkeyserverjob.h"
60 #include "qgpgmeverifyopaquejob.h"
61 #include "qgpgmechangeexpiryjob.h"
62 #include "qgpgmechangeownertrustjob.h"
63 #include "qgpgmechangepasswdjob.h"
64 #include "qgpgmeaddexistingsubkeyjob.h"
65 #include "qgpgmeadduseridjob.h"
66 #include "qgpgmekeyformailboxjob.h"
67 #include "qgpgmewkdlookupjob.h"
68 #include "qgpgmewkspublishjob.h"
69 #include "qgpgmetofupolicyjob.h"
70 #include "qgpgmequickjob.h"
71 #include "qgpgmereceivekeysjob.h"
72 #include "qgpgmerevokekeyjob.h"
73 #include "qgpgmesetprimaryuseridjob.h"
74 
75 namespace
76 {
77 
78 class Protocol : public QGpgME::Protocol
79 {
80  GpgME::Protocol mProtocol;
81 public:
82  explicit Protocol(GpgME::Protocol proto) : mProtocol(proto) {}
83 
84  QString name() const override
85  {
86  switch (mProtocol) {
87  case GpgME::OpenPGP: return QStringLiteral("OpenPGP");
88  case GpgME::CMS: return QStringLiteral("SMIME");
89  default: return QString();
90  }
91  }
92 
93  QString displayName() const override
94  {
95  // ah (2.4.16): Where is this used and isn't this inverted
96  // with name
97  switch (mProtocol) {
98  case GpgME::OpenPGP: return QStringLiteral("gpg");
99  case GpgME::CMS: return QStringLiteral("gpgsm");
100  default: return QStringLiteral("unknown");
101  }
102  }
103 
104  QGpgME::SpecialJob *specialJob(const char *, const QMap<QString, QVariant> &) const override
105  {
106  return nullptr;
107  }
108 
109  QGpgME::KeyListJob *keyListJob(bool remote, bool includeSigs, bool validate) const override
110  {
111  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
112  if (!context) {
113  return nullptr;
114  }
115 
116  unsigned int mode = context->keyListMode();
117  if (remote) {
118  mode |= GpgME::Extern;
119  mode &= ~GpgME::Local;
120  } else {
121  mode |= GpgME::Local;
122  mode &= ~GpgME::Extern;
123  }
124  if (includeSigs) {
125  mode |= GpgME::Signatures;
126  }
127  if (validate) {
128  mode |= GpgME::Validate;
129  }
130  context->setKeyListMode(mode);
131  return new QGpgME::QGpgMEKeyListJob(context);
132  }
133 
134  QGpgME::ListAllKeysJob *listAllKeysJob(bool includeSigs, bool validate) const override
135  {
136  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
137  if (!context) {
138  return nullptr;
139  }
140 
141  unsigned int mode = context->keyListMode();
142  mode |= GpgME::Local;
143  mode &= ~GpgME::Extern;
144  if (includeSigs) {
145  mode |= GpgME::Signatures;
146  }
147  if (validate) {
148  mode |= GpgME::Validate;
149  /* Setting the context to offline mode disables CRL / OCSP checks in
150  this Job. Otherwise we would try to fetch the CRL's for all CMS
151  keys in the users keyring because GpgME::Validate includes remote
152  resources by default in the validity check.
153  This setting only has any effect if gpgsm >= 2.1.6 is used.
154  */
155  context->setOffline(true);
156  }
157  context->setKeyListMode(mode);
158  return new QGpgME::QGpgMEListAllKeysJob(context);
159  }
160 
161  QGpgME::EncryptJob *encryptJob(bool armor, bool textmode) const override
162  {
163  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
164  if (!context) {
165  return nullptr;
166  }
167 
168  context->setArmor(armor);
169  context->setTextMode(textmode);
170  return new QGpgME::QGpgMEEncryptJob(context);
171  }
172 
173  QGpgME::DecryptJob *decryptJob() const override
174  {
175  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
176  if (!context) {
177  return nullptr;
178  }
179  return new QGpgME::QGpgMEDecryptJob(context);
180  }
181 
182  QGpgME::SignJob *signJob(bool armor, bool textMode) const override
183  {
184  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
185  if (!context) {
186  return nullptr;
187  }
188 
189  context->setArmor(armor);
190  context->setTextMode(textMode);
191  return new QGpgME::QGpgMESignJob(context);
192  }
193 
194  QGpgME::VerifyDetachedJob *verifyDetachedJob(bool textMode) const override
195  {
196  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
197  if (!context) {
198  return nullptr;
199  }
200 
201  context->setTextMode(textMode);
202  return new QGpgME::QGpgMEVerifyDetachedJob(context);
203  }
204 
205  QGpgME::VerifyOpaqueJob *verifyOpaqueJob(bool textMode) const override
206  {
207  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
208  if (!context) {
209  return nullptr;
210  }
211 
212  context->setTextMode(textMode);
213  return new QGpgME::QGpgMEVerifyOpaqueJob(context);
214  }
215 
216  QGpgME::KeyGenerationJob *keyGenerationJob() const override
217  {
218  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
219  if (!context) {
220  return nullptr;
221  }
222  return new QGpgME::QGpgMEKeyGenerationJob(context);
223  }
224 
225  QGpgME::ImportJob *importJob() const override
226  {
227  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
228  if (!context) {
229  return nullptr;
230  }
231  return new QGpgME::QGpgMEImportJob(context);
232  }
233 
234  QGpgME::ImportFromKeyserverJob *importFromKeyserverJob() const override
235  {
236  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
237  if (!context) {
238  return nullptr;
239  }
240  return new QGpgME::QGpgMEImportFromKeyserverJob(context);
241  }
242 
243  QGpgME::ReceiveKeysJob *receiveKeysJob() const override
244  {
245  if (mProtocol != GpgME::OpenPGP) {
246  return nullptr;
247  }
248 
249  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
250  if (!context) {
251  return nullptr;
252  }
253  return new QGpgME::QGpgMEReceiveKeysJob{context};
254  }
255 
256  QGpgME::ExportJob *publicKeyExportJob(bool armor) const override
257  {
258  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
259  if (!context) {
260  return nullptr;
261  }
262 
263  context->setArmor(armor);
264  return new QGpgME::QGpgMEExportJob(context);
265  }
266 
267  QGpgME::ExportJob *secretKeyExportJob(bool armor, const QString &) const override
268  {
269  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
270  if (!context) {
271  return nullptr;
272  }
273 
274  context->setArmor(armor);
275  return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecret);
276  }
277 
278  QGpgME::ExportJob *secretSubkeyExportJob(bool armor) const override
279  {
280  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
281  if (!context) {
282  return nullptr;
283  }
284 
285  context->setArmor(armor);
286  return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecretSubkey);
287  }
288 
289  QGpgME::RefreshKeysJob *refreshKeysJob() const override
290  {
291  if (mProtocol != GpgME::CMS) {
292  return nullptr;
293  }
294 
296  }
297 
298  QGpgME::DownloadJob *downloadJob(bool armor) const override
299  {
300  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
301  if (!context) {
302  return nullptr;
303  }
304 
305  context->setArmor(armor);
306  // this is the hackish interface for downloading from keyserers currently:
307  context->setKeyListMode(GpgME::Extern);
308  return new QGpgME::QGpgMEDownloadJob(context);
309  }
310 
311  QGpgME::DeleteJob *deleteJob() const override
312  {
313  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
314  if (!context) {
315  return nullptr;
316  }
317  return new QGpgME::QGpgMEDeleteJob(context);
318  }
319 
320  QGpgME::SignEncryptJob *signEncryptJob(bool armor, bool textMode) const override
321  {
322  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
323  if (!context) {
324  return nullptr;
325  }
326 
327  context->setArmor(armor);
328  context->setTextMode(textMode);
329  return new QGpgME::QGpgMESignEncryptJob(context);
330  }
331 
332  QGpgME::DecryptVerifyJob *decryptVerifyJob(bool textMode) const override
333  {
334  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
335  if (!context) {
336  return nullptr;
337  }
338 
339  context->setTextMode(textMode);
340  return new QGpgME::QGpgMEDecryptVerifyJob(context);
341  }
342 
343  QGpgME::ChangeExpiryJob *changeExpiryJob() const override
344  {
345  if (mProtocol != GpgME::OpenPGP) {
346  return nullptr; // only supported by gpg
347  }
348 
349  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
350  if (!context) {
351  return nullptr;
352  }
353  return new QGpgME::QGpgMEChangeExpiryJob(context);
354  }
355 
356  QGpgME::ChangePasswdJob *changePasswdJob() const override
357  {
358  if (!GpgME::hasFeature(GpgME::PasswdFeature, 0)) {
359  return nullptr;
360  }
361  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
362  if (!context) {
363  return nullptr;
364  }
365  return new QGpgME::QGpgMEChangePasswdJob(context);
366  }
367 
368  QGpgME::SignKeyJob *signKeyJob() const override
369  {
370  if (mProtocol != GpgME::OpenPGP) {
371  return nullptr; // only supported by gpg
372  }
373 
374  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
375  if (!context) {
376  return nullptr;
377  }
378  return new QGpgME::QGpgMESignKeyJob(context);
379  }
380 
381  QGpgME::ChangeOwnerTrustJob *changeOwnerTrustJob() const override
382  {
383  if (mProtocol != GpgME::OpenPGP) {
384  return nullptr; // only supported by gpg
385  }
386 
387  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
388  if (!context) {
389  return nullptr;
390  }
391  return new QGpgME::QGpgMEChangeOwnerTrustJob(context);
392  }
393 
394  QGpgME:: AddExistingSubkeyJob *addExistingSubkeyJob() const override
395  {
396  if (mProtocol != GpgME::OpenPGP) {
397  return nullptr; // only supported by gpg
398  }
399 
400  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
401  if (!context) {
402  return nullptr;
403  }
404  return new QGpgME::QGpgMEAddExistingSubkeyJob{context};
405  }
406 
407  QGpgME::AddUserIDJob *addUserIDJob() const override
408  {
409  if (mProtocol != GpgME::OpenPGP) {
410  return nullptr; // only supported by gpg
411  }
412 
413  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
414  if (!context) {
415  return nullptr;
416  }
417  return new QGpgME::QGpgMEAddUserIDJob(context);
418  }
419 
420  QGpgME::KeyListJob *locateKeysJob() const override
421  {
422  if (mProtocol != GpgME::OpenPGP) {
423  return nullptr;
424  }
425  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
426  if (!context) {
427  return nullptr;
428  }
429  context->setKeyListMode(GpgME::Locate | GpgME::Signatures | GpgME::Validate);
430  return new QGpgME::QGpgMEKeyListJob(context);
431  }
432 
434  {
435  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
436  if (!context) {
437  return nullptr;
438  }
439  return new QGpgME::QGpgMEKeyForMailboxJob(context);
440  }
441 
442  QGpgME::WKDLookupJob *wkdLookupJob() const override
443  {
444  if (mProtocol != GpgME::OpenPGP) {
445  return nullptr;
446  }
447  auto context = GpgME::Context::createForEngine(GpgME::AssuanEngine);
448  if (!context) {
449  return nullptr;
450  }
451  return new QGpgME::QGpgMEWKDLookupJob(context.release());
452  }
453 
454  QGpgME::WKSPublishJob *wksPublishJob() const override
455  {
456  if (mProtocol != GpgME::OpenPGP) {
457  return nullptr;
458  }
459  auto context = GpgME::Context::createForEngine(GpgME::SpawnEngine);
460  if (!context) {
461  return nullptr;
462  }
463  return new QGpgME::QGpgMEWKSPublishJob(context.release());
464  }
465 
466  QGpgME::TofuPolicyJob *tofuPolicyJob() const override
467  {
468  if (mProtocol != GpgME::OpenPGP) {
469  return nullptr;
470  }
471  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
472  if (!context) {
473  return nullptr;
474  }
475  return new QGpgME::QGpgMETofuPolicyJob(context);
476  }
477 
478  QGpgME::QuickJob *quickJob() const override
479  {
480  if (mProtocol != GpgME::OpenPGP) {
481  return nullptr;
482  }
483  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
484  if (!context) {
485  return nullptr;
486  }
487  return new QGpgME::QGpgMEQuickJob(context);
488  }
489 
490  QGpgME::RevokeKeyJob *revokeKeyJob() const override
491  {
492  if (mProtocol != GpgME::OpenPGP) {
493  return nullptr;
494  }
495  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
496  if (!context) {
497  return nullptr;
498  }
499  return new QGpgME::QGpgMERevokeKeyJob(context);
500  }
501 
503  {
504  if (mProtocol != GpgME::OpenPGP) {
505  return nullptr;
506  }
507  GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
508  if (!context) {
509  return nullptr;
510  }
511  return new QGpgME::QGpgMESetPrimaryUserIDJob{context};
512  }
513 
514  QGpgME::EncryptArchiveJob *encryptArchiveJob(bool armor) const override
515  {
516  if (mProtocol != GpgME::OpenPGP) {
517  return nullptr;
518  }
519  if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
520  context->setArmor(armor);
521  return new QGpgME::QGpgMEEncryptArchiveJob{context};
522  }
523  return nullptr;
524  }
525 
526  QGpgME::SignArchiveJob *signArchiveJob(bool armor) const override
527  {
528  if (mProtocol != GpgME::OpenPGP) {
529  return nullptr;
530  }
531  if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
532  context->setArmor(armor);
533  return new QGpgME::QGpgMESignArchiveJob{context};
534  }
535  return nullptr;
536  }
537 
538  QGpgME::SignEncryptArchiveJob *signEncryptArchiveJob(bool armor) const override
539  {
540  if (mProtocol != GpgME::OpenPGP) {
541  return nullptr;
542  }
543  if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
544  context->setArmor(armor);
545  return new QGpgME::QGpgMESignEncryptArchiveJob{context};
546  }
547  return nullptr;
548  }
549 
550  QGpgME::DecryptVerifyArchiveJob *decryptVerifyArchiveJob() const override
551  {
552  if (mProtocol != GpgME::OpenPGP) {
553  return nullptr;
554  }
555  if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
556  return new QGpgME::QGpgMEDecryptVerifyArchiveJob{context};
557  }
558  return nullptr;
559  }
560 };
561 
562 }
563 #endif
Definition: addexistingsubkeyjob.h:53
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:72
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
Definition: decryptverifyarchivejob.h:57
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
Definition: encryptarchivejob.h:57
An abstract base class for asynchronous encrypters.
Definition: encryptjob.h:79
An abstract base class for asynchronous exporters.
Definition: exportjob.h:66
An abstract base class for asynchronous keyserver-importers.
Definition: importfromkeyserverjob.h:67
An abstract base class for asynchronous importers.
Definition: importjob.h:72
Get the best key to use for a Mailbox.
Definition: keyformailboxjob.h:70
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:77
Definition: protocol.h:118
virtual TofuPolicyJob * tofuPolicyJob() const =0
virtual KeyListJob * locateKeysJob() const =0
virtual RefreshKeysJob * refreshKeysJob() const =0
virtual QuickJob * quickJob() const =0
virtual WKDLookupJob * wkdLookupJob() const =0
virtual SetPrimaryUserIDJob * setPrimaryUserIDJob() const =0
virtual WKSPublishJob * wksPublishJob() const =0
virtual KeyForMailboxJob * keyForMailboxJob() const =0
Definition: qgpgmeaddexistingsubkeyjob.h:49
Definition: qgpgmeadduseridjob.h:51
Definition: qgpgmechangeexpiryjob.h:51
Definition: qgpgmechangeownertrustjob.h:51
Definition: qgpgmechangepasswdjob.h:51
Definition: qgpgmedecryptjob.h:57
Definition: qgpgmedecryptverifyarchivejob.h:53
Definition: qgpgmedecryptverifyjob.h:62
Definition: qgpgmedeletejob.h:56
Definition: qgpgmedownloadjob.h:51
Definition: qgpgmeencryptarchivejob.h:52
Definition: qgpgmeencryptjob.h:62
Definition: qgpgmeexportjob.h:53
Definition: qgpgmeimportfromkeyserverjob.h:57
Definition: qgpgmeimportjob.h:59
Definition: qgpgmekeyformailboxjob.h:59
Definition: qgpgmekeygenerationjob.h:57
Definition: qgpgmekeylistjob.h:62
Definition: qgpgmelistallkeysjob.h:62
Definition: qgpgmequickjob.h:52
Definition: qgpgmereceivekeysjob.h:56
Definition: qgpgmerefreshsmimekeysjob.h:52
Definition: qgpgmerevokekeyjob.h:49
Definition: qgpgmesetprimaryuseridjob.h:49
Definition: qgpgmesignarchivejob.h:52
Definition: qgpgmesignencryptarchivejob.h:53
Definition: qgpgmesignencryptjob.h:69
Definition: qgpgmesignjob.h:62
Definition: qgpgmesignkeyjob.h:53
Definition: qgpgmetofupolicyjob.h:50
Definition: qgpgmeverifydetachedjob.h:57
Definition: qgpgmeverifyopaquejob.h:57
Definition: qgpgmewkdlookupjob.h:51
Definition: qgpgmewkspublishjob.h:54
Definition: quickjob.h:56
Definition: receivekeysjob.h:44
An abstract base class for asynchronous key refreshers.
Definition: refreshkeysjob.h:68
Definition: revokekeyjob.h:52
Definition: setprimaryuseridjob.h:51
Definition: signarchivejob.h:57
Definition: signencryptarchivejob.h:57
An abstract base class for asynchronous combined signing and encrypting.
Definition: signencryptjob.h:83
An abstract base class for asynchronous signing.
Definition: signjob.h:77
An abstract base class to sign keys asynchronously.
Definition: signkeyjob.h:69
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: wkdlookupjob.h:54
Definition: wkspublishjob.h:60
Definition: qgpgmebackend.h:43