QGpgME 2.0.0-unknown
Qt API for GpgME
Loading...
Searching...
No Matches
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#include "qgpgmewkdrefreshjob.h"
75
76namespace
77{
78
79class Protocol : public QGpgME::Protocol
80{
81 GpgME::Protocol mProtocol;
82public:
83 explicit Protocol(GpgME::Protocol proto) : mProtocol(proto) {}
84
85 QString name() const override
86 {
87 switch (mProtocol) {
88 case GpgME::OpenPGP: return QStringLiteral("OpenPGP");
89 case GpgME::CMS: return QStringLiteral("SMIME");
90 default: return QString();
91 }
92 }
93
94 QString displayName() const override
95 {
96 // ah (2.4.16): Where is this used and isn't this inverted
97 // with name
98 switch (mProtocol) {
99 case GpgME::OpenPGP: return QStringLiteral("gpg");
100 case GpgME::CMS: return QStringLiteral("gpgsm");
101 default: return QStringLiteral("unknown");
102 }
103 }
104
105 QGpgME::SpecialJob *specialJob(const char *, const QMap<QString, QVariant> &) const override
106 {
107 return nullptr;
108 }
109
110 QGpgME::KeyListJob *keyListJob(bool remote, bool includeSigs, bool validate) const override
111 {
112 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
113 if (!context) {
114 return nullptr;
115 }
116
117 unsigned int mode = context->keyListMode();
118 if (remote) {
119 mode |= GpgME::Extern;
120 mode &= ~GpgME::Local;
121 } else {
122 mode |= GpgME::Local;
123 mode &= ~GpgME::Extern;
124 }
125 if (includeSigs) {
126 mode |= GpgME::Signatures;
127 }
128 if (validate) {
129 mode |= GpgME::Validate;
130 }
131 context->setKeyListMode(mode);
132 return new QGpgME::QGpgMEKeyListJob(context);
133 }
134
135 QGpgME::ListAllKeysJob *listAllKeysJob(bool includeSigs, bool validate) const override
136 {
137 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
138 if (!context) {
139 return nullptr;
140 }
141
142 unsigned int mode = context->keyListMode();
143 mode |= GpgME::Local;
144 mode &= ~GpgME::Extern;
145 if (includeSigs) {
146 mode |= GpgME::Signatures;
147 }
148 if (validate) {
149 mode |= GpgME::Validate;
150 /* Setting the context to offline mode disables CRL / OCSP checks in
151 this Job. Otherwise we would try to fetch the CRL's for all CMS
152 keys in the users keyring because GpgME::Validate includes remote
153 resources by default in the validity check.
154 This setting only has any effect if gpgsm >= 2.1.6 is used.
155 */
156 context->setOffline(true);
157 }
158 context->setKeyListMode(mode);
159 return new QGpgME::QGpgMEListAllKeysJob(context);
160 }
161
162 QGpgME::EncryptJob *encryptJob(bool armor, bool textmode) const override
163 {
164 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
165 if (!context) {
166 return nullptr;
167 }
168
169 context->setArmor(armor);
170 context->setTextMode(textmode);
171 return new QGpgME::QGpgMEEncryptJob(context);
172 }
173
174 QGpgME::DecryptJob *decryptJob() const override
175 {
176 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
177 if (!context) {
178 return nullptr;
179 }
180 return new QGpgME::QGpgMEDecryptJob(context);
181 }
182
183 QGpgME::SignJob *signJob(bool armor, bool textMode) const override
184 {
185 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
186 if (!context) {
187 return nullptr;
188 }
189
190 context->setArmor(armor);
191 context->setTextMode(textMode);
192 return new QGpgME::QGpgMESignJob(context);
193 }
194
195 QGpgME::VerifyDetachedJob *verifyDetachedJob(bool textMode) const 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::QGpgMEVerifyDetachedJob(context);
204 }
205
206 QGpgME::VerifyOpaqueJob *verifyOpaqueJob(bool textMode) const override
207 {
208 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
209 if (!context) {
210 return nullptr;
211 }
212
213 context->setTextMode(textMode);
214 return new QGpgME::QGpgMEVerifyOpaqueJob(context);
215 }
216
217 QGpgME::KeyGenerationJob *keyGenerationJob() const override
218 {
219 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
220 if (!context) {
221 return nullptr;
222 }
223 return new QGpgME::QGpgMEKeyGenerationJob(context);
224 }
225
226 QGpgME::ImportJob *importJob() const override
227 {
228 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
229 if (!context) {
230 return nullptr;
231 }
232 return new QGpgME::QGpgMEImportJob(context);
233 }
234
235 QGpgME::ImportFromKeyserverJob *importFromKeyserverJob() const override
236 {
237 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
238 if (!context) {
239 return nullptr;
240 }
241 return new QGpgME::QGpgMEImportFromKeyserverJob(context);
242 }
243
244 QGpgME::ReceiveKeysJob *receiveKeysJob() const override
245 {
246 if (mProtocol != GpgME::OpenPGP) {
247 return nullptr;
248 }
249
250 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
251 if (!context) {
252 return nullptr;
253 }
254 return new QGpgME::QGpgMEReceiveKeysJob{context};
255 }
256
257 QGpgME::ExportJob *publicKeyExportJob(bool armor) const override
258 {
259 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
260 if (!context) {
261 return nullptr;
262 }
263
264 context->setArmor(armor);
265 return new QGpgME::QGpgMEExportJob(context);
266 }
267
268 QGpgME::ExportJob *secretKeyExportJob(bool armor, const QString &) const override
269 {
270 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
271 if (!context) {
272 return nullptr;
273 }
274
275 context->setArmor(armor);
276 return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecret);
277 }
278
279 QGpgME::ExportJob *secretSubkeyExportJob(bool armor) const override
280 {
281 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
282 if (!context) {
283 return nullptr;
284 }
285
286 context->setArmor(armor);
287 return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecretSubkey);
288 }
289
290 QGpgME::RefreshKeysJob *refreshKeysJob() const override
291 {
292 if (mProtocol != GpgME::CMS) {
293 return nullptr;
294 }
295
297 }
298
299 QGpgME::DownloadJob *downloadJob(bool armor) const override
300 {
301 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
302 if (!context) {
303 return nullptr;
304 }
305
306 context->setArmor(armor);
307 // this is the hackish interface for downloading from keyserers currently:
308 context->setKeyListMode(GpgME::Extern);
309 return new QGpgME::QGpgMEDownloadJob(context);
310 }
311
312 QGpgME::DeleteJob *deleteJob() const override
313 {
314 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
315 if (!context) {
316 return nullptr;
317 }
318 return new QGpgME::QGpgMEDeleteJob(context);
319 }
320
321 QGpgME::SignEncryptJob *signEncryptJob(bool armor, bool textMode) const override
322 {
323 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
324 if (!context) {
325 return nullptr;
326 }
327
328 context->setArmor(armor);
329 context->setTextMode(textMode);
330 return new QGpgME::QGpgMESignEncryptJob(context);
331 }
332
333 QGpgME::DecryptVerifyJob *decryptVerifyJob(bool textMode) const override
334 {
335 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
336 if (!context) {
337 return nullptr;
338 }
339
340 context->setTextMode(textMode);
341 return new QGpgME::QGpgMEDecryptVerifyJob(context);
342 }
343
344 QGpgME::ChangeExpiryJob *changeExpiryJob() const override
345 {
346 if (mProtocol != GpgME::OpenPGP) {
347 return nullptr; // only supported by gpg
348 }
349
350 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
351 if (!context) {
352 return nullptr;
353 }
354 return new QGpgME::QGpgMEChangeExpiryJob(context);
355 }
356
357 QGpgME::ChangePasswdJob *changePasswdJob() const override
358 {
359 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
360 if (!context) {
361 return nullptr;
362 }
363 return new QGpgME::QGpgMEChangePasswdJob(context);
364 }
365
366 QGpgME::SignKeyJob *signKeyJob() const override
367 {
368 if (mProtocol != GpgME::OpenPGP) {
369 return nullptr; // only supported by gpg
370 }
371
372 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
373 if (!context) {
374 return nullptr;
375 }
376 return new QGpgME::QGpgMESignKeyJob(context);
377 }
378
379 QGpgME::ChangeOwnerTrustJob *changeOwnerTrustJob() const override
380 {
381 if (mProtocol != GpgME::OpenPGP) {
382 return nullptr; // only supported by gpg
383 }
384
385 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
386 if (!context) {
387 return nullptr;
388 }
389 return new QGpgME::QGpgMEChangeOwnerTrustJob(context);
390 }
391
392 QGpgME:: AddExistingSubkeyJob *addExistingSubkeyJob() const override
393 {
394 if (mProtocol != GpgME::OpenPGP) {
395 return nullptr; // only supported by gpg
396 }
397
398 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
399 if (!context) {
400 return nullptr;
401 }
402 return new QGpgME::QGpgMEAddExistingSubkeyJob{context};
403 }
404
405 QGpgME::AddUserIDJob *addUserIDJob() const override
406 {
407 if (mProtocol != GpgME::OpenPGP) {
408 return nullptr; // only supported by gpg
409 }
410
411 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
412 if (!context) {
413 return nullptr;
414 }
415 return new QGpgME::QGpgMEAddUserIDJob(context);
416 }
417
418 QGpgME::KeyListJob *locateKeysJob() const override
419 {
420 if (mProtocol != GpgME::OpenPGP) {
421 return nullptr;
422 }
423 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
424 if (!context) {
425 return nullptr;
426 }
427 context->setKeyListMode(GpgME::Locate | GpgME::Signatures | GpgME::Validate);
428 return new QGpgME::QGpgMEKeyListJob(context);
429 }
430
432 {
433 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
434 if (!context) {
435 return nullptr;
436 }
437 return new QGpgME::QGpgMEKeyForMailboxJob(context);
438 }
439
440 QGpgME::WKDLookupJob *wkdLookupJob() const override
441 {
442 if (mProtocol != GpgME::OpenPGP) {
443 return nullptr;
444 }
445 auto context = GpgME::Context::createForEngine(GpgME::AssuanEngine);
446 if (!context) {
447 return nullptr;
448 }
449 return new QGpgME::QGpgMEWKDLookupJob(context.release());
450 }
451
452 QGpgME::WKSPublishJob *wksPublishJob() const override
453 {
454 if (mProtocol != GpgME::OpenPGP) {
455 return nullptr;
456 }
457 auto context = GpgME::Context::createForEngine(GpgME::SpawnEngine);
458 if (!context) {
459 return nullptr;
460 }
461 return new QGpgME::QGpgMEWKSPublishJob(context.release());
462 }
463
464 QGpgME::TofuPolicyJob *tofuPolicyJob() const override
465 {
466 if (mProtocol != GpgME::OpenPGP) {
467 return nullptr;
468 }
469 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
470 if (!context) {
471 return nullptr;
472 }
473 return new QGpgME::QGpgMETofuPolicyJob(context);
474 }
475
476 QGpgME::QuickJob *quickJob() const override
477 {
478 if (mProtocol != GpgME::OpenPGP) {
479 return nullptr;
480 }
481 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
482 if (!context) {
483 return nullptr;
484 }
485 return new QGpgME::QGpgMEQuickJob(context);
486 }
487
488 QGpgME::RevokeKeyJob *revokeKeyJob() const override
489 {
490 if (mProtocol != GpgME::OpenPGP) {
491 return nullptr;
492 }
493 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
494 if (!context) {
495 return nullptr;
496 }
497 return new QGpgME::QGpgMERevokeKeyJob(context);
498 }
499
501 {
502 if (mProtocol != GpgME::OpenPGP) {
503 return nullptr;
504 }
505 GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
506 if (!context) {
507 return nullptr;
508 }
509 return new QGpgME::QGpgMESetPrimaryUserIDJob{context};
510 }
511
512 QGpgME::EncryptArchiveJob *encryptArchiveJob(bool armor) const override
513 {
514 if (mProtocol != GpgME::OpenPGP) {
515 return nullptr;
516 }
517 if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
518 context->setArmor(armor);
519 return new QGpgME::QGpgMEEncryptArchiveJob{context};
520 }
521 return nullptr;
522 }
523
524 QGpgME::SignArchiveJob *signArchiveJob(bool armor) const override
525 {
526 if (mProtocol != GpgME::OpenPGP) {
527 return nullptr;
528 }
529 if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
530 context->setArmor(armor);
531 return new QGpgME::QGpgMESignArchiveJob{context};
532 }
533 return nullptr;
534 }
535
536 QGpgME::SignEncryptArchiveJob *signEncryptArchiveJob(bool armor) const override
537 {
538 if (mProtocol != GpgME::OpenPGP) {
539 return nullptr;
540 }
541 if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
542 context->setArmor(armor);
543 return new QGpgME::QGpgMESignEncryptArchiveJob{context};
544 }
545 return nullptr;
546 }
547
548 QGpgME::DecryptVerifyArchiveJob *decryptVerifyArchiveJob() const override
549 {
550 if (mProtocol != GpgME::OpenPGP) {
551 return nullptr;
552 }
553 if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
554 return new QGpgME::QGpgMEDecryptVerifyArchiveJob{context};
555 }
556 return nullptr;
557 }
558
559 QGpgME::WKDRefreshJob *wkdRefreshJob() const override
560 {
561 if (mProtocol != GpgME::OpenPGP) {
562 return nullptr;
563 }
564 if (auto context = GpgME::Context::createForProtocol(mProtocol)) {
565 return new QGpgME::QGpgMEWKDRefreshJob{context};
566 }
567 return nullptr;
568 }
569};
570
571}
572#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:70
An abstract base class to change owner trust asynchronously.
Definition changeownertrustjob.h:59
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:55
An abstract base class for asynchronous combined decrypters and verifiers.
Definition decryptverifyjob.h:79
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:55
An abstract base class for asynchronous encrypters.
Definition encryptjob.h:86
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:70
Get the best key to use for a Mailbox.
Definition keyformailboxjob.h:66
An abstract base class for asynchronous key generation.
Definition keygenerationjob.h:66
An abstract base class for asynchronous key listers.
Definition keylistjob.h:72
An abstract base class for asynchronously listing all keys.
Definition listallkeysjob.h:75
Definition protocol.h:119
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 SetPrimaryUserIDJob * setPrimaryUserIDJob() const =0
virtual TofuPolicyJob * tofuPolicyJob() const =0
virtual RefreshKeysJob * refreshKeysJob() const =0
Definition qgpgmeaddexistingsubkeyjob.h:49
Definition qgpgmeadduseridjob.h:51
Definition qgpgmechangeexpiryjob.h:53
Definition qgpgmechangeownertrustjob.h:51
Definition qgpgmechangepasswdjob.h:51
Definition qgpgmedecryptjob.h:53
Definition qgpgmedecryptverifyarchivejob.h:55
Definition qgpgmedecryptverifyjob.h:56
Definition qgpgmedeletejob.h:56
Definition qgpgmedownloadjob.h:51
Definition qgpgmeencryptarchivejob.h:54
Definition qgpgmeencryptjob.h:56
Definition qgpgmeexportjob.h:53
Definition qgpgmeimportfromkeyserverjob.h:53
Definition qgpgmeimportjob.h:57
Definition qgpgmekeyformailboxjob.h:54
Definition qgpgmekeygenerationjob.h:53
Definition qgpgmekeylistjob.h:54
Definition qgpgmelistallkeysjob.h:56
Definition qgpgmequickjob.h:54
Definition qgpgmereceivekeysjob.h:52
Definition qgpgmerefreshsmimekeysjob.h:49
Definition qgpgmerevokekeyjob.h:49
Definition qgpgmesetprimaryuseridjob.h:49
Definition qgpgmesignarchivejob.h:54
Definition qgpgmesignencryptarchivejob.h:55
Definition qgpgmesignencryptjob.h:59
Definition qgpgmesignjob.h:56
Definition qgpgmesignkeyjob.h:53
Definition qgpgmetofupolicyjob.h:50
Definition qgpgmeverifydetachedjob.h:55
Definition qgpgmeverifyopaquejob.h:55
Definition qgpgmewkdlookupjob.h:51
Definition qgpgmewkdrefreshjob.h:53
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:55
Definition signencryptarchivejob.h:55
An abstract base class for asynchronous combined signing and encrypting.
Definition signencryptjob.h:89
An abstract base class for asynchronous signing.
Definition signjob.h:83
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:51
An abstract base class for asynchronous verification of detached signatures.
Definition verifydetachedjob.h:76
An abstract base class for asynchronous verification of opaque signatures.
Definition verifyopaquejob.h:78
Definition wkdlookupjob.h:54
Definition wkdrefreshjob.h:58
Definition wkspublishjob.h:60
Definition qgpgmebackend.h:43