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