00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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>
00045 #include <gpgmepp/key.h>
00046
00047 #include <vector>
00048
00049 class QStringList;
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 QString & 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 QString & 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 QStringList & fingerprints );
00173 Kpgp::Result setSigningKeys( const QStringList & fingerprints );
00178 void setPrimaryRecipients( const QStringList & addresses );
00183 void setSecondaryRecipients( const QStringList & 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 QStringList & r ) : recipients( r ) {}
00214 SplitInfo( const QStringList & r, const std::vector<GpgME::Key> & k )
00215 : recipients( r ), keys( k ) {}
00216 QStringList 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 QStringList & recipients );
00228 std::vector<GpgME::Key> getEncryptionKeys( const QString & 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 QStringList 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 QStringList & patterns, bool secret=false ) const;
00250
00251 bool haveTrustedEncryptionKey( const QString & person ) const;
00252
00253 std::vector<GpgME::Key> selectKeys( const QString & person, const QString & msg,
00254 const std::vector<GpgME::Key> & selectedKeys=std::vector<GpgME::Key>() ) const;
00255
00256 QStringList keysForAddress( const QString & address ) const;
00257 void setKeysForAddress( const QString & address, const QStringList& pgpKeyFingerprints, const QStringList& 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 QStringList pgpKeyFingerprints;
00289 QStringList smimeCertFingerprints;
00290 };
00291
00292 ContactPreferences lookupContactPreferences( const QString& address ) const;
00293 void saveContactPreference( const QString& 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 }
00318
00319 #endif // __KLEO_KEYRESOLVER_H__