keyresolver.h
00001 /* -*- c++ -*- 00002 keyresolver.h 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Based on kpgp.h 00008 Copyright (C) 2001,2002 the KPGP authors 00009 See file libtdenetwork/AUTHORS.kpgp for details 00010 00011 Libkleopatra is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License as 00013 published by the Free Software Foundation; either version 2 of the 00014 License, or (at your option) any later version. 00015 00016 Libkleopatra is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with this program; if not, write to the Free Software 00023 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 In addition, as a special exception, the copyright holders give 00026 permission to link the code of this program with any edition of 00027 the TQt library by Trolltech AS, Norway (or with modified versions 00028 of TQt that use the same license as TQt), and distribute linked 00029 combinations including the two. You must obey the GNU General 00030 Public License in all respects for all of the code used other than 00031 TQt. If you modify this file, you may extend this exception to 00032 your version of the file, but you are not obligated to do so. If 00033 you do not wish to do so, delete this exception statement from 00034 your version. 00035 */ 00036 00037 #ifndef __KLEO_KEYRESOLVER_H__ 00038 #define __KLEO_KEYRESOLVER_H__ 00039 00040 #include <ui/keyapprovaldialog.h> 00041 00042 #include <kleo/enum.h> 00043 00044 #include <kpgp.h> // for Kpgp::Result 00045 #include <gpgmepp/key.h> 00046 00047 #include <vector> 00048 00049 class TQStringList; 00050 00051 namespace Kleo { 00052 00053 00127 class KeyResolver { 00128 public: 00129 KeyResolver( bool encToSelf, bool showApproval, bool oppEncryption, 00130 unsigned int format, 00131 int encrKeyNearExpiryThresholdDays, 00132 int signKeyNearExpiryThresholdDays, 00133 int encrRootCertNearExpiryThresholdDays, 00134 int signRootCertNearExpiryThresholdDays, 00135 int encrChainCertNearExpiryThresholdDays, 00136 int signChainCertNearExpiryThresholdDays ); 00137 00138 ~KeyResolver(); 00139 00140 struct Item : public KeyApprovalDialog::Item { 00141 Item() 00142 : KeyApprovalDialog::Item(), 00143 signPref( UnknownSigningPreference ), 00144 format( AutoFormat ), 00145 needKeys( true ) {} 00146 Item( const TQString & a, 00147 EncryptionPreference e, SigningPreference s, 00148 CryptoMessageFormat f ) 00149 : KeyApprovalDialog::Item( a, std::vector<GpgME::Key>(), e ), 00150 signPref( s ), format( f ), needKeys( true ) {} 00151 Item( const TQString & a, const std::vector<GpgME::Key> & k, 00152 EncryptionPreference e, SigningPreference s, 00153 CryptoMessageFormat f ) 00154 : KeyApprovalDialog::Item( a, k, e ), 00155 signPref( s ), format( f ), needKeys( false ) {} 00156 00157 SigningPreference signPref; 00158 CryptoMessageFormat format; 00159 bool needKeys; 00160 }; 00161 00162 00168 Kpgp::Result setEncryptToSelfKeys( const TQStringList & fingerprints ); 00173 Kpgp::Result setSigningKeys( const TQStringList & fingerprints ); 00178 void setPrimaryRecipients( const TQStringList & addresses ); 00183 void setSecondaryRecipients( const TQStringList & addresses ); 00184 00185 00191 Action checkSigningPreferences( bool signingRequested ) const; 00197 Action checkEncryptionPreferences( bool encryptionRequested ) const; 00198 00203 Kpgp::Result resolveAllKeys( bool& signingRequested, bool& encryptionRequested ); 00204 00209 std::vector<GpgME::Key> signingKeys( CryptoMessageFormat f ) const; 00210 00211 struct SplitInfo { 00212 SplitInfo() {} 00213 SplitInfo( const TQStringList & r ) : recipients( r ) {} 00214 SplitInfo( const TQStringList & r, const std::vector<GpgME::Key> & k ) 00215 : recipients( r ), keys( k ) {} 00216 TQStringList recipients; 00217 std::vector<GpgME::Key> keys; 00218 }; 00223 std::vector<SplitInfo> encryptionItems( CryptoMessageFormat f ) const; 00224 00225 private: 00226 void dump() const; 00227 std::vector<Item> getEncryptionItems( const TQStringList & recipients ); 00228 std::vector<GpgME::Key> getEncryptionKeys( const TQString & recipient, bool quiet ) const; 00229 00230 Kpgp::Result showKeyApprovalDialog(); 00231 00232 bool encryptionPossible() const; 00233 bool signingPossible() const; 00234 Kpgp::Result resolveEncryptionKeys( bool signingRequested ); 00235 Kpgp::Result resolveSigningKeysForEncryption(); 00236 Kpgp::Result resolveSigningKeysForSigningOnly(); 00237 Kpgp::Result checkKeyNearExpiry( const GpgME::Key & key, 00238 const char * dontAskAgainName, bool mine, 00239 bool sign, bool ca=false, int recurse_limit=100, 00240 const GpgME::Key & orig_key=GpgME::Key::null ) const; 00241 void collapseAllSplitInfos(); 00242 void addToAllSplitInfos( const std::vector<GpgME::Key> & keys, unsigned int formats ); 00243 void addKeys( const std::vector<Item> & items, CryptoMessageFormat f ); 00244 void addKeys( const std::vector<Item> & items ); 00245 TQStringList allRecipients() const; 00246 std::vector<GpgME::Key> signingKeysFor( CryptoMessageFormat f ) const; 00247 std::vector<GpgME::Key> encryptToSelfKeysFor( CryptoMessageFormat f ) const; 00248 00249 std::vector<GpgME::Key> lookup( const TQStringList & patterns, bool secret=false ) const; 00250 00251 bool haveTrustedEncryptionKey( const TQString & person ) const; 00252 00253 std::vector<GpgME::Key> selectKeys( const TQString & person, const TQString & msg, 00254 const std::vector<GpgME::Key> & selectedKeys=std::vector<GpgME::Key>() ) const; 00255 00256 TQStringList keysForAddress( const TQString & address ) const; 00257 void setKeysForAddress( const TQString & address, const TQStringList& pgpKeyFingerprints, const TQStringList& smimeCertFingerprints ) const; 00258 00259 bool encryptToSelf() const { return mEncryptToSelf; } 00260 bool showApprovalDialog() const { return mShowApprovalDialog; } 00261 00262 int encryptKeyNearExpiryWarningThresholdInDays() const { 00263 return mEncryptKeyNearExpiryWarningThreshold; 00264 } 00265 int signingKeyNearExpiryWarningThresholdInDays() const { 00266 return mSigningKeyNearExpiryWarningThreshold; 00267 } 00268 00269 int encryptRootCertNearExpiryWarningThresholdInDays() const { 00270 return mEncryptRootCertNearExpiryWarningThreshold; 00271 } 00272 int signingRootCertNearExpiryWarningThresholdInDays() const { 00273 return mSigningRootCertNearExpiryWarningThreshold; 00274 } 00275 00276 int encryptChainCertNearExpiryWarningThresholdInDays() const { 00277 return mEncryptChainCertNearExpiryWarningThreshold; 00278 } 00279 int signingChainCertNearExpiryWarningThresholdInDays() const { 00280 return mSigningChainCertNearExpiryWarningThreshold; 00281 } 00282 00283 struct ContactPreferences { 00284 ContactPreferences(); 00285 Kleo::EncryptionPreference encryptionPreference; 00286 Kleo::SigningPreference signingPreference; 00287 Kleo::CryptoMessageFormat cryptoMessageFormat; 00288 TQStringList pgpKeyFingerprints; 00289 TQStringList smimeCertFingerprints; 00290 }; 00291 00292 ContactPreferences lookupContactPreferences( const TQString& address ) const; 00293 void saveContactPreference( const TQString& email, const ContactPreferences& pref ) const; 00294 00295 private: 00296 class EncryptionPreferenceCounter; 00297 friend class ::Kleo::KeyResolver::EncryptionPreferenceCounter; 00298 class SigningPreferenceCounter; 00299 friend class ::Kleo::KeyResolver::SigningPreferenceCounter; 00300 00301 class Private; 00302 Private * d; 00303 00304 bool mEncryptToSelf; 00305 const bool mShowApprovalDialog : 1; 00306 const bool mOpportunisticEncyption : 1; 00307 const unsigned int mCryptoMessageFormats; 00308 00309 const int mEncryptKeyNearExpiryWarningThreshold; 00310 const int mSigningKeyNearExpiryWarningThreshold; 00311 const int mEncryptRootCertNearExpiryWarningThreshold; 00312 const int mSigningRootCertNearExpiryWarningThreshold; 00313 const int mEncryptChainCertNearExpiryWarningThreshold; 00314 const int mSigningChainCertNearExpiryWarningThreshold; 00315 }; 00316 00317 } // namespace Kleo 00318 00319 #endif // __KLEO_KEYRESOLVER_H__