certmanager/lib

cryptplugwrapper.cpp
Go to the documentation of this file.
1
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include "cryptplugwrapper.h"
35#include "cryptplug.h"
36
37#include <backends/qgpgme/qgpgmekeylistjob.h>
38#include <backends/qgpgme/qgpgmeencryptjob.h>
39#include <backends/qgpgme/qgpgmedecryptjob.h>
40#include <backends/qgpgme/qgpgmesignjob.h>
41#include <backends/qgpgme/qgpgmeverifydetachedjob.h>
42#include <backends/qgpgme/qgpgmeverifyopaquejob.h>
43#include <backends/qgpgme/qgpgmekeygenerationjob.h>
44#include <backends/qgpgme/qgpgmeimportjob.h>
45#include <backends/qgpgme/qgpgmeexportjob.h>
46#include <backends/qgpgme/qgpgmesecretkeyexportjob.h>
47#include <backends/qgpgme/qgpgmedownloadjob.h>
48#include <backends/qgpgme/qgpgmedeletejob.h>
49#include <backends/qgpgme/qgpgmesignencryptjob.h>
50#include <backends/qgpgme/qgpgmedecryptverifyjob.h>
51#include <backends/qgpgme/qgpgmecryptoconfig.h>
52#include <backends/qgpgme/qgpgmerefreshkeysjob.h>
53
54// qgpgme
55#include <qgpgme/dataprovider.h>
56
57// gpgme++
58#include <gpgmepp/data.h>
59#include <gpgmepp/importresult.h>
60#include <gpgmepp/keygenerationresult.h>
61
62// kde
63#include <kdebug.h>
64#include <tdeapplication.h>
65#include <tdelocale.h>
66#include <tdeglobal.h>
67#include <tdeconfig.h>
68
69// other
70#include <memory>
71
72#include <assert.h>
73#include <stdlib.h>
74#include <stdio.h>
75
76
77
78
79/*
80 *
81 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
82 * *
83 * This file's source comments - as well as those in interface file *
84 * cryptplugwrapper.h - are optimized for processing by Doxygen. *
85 * *
86 * To obtain best results please get an updated version of Doxygen, *
87 * for sources and binaries goto http://www.doxygen.org/index.html *
88 * *
89 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
90 *
91 */
92
93
94
121// a little helper class for reordering of DN attributes
122class DNBeautifier {
123public:
124 enum UnknownAttrsHandling { unknownAttrsHide,
125 unknownAttrsPrefix,
126 unknownAttrsPostfix,
127 unknownAttrsInfix };
128 // infix: at the position of "_X_", if any, else Postfix
129
130 DNBeautifier()
131 {
132 // the attrOrder is defaulted to an empty string automatically
133 _unknownAttrsHandling = unknownAttrsInfix;
134 _unknownAttrsHandlingChar = "INFIX";
135 }
136 DNBeautifier( TDEConfig* config,
137 const TQString& cfgGroup,
138 const TQString& cfgAttributeOrderEntry,
139 const TQString& cfgUnknownAttrsEntry,
140 const TQStringList& fallbackAttrOrder = TQStringList(),
141 UnknownAttrsHandling fallbackUnknowAttrsHandling = unknownAttrsInfix )
142 {
143 _unknownAttrsHandling = unknownAttrsInfix;
144 _unknownAttrsHandlingChar = "INFIX";
145 if( config ){
146 const TQString oldGroup( config->group() );
147 config->setGroup( cfgGroup ); // e.g. "General"
148 _attrOrder =
149 config->readListEntry( cfgAttributeOrderEntry ); // e.g. "DNAttributeOrder"
150 _unknownAttrsHandlingChar =
151 config->readEntry( cfgUnknownAttrsEntry ).upper().latin1(); // e.g. "DNUnknownAttributes"
152 config->setGroup( oldGroup );
153 if( _unknownAttrsHandlingChar == "HIDE" )
154 _unknownAttrsHandling = unknownAttrsHide;
155 else if( _unknownAttrsHandlingChar == "PREFIX" )
156 _unknownAttrsHandling = unknownAttrsPrefix;
157 else if( _unknownAttrsHandlingChar == "POSTFIX" )
158 _unknownAttrsHandling = unknownAttrsPostfix;
159 else if( _unknownAttrsHandlingChar == "INFIX" )
160 _unknownAttrsHandling = unknownAttrsInfix;
161 else
162 _unknownAttrsHandlingChar = "INFIX";
163 }
164 if( _attrOrder.isEmpty() && ! fallbackAttrOrder.isEmpty() )
165 _attrOrder = fallbackAttrOrder;
166
167 if( _attrOrder.isEmpty() ){
168 _attrOrderChar = 0;
169 }else{
170 _attrOrderChar = new char*[ _attrOrder.count()+1 ];
171 int i=0;
172 for( TQStringList::ConstIterator itOrder = _attrOrder.begin();
173 itOrder != _attrOrder.end();
174 ++itOrder ){
175 _attrOrderChar[ i ] = (char*)malloc( ((*itOrder).length()+1)*sizeof(char) );
176 strcpy( _attrOrderChar[ i ], (*itOrder).latin1() );
177 ++i;
178 }
179 _attrOrderChar[ i ] = NULL;
180 }
181 }
182 ~DNBeautifier()
183 {
184 int i=0;
185 for( TQStringList::ConstIterator itOrder = _attrOrder.begin();
186 itOrder != _attrOrder.end();
187 ++itOrder ){
188 free( _attrOrderChar[ i ] );
189 ++i;
190 }
191 delete[] _attrOrderChar;
192 }
193
194 TQStringList attrOrder() const
195 {
196 return _attrOrder;
197 }
198 char** attrOrderChar()
199 {
200 return _attrOrderChar;
201 }
202
203 UnknownAttrsHandling unknownAttrsHandling() const
204 {
205 return _unknownAttrsHandling;
206 }
207 const char* unknownAttrsHandlingChar() const
208 {
209 return _unknownAttrsHandlingChar;
210 }
211
212 TQValueList< TQPair<TQString,TQString> > reorder( const TQValueList< TQPair<TQString,TQString> > & dn ) const
213 {
214 return reorder( dn, _attrOrder, _unknownAttrsHandling );
215 }
216
217
218 static TQValueList< TQPair<TQString,TQString> > reorder(
219 const TQValueList< TQPair<TQString,TQString> > & dn,
220 TQStringList attrOrder,
221 UnknownAttrsHandling unknownAttrsHandling )
222 {
223 if( !attrOrder.isEmpty() ){
224 TQPtrList< TQPair<TQString,TQString> > unknownEntries;
225 TQValueList< TQPair<TQString,TQString> > dnNew;
226
227 TQPair<TQString,TQString>* unknownEntry;
228 TQStringList::ConstIterator itOrder;
229 TQValueList< TQPair<TQString,TQString> >::ConstIterator itDN;
230 bool bFound;
231
232 if( unknownAttrsHandling != unknownAttrsHide ){
233 // find all unknown entries in their order of appearance
234 for( itDN = dn.begin(); itDN != dn.end(); ++itDN ){
235 bFound = false;
236 for( itOrder = attrOrder.begin(); itOrder != attrOrder.end(); ++itOrder ){
237 if( (*itOrder) == (*itDN).first ){
238 bFound = true;
239 break;
240 }
241 }
242 if( !bFound )
243 unknownEntries.append( &(*itDN) );
244 }
245 }
246
247 // prepend the unknown attrs (if desired)
248 if( unknownAttrsHandling == unknownAttrsPrefix ){
249 for( unknownEntry = unknownEntries.first(); unknownEntry; unknownEntry = unknownEntries.next() ){
250 dnNew << *unknownEntry;
251 }
252 }
253
254 // process the known attrs in the desired order
255 bool b_X_declared = false;
256 for( itOrder = attrOrder.begin(); itOrder != attrOrder.end(); ++itOrder ){
257 if( (*itOrder) == "_X_" ){
258 b_X_declared = true;
259 // insert the unknown attrs (if desired)
260 if( unknownAttrsHandling == unknownAttrsInfix ){
261 for( unknownEntry = unknownEntries.first(); unknownEntry; unknownEntry = unknownEntries.next() ){
262 dnNew << *unknownEntry;
263 }
264 }
265 }else{
266 for( itDN = dn.begin(); itDN != dn.end(); ++itDN ){
267 if( (*itOrder) == (*itDN).first ){
268 dnNew << *itDN;
269 //kdDebug(5150) << TQString((*itDN).first) <<" = " << TQString((*itDN).second) << endl;;
270 }
271 }
272 }
273 }
274
275 // append the unknown attrs (if desired)
276 if( unknownAttrsHandling == unknownAttrsPostfix ||
277 ( unknownAttrsHandling == unknownAttrsInfix && ! b_X_declared ) ){
278 for( unknownEntry = unknownEntries.first(); unknownEntry; unknownEntry = unknownEntries.next() ){
279 dnNew << *unknownEntry;
280 }
281 }
282
283 return dnNew;
284 }
285 return dn;
286 }
287
288private:
289 TQStringList _attrOrder;
290 char** _attrOrderChar;
291 UnknownAttrsHandling _unknownAttrsHandling;
292 TQCString _unknownAttrsHandlingChar;
293};
294
295
296
297/* special helper class to be used by signing/encrypting functions *******/
298
299
300
301StructuringInfoWrapper::StructuringInfoWrapper( CryptPlugWrapper* wrapper )
302 : _initDone( false ), _wrapper( wrapper )
303{
304 initMe();
305}
306StructuringInfoWrapper::~StructuringInfoWrapper()
307{
308 freeMe();
309}
310void StructuringInfoWrapper::reset()
311{
312 freeMe();
313 initMe();
314}
315void StructuringInfoWrapper::initMe()
316{
317 if ( _wrapper && _wrapper->cryptPlug() ) {
318 _wrapper->cryptPlug()->init_StructuringInfo( &data );
319 _initDone = true;
320 }
321}
322void StructuringInfoWrapper::freeMe()
323{
324 if( _wrapper && _wrapper->cryptPlug() && _initDone ) {
325 _wrapper->cryptPlug()->free_StructuringInfo( &data );
326 _initDone = false;
327 }
328}
329
330class CryptPlugWrapper::Config {
331public:
332 Config( gpgme_protocol_t proto );
333 ~Config();
334
335 const char* signatureKeyCertificate;
336 SignatureAlgorithm signatureAlgorithm;
337 SignatureCompoundMode signatureCompoundMode;
338 SendCertificates sendCertificates;
339 bool saveSentSignatures;
340 bool warnNoCertificate;
341 bool signatureUseCRLs;
342 EncryptionAlgorithm encryptionAlgorithm;
343 EncryptEmail encryptEmail;
344 bool saveMessagesEncrypted;
345 bool encryptionUseCRLs;
346 bool encryptionCRLExpiryNearWarning;
347 int encryptionCRLNearExpiryInterval;
348 CertificateSource certificateSource;
349 bool warnSendUnsigned;
350 bool signatureCertificateExpiryNearWarning;
351 int signatureCertificateExpiryNearInterval;
352 bool cACertificateExpiryNearWarning;
353 int cACertificateExpiryNearInterval;
354 bool rootCertificateExpiryNearWarning;
355 int rootCertificateExpiryNearInterval;
356 bool warnSendUnencrypted;
357 bool checkCertificatePath;
358 bool receiverCertificateExpiryNearWarning;
359 int receiverCertificateExpiryNearWarningInterval;
360 bool certificateInChainExpiryNearWarning;
361 int certificateInChainExpiryNearWarningInterval;
362 bool receiverEmailAddressNotInCertificateWarning;
363 const char* libVersion; /* a statically allocated string with the GPGME Version used */
364};
365
366static const int NEAR_EXPIRY = 14;
367
368CryptPlugWrapper::Config::Config( gpgme_protocol_t proto )
369{
370 signatureAlgorithm = SignAlg_SHA1;
371 if ( proto == GPGME_PROTOCOL_CMS )
372 signatureCompoundMode = SignatureCompoundMode_Opaque;
373 else
374 signatureCompoundMode = SignatureCompoundMode_Detached;
375 sendCertificates = SendCert_SendChainWithRoot;
376 saveSentSignatures = true;
377 warnNoCertificate = true;
378 signatureUseCRLs = true;
379 encryptionAlgorithm = EncryptAlg_RSA;
380 encryptEmail = EncryptEmail_Ask;
381 saveMessagesEncrypted = true;
382 encryptionUseCRLs = true;
383 encryptionCRLExpiryNearWarning = false;
384 encryptionCRLNearExpiryInterval = NEAR_EXPIRY;
385 certificateSource = CertSrc_Server;
386 warnSendUnsigned = true;
387 signatureCertificateExpiryNearWarning = true;
388 signatureCertificateExpiryNearInterval = NEAR_EXPIRY;
389 cACertificateExpiryNearWarning = true;
390 cACertificateExpiryNearInterval = NEAR_EXPIRY;
391 rootCertificateExpiryNearWarning = true;
392 rootCertificateExpiryNearInterval = NEAR_EXPIRY;
393 warnSendUnencrypted = false;
394 checkCertificatePath = true;
395 receiverCertificateExpiryNearWarning = true;
396 receiverCertificateExpiryNearWarningInterval = NEAR_EXPIRY;
397 certificateInChainExpiryNearWarning = true;
398 certificateInChainExpiryNearWarningInterval = NEAR_EXPIRY;
399 receiverEmailAddressNotInCertificateWarning = true;
400 libVersion = gpgme_check_version (NULL);
401}
402
403CryptPlugWrapper::Config::~Config() {
404}
405
406/* Some multi purpose functions ******************************************/
407
408TQString CryptPlugWrapper::errorIdToText( int errId, bool & isPassphraseError ) {
409 const GpgME::Error err( errId );
410 isPassphraseError = err.isCanceled()
411 || gpgme_err_code( errId ) == GPG_ERR_NO_SECKEY ; // FIXME: more?
412 return TQString::fromLocal8Bit( err.asString() );
413}
414
415/* some special functions ************************************************/
416
417
419 const TQString& libName,
420 const TQString& update,
421 bool active )
422 : Kleo::CryptoBackend::Protocol(),
423 _name( name ),
424 _libName( libName ),
425 _updateURL( update ),
426 _active( active ),
427 _iniStatus( IniStatus_undef ),
428 _cp( 0 ),
429 _config( 0 ),
430 _cryptoConfig( 0 )
431{
432 const bool ok = initialize( 0, 0 );
433 assert( ok );
434}
435
436
438{
439 deinitialize();
440}
441
442
444{
445 _active = active;
446}
447
448
450{
451 return _active;
452}
453
454
455
456bool CryptPlugWrapper::setLibName( const TQString& libName )
457{
458 bool bOk = ! _cp; // Changing the lib name is only allowed
459 if( bOk ) // when either no initialization took
460 _libName = libName; // place or 'deinitialize()' has been
461 return bOk; // called afterwards.
462}
463
465{
466 return _libName;
467}
468
469TQString CryptPlugWrapper::protocol() const
470{
471 if ( _libName.contains( "smime" ) )
472 return "SMIME";
473 if ( _libName.contains( "openpgp" ) )
474 return "OpenPGP";
475 return TQString();
476}
477
478void CryptPlugWrapper::setDisplayName( const TQString& name )
479{
480 _name = name;
481}
482
483
485{
486 if ( !_name.isEmpty() )
487 return _name;
488 if ( _libName.contains( "smime" ) )
489 return "gpgsm";
490 if ( _libName.contains( "openpgp" ) )
491 return "gpg";
492 return i18n("(Unknown Protocol)");
493}
494
495bool CryptPlugWrapper::initialize( IniStatus* iniStatus, TQString* errorMsg )
496{
497 if ( _cp )
498 return true;
499
500 _iniStatus = IniStatus_undef;
501 /* make sure we have a lib name */
502 if ( _libName.isEmpty() ) {
503 _iniStatus = IniStatus_NoLibName;
504 kdDebug(5150) << "No library name was given.\n" << endl;
505 } else {
506 if ( _libName.contains( "smime" ) ) {
507 _cp = new SMIMECryptPlug();
508 _config = new Config( GPGME_PROTOCOL_CMS );
509 } else if ( _libName.contains( "openpgp" ) ) {
510 _cp = new OpenPGPCryptPlug();
511 _config = new Config( GPGME_PROTOCOL_OpenPGP );
512 } else {
513 _cp = 0;
514 _config = 0;
515 }
516
517 if ( !_cp ) {
518 _iniStatus = IniStatus_LoadError;
519 kdDebug(5150) << "Couldn't create '" << _libName.latin1() << "'" << endl;
520 } else {
521 /* now call the init function */
522 if( !_cp->initialize() ) {
523 _iniStatus = IniStatus_InitError;
524 kdDebug(5150) << "Error while executing function 'initialize' on plugin " << _libName << endl;
525 _lastError = i18n("Error while initializing plugin \"%1\"").arg( _libName );
526 if ( errorMsg )
527 *errorMsg = _lastError;
528 delete _cp; _cp = 0;
529 delete _config; _config = 0;
530 } else {
531 _iniStatus = IniStatus_Ok;
532 }
533 }
534 }
535 if( iniStatus )
536 *iniStatus = _iniStatus;
537 return _iniStatus == IniStatus_Ok;
538}
539
540
541
543{
544 delete _cp; _cp = 0;
545 delete _config; _config = 0;
546 delete _cryptoConfig; _cryptoConfig = 0;
547}
548
549
551{
552 if( errorMsg )
553 *errorMsg = _lastError;
554 return _iniStatus;
555}
556
557
559{
560 return _cp && _cp->hasFeature( flag );
561}
562
563
564/* normal functions ******************************************************/
565
567 const char* signaturetext,
568 bool signatureIsBinary,
569 int signatureLen,
570 CryptPlug::SignatureMetaData* sigmeta )
571{
572 DNBeautifier dnBeautifier( tdeApp->config(),
573 "DN",
574 "AttributeOrder",
575 "UnknownAttributes" );
576 return _cp && _cp->checkMessageSignature( cleartext,
577 signaturetext,
578 signatureIsBinary,
579 signatureLen,
580 sigmeta,
581 dnBeautifier.attrOrderChar(),
582 dnBeautifier.unknownAttrsHandlingChar() );
583}
584
585
586bool CryptPlugWrapper::decryptMessage( const char* ciphertext,
587 bool cipherIsBinary,
588 int cipherLen,
589 char** cleartext,
590 const char* certificate,
591 int* errId,
592 char** errTxt )
593{
594 return _cp && _cp->decryptMessage( ciphertext, cipherIsBinary, cipherLen,
595 (const char**)cleartext, certificate, errId, errTxt );
596}
597
598
600 const char* ciphertext,
601 bool cipherIsBinary,
602 int cipherLen,
603 char** cleartext,
604 const char* certificate,
605 bool* signatureFound,
606 CryptPlug::SignatureMetaData* sigmeta,
607 int* errId,
608 char** errTxt )
609{
610 DNBeautifier dnBeautifier( tdeApp->config(),
611 "DN",
612 "AttributeOrder",
613 "UnknownAttributes" );
614 return _cp && _cp->decryptAndCheckMessage( ciphertext,
615 cipherIsBinary,
616 cipherLen,
617 (const char**)cleartext,
618 certificate,
619 signatureFound,
620 sigmeta,
621 errId,
622 errTxt,
623 dnBeautifier.attrOrderChar(),
624 dnBeautifier.unknownAttrsHandlingChar() );
625}
626
627
628
629
630void CryptPlugWrapper::freeSignatureMetaData( CryptPlug::SignatureMetaData* sigmeta )
631{
632 if ( !sigmeta )
633 return;
634 free( sigmeta->status );
635 for( int i = 0; i < sigmeta->extended_info_count; ++i ) {
636 free( sigmeta->extended_info[i].creation_time );
637 free( (void*)sigmeta->extended_info[i].status_text );
638 free( (void*)sigmeta->extended_info[i].keyid );
639 free( (void*)sigmeta->extended_info[i].fingerprint );
640 free( (void*)sigmeta->extended_info[i].algo );
641 free( (void*)sigmeta->extended_info[i].userid );
642 free( (void*)sigmeta->extended_info[i].name );
643 free( (void*)sigmeta->extended_info[i].comment );
644 if( sigmeta->extended_info[i].emailCount ){
645 for( int j=0; j < sigmeta->extended_info[i].emailCount; ++j)
646 if( sigmeta->extended_info[i].emailList[j] )
647 free( (void*)sigmeta->extended_info[i].emailList[j] );
648 free( (void*)sigmeta->extended_info[i].emailList );
649 }
650 }
651 free( sigmeta->extended_info );
652}
653
654GpgME::ImportResult CryptPlugWrapper::importCertificate( const char* data, size_t length )
655{
656 if ( !_cp )
657 return GpgME::ImportResult();
658
659
660 return _cp->importCertificateFromMem( data, length );
661}
662
663Kleo::KeyListJob * CryptPlugWrapper::keyListJob( bool remote, bool includeSigs, bool validate ) const {
664 if ( !_cp )
665 return 0;
666
667 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
668 if ( !context )
669 return 0;
670
671 unsigned int mode = context->keyListMode();
672 if ( remote ) {
673 mode |= GpgME::Context::Extern;
674 mode &= ~GpgME::Context::Local;
675 } else {
676 mode |= GpgME::Context::Local;
677 mode &= ~GpgME::Context::Extern;
678 }
679 if ( includeSigs ) mode |= GpgME::Context::Signatures;
680 if ( validate ) mode |= GpgME::Context::Validate;
681 context->setKeyListMode( mode );
682 return new Kleo::QGpgMEKeyListJob( context );
683}
684
685Kleo::EncryptJob * CryptPlugWrapper::encryptJob( bool armor, bool textmode ) const {
686 if ( !_cp )
687 return 0;
688
689 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
690 if ( !context )
691 return 0;
692
693 context->setArmor( armor );
694 context->setTextMode( textmode );
695 return new Kleo::QGpgMEEncryptJob( context );
696}
697
698Kleo::DecryptJob * CryptPlugWrapper::decryptJob() const {
699 if ( !_cp )
700 return 0;
701
702 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
703 if ( !context )
704 return 0;
705
706 return new Kleo::QGpgMEDecryptJob( context );
707}
708
709Kleo::SignJob * CryptPlugWrapper::signJob( bool armor, bool textMode ) const {
710 if ( !_cp )
711 return 0;
712
713 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
714 if ( !context )
715 return 0;
716
717 context->setArmor( armor );
718 context->setTextMode( textMode );
719
720 return new Kleo::QGpgMESignJob( context );
721}
722
723Kleo::VerifyDetachedJob * CryptPlugWrapper::verifyDetachedJob( bool textMode ) const {
724 if ( !_cp )
725 return 0;
726
727 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
728 if ( !context )
729 return 0;
730
731 context->setTextMode( textMode );
732
733 return new Kleo::QGpgMEVerifyDetachedJob( context );
734}
735
736Kleo::VerifyOpaqueJob * CryptPlugWrapper::verifyOpaqueJob( bool textMode ) const {
737 if ( !_cp )
738 return 0;
739
740 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
741 if ( !context )
742 return 0;
743
744 context->setTextMode( textMode );
745
746 return new Kleo::QGpgMEVerifyOpaqueJob( context );
747}
748
749Kleo::KeyGenerationJob * CryptPlugWrapper::keyGenerationJob() const {
750 if ( !_cp )
751 return 0;
752
753 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
754 if ( !context )
755 return 0;
756
757 return new Kleo::QGpgMEKeyGenerationJob( context );
758}
759
760Kleo::ImportJob * CryptPlugWrapper::importJob() const {
761 if ( !_cp )
762 return 0;
763
764 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
765 if ( !context )
766 return 0;
767
768 return new Kleo::QGpgMEImportJob( context );
769}
770
771Kleo::ExportJob * CryptPlugWrapper::publicKeyExportJob( bool armor ) const {
772 if ( !_cp )
773 return 0;
774
775 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
776 if ( !context )
777 return 0;
778
779 context->setArmor( armor );
780 return new Kleo::QGpgMEExportJob( context );
781}
782
783Kleo::ExportJob * CryptPlugWrapper::secretKeyExportJob( bool armor, const TQString& charset ) const {
784 if ( !_cp || _cp->mProtocol != GpgME::Context::CMS ) // fixme: add support for gpg, too
785 return 0;
786
787 // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
788 return new Kleo::QGpgMESecretKeyExportJob( armor, charset );
789}
790
791Kleo::RefreshKeysJob * CryptPlugWrapper::refreshKeysJob() const {
792 if ( !_cp || _cp->mProtocol != GpgME::Context::CMS ) // fixme: add support for gpg, too
793 return 0;
794
795 // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
796 return new Kleo::QGpgMERefreshKeysJob();
797}
798
799Kleo::DownloadJob * CryptPlugWrapper::downloadJob( bool armor ) const {
800 if ( !_cp )
801 return 0;
802
803 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
804 if ( !context )
805 return 0;
806
807 context->setArmor( armor );
808 // this is the hackish interface for downloading from keyserers currently:
809 context->setKeyListMode( GpgME::Context::Extern );
810
811 return new Kleo::QGpgMEDownloadJob( context );
812}
813
814Kleo::DeleteJob * CryptPlugWrapper::deleteJob() const {
815 if ( !_cp )
816 return 0;
817
818 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
819 if ( !context )
820 return 0;
821
822 return new Kleo::QGpgMEDeleteJob( context );
823}
824
825Kleo::SignEncryptJob * CryptPlugWrapper::signEncryptJob( bool armor, bool textMode ) const {
826 if ( !_cp )
827 return 0;
828
829 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
830 if ( !context )
831 return 0;
832
833 context->setArmor( armor );
834 context->setTextMode( textMode );
835
836 return new Kleo::QGpgMESignEncryptJob( context );
837}
838
839Kleo::DecryptVerifyJob * CryptPlugWrapper::decryptVerifyJob( bool textMode ) const {
840 if ( !_cp )
841 return 0;
842
843 GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
844 if ( !context )
845 return 0;
846
847 context->setTextMode( textMode );
848
849 return new Kleo::QGpgMEDecryptVerifyJob( context );
850}
This class provides C++ access to the CRYPTPLUG API.
An abstract base class for asynchronous decrypters.
Definition: decryptjob.h:62
An abstract base class for asynchronous combined decrypters and verifiers.
An abstract base class for asynchronous deleters.
Definition: deletejob.h:58
An abstract base class for asynchronous downloaders.
Definition: downloadjob.h:61
An abstract base class for asynchronous encrypters.
Definition: encryptjob.h:64
An abstract base class for asynchronous exporters.
Definition: exportjob.h:61
An abstract base class for asynchronous importers.
Definition: importjob.h:62
An abstract base class for asynchronous key generation.
An abstract base class for asynchronous key listers.
Definition: keylistjob.h:65
An abstract base class for asynchronous key refreshers.
An abstract base class for asynchronous combined signing and encrypting.
An abstract base class for asynchronous signing.
Definition: signjob.h:65
An abstract base class for asynchronous verification of detached signatures.
An abstract base class for asynchronous verification of opaque signatures.
Common API header for CRYPTPLUG.
C++ wrapper for the CRYPTPLUG library API.
TQString libName() const
Returns the CRYPTPLUG library name.
~CryptPlugWrapper()
Destructor of CRYPTPLUG wrapper class.
bool setLibName(const TQString &libName)
Set the CRYPTPLUG library name.
void setActive(bool active)
Set this CRYPTPLUG wrapper's internal active flag.
CryptPlugWrapper(const TQString &name=TQString(), const TQString &libName=TQString(), const TQString &update=TQString(), bool active=false)
Constructor of CRYPTPLUG wrapper class.
bool active() const
Returns this CRYPTPLUG wrapper's internal active flag.
TQString displayName() const
Returns the external name.
void setDisplayName(const TQString &name)
Specifies the external name that is visible in lists, messages, etc.
bool decryptMessage(const char *ciphertext, bool cipherIsBinary, int cipherLen, char **cleartext, const char *certificate, int *errId, char **errTxt)
Tries to decrypt an email message ciphertext and returns the decrypted message in cleartext.
bool decryptAndCheckMessage(const char *ciphertext, bool cipherIsBinary, int cipherLen, char **cleartext, const char *certificate, bool *signatureFound, CryptPlug::SignatureMetaData *sigmeta, int *errId, char **errTxt)
Combines the functionality of checkMessageSignature() and decryptMessage().
IniStatus
Current initialization state.
IniStatus iniStatus(TQString *errorMsg) const
Returns this CRYPTPLUG wrapper's initialization state.
void deinitialize()
This function unloads the lib and frees all internal structures.
bool hasFeature(::Feature)
This function returns true if the specified feature is available in the plugin, and false otherwise.
bool checkMessageSignature(char **cleartext, const char *signaturetext, bool signatureIsBinary, int signatureLen, CryptPlug::SignatureMetaData *sigmeta)
Checks whether the signature of a message is valid.