kmail

keyresolver.h
1 /*
2  keyresolver.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Based on kpgp.h
8  Copyright (C) 2001,2002 the KPGP authors
9  See file libtdenetwork/AUTHORS.kpgp for details
10 
11  Libkleopatra is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15 
16  Libkleopatra is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 
25  In addition, as a special exception, the copyright holders give
26  permission to link the code of this program with any edition of
27  the TQt library by Trolltech AS, Norway (or with modified versions
28  of TQt that use the same license as TQt), and distribute linked
29  combinations including the two. You must obey the GNU General
30  Public License in all respects for all of the code used other than
31  TQt. If you modify this file, you may extend this exception to
32  your version of the file, but you are not obligated to do so. If
33  you do not wish to do so, delete this exception statement from
34  your version.
35 */
36 
37 #ifndef __KLEO_KEYRESOLVER_H__
38 #define __KLEO_KEYRESOLVER_H__
39 
40 #include <ui/keyapprovaldialog.h>
41 
42 #include <kleo/enum.h>
43 
44 #include <kpgp.h> // for Kpgp::Result
45 #include <gpgmepp/key.h>
46 
47 #include <vector>
48 
49 class TQStringList;
50 
51 namespace Kleo {
52 
53 
127  class KeyResolver {
128  public:
129  KeyResolver( bool encToSelf, bool showApproval, bool oppEncryption,
130  unsigned int format,
131  int encrKeyNearExpiryThresholdDays,
132  int signKeyNearExpiryThresholdDays,
133  int encrRootCertNearExpiryThresholdDays,
134  int signRootCertNearExpiryThresholdDays,
135  int encrChainCertNearExpiryThresholdDays,
136  int signChainCertNearExpiryThresholdDays );
137 
138  ~KeyResolver();
139 
140  struct Item : public KeyApprovalDialog::Item {
141  Item()
142  : KeyApprovalDialog::Item(),
143  signPref( UnknownSigningPreference ),
144  format( AutoFormat ),
145  needKeys( true ) {}
146  Item( const TQString & a,
147  EncryptionPreference e, SigningPreference s,
148  CryptoMessageFormat f )
149  : KeyApprovalDialog::Item( a, std::vector<GpgME::Key>(), e ),
150  signPref( s ), format( f ), needKeys( true ) {}
151  Item( const TQString & a, const std::vector<GpgME::Key> & k,
152  EncryptionPreference e, SigningPreference s,
153  CryptoMessageFormat f )
154  : KeyApprovalDialog::Item( a, k, e ),
155  signPref( s ), format( f ), needKeys( false ) {}
156 
157  SigningPreference signPref;
158  CryptoMessageFormat format;
159  bool needKeys;
160  };
161 
162 
168  Kpgp::Result setEncryptToSelfKeys( const TQStringList & fingerprints );
173  Kpgp::Result setSigningKeys( const TQStringList & fingerprints );
178  void setPrimaryRecipients( const TQStringList & addresses );
183  void setSecondaryRecipients( const TQStringList & addresses );
184 
185 
191  Action checkSigningPreferences( bool signingRequested ) const;
197  Action checkEncryptionPreferences( bool encryptionRequested ) const;
198 
203  Kpgp::Result resolveAllKeys( bool& signingRequested, bool& encryptionRequested );
204 
209  std::vector<GpgME::Key> signingKeys( CryptoMessageFormat f ) const;
210 
211  struct SplitInfo {
212  SplitInfo() {}
213  SplitInfo( const TQStringList & r ) : recipients( r ) {}
214  SplitInfo( const TQStringList & r, const std::vector<GpgME::Key> & k )
215  : recipients( r ), keys( k ) {}
216  TQStringList recipients;
217  std::vector<GpgME::Key> keys;
218  };
223  std::vector<SplitInfo> encryptionItems( CryptoMessageFormat f ) const;
224 
225  private:
226  void dump() const;
227  std::vector<Item> getEncryptionItems( const TQStringList & recipients );
228  std::vector<GpgME::Key> getEncryptionKeys( const TQString & recipient, bool quiet ) const;
229 
230  Kpgp::Result showKeyApprovalDialog();
231 
232  bool encryptionPossible() const;
233  bool signingPossible() const;
234  Kpgp::Result resolveEncryptionKeys( bool signingRequested );
235  Kpgp::Result resolveSigningKeysForEncryption();
236  Kpgp::Result resolveSigningKeysForSigningOnly();
237  Kpgp::Result checkKeyNearExpiry( const GpgME::Key & key,
238  const char * dontAskAgainName, bool mine,
239  bool sign, bool ca=false, int recurse_limit=100,
240  const GpgME::Key & orig_key=GpgME::Key::null ) const;
241  void collapseAllSplitInfos();
242  void addToAllSplitInfos( const std::vector<GpgME::Key> & keys, unsigned int formats );
243  void addKeys( const std::vector<Item> & items, CryptoMessageFormat f );
244  void addKeys( const std::vector<Item> & items );
245  TQStringList allRecipients() const;
246  std::vector<GpgME::Key> signingKeysFor( CryptoMessageFormat f ) const;
247  std::vector<GpgME::Key> encryptToSelfKeysFor( CryptoMessageFormat f ) const;
248 
249  std::vector<GpgME::Key> lookup( const TQStringList & patterns, bool secret=false ) const;
250 
251  bool haveTrustedEncryptionKey( const TQString & person ) const;
252 
253  std::vector<GpgME::Key> selectKeys( const TQString & person, const TQString & msg,
254  const std::vector<GpgME::Key> & selectedKeys=std::vector<GpgME::Key>() ) const;
255 
256  TQStringList keysForAddress( const TQString & address ) const;
257  void setKeysForAddress( const TQString & address, const TQStringList& pgpKeyFingerprints, const TQStringList& smimeCertFingerprints ) const;
258 
259  bool encryptToSelf() const { return mEncryptToSelf; }
260  bool showApprovalDialog() const { return mShowApprovalDialog; }
261 
262  int encryptKeyNearExpiryWarningThresholdInDays() const {
263  return mEncryptKeyNearExpiryWarningThreshold;
264  }
265  int signingKeyNearExpiryWarningThresholdInDays() const {
266  return mSigningKeyNearExpiryWarningThreshold;
267  }
268 
269  int encryptRootCertNearExpiryWarningThresholdInDays() const {
270  return mEncryptRootCertNearExpiryWarningThreshold;
271  }
272  int signingRootCertNearExpiryWarningThresholdInDays() const {
273  return mSigningRootCertNearExpiryWarningThreshold;
274  }
275 
276  int encryptChainCertNearExpiryWarningThresholdInDays() const {
277  return mEncryptChainCertNearExpiryWarningThreshold;
278  }
279  int signingChainCertNearExpiryWarningThresholdInDays() const {
280  return mSigningChainCertNearExpiryWarningThreshold;
281  }
282 
283  struct ContactPreferences {
284  ContactPreferences();
285  Kleo::EncryptionPreference encryptionPreference;
286  Kleo::SigningPreference signingPreference;
287  Kleo::CryptoMessageFormat cryptoMessageFormat;
288  TQStringList pgpKeyFingerprints;
289  TQStringList smimeCertFingerprints;
290  };
291 
292  ContactPreferences lookupContactPreferences( const TQString& address ) const;
293  void saveContactPreference( const TQString& email, const ContactPreferences& pref ) const;
294 
295  private:
296  class EncryptionPreferenceCounter;
297  friend class ::Kleo::KeyResolver::EncryptionPreferenceCounter;
298  class SigningPreferenceCounter;
299  friend class ::Kleo::KeyResolver::SigningPreferenceCounter;
300 
301  class Private;
302  Private * d;
303 
304  bool mEncryptToSelf;
305  const bool mShowApprovalDialog : 1;
306  const bool mOpportunisticEncyption : 1;
307  const unsigned int mCryptoMessageFormats;
308 
309  const int mEncryptKeyNearExpiryWarningThreshold;
310  const int mSigningKeyNearExpiryWarningThreshold;
311  const int mEncryptRootCertNearExpiryWarningThreshold;
312  const int mSigningRootCertNearExpiryWarningThreshold;
313  const int mEncryptChainCertNearExpiryWarningThreshold;
314  const int mSigningChainCertNearExpiryWarningThreshold;
315  };
316 
317 } // namespace Kleo
318 
319 #endif // __KLEO_KEYRESOLVER_H__
A class to resolve signing/encryption keys w.r.t.
Definition: keyresolver.h:127
std::vector< SplitInfo > encryptionItems(CryptoMessageFormat f) const
std::vector< GpgME::Key > signingKeys(CryptoMessageFormat f) const
void setSecondaryRecipients(const TQStringList &addresses)
Set the list of secondary (BCC) recipient addresses.
Action checkSigningPreferences(bool signingRequested) const
Determine whether to sign or not, depending on the per-recipient signing preferences,...
Kpgp::Result setEncryptToSelfKeys(const TQStringList &fingerprints)
Set the fingerprints of keys to be used for encrypting to self.
Action checkEncryptionPreferences(bool encryptionRequested) const
Determine whether to encrypt or not, depending on the per-recipient encryption preferences,...
Kpgp::Result setSigningKeys(const TQStringList &fingerprints)
Set the fingerprints of keys to be used for signing.
Kpgp::Result resolveAllKeys(bool &signingRequested, bool &encryptionRequested)
Queries the user for missing keys and displays a key approval dialog if needed.
void setPrimaryRecipients(const TQStringList &addresses)
Set the list of primary (To/CC) recipient addresses.