• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkpgp

  • sources
  • kde-4.14
  • kdepim
  • libkpgp
kpgp.h
Go to the documentation of this file.
1 /*
2  kpgp.h
3 
4  Copyright (C) 2001,2002 the KPGP authors
5  See file AUTHORS.kpgp for details
6 
7  This file is part of KPGP, the KDE PGP/GnuPG support library.
8 
9  KPGP is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software Foundation,
16  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #ifndef KPGP_H
20 #define KPGP_H
21 
22 #include "libkpgp_export.h"
23 #include "kpgpkey.h"
24 
25 #include <QtCore/QByteArray>
26 #include <QtCore/QString>
27 #include <QWidget>
28 #include <QComboBox>
29 #include <QLayout>
30 #include <QPushButton>
31 #include <QRadioButton>
32 #include <QCheckBox>
33 #include <QGridLayout>
34 
35 #include <stdio.h>
36 
37 class QCheckBox;
38 class QGridLayout;
39 
40 class KConfig;
41 
42 namespace Kpgp {
43 
54 enum { PublicKeys = 1,
55  SecretKeys = 2,
56  EncryptionKeys = 4,
57  SigningKeys = 8,
58  ValidKeys = 16,
59  TrustedKeys = 32,
60  AllKeys = PublicKeys | SecretKeys | EncryptionKeys | SigningKeys,
61  PubSecKeys = PublicKeys | SecretKeys,
62  EncrSignKeys = EncryptionKeys | SigningKeys
63 };
64 
65 enum Result
66 {
67  Failure = 0,
68  Ok = 1,
69  Canceled = 2
70 };
71 
72 class Base;
73 class Block;
74 
75 class KPGP_EXPORT Module
76 {
77  friend class Block;
78 
79 private:
80  // the class running pgp
81  Base *pgp;
82 
86  Module();
87 
88 public:
89  virtual ~Module();
90 
94  virtual void readConfig();
95  virtual void writeConfig(bool sync);
96  virtual void init();
97 
100  bool decrypt( Block& block );
101 
103  bool verify( Block& block );
104 
112  Kpgp::Result clearsign( Block& block,
113  const KeyID& keyId, const QByteArray& charset = 0 );
114 
123  Kpgp::Result encrypt( Block& block,
124  const QStringList& receivers, const KeyID& keyId,
125  bool sign, const QByteArray& charset = 0 );
126 
134  Kpgp::Result getEncryptionKeys( KeyIDList& encryptionKeyIds,
135  const QStringList& recipients,
136  const KeyID& keyId );
137 
147  int encryptionPossible( const QStringList& recipients );
148 
149 protected:
150  int doEncSign( Block& block, const KeyIDList& recipientKeyIds, bool sign );
151 
152 public:
154  bool signKey( const KeyID& keyID );
155 
157  const KeyList publicKeys();
158 
160  const KeyList secretKeys();
161 
164  void readPublicKeys( bool reread = false );
165 
168  void readSecretKeys( bool reread = false );
169 
171  QByteArray getAsciiPublicKey( const KeyID& keyID );
172 
176  Key* publicKey( const KeyID& keyID );
177 
181  Key* publicKey( const QString& userID );
182 
186  Key* secretKey( const KeyID& keyID );
187 
191  Validity keyTrust( const KeyID& keyID );
192 
197  Validity keyTrust( const QString& userID );
198 
202  bool isTrusted( const KeyID& keyID );
203 
207  Key* rereadKey( const KeyID& keyID, const bool readTrust = true );
208 
211  bool changePassPhrase();
212 
215  void setUser(const KeyID& keyID);
217  const KeyID user() const;
218 
220  void setEncryptToSelf(bool flag);
221  bool encryptToSelf(void) const;
222 
228  void setStorePassPhrase(bool);
229  bool storePassPhrase(void) const;
230 
232  void clear(const bool erasePassPhrase = false);
233 
235  const QString lastErrorMsg(void) const;
236 
237  // what version of PGP/GPG should we use
238  enum PGPType { tAuto, tGPG, tPGP2, tPGP5, tPGP6, tOff } pgpType;
239 
240  // did we find a pgp executable?
241  bool havePGP(void) const;
242 
244  bool usePGP(void) const { return (havePGP() && (pgpType != tOff)); }
245 
246  // show the result of encryption/signing?
247  void setShowCipherText(const bool flag);
248  bool showCipherText(void) const;
249 
250  // show the encryption keys for approval?
251  void setShowKeyApprovalDlg(const bool flag);
252  bool showKeyApprovalDlg(void) const;
253 
258  KeyID selectSecretKey( const QString& title,
259  const QString& text = QString(),
260  const KeyID& keyId = KeyID() );
261 
268  KeyID selectPublicKey( const QString& title,
269  const QString& text = QString(),
270  const KeyID& oldKeyId = KeyID(),
271  const QString& address = QString(),
272  const unsigned int allowedKeys = AllKeys );
273 
280  KeyIDList selectPublicKeys( const QString& title,
281  const QString& text = QString(),
282  const KeyIDList& oldKeyIds = KeyIDList(),
283  const QString& address = QString(),
284  const unsigned int allowedKeys = AllKeys );
285 
286  // FIXME: key management
287 
291  EncryptPref encryptionPreference( const QString& address );
292 
296  void setEncryptionPreference( const QString& address,
297  const EncryptPref pref );
298 
299  // -- static member functions --------------------------------------------
300 
302  static Kpgp::Module *getKpgp();
303 
305  static KConfig *getConfig();
306 
321  static bool prepareMessageForDecryption( const QByteArray& msg,
322  QList<Block>& pgpBlocks,
323  QList<QByteArray>& nonPgpBlocks );
324 
325 private:
327  bool haveTrustedEncryptionKey( const QString& person );
328 
330  KeyIDList getEncryptionKeys( const QString& person );
331 
333  bool setPassPhrase(const QString &pass);
334 
341  int prepare(bool needPassPhrase=false, Block* block = 0 );
342 
344  void cleanupPass() { if (!storePass) wipePassPhrase(); }
345 
348  void wipePassPhrase(bool free=false);
349 
350  // transform an address into canonical form
351  QString canonicalAddress( const QString& person );
352 
355  KeyID selectKey( const KeyList& keys,
356  const QString& title,
357  const QString& text = QString(),
358  const KeyID& keyId = KeyID(),
359  const unsigned int allowedKeys = AllKeys );
360 
363  KeyIDList selectKeys( const KeyList& keys,
364  const QString& title,
365  const QString& text = QString(),
366  const KeyIDList& keyIds = KeyIDList(),
367  const unsigned int allowedKeys = AllKeys );
368 
373  KeyID selectKey( bool& rememberChoice,
374  const KeyList& keys,
375  const QString& title,
376  const QString& text = QString(),
377  const KeyID& keyId = KeyID(),
378  const unsigned int allowedKeys = AllKeys );
379 
384  KeyIDList selectKeys( bool& rememberChoice,
385  const KeyList& keys,
386  const QString& title,
387  const QString& text = QString(),
388  const KeyIDList& keyIds = KeyIDList(),
389  const unsigned int allowedKeys = AllKeys );
390 
394  KeyIDList keysForAddress( const QString& address );
395 
398  void setKeysForAddress( const QString& address, const KeyIDList& keyIDs );
399 
401  void removeKeyForAddress( const QString& address );
402 
406  void readAddressData();
407 
411  void writeAddressData();
412 
413  bool checkForPGP(void);
414  void assignPGPBase(void);
415 
416  KConfig *config;
417 
418  struct AddressData {
419  KeyIDList keyIds;
420  EncryptPref encrPref;
421  };
422  typedef QMap<QString, AddressData> AddressDataDict;
423  AddressDataDict addressDataDict;
424 
425  KeyList mPublicKeys;
426  bool mPublicKeysCached : 1; // did we already read the public keys?
427  KeyList mSecretKeys;
428  bool mSecretKeysCached : 1; // did we already read the secret keys?
429 
430  bool storePass : 1;
431  char * passphrase;
432  size_t passphrase_buffer_len;
433 
434  QString errMsg;
435 
436  KeyID pgpUser; // the key ID which is used to sign/encrypt to self
437  bool flagEncryptToSelf : 1;
438 
439  bool havePgp : 1;
440  bool havePGP5 : 1;
441  bool haveGpg : 1;
442  bool havePassPhrase : 1;
443  bool showEncryptionResult : 1;
444  bool mShowKeyApprovalDlg : 1;
445 }; // class Module
446 
447 // -- inlined member functions ---------------------------------------------
448 
449 inline void
450 Module::setShowKeyApprovalDlg( const bool flag )
451 {
452  mShowKeyApprovalDlg = flag;
453 }
454 
455 inline bool
456 Module::showKeyApprovalDlg( void ) const
457 {
458  return mShowKeyApprovalDlg;
459 }
460 
461 // -------------------------------------------------------------------------
462 
463 } // namespace Kpgp
464 
465 #endif
466 
Kpgp::TrustedKeys
Definition: kpgp.h:59
Kpgp::AllKeys
Definition: kpgp.h:60
Kpgp::Validity
Validity
These are the possible validity values for a PGP user id and for the owner trust. ...
Definition: kpgpkey.h:32
Kpgp::KeyList
QList< Key * > KeyList
Definition: kpgpkey.h:843
Kpgp::Canceled
Definition: kpgp.h:69
Kpgp::SigningKeys
Definition: kpgp.h:57
QByteArray
Kpgp::Module::tPGP6
Definition: kpgp.h:238
Kpgp::PublicKeys
Definition: kpgp.h:54
QMap< QString, AddressData >
Kpgp::Block
Definition: kpgpblock.h:89
QGridLayout
Kpgp::Module::showKeyApprovalDlg
bool showKeyApprovalDlg(void) const
Definition: kpgp.h:456
Kpgp::EncrSignKeys
Definition: kpgp.h:62
Kpgp::PubSecKeys
Definition: kpgp.h:61
Kpgp::Module::PGPType
PGPType
Definition: kpgp.h:238
Kpgp::Module
Definition: kpgp.h:75
Kpgp::SecretKeys
Definition: kpgp.h:55
QCheckBox
Kpgp::KeyID
QByteArray KeyID
Definition: kpgpkey.h:55
QString
QList
Kpgp::KeyIDList
Definition: kpgpkey.h:57
QStringList
Kpgp::Failure
Definition: kpgp.h:67
libkpgp_export.h
kpgpkey.h
Kpgp::ValidKeys
Definition: kpgp.h:58
Kpgp::Result
Result
Definition: kpgp.h:65
Kpgp::EncryptPref
EncryptPref
These are the possible preferences for encryption.
Definition: kpgpkey.h:44
Kpgp::Base
Definition: kpgpbase.h:30
Kpgp::EncryptionKeys
Definition: kpgp.h:56
Kpgp::Key
This class is used to store information about a PGP key.
Definition: kpgpkey.h:506
Kpgp::Module::setShowKeyApprovalDlg
void setShowKeyApprovalDlg(const bool flag)
Definition: kpgp.h:450
KPGP_EXPORT
#define KPGP_EXPORT
Definition: libkpgp_export.h:35
Kpgp::Ok
Definition: kpgp.h:68
Kpgp::Module::usePGP
bool usePGP(void) const
Should PGP/GnuPG be used?
Definition: kpgp.h:244
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkpgp

Skip menu "libkpgp"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal