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