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