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