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