libkdenetwork Library API Documentation

kpgp.h

00001 /*
00002     kpgp.h
00003 
00004     Copyright (C) 2001,2002 the KPGP authors
00005     See file AUTHORS.kpgp for details
00006 
00007     This file is part of KPGP, the KDE PGP/GnuPG support library.
00008 
00009     KPGP is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software Foundation,
00016     Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00017  */
00018 
00019 #ifndef KPGP_H
00020 #define KPGP_H
00021 
00022 #include <stdio.h>
00023 #include <qstring.h>
00024 #include <qstrlist.h>
00025 #include <qdialog.h>
00026 #include <qwidget.h>
00027 #include <qcombobox.h>
00028 #include <qlayout.h>
00029 #include <qpushbutton.h>
00030 #include <qlistview.h>
00031 #include <qbuttongroup.h>
00032 #include <qradiobutton.h>
00033 #include <qmultilineedit.h>
00034 #include <qcheckbox.h>
00035 
00036 #include <kdialogbase.h>
00037 
00038 #include "kpgpkey.h"
00039 
00040 class QLineEdit;
00041 class QCursor;
00042 class QCheckBox;
00043 class QGridLayout;
00044 
00045 class KConfig;
00046 
00047 namespace Kpgp {
00048 
00059 enum { PublicKeys = 1,
00060        SecretKeys = 2,
00061        EncryptionKeys = 4,
00062        SigningKeys = 8,
00063        ValidKeys = 16,
00064        TrustedKeys = 32,
00065        AllKeys = PublicKeys | SecretKeys | EncryptionKeys | SigningKeys,
00066        PubSecKeys = PublicKeys | SecretKeys,
00067        EncrSignKeys = EncryptionKeys | SigningKeys
00068 };
00069 
00070 enum Result
00071 {
00072        Failure = 0,
00073        Ok = 1,
00074        Canceled = 2
00075 };
00076 
00077 class Base;
00078 class Block;
00079 
00080 class Module
00081 {
00082   friend class Block;
00083 
00084 private:
00085     // the class running pgp
00086     Base *pgp;
00087 
00088 public:
00089     Module();
00090     virtual ~Module();
00091 
00095   virtual void readConfig();
00096   virtual void writeConfig(bool sync);
00097   virtual void init();
00098 
00101   bool decrypt( Block& block );
00102 
00104   bool verify( Block& block );
00105 
00113   Kpgp::Result clearsign( Block& block,
00114                   const KeyID& keyId, const QCString& charset = 0 );
00115 
00124   Kpgp::Result encrypt( Block& block,
00125                 const QStringList& receivers, const KeyID& keyId,
00126                 bool sign, const QCString& charset = 0 );
00127 
00135   Kpgp::Result getEncryptionKeys( KeyIDList& encryptionKeyIds,
00136                                   const QStringList& recipients,
00137                                   const KeyID& keyId );
00138 
00148   int encryptionPossible( const QStringList& recipients );
00149 
00150 protected:
00151   int doEncSign( Block& block, const KeyIDList& recipientKeyIds, bool sign );
00152 
00153 public:
00155   bool signKey( const KeyID& keyID );
00156 
00158   const KeyList publicKeys();
00159 
00161   const KeyList secretKeys();
00162 
00165   void readPublicKeys( bool reread = false );
00166 
00169   void readSecretKeys( bool reread = false );
00170 
00172   QCString getAsciiPublicKey( const KeyID& keyID );
00173 
00177   Key* publicKey( const KeyID& keyID );
00178 
00182   Key* publicKey( const QString& userID );
00183 
00187   Key* secretKey( const KeyID& keyID );
00188 
00192   Validity keyTrust( const KeyID& keyID );
00193 
00198   Validity keyTrust( const QString& userID );
00199 
00203   bool isTrusted( const KeyID& keyID );
00204 
00208   Key* rereadKey( const KeyID& keyID, const bool readTrust = true );
00209 
00212   bool changePassPhrase();
00213 
00216   void setUser(const KeyID& keyID);
00218   const KeyID user() const;
00219 
00221   void setEncryptToSelf(bool flag);
00222   bool encryptToSelf(void) const;
00223 
00229   void setStorePassPhrase(bool);
00230   bool storePassPhrase(void) const;
00231 
00233   void clear(const bool erasePassPhrase = FALSE);
00234 
00236   const QString lastErrorMsg(void) const;
00237 
00238   // what version of PGP/GPG should we use
00239   enum PGPType { tAuto, tGPG, tPGP2, tPGP5, tPGP6, tOff } pgpType;
00240 
00241   // did we find a pgp executable?
00242   bool havePGP(void) const;
00243 
00245   bool usePGP(void) const { return (havePGP() && (pgpType != tOff)); }
00246 
00247   // show the result of encryption/signing?
00248   void setShowCipherText(const bool flag);
00249   bool showCipherText(void) const;
00250 
00251   // show the encryption keys for approval?
00252   void setShowKeyApprovalDlg(const bool flag);
00253   bool showKeyApprovalDlg(void) const;
00254 
00259   KeyID selectSecretKey( const QString& title,
00260                          const QString& text = QString::null,
00261                          const KeyID& keyId = KeyID() );
00262 
00269   KeyID selectPublicKey( const QString& title,
00270                          const QString& text = QString::null,
00271                          const KeyID& oldKeyId = KeyID(),
00272                          const QString& address = QString::null,
00273                          const unsigned int allowedKeys = AllKeys );
00274 
00281   KeyIDList selectPublicKeys( const QString& title,
00282                               const QString& text = QString::null,
00283                               const KeyIDList& oldKeyIds = KeyIDList(),
00284                               const QString& address = QString::null,
00285                               const unsigned int allowedKeys = AllKeys );
00286 
00287   // FIXME: key management
00288 
00292   EncryptPref encryptionPreference( const QString& address );
00293 
00297   void setEncryptionPreference( const QString& address,
00298                                 const EncryptPref pref );
00299 
00300   // -- static member functions --------------------------------------------
00301 
00303   static Kpgp::Module *getKpgp();
00304 
00306   static KConfig *getConfig();
00307 
00322   static bool prepareMessageForDecryption( const QCString& msg,
00323                                            QPtrList<Block>& pgpBlocks,
00324                                            QStrList& nonPgpBlocks );
00325 
00326 private:
00328   bool haveTrustedEncryptionKey( const QString& person );
00329 
00331   KeyIDList getEncryptionKeys( const QString& person );
00332 
00334   bool setPassPhrase(const char* pass);
00335 
00342   int prepare(bool needPassPhrase=FALSE, Block* block = 0 );
00343 
00345   void cleanupPass() { if (!storePass) wipePassPhrase(); }
00346 
00349   void wipePassPhrase(bool free=false);
00350 
00351   // transform an address into canonical form
00352   QString canonicalAddress( const QString& person );
00353 
00356   KeyID selectKey( const KeyList& keys,
00357                    const QString& title,
00358                    const QString& text = QString::null,
00359                    const KeyID& keyId = KeyID(),
00360                    const unsigned int allowedKeys = AllKeys );
00361 
00364   KeyIDList selectKeys( const KeyList& keys,
00365                         const QString& title,
00366                         const QString& text = QString::null,
00367                         const KeyIDList& keyIds = KeyIDList(),
00368                         const unsigned int allowedKeys = AllKeys );
00369 
00374   KeyID selectKey( bool& rememberChoice,
00375                    const KeyList& keys,
00376                    const QString& title,
00377                    const QString& text = QString::null,
00378                    const KeyID& keyId = KeyID(),
00379                    const unsigned int allowedKeys = AllKeys );
00380 
00385   KeyIDList selectKeys( bool& rememberChoice,
00386                         const KeyList& keys,
00387                         const QString& title,
00388                         const QString& text = QString::null,
00389                         const KeyIDList& keyIds = KeyIDList(),
00390                         const unsigned int allowedKeys = AllKeys );
00391 
00395   KeyIDList keysForAddress( const QString& address );
00396 
00399   void setKeysForAddress( const QString& address, const KeyIDList& keyIDs );
00400 
00402   void removeKeyForAddress( const QString& address );
00403 
00407   void readAddressData();
00408 
00412   void writeAddressData();
00413 
00414   bool checkForPGP(void);
00415   void assignPGPBase(void);
00416 
00417   static Kpgp::Module *kpgpObject;
00418   KConfig *config;
00419 
00420   struct AddressData {
00421     KeyIDList keyIds;
00422     EncryptPref encrPref;
00423   };
00424   typedef QMap<QString, AddressData> AddressDataDict;
00425   AddressDataDict addressDataDict;
00426 
00427   KeyList mPublicKeys;
00428   bool mPublicKeysCached : 1; // did we already read the public keys?
00429   KeyList mSecretKeys;
00430   bool mSecretKeysCached : 1; // did we already read the secret keys?
00431 
00432   bool storePass : 1;
00433   char * passphrase;
00434   size_t passphrase_buffer_len;
00435 
00436   QString errMsg;
00437 
00438   KeyID pgpUser; // the key ID which is used to sign/encrypt to self
00439   bool flagEncryptToSelf : 1;
00440 
00441   bool havePgp : 1;
00442   bool havePGP5 : 1;
00443   bool haveGpg : 1;
00444   bool havePassPhrase : 1;
00445   bool showEncryptionResult : 1;
00446   bool mShowKeyApprovalDlg : 1;
00447 }; // class Module
00448 
00449 // -- inlined member functions ---------------------------------------------
00450 
00451 inline void
00452 Module::setShowKeyApprovalDlg( const bool flag )
00453 {
00454   mShowKeyApprovalDlg = flag;
00455 }
00456 
00457 inline bool
00458 Module::showKeyApprovalDlg( void ) const
00459 {
00460   return mShowKeyApprovalDlg;
00461 }
00462 
00463 // -------------------------------------------------------------------------
00464 
00465 } // namespace Kpgp
00466 
00467 #endif
00468 
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 17 09:52:21 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003