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 "libkleo/ui/keyapprovaldialog.h"
00041 #include "kleo/enum.h"
00042
00043 #include <libkpgp/kpgp.h>
00044 #include <gpgme++/key.h>
00045
00046 #include <vector>
00047
00048 class QStringList;
00049
00050 namespace Kleo {
00051
00052
00126 class KeyResolver {
00127 public:
00128 KeyResolver( bool encToSelf, bool showApproval, bool oppEncryption,
00129 unsigned int format,
00130 int encrKeyNearExpiryThresholdDays,
00131 int signKeyNearExpiryThresholdDays,
00132 int encrRootCertNearExpiryThresholdDays,
00133 int signRootCertNearExpiryThresholdDays,
00134 int encrChainCertNearExpiryThresholdDays,
00135 int signChainCertNearExpiryThresholdDays );
00136
00137 ~KeyResolver();
00138
00139 struct Item : public KeyApprovalDialog::Item {
00140 Item()
00141 : KeyApprovalDialog::Item(),
00142 signPref( UnknownSigningPreference ),
00143 format( AutoFormat ),
00144 needKeys( true ) {}
00145 Item( const QString & a,
00146 EncryptionPreference e, SigningPreference s,
00147 CryptoMessageFormat f )
00148 : KeyApprovalDialog::Item( a, std::vector<GpgME::Key>(), e ),
00149 signPref( s ), format( f ), needKeys( true ) {}
00150 Item( const QString & a, const std::vector<GpgME::Key> & k,
00151 EncryptionPreference e, SigningPreference s,
00152 CryptoMessageFormat f )
00153 : KeyApprovalDialog::Item( a, k, e ),
00154 signPref( s ), format( f ), needKeys( false ) {}
00155
00156 SigningPreference signPref;
00157 CryptoMessageFormat format;
00158 bool needKeys;
00159 };
00160
00161
00167 Kpgp::Result setEncryptToSelfKeys( const QStringList & fingerprints );
00172 Kpgp::Result setSigningKeys( const QStringList & fingerprints );
00177 void setPrimaryRecipients( const QStringList & addresses );
00182 void setSecondaryRecipients( const QStringList & addresses );
00183
00184
00190 Action checkSigningPreferences( bool signingRequested ) const;
00196 Action checkEncryptionPreferences( bool encryptionRequested ) const;
00197
00202 Kpgp::Result resolveAllKeys( bool& signingRequested, bool& encryptionRequested );
00203
00208 std::vector<GpgME::Key> signingKeys( CryptoMessageFormat f ) const;
00209
00210 struct SplitInfo {
00211 SplitInfo() {}
00212 SplitInfo( const QStringList & r ) : recipients( r ) {}
00213 SplitInfo( const QStringList & r, const std::vector<GpgME::Key> & k )
00214 : recipients( r ), keys( k ) {}
00215 QStringList recipients;
00216 std::vector<GpgME::Key> keys;
00217 };
00222 std::vector<SplitInfo> encryptionItems( CryptoMessageFormat f ) const;
00223
00224 private:
00225 void dump() const;
00226 std::vector<Item> getEncryptionItems( const QStringList & recipients );
00227 std::vector<GpgME::Key> getEncryptionKeys( const QString & recipient, bool quiet ) const;
00228
00229 Kpgp::Result showKeyApprovalDialog();
00230
00231 bool encryptionPossible() const;
00232 bool signingPossible() const;
00233 Kpgp::Result resolveEncryptionKeys( bool signingRequested );
00234 Kpgp::Result resolveSigningKeysForEncryption();
00235 Kpgp::Result resolveSigningKeysForSigningOnly();
00236 Kpgp::Result checkKeyNearExpiry( const GpgME::Key & key,
00237 const char * dontAskAgainName, bool mine,
00238 bool sign, bool ca=false, int recurse_limit=100,
00239 const GpgME::Key & orig_key=GpgME::Key::null ) const;
00240 void collapseAllSplitInfos();
00241 void addToAllSplitInfos( const std::vector<GpgME::Key> & keys, unsigned int formats );
00242 void addKeys( const std::vector<Item> & items, CryptoMessageFormat f );
00243 void addKeys( const std::vector<Item> & items );
00244 QStringList allRecipients() const;
00245 std::vector<GpgME::Key> signingKeysFor( CryptoMessageFormat f ) const;
00246 std::vector<GpgME::Key> encryptToSelfKeysFor( CryptoMessageFormat f ) const;
00247
00248 std::vector<GpgME::Key> lookup( const QStringList & patterns, bool secret=false ) const;
00249
00250 bool haveTrustedEncryptionKey( const QString & person ) const;
00251
00252 std::vector<GpgME::Key> selectKeys( const QString & person, const QString & msg,
00253 const std::vector<GpgME::Key> & selectedKeys=std::vector<GpgME::Key>() ) const;
00254
00255 QStringList keysForAddress( const QString & address ) const;
00256 void setKeysForAddress( const QString & address, const QStringList& pgpKeyFingerprints, const QStringList& smimeCertFingerprints ) const;
00257
00258 bool encryptToSelf() const { return mEncryptToSelf; }
00259 bool showApprovalDialog() const { return mShowApprovalDialog; }
00260
00261 int encryptKeyNearExpiryWarningThresholdInDays() const {
00262 return mEncryptKeyNearExpiryWarningThreshold;
00263 }
00264 int signingKeyNearExpiryWarningThresholdInDays() const {
00265 return mSigningKeyNearExpiryWarningThreshold;
00266 }
00267
00268 int encryptRootCertNearExpiryWarningThresholdInDays() const {
00269 return mEncryptRootCertNearExpiryWarningThreshold;
00270 }
00271 int signingRootCertNearExpiryWarningThresholdInDays() const {
00272 return mSigningRootCertNearExpiryWarningThreshold;
00273 }
00274
00275 int encryptChainCertNearExpiryWarningThresholdInDays() const {
00276 return mEncryptChainCertNearExpiryWarningThreshold;
00277 }
00278 int signingChainCertNearExpiryWarningThresholdInDays() const {
00279 return mSigningChainCertNearExpiryWarningThreshold;
00280 }
00281
00282 struct ContactPreferences {
00283 ContactPreferences();
00284 Kleo::EncryptionPreference encryptionPreference;
00285 Kleo::SigningPreference signingPreference;
00286 Kleo::CryptoMessageFormat cryptoMessageFormat;
00287 QStringList pgpKeyFingerprints;
00288 QStringList smimeCertFingerprints;
00289 };
00290
00291 ContactPreferences lookupContactPreferences( const QString& address ) const;
00292 void saveContactPreference( const QString& email, const ContactPreferences& pref ) const;
00293
00294 private:
00295 class EncryptionPreferenceCounter;
00296 friend class ::Kleo::KeyResolver::EncryptionPreferenceCounter;
00297 class SigningPreferenceCounter;
00298 friend class ::Kleo::KeyResolver::SigningPreferenceCounter;
00299
00300 struct Private;
00301 Private * d;
00302
00303 bool mEncryptToSelf;
00304 const bool mShowApprovalDialog : 1;
00305 const bool mOpportunisticEncyption : 1;
00306 const unsigned int mCryptoMessageFormats;
00307
00308 const int mEncryptKeyNearExpiryWarningThreshold;
00309 const int mSigningKeyNearExpiryWarningThreshold;
00310 const int mEncryptRootCertNearExpiryWarningThreshold;
00311 const int mSigningRootCertNearExpiryWarningThreshold;
00312 const int mEncryptChainCertNearExpiryWarningThreshold;
00313 const int mSigningChainCertNearExpiryWarningThreshold;
00314 };
00315
00316 }
00317
00318 #endif // __KLEO_KEYRESOLVER_H__