certmanager/lib

cryptplugwrapper.cpp

Go to the documentation of this file.
00001 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "cryptplugwrapper.h"
00035 #include "cryptplug.h"
00036 
00037 #include <backends/qgpgme/qgpgmekeylistjob.h>
00038 #include <backends/qgpgme/qgpgmeencryptjob.h>
00039 #include <backends/qgpgme/qgpgmedecryptjob.h>
00040 #include <backends/qgpgme/qgpgmesignjob.h>
00041 #include <backends/qgpgme/qgpgmeverifydetachedjob.h>
00042 #include <backends/qgpgme/qgpgmeverifyopaquejob.h>
00043 #include <backends/qgpgme/qgpgmekeygenerationjob.h>
00044 #include <backends/qgpgme/qgpgmeimportjob.h>
00045 #include <backends/qgpgme/qgpgmeexportjob.h>
00046 #include <backends/qgpgme/qgpgmesecretkeyexportjob.h>
00047 #include <backends/qgpgme/qgpgmedownloadjob.h>
00048 #include <backends/qgpgme/qgpgmedeletejob.h>
00049 #include <backends/qgpgme/qgpgmesignencryptjob.h>
00050 #include <backends/qgpgme/qgpgmedecryptverifyjob.h>
00051 #include <backends/qgpgme/qgpgmecryptoconfig.h>
00052 #include <backends/qgpgme/qgpgmerefreshkeysjob.h>
00053 
00054 // qgpgme
00055 #include <qgpgme/dataprovider.h>
00056 
00057 // gpgme++
00058 #include <gpgmepp/data.h>
00059 #include <gpgmepp/importresult.h>
00060 #include <gpgmepp/keygenerationresult.h>
00061 
00062 // kde
00063 #include <kdebug.h>
00064 #include <kapplication.h>
00065 #include <klocale.h>
00066 #include <kglobal.h>
00067 #include <kconfig.h>
00068 
00069 // other
00070 #include <memory>
00071 
00072 #include <assert.h>
00073 #include <stdlib.h>
00074 #include <stdio.h>
00075 
00076 
00077 
00078 
00079 /*
00080  *
00081  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00082  *                                                                    *
00083  *  This file's source comments - as well as those in interface file  *
00084  *  cryptplugwrapper.h - are optimized for processing by Doxygen.     *
00085  *                                                                    *
00086  *  To obtain best results please get an updated version of Doxygen,  *
00087  *  for sources and binaries goto http://www.doxygen.org/index.html   *
00088  *                                                                    *
00089   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00090                                                                       *
00091                                                                       */
00092 
00093 
00094 
00121 // a little helper class for reordering of DN attributes
00122 class DNBeautifier {
00123 public:
00124   enum UnknownAttrsHandling { unknownAttrsHide,
00125                               unknownAttrsPrefix,
00126                               unknownAttrsPostfix,
00127                               unknownAttrsInfix };
00128   // infix: at the position of "_X_", if any, else Postfix
00129 
00130   DNBeautifier()
00131   {
00132     // the attrOrder is defaulted to an empty string automatically
00133     _unknownAttrsHandling = unknownAttrsInfix;
00134     _unknownAttrsHandlingChar = "INFIX";
00135   }
00136   DNBeautifier( KConfig* config,
00137                 const QString& cfgGroup,
00138                 const QString& cfgAttributeOrderEntry,
00139                 const QString& cfgUnknownAttrsEntry,
00140                 const QStringList& fallbackAttrOrder = QStringList(),
00141                 UnknownAttrsHandling fallbackUnknowAttrsHandling = unknownAttrsInfix )
00142   {
00143     _unknownAttrsHandling = unknownAttrsInfix;
00144     _unknownAttrsHandlingChar = "INFIX";
00145     if( config ){
00146       const QString oldGroup( config->group() );
00147       config->setGroup( cfgGroup );                             // e.g. "General"
00148       _attrOrder =
00149         config->readListEntry( cfgAttributeOrderEntry );        // e.g. "DNAttributeOrder"
00150       _unknownAttrsHandlingChar =
00151         config->readEntry( cfgUnknownAttrsEntry ).upper().latin1(); // e.g. "DNUnknownAttributes"
00152       config->setGroup( oldGroup );
00153       if( _unknownAttrsHandlingChar == "HIDE" )
00154         _unknownAttrsHandling = unknownAttrsHide;
00155       else if( _unknownAttrsHandlingChar == "PREFIX" )
00156         _unknownAttrsHandling = unknownAttrsPrefix;
00157       else if( _unknownAttrsHandlingChar == "POSTFIX" )
00158         _unknownAttrsHandling = unknownAttrsPostfix;
00159       else if( _unknownAttrsHandlingChar == "INFIX" )
00160         _unknownAttrsHandling = unknownAttrsInfix;
00161       else
00162         _unknownAttrsHandlingChar = "INFIX";
00163     }
00164     if( _attrOrder.isEmpty() && ! fallbackAttrOrder.isEmpty() )
00165       _attrOrder = fallbackAttrOrder;
00166 
00167     if( _attrOrder.isEmpty() ){
00168       _attrOrderChar = 0;
00169     }else{
00170       _attrOrderChar = new char*[ _attrOrder.count()+1 ];
00171       int i=0;
00172       for( QStringList::ConstIterator itOrder = _attrOrder.begin();
00173            itOrder != _attrOrder.end();
00174            ++itOrder ){
00175         _attrOrderChar[ i ] = (char*)malloc( ((*itOrder).length()+1)*sizeof(char) );
00176         strcpy( _attrOrderChar[ i ], (*itOrder).latin1() );
00177         ++i;
00178       }
00179       _attrOrderChar[ i ] = NULL;
00180     }
00181   }
00182   ~DNBeautifier()
00183   {
00184     int i=0;
00185     for( QStringList::ConstIterator itOrder = _attrOrder.begin();
00186          itOrder != _attrOrder.end();
00187          ++itOrder ){
00188       free( _attrOrderChar[ i ] );
00189       ++i;
00190     }
00191     delete[] _attrOrderChar;
00192   }
00193 
00194   QStringList attrOrder() const
00195   {
00196     return _attrOrder;
00197   }
00198   char** attrOrderChar()
00199   {
00200     return _attrOrderChar;
00201   }
00202 
00203   UnknownAttrsHandling unknownAttrsHandling() const
00204   {
00205     return _unknownAttrsHandling;
00206   }
00207   const char* unknownAttrsHandlingChar() const
00208   {
00209     return _unknownAttrsHandlingChar;
00210   }
00211 
00212   QValueList< QPair<QString,QString> > reorder( const QValueList< QPair<QString,QString> > & dn ) const
00213   {
00214     return reorder( dn, _attrOrder, _unknownAttrsHandling );
00215   }
00216 
00217 
00218   static QValueList< QPair<QString,QString> > reorder(
00219     const QValueList< QPair<QString,QString> > & dn,
00220     QStringList attrOrder,
00221     UnknownAttrsHandling unknownAttrsHandling )
00222   {
00223     if( !attrOrder.isEmpty() ){
00224       QPtrList<   QPair<QString,QString> > unknownEntries;
00225       QValueList< QPair<QString,QString> > dnNew;
00226 
00227       QPair<QString,QString>* unknownEntry;
00228       QStringList::ConstIterator itOrder;
00229       QValueList< QPair<QString,QString> >::ConstIterator itDN;
00230       bool bFound;
00231 
00232       if( unknownAttrsHandling != unknownAttrsHide ){
00233         // find all unknown entries in their order of appearance
00234         for( itDN = dn.begin(); itDN != dn.end(); ++itDN ){
00235           bFound = false;
00236           for( itOrder = attrOrder.begin(); itOrder != attrOrder.end(); ++itOrder ){
00237             if( (*itOrder) == (*itDN).first ){
00238               bFound = true;
00239               break;
00240             }
00241           }
00242           if( !bFound )
00243             unknownEntries.append( &(*itDN) );
00244         }
00245       }
00246 
00247       // prepend the unknown attrs (if desired)
00248       if( unknownAttrsHandling == unknownAttrsPrefix ){
00249         for( unknownEntry = unknownEntries.first(); unknownEntry; unknownEntry = unknownEntries.next() ){
00250           dnNew << *unknownEntry;
00251         }
00252       }
00253 
00254       // process the known attrs in the desired order
00255       bool b_X_declared = false;
00256       for( itOrder = attrOrder.begin(); itOrder != attrOrder.end(); ++itOrder ){
00257         if( (*itOrder) == "_X_" ){
00258           b_X_declared = true;
00259           // insert the unknown attrs (if desired)
00260           if( unknownAttrsHandling == unknownAttrsInfix ){
00261             for( unknownEntry = unknownEntries.first(); unknownEntry; unknownEntry = unknownEntries.next() ){
00262               dnNew << *unknownEntry;
00263             }
00264           }
00265         }else{
00266           for( itDN = dn.begin(); itDN != dn.end(); ++itDN ){
00267             if( (*itOrder) == (*itDN).first ){
00268               dnNew << *itDN;
00269               //kdDebug(5150) << QString((*itDN).first) <<" = " << QString((*itDN).second) << endl;;
00270             }
00271           }
00272         }
00273       }
00274 
00275       // append the unknown attrs (if desired)
00276       if( unknownAttrsHandling == unknownAttrsPostfix ||
00277           ( unknownAttrsHandling == unknownAttrsInfix && ! b_X_declared ) ){
00278         for( unknownEntry = unknownEntries.first(); unknownEntry; unknownEntry = unknownEntries.next() ){
00279           dnNew << *unknownEntry;
00280         }
00281       }
00282 
00283       return dnNew;
00284     }
00285     return dn;
00286   }
00287 
00288 private:
00289   QStringList _attrOrder;
00290   char**      _attrOrderChar;
00291   UnknownAttrsHandling _unknownAttrsHandling;
00292   QCString    _unknownAttrsHandlingChar;
00293 };
00294 
00295 
00296 
00297 /* special helper class to be used by signing/encrypting functions *******/
00298 
00299 
00300 
00301 StructuringInfoWrapper::StructuringInfoWrapper( CryptPlugWrapper* wrapper )
00302   : _initDone( false ), _wrapper( wrapper )
00303 {
00304     initMe();
00305 }
00306 StructuringInfoWrapper::~StructuringInfoWrapper()
00307 {
00308     freeMe();
00309 }
00310 void StructuringInfoWrapper::reset()
00311 {
00312     freeMe();
00313     initMe();
00314 }
00315 void StructuringInfoWrapper::initMe()
00316 {
00317     if ( _wrapper && _wrapper->cryptPlug() ) {
00318       _wrapper->cryptPlug()->init_StructuringInfo( &data );
00319       _initDone = true;
00320     }
00321 }
00322 void StructuringInfoWrapper::freeMe()
00323 {
00324     if( _wrapper && _wrapper->cryptPlug() && _initDone ) {
00325       _wrapper->cryptPlug()->free_StructuringInfo( &data );
00326       _initDone = false;
00327     }
00328 }
00329 
00330 class CryptPlugWrapper::Config {
00331 public:
00332   Config( gpgme_protocol_t proto );
00333   ~Config();
00334 
00335   const char*             signatureKeyCertificate;
00336   SignatureAlgorithm      signatureAlgorithm;
00337   SignatureCompoundMode   signatureCompoundMode;
00338   SendCertificates        sendCertificates;
00339   bool                    saveSentSignatures;
00340   bool                    warnNoCertificate;
00341   bool                    signatureUseCRLs;
00342   EncryptionAlgorithm     encryptionAlgorithm;
00343   EncryptEmail            encryptEmail;
00344   bool                    saveMessagesEncrypted;
00345   bool                    encryptionUseCRLs;
00346   bool                    encryptionCRLExpiryNearWarning;
00347   int                     encryptionCRLNearExpiryInterval;
00348   CertificateSource       certificateSource;
00349   bool                    warnSendUnsigned;
00350   bool                    signatureCertificateExpiryNearWarning;
00351   int                     signatureCertificateExpiryNearInterval;
00352   bool                    cACertificateExpiryNearWarning;
00353   int                     cACertificateExpiryNearInterval;
00354   bool                    rootCertificateExpiryNearWarning;
00355   int                     rootCertificateExpiryNearInterval;
00356   bool                    warnSendUnencrypted;
00357   bool                    checkCertificatePath;
00358   bool                    receiverCertificateExpiryNearWarning;
00359   int                     receiverCertificateExpiryNearWarningInterval;
00360   bool                    certificateInChainExpiryNearWarning;
00361   int                     certificateInChainExpiryNearWarningInterval;
00362   bool                    receiverEmailAddressNotInCertificateWarning;
00363   const char* libVersion; /* a statically allocated string with the GPGME Version used */
00364 };
00365 
00366 static const int NEAR_EXPIRY = 14;
00367 
00368 CryptPlugWrapper::Config::Config( gpgme_protocol_t proto )
00369 {
00370   signatureAlgorithm                   = SignAlg_SHA1;
00371   if ( proto == GPGME_PROTOCOL_CMS )
00372     signatureCompoundMode              = SignatureCompoundMode_Opaque;
00373   else
00374     signatureCompoundMode              = SignatureCompoundMode_Detached;
00375   sendCertificates                     = SendCert_SendChainWithRoot;
00376   saveSentSignatures                   = true;
00377   warnNoCertificate                    = true;
00378   signatureUseCRLs                     = true;
00379   encryptionAlgorithm                  = EncryptAlg_RSA;
00380   encryptEmail                         = EncryptEmail_Ask;
00381   saveMessagesEncrypted                = true;
00382   encryptionUseCRLs                    = true;
00383   encryptionCRLExpiryNearWarning       = false;
00384   encryptionCRLNearExpiryInterval      = NEAR_EXPIRY;
00385   certificateSource                    = CertSrc_Server;
00386   warnSendUnsigned                             = true;
00387   signatureCertificateExpiryNearWarning        = true;
00388   signatureCertificateExpiryNearInterval       = NEAR_EXPIRY;
00389   cACertificateExpiryNearWarning               = true;
00390   cACertificateExpiryNearInterval              = NEAR_EXPIRY;
00391   rootCertificateExpiryNearWarning             = true;
00392   rootCertificateExpiryNearInterval            = NEAR_EXPIRY;
00393   warnSendUnencrypted                          = false;
00394   checkCertificatePath                         = true;
00395   receiverCertificateExpiryNearWarning         = true;
00396   receiverCertificateExpiryNearWarningInterval = NEAR_EXPIRY;
00397   certificateInChainExpiryNearWarning          = true;
00398   certificateInChainExpiryNearWarningInterval  = NEAR_EXPIRY;
00399   receiverEmailAddressNotInCertificateWarning  = true;
00400   libVersion = gpgme_check_version (NULL);
00401 }
00402 
00403 CryptPlugWrapper::Config::~Config() {
00404 }
00405 
00406 /* Some multi purpose functions ******************************************/
00407 
00408 QString CryptPlugWrapper::errorIdToText( int errId, bool & isPassphraseError ) {
00409   const GpgME::Error err( errId );
00410   isPassphraseError = err.isCanceled()
00411     || gpgme_err_code( errId ) == GPG_ERR_NO_SECKEY ; // FIXME: more?
00412   return QString::fromLocal8Bit( err.asString() );
00413 }
00414 
00415 /* some special functions ************************************************/
00416 
00417 
00418 CryptPlugWrapper::CryptPlugWrapper( const QString& name,
00419                                     const QString& libName,
00420                                     const QString& update,
00421                                     bool           active )
00422   : Kleo::CryptoBackend::Protocol(),
00423     _name( name ),
00424     _libName( libName ),
00425     _updateURL( update ),
00426     _active(  active  ),
00427     _initStatus( InitStatus_undef ),
00428     _cp( 0 ),
00429     _config( 0 ),
00430     _cryptoConfig( 0 )
00431 {
00432   const bool ok = initialize( 0, 0 );
00433   assert( ok );
00434 }
00435 
00436 
00437 CryptPlugWrapper::~CryptPlugWrapper()
00438 {
00439     deinitialize();
00440 }
00441 
00442 
00443 void CryptPlugWrapper::setActive( bool active )
00444 {
00445     _active = active;
00446 }
00447 
00448 
00449 bool CryptPlugWrapper::active() const
00450 {
00451     return _active;
00452 }
00453 
00454 
00455 
00456 bool CryptPlugWrapper::setLibName( const QString& libName )
00457 {
00458     bool bOk = ! _cp;           // Changing the lib name is only allowed
00459     if( bOk )                   // when either no initialization took
00460         _libName = libName;     // place or 'deinitialize()' has been
00461     return bOk;                 // called afterwards.
00462 }
00463 
00464 QString CryptPlugWrapper::libName() const
00465 {
00466     return _libName;
00467 }
00468 
00469 QString CryptPlugWrapper::protocol() const
00470 {
00471   if ( _libName.contains( "smime" ) )
00472     return "SMIME";
00473   if ( _libName.contains( "openpgp" ) )
00474     return "OpenPGP";
00475   return QString::null;
00476 }
00477 
00478 void CryptPlugWrapper::setDisplayName( const QString& name )
00479 {
00480     _name = name;
00481 }
00482 
00483 
00484 QString CryptPlugWrapper::displayName() const
00485 {
00486     if ( !_name.isEmpty() )
00487       return _name;
00488     if ( _libName.contains( "smime" ) )
00489       return "gpgsm";
00490     if ( _libName.contains( "openpgp" ) )
00491       return "gpg";
00492     return i18n("(Unknown Protocol)");
00493 }
00494 
00495 bool CryptPlugWrapper::initialize( InitStatus* initStatus, QString* errorMsg )
00496 {
00497     if ( _cp )
00498       return true;
00499 
00500     _initStatus = InitStatus_undef;
00501     /* make sure we have a lib name */
00502     if ( _libName.isEmpty() ) {
00503       _initStatus = InitStatus_NoLibName;
00504       kdDebug(5150) << "No library name was given.\n" << endl;
00505     } else {
00506       if ( _libName.contains( "smime" ) ) {
00507     _cp = new SMIMECryptPlug();
00508     _config = new Config( GPGME_PROTOCOL_CMS );
00509       } else if ( _libName.contains( "openpgp" ) ) {
00510     _cp = new OpenPGPCryptPlug();
00511     _config = new Config( GPGME_PROTOCOL_OpenPGP );
00512       } else {
00513     _cp = 0;
00514     _config = 0;
00515       }
00516 
00517       if ( !_cp ) {
00518     _initStatus = InitStatus_LoadError;
00519     kdDebug(5150) << "Couldn't create '" << _libName.latin1() << "'" << endl;
00520       } else {
00521     /* now call the init function */
00522     if( !_cp->initialize() ) {
00523       _initStatus = InitStatus_InitError;
00524       kdDebug(5150) << "Error while executing function 'initialize' on plugin " << _libName << endl;
00525       _lastError = i18n("Error while initializing plugin \"%1\"").arg( _libName );
00526       if ( errorMsg )
00527         *errorMsg = _lastError;
00528       delete _cp; _cp = 0;
00529       delete _config; _config = 0;
00530     } else {
00531       _initStatus  = InitStatus_Ok;
00532     }
00533       }
00534     }
00535     if( initStatus )
00536         *initStatus = _initStatus;
00537     return _initStatus == InitStatus_Ok;
00538 }
00539 
00540 
00541 
00542 void CryptPlugWrapper::deinitialize()
00543 {
00544     delete _cp; _cp = 0;
00545     delete _config; _config = 0;
00546     delete _cryptoConfig; _cryptoConfig = 0;
00547 }
00548 
00549 
00550 CryptPlugWrapper::InitStatus CryptPlugWrapper::initStatus( QString* errorMsg ) const
00551 {
00552     if( errorMsg )
00553         *errorMsg = _lastError;
00554     return _initStatus;
00555 }
00556 
00557 
00558 bool CryptPlugWrapper::hasFeature( Feature flag )
00559 {
00560   return _cp && _cp->hasFeature( flag );
00561 }
00562 
00563 
00564 /* normal functions ******************************************************/
00565 
00566 bool CryptPlugWrapper::checkMessageSignature( char** cleartext,
00567                                               const char* signaturetext,
00568                                               bool signatureIsBinary,
00569                                               int signatureLen,
00570                                               CryptPlug::SignatureMetaData* sigmeta )
00571 {
00572   DNBeautifier dnBeautifier( kapp->config(),
00573                              "DN",
00574                              "AttributeOrder",
00575                              "UnknownAttributes" );
00576   return _cp && _cp->checkMessageSignature( cleartext,
00577                                             signaturetext,
00578                                             signatureIsBinary,
00579                                             signatureLen,
00580                                             sigmeta,
00581                                             dnBeautifier.attrOrderChar(),
00582                                             dnBeautifier.unknownAttrsHandlingChar() );
00583 }
00584 
00585 
00586 bool CryptPlugWrapper::decryptMessage( const char* ciphertext,
00587                                        bool        cipherIsBinary,
00588                                        int         cipherLen,
00589                                        char**      cleartext,
00590                                        const char* certificate,
00591                                        int* errId,
00592                                        char** errTxt )
00593 {
00594   return _cp && _cp->decryptMessage( ciphertext, cipherIsBinary, cipherLen,
00595                      (const char**)cleartext, certificate, errId, errTxt );
00596 }
00597 
00598 
00599 bool CryptPlugWrapper::decryptAndCheckMessage(
00600                             const char*  ciphertext,
00601                             bool         cipherIsBinary,
00602                             int          cipherLen,
00603                             char**       cleartext,
00604                             const char*  certificate,
00605                             bool*        signatureFound,
00606                             CryptPlug::SignatureMetaData* sigmeta,
00607                             int*   errId,
00608                             char** errTxt )
00609 {
00610   DNBeautifier dnBeautifier( kapp->config(),
00611                              "DN",
00612                              "AttributeOrder",
00613                              "UnknownAttributes" );
00614   return _cp && _cp->decryptAndCheckMessage( ciphertext,
00615                                              cipherIsBinary,
00616                                              cipherLen,
00617                                              (const char**)cleartext,
00618                                              certificate,
00619                                              signatureFound,
00620                                              sigmeta,
00621                                              errId,
00622                                              errTxt,
00623                                              dnBeautifier.attrOrderChar(),
00624                                              dnBeautifier.unknownAttrsHandlingChar() );
00625 }
00626 
00627 
00628 
00629 
00630 void CryptPlugWrapper::freeSignatureMetaData( CryptPlug::SignatureMetaData* sigmeta )
00631 {
00632     if ( !sigmeta )
00633       return;
00634     free( sigmeta->status );
00635     for( int i = 0; i < sigmeta->extended_info_count; ++i ) {
00636         free( sigmeta->extended_info[i].creation_time );
00637         free( (void*)sigmeta->extended_info[i].status_text );
00638         free( (void*)sigmeta->extended_info[i].keyid );
00639         free( (void*)sigmeta->extended_info[i].fingerprint );
00640         free( (void*)sigmeta->extended_info[i].algo );
00641         free( (void*)sigmeta->extended_info[i].userid );
00642         free( (void*)sigmeta->extended_info[i].name );
00643         free( (void*)sigmeta->extended_info[i].comment );
00644         if( sigmeta->extended_info[i].emailCount ){
00645             for( int j=0; j < sigmeta->extended_info[i].emailCount; ++j)
00646                 if( sigmeta->extended_info[i].emailList[j] )
00647                     free( (void*)sigmeta->extended_info[i].emailList[j] );
00648             free( (void*)sigmeta->extended_info[i].emailList );
00649         }
00650     }
00651     free( sigmeta->extended_info );
00652 }
00653 
00654 GpgME::ImportResult CryptPlugWrapper::importCertificate( const char* data, size_t length )
00655 {
00656     if ( !_cp )
00657       return GpgME::ImportResult();
00658 
00659 
00660    return _cp->importCertificateFromMem( data, length );
00661 }
00662 
00663 Kleo::KeyListJob * CryptPlugWrapper::keyListJob( bool remote, bool includeSigs, bool validate ) const {
00664   if ( !_cp )
00665     return 0;
00666 
00667   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00668   if ( !context )
00669     return 0;
00670 
00671   unsigned int mode = context->keyListMode();
00672   if ( remote ) {
00673     mode |= GpgME::Context::Extern;
00674     mode &= ~GpgME::Context::Local;
00675   } else {
00676     mode |= GpgME::Context::Local;
00677     mode &= ~GpgME::Context::Extern;
00678   }
00679   if ( includeSigs ) mode |= GpgME::Context::Signatures;
00680   if ( validate ) mode |= GpgME::Context::Validate;
00681   context->setKeyListMode( mode );
00682   return new Kleo::QGpgMEKeyListJob( context );
00683 }
00684 
00685 Kleo::EncryptJob * CryptPlugWrapper::encryptJob( bool armor, bool textmode ) const {
00686   if ( !_cp )
00687     return 0;
00688 
00689   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00690   if ( !context )
00691     return 0;
00692 
00693   context->setArmor( armor );
00694   context->setTextMode( textmode );
00695   return new Kleo::QGpgMEEncryptJob( context );
00696 }
00697 
00698 Kleo::DecryptJob * CryptPlugWrapper::decryptJob() const {
00699   if ( !_cp )
00700     return 0;
00701 
00702   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00703   if ( !context )
00704     return 0;
00705 
00706   return new Kleo::QGpgMEDecryptJob( context );
00707 }
00708 
00709 Kleo::SignJob * CryptPlugWrapper::signJob( bool armor, bool textMode ) const {
00710   if ( !_cp )
00711     return 0;
00712 
00713   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00714   if ( !context )
00715     return 0;
00716 
00717   context->setArmor( armor );
00718   context->setTextMode( textMode );
00719 
00720   return new Kleo::QGpgMESignJob( context );
00721 }
00722 
00723 Kleo::VerifyDetachedJob * CryptPlugWrapper::verifyDetachedJob( bool textMode ) const {
00724   if ( !_cp )
00725     return 0;
00726 
00727   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00728   if ( !context )
00729     return 0;
00730 
00731   context->setTextMode( textMode );
00732 
00733   return new Kleo::QGpgMEVerifyDetachedJob( context );
00734 }
00735 
00736 Kleo::VerifyOpaqueJob * CryptPlugWrapper::verifyOpaqueJob( bool textMode ) const {
00737   if ( !_cp )
00738     return 0;
00739 
00740   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00741   if ( !context )
00742     return 0;
00743 
00744   context->setTextMode( textMode );
00745 
00746   return new Kleo::QGpgMEVerifyOpaqueJob( context );
00747 }
00748 
00749 Kleo::KeyGenerationJob * CryptPlugWrapper::keyGenerationJob() const {
00750   if ( !_cp )
00751     return 0;
00752 
00753   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00754   if ( !context )
00755     return 0;
00756 
00757   return new Kleo::QGpgMEKeyGenerationJob( context );
00758 }
00759 
00760 Kleo::ImportJob * CryptPlugWrapper::importJob() const {
00761   if ( !_cp )
00762     return 0;
00763 
00764   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00765   if ( !context )
00766     return 0;
00767 
00768   return new Kleo::QGpgMEImportJob( context );
00769 }
00770 
00771 Kleo::ExportJob * CryptPlugWrapper::publicKeyExportJob( bool armor ) const {
00772   if ( !_cp )
00773     return 0;
00774 
00775   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00776   if ( !context )
00777     return 0;
00778 
00779   context->setArmor( armor );
00780   return new Kleo::QGpgMEExportJob( context );
00781 }
00782 
00783 Kleo::ExportJob * CryptPlugWrapper::secretKeyExportJob( bool armor ) const {
00784   if ( !_cp || _cp->mProtocol != GpgME::Context::CMS ) // fixme: add support for gpg, too
00785     return 0;
00786 
00787   // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
00788   return new Kleo::QGpgMESecretKeyExportJob( armor );
00789 }
00790 
00791 Kleo::RefreshKeysJob * CryptPlugWrapper::refreshKeysJob() const {
00792   if ( !_cp || _cp->mProtocol != GpgME::Context::CMS ) // fixme: add support for gpg, too
00793     return 0;
00794 
00795   // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
00796   return new Kleo::QGpgMERefreshKeysJob();
00797 }
00798 
00799 Kleo::DownloadJob * CryptPlugWrapper::downloadJob( bool armor ) const {
00800   if ( !_cp )
00801     return 0;
00802 
00803   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00804   if ( !context )
00805     return 0;
00806 
00807   context->setArmor( armor );
00808   // this is the hackish interface for downloading from keyserers currently:
00809   context->setKeyListMode( GpgME::Context::Extern );
00810 
00811   return new Kleo::QGpgMEDownloadJob( context );
00812 }
00813 
00814 Kleo::DeleteJob * CryptPlugWrapper::deleteJob() const {
00815   if ( !_cp )
00816     return 0;
00817 
00818   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00819   if ( !context )
00820     return 0;
00821 
00822   return new Kleo::QGpgMEDeleteJob( context );
00823 }
00824 
00825 Kleo::SignEncryptJob * CryptPlugWrapper::signEncryptJob( bool armor, bool textMode ) const {
00826   if ( !_cp )
00827     return 0;
00828 
00829   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00830   if ( !context )
00831     return 0;
00832 
00833   context->setArmor( armor );
00834   context->setTextMode( textMode );
00835 
00836   return new Kleo::QGpgMESignEncryptJob( context );
00837 }
00838 
00839 Kleo::DecryptVerifyJob * CryptPlugWrapper::decryptVerifyJob( bool textMode ) const {
00840   if ( !_cp )
00841     return 0;
00842 
00843   GpgME::Context * context = GpgME::Context::createForProtocol( _cp->mProtocol );
00844   if ( !context )
00845     return 0;
00846 
00847   context->setTextMode( textMode );
00848 
00849   return new Kleo::QGpgMEDecryptVerifyJob( context );
00850 }
KDE Home | KDE Accessibility Home | Description of Access Keys