QGpgME 15.0.0.0000457
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 "qgpgmedecryptverifyjob.h"
45#include "qgpgmerefreshkeysjob.h"
46#include "qgpgmedeletejob.h"
47#include "qgpgmedownloadjob.h"
48#include "qgpgmesignencryptjob.h"
49#include "qgpgmeencryptjob.h"
50#include "qgpgmesignjob.h"
51#include "qgpgmesignkeyjob.h"
52#include "qgpgmeexportjob.h"
53#include "qgpgmeverifydetachedjob.h"
54#include "qgpgmeimportjob.h"
55#include "qgpgmeimportfromkeyserverjob.h"
56#include "qgpgmeverifyopaquejob.h"
57#include "qgpgmechangeexpiryjob.h"
58#include "qgpgmechangeownertrustjob.h"
59#include "qgpgmechangepasswdjob.h"
60#include "qgpgmeaddexistingsubkeyjob.h"
61#include "qgpgmeadduseridjob.h"
62#include "qgpgmekeyformailboxjob.h"
63#include "qgpgmewkdlookupjob.h"
64#include "qgpgmewkspublishjob.h"
65#include "qgpgmetofupolicyjob.h"
66#include "qgpgmequickjob.h"
67#include "qgpgmereceivekeysjob.h"
68
69namespace
70{
71
72class Protocol : public QGpgME::Protocol
73{
74 GpgME::Protocol mProtocol;
75public:
76 explicit Protocol(GpgME::Protocol proto) : mProtocol(proto) {}
77
78 QString name() const Q_DECL_OVERRIDE
79 {
80 switch (mProtocol) {
81 case GpgME::OpenPGP: return QStringLiteral("OpenPGP");
82 case GpgME::CMS: return QStringLiteral("SMIME");
83 default: return QString();
84 }
85 }
86
87 QString displayName() const Q_DECL_OVERRIDE
88 {
89 // ah (2.4.16): Where is this used and isn't this inverted
90 // with name
91 switch (mProtocol) {
92 case GpgME::OpenPGP: return QStringLiteral("gpg");
93 case GpgME::CMS: return QStringLiteral("gpgsm");
94 default: return QStringLiteral("unknown");
95 }
96 }
97
98 QGpgME::SpecialJob *specialJob(const char *, const QMap<QString, QVariant> &) const Q_DECL_OVERRIDE
99 {
100 return nullptr;
101 }
102
103 QGpgME::KeyListJob *keyListJob(bool remote, bool includeSigs, bool validate) const Q_DECL_OVERRIDE
104 {
105 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
106 if (!context) {
107 return nullptr;
108 }
109
110 unsigned int mode = context->keyListMode();
111 if (remote) {
112 mode |= GpgME::Extern;
113 mode &= ~GpgME::Local;
114 } else {
115 mode |= GpgME::Local;
116 mode &= ~GpgME::Extern;
117 }
118 if (includeSigs) {
119 mode |= GpgME::Signatures;
120 }
121 if (validate) {
122 mode |= GpgME::Validate;
123 }
124 context->setKeyListMode(mode);
125 return new QGpgME::QGpgMEKeyListJob(context);
126 }
127
128 QGpgME::ListAllKeysJob *listAllKeysJob(bool includeSigs, bool validate) const Q_DECL_OVERRIDE
129 {
130 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
131 if (!context) {
132 return nullptr;
133 }
134
135 unsigned int mode = context->keyListMode();
136 mode |= GpgME::Local;
137 mode &= ~GpgME::Extern;
138 if (includeSigs) {
139 mode |= GpgME::Signatures;
140 }
141 if (validate) {
142 mode |= GpgME::Validate;
143 /* Setting the context to offline mode disables CRL / OCSP checks in
144 this Job. Otherwise we would try to fetch the CRL's for all CMS
145 keys in the users keyring because GpgME::Validate includes remote
146 resources by default in the validity check.
147 This setting only has any effect if gpgsm >= 2.1.6 is used.
148 */
149 context->setOffline(true);
150 }
151 context->setKeyListMode(mode);
152 return new QGpgME::QGpgMEListAllKeysJob(context);
153 }
154
155 QGpgME::EncryptJob *encryptJob(bool armor, bool textmode) const Q_DECL_OVERRIDE
156 {
157 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
158 if (!context) {
159 return nullptr;
160 }
161
162 context->setArmor(armor);
163 context->setTextMode(textmode);
164 return new QGpgME::QGpgMEEncryptJob(context);
165 }
166
167 QGpgME::DecryptJob *decryptJob() const Q_DECL_OVERRIDE
168 {
169 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
170 if (!context) {
171 return nullptr;
172 }
173 return new QGpgME::QGpgMEDecryptJob(context);
174 }
175
176 QGpgME::SignJob *signJob(bool armor, bool textMode) const Q_DECL_OVERRIDE
177 {
178 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
179 if (!context) {
180 return nullptr;
181 }
182
183 context->setArmor(armor);
184 context->setTextMode(textMode);
185 return new QGpgME::QGpgMESignJob(context);
186 }
187
188 QGpgME::VerifyDetachedJob *verifyDetachedJob(bool textMode) const Q_DECL_OVERRIDE
189 {
190 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
191 if (!context) {
192 return nullptr;
193 }
194
195 context->setTextMode(textMode);
196 return new QGpgME::QGpgMEVerifyDetachedJob(context);
197 }
198
199 QGpgME::VerifyOpaqueJob *verifyOpaqueJob(bool textMode) const Q_DECL_OVERRIDE
200 {
201 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
202 if (!context) {
203 return nullptr;
204 }
205
206 context->setTextMode(textMode);
207 return new QGpgME::QGpgMEVerifyOpaqueJob(context);
208 }
209
210 QGpgME::KeyGenerationJob *keyGenerationJob() const Q_DECL_OVERRIDE
211 {
212 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
213 if (!context) {
214 return nullptr;
215 }
216 return new QGpgME::QGpgMEKeyGenerationJob(context);
217 }
218
219 QGpgME::ImportJob *importJob() const Q_DECL_OVERRIDE
220 {
221 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
222 if (!context) {
223 return nullptr;
224 }
225 return new QGpgME::QGpgMEImportJob(context);
226 }
227
228 QGpgME::ImportFromKeyserverJob *importFromKeyserverJob() const Q_DECL_OVERRIDE
229 {
230 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
231 if (!context) {
232 return nullptr;
233 }
234 return new QGpgME::QGpgMEImportFromKeyserverJob(context);
235 }
236
237 QGpgME::ReceiveKeysJob *receiveKeysJob() const override
238 {
239 if (mProtocol != GpgME::OpenPGP) {
240 return nullptr;
241 }
242
243 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
244 if (!context) {
245 return nullptr;
246 }
247 return new QGpgME::QGpgMEReceiveKeysJob{context};
248 }
249
250 QGpgME::ExportJob *publicKeyExportJob(bool armor) const Q_DECL_OVERRIDE
251 {
252 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
253 if (!context) {
254 return nullptr;
255 }
256
257 context->setArmor(armor);
258 return new QGpgME::QGpgMEExportJob(context);
259 }
260
261 QGpgME::ExportJob *secretKeyExportJob(bool armor, const QString &) const Q_DECL_OVERRIDE
262 {
263 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
264 if (!context) {
265 return nullptr;
266 }
267
268 context->setArmor(armor);
269 return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecret);
270 }
271
272 QGpgME::ExportJob *secretSubkeyExportJob(bool armor) const Q_DECL_OVERRIDE
273 {
274 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
275 if (!context) {
276 return nullptr;
277 }
278
279 context->setArmor(armor);
280 return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecretSubkey);
281 }
282
283 QGpgME::RefreshKeysJob *refreshKeysJob() const Q_DECL_OVERRIDE
284 {
285 if (mProtocol != GpgME::CMS) { // fixme: add support for gpg, too
286 return nullptr;
287 }
288
289 // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
290 return new QGpgME::QGpgMERefreshKeysJob();
291 }
292
293 QGpgME::DownloadJob *downloadJob(bool armor) const Q_DECL_OVERRIDE
294 {
295 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
296 if (!context) {
297 return nullptr;
298 }
299
300 context->setArmor(armor);
301 // this is the hackish interface for downloading from keyserers currently:
302 context->setKeyListMode(GpgME::Extern);
303 return new QGpgME::QGpgMEDownloadJob(context);
304 }
305
306 QGpgME::DeleteJob *deleteJob() const Q_DECL_OVERRIDE
307 {
308 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
309 if (!context) {
310 return nullptr;
311 }
312 return new QGpgME::QGpgMEDeleteJob(context);
313 }
314
315 QGpgME::SignEncryptJob *signEncryptJob(bool armor, bool textMode) const Q_DECL_OVERRIDE
316 {
317 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
318 if (!context) {
319 return nullptr;
320 }
321
322 context->setArmor(armor);
323 context->setTextMode(textMode);
324 return new QGpgME::QGpgMESignEncryptJob(context);
325 }
326
327 QGpgME::DecryptVerifyJob *decryptVerifyJob(bool textMode) const Q_DECL_OVERRIDE
328 {
329 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
330 if (!context) {
331 return nullptr;
332 }
333
334 context->setTextMode(textMode);
335 return new QGpgME::QGpgMEDecryptVerifyJob(context);
336 }
337
338 QGpgME::ChangeExpiryJob *changeExpiryJob() const Q_DECL_OVERRIDE
339 {
340 if (mProtocol != GpgME::OpenPGP) {
341 return nullptr; // only supported by gpg
342 }
343
344 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
345 if (!context) {
346 return nullptr;
347 }
348 return new QGpgME::QGpgMEChangeExpiryJob(context);
349 }
350
351 QGpgME::ChangePasswdJob *changePasswdJob() const Q_DECL_OVERRIDE
352 {
353 if (!GpgME::hasFeature(GpgME::PasswdFeature, 0)) {
354 return nullptr;
355 }
356 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
357 if (!context) {
358 return nullptr;
359 }
360 return new QGpgME::QGpgMEChangePasswdJob(context);
361 }
362
363 QGpgME::SignKeyJob *signKeyJob() const Q_DECL_OVERRIDE
364 {
365 if (mProtocol != GpgME::OpenPGP) {
366 return nullptr; // only supported by gpg
367 }
368
369 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
370 if (!context) {
371 return nullptr;
372 }
373 return new QGpgME::QGpgMESignKeyJob(context);
374 }
375
376 QGpgME::ChangeOwnerTrustJob *changeOwnerTrustJob() const Q_DECL_OVERRIDE
377 {
378 if (mProtocol != GpgME::OpenPGP) {
379 return nullptr; // only supported by gpg
380 }
381
382 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
383 if (!context) {
384 return nullptr;
385 }
386 return new QGpgME::QGpgMEChangeOwnerTrustJob(context);
387 }
388
389 QGpgME:: AddExistingSubkeyJob *addExistingSubkeyJob() const override
390 {
391 if (mProtocol != GpgME::OpenPGP) {
392 return nullptr; // only supported by gpg
393 }
394
395 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
396 if (!context) {
397 return nullptr;
398 }
399 return new QGpgME::QGpgMEAddExistingSubkeyJob{context};
400 }
401
402 QGpgME::AddUserIDJob *addUserIDJob() const Q_DECL_OVERRIDE
403 {
404 if (mProtocol != GpgME::OpenPGP) {
405 return nullptr; // only supported by gpg
406 }
407
408 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
409 if (!context) {
410 return nullptr;
411 }
412 return new QGpgME::QGpgMEAddUserIDJob(context);
413 }
414
415 QGpgME::KeyListJob *locateKeysJob() const Q_DECL_OVERRIDE
416 {
417 if (mProtocol != GpgME::OpenPGP) {
418 return nullptr;
419 }
420 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
421 if (!context) {
422 return nullptr;
423 }
424 context->setKeyListMode(GpgME::Extern | GpgME::Local | GpgME::Signatures | GpgME::Validate);
425 return new QGpgME::QGpgMEKeyListJob(context);
426 }
427
428 QGpgME::KeyForMailboxJob *keyForMailboxJob() const Q_DECL_OVERRIDE
429 {
430 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
431 if (!context) {
432 return nullptr;
433 }
434 return new QGpgME::QGpgMEKeyForMailboxJob(context);
435 }
436
437 QGpgME::WKDLookupJob *wkdLookupJob() const Q_DECL_OVERRIDE
438 {
439 if (mProtocol != GpgME::OpenPGP) {
440 return nullptr;
441 }
442 auto context = GpgME::Context::createForEngine(GpgME::AssuanEngine);
443 if (!context) {
444 return nullptr;
445 }
446 return new QGpgME::QGpgMEWKDLookupJob(context.release());
447 }
448
449 QGpgME::WKSPublishJob *wksPublishJob() const Q_DECL_OVERRIDE
450 {
451 if (mProtocol != GpgME::OpenPGP) {
452 return nullptr;
453 }
454 auto context = GpgME::Context::createForEngine(GpgME::SpawnEngine);
455 if (!context) {
456 return nullptr;
457 }
458 return new QGpgME::QGpgMEWKSPublishJob(context.release());
459 }
460
461 QGpgME::TofuPolicyJob *tofuPolicyJob() const Q_DECL_OVERRIDE
462 {
463 if (mProtocol != GpgME::OpenPGP) {
464 return nullptr;
465 }
466 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
467 if (!context) {
468 return nullptr;
469 }
470 return new QGpgME::QGpgMETofuPolicyJob(context);
471 }
472
473 QGpgME::QuickJob *quickJob() const Q_DECL_OVERRIDE
474 {
475 if (mProtocol != GpgME::OpenPGP) {
476 return nullptr;
477 }
478 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
479 if (!context) {
480 return nullptr;
481 }
482 return new QGpgME::QGpgMEQuickJob(context);
483 }
484};
485
486}
487#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
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:70
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:112
virtual KeyListJob * locateKeysJob() const =0
virtual WKSPublishJob * wksPublishJob() const =0
virtual QuickJob * quickJob() const =0
virtual KeyForMailboxJob * keyForMailboxJob() const =0
virtual WKDLookupJob * wkdLookupJob() const =0
virtual TofuPolicyJob * tofuPolicyJob() 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: qgpgmedecryptverifyjob.h:62
Definition: qgpgmedeletejob.h:56
Definition: qgpgmedownloadjob.h:51
Definition: qgpgmeencryptjob.h:62
Definition: qgpgmeexportjob.h:53
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:52
Definition: qgpgmereceivekeysjob.h:56
Definition: qgpgmerefreshkeysjob.h:52
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
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: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:62
Definition: qgpgmebackend.h:43