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

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • commands
certifycertificatecommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/signcertificatecommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Softwarls Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the Qt library by Trolltech AS, Norway (or with modified versions
23  of Qt that use the same license as Qt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  Qt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 */
31 
32 #include <config-kleopatra.h>
33 
34 #include "certifycertificatecommand.h"
35 
36 #include "command_p.h"
37 
38 #include "exportopenpgpcertstoservercommand.h"
39 
40 #include <dialogs/certifycertificatedialog.h>
41 
42 #include <models/keycache.h>
43 
44 #include <utils/formatting.h>
45 
46 #include <kleo/cryptobackendfactory.h>
47 #include <kleo/cryptobackend.h>
48 #include <kleo/signkeyjob.h>
49 
50 #include <gpgme++/key.h>
51 
52 #include <KLocalizedString>
53 #include <kdebug.h>
54 
55 #ifndef Q_MOC_RUN
56 #include <boost/bind.hpp>
57 #endif
58 
59 #include <cassert>
60 
61 using namespace Kleo;
62 using namespace Kleo::Commands;
63 using namespace Kleo::Dialogs;
64 using namespace GpgME;
65 
66 class CertifyCertificateCommand::Private : public Command::Private {
67  friend class ::Kleo::Commands::CertifyCertificateCommand;
68  CertifyCertificateCommand * q_func() const { return static_cast<CertifyCertificateCommand*>( q ); }
69 public:
70  explicit Private( CertifyCertificateCommand * qq, KeyListController * c );
71  ~Private();
72 
73  void init();
74 
75 private:
76  void slotDialogRejected();
77  void slotResult( const Error & err );
78  void slotCertificationPrepared();
79 
80 private:
81  void ensureDialogCreated();
82  void createJob();
83 
84 private:
85  std::vector<UserID> uids;
86  QPointer<CertifyCertificateDialog> dialog;
87  QPointer<SignKeyJob> job;
88 };
89 
90 
91 CertifyCertificateCommand::Private * CertifyCertificateCommand::d_func() { return static_cast<Private*>( d.get() ); }
92 const CertifyCertificateCommand::Private * CertifyCertificateCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
93 
94 #define d d_func()
95 #define q q_func()
96 
97 CertifyCertificateCommand::Private::Private( CertifyCertificateCommand * qq, KeyListController * c )
98  : Command::Private( qq, c ),
99  uids(),
100  dialog(),
101  job()
102 {
103 
104 }
105 
106 CertifyCertificateCommand::Private::~Private() { kDebug(); }
107 
108 CertifyCertificateCommand::CertifyCertificateCommand( KeyListController * c )
109  : Command( new Private( this, c ) )
110 {
111  d->init();
112 }
113 
114 CertifyCertificateCommand::CertifyCertificateCommand( QAbstractItemView * v, KeyListController * c )
115  : Command( v, new Private( this, c ) )
116 {
117  d->init();
118 }
119 
120 CertifyCertificateCommand::CertifyCertificateCommand( const Key & key )
121  : Command( key, new Private( this, 0 ) )
122 {
123  d->init();
124 }
125 
126 CertifyCertificateCommand::CertifyCertificateCommand( const UserID & uid )
127  : Command( uid.parent(), new Private( this, 0 ) )
128 {
129  std::vector<UserID>( 1, uid ).swap( d->uids );
130  d->init();
131 }
132 
133 CertifyCertificateCommand::CertifyCertificateCommand( const std::vector<UserID> & uids )
134  : Command( uids.empty() ? Key() : uids.front().parent(), new Private( this, 0 ) )
135 {
136  d->uids = uids;
137  d->init();
138 }
139 
140 void CertifyCertificateCommand::Private::init() {
141 
142 }
143 
144 CertifyCertificateCommand::~CertifyCertificateCommand() { kDebug(); }
145 
146 void CertifyCertificateCommand::setCertificationExportable( bool on ) {
147  Q_UNUSED( on );
148 }
149 
150 void CertifyCertificateCommand::setCertificationRevocable( bool on ) {
151  Q_UNUSED( on );
152 }
153 
154 void CertifyCertificateCommand::setCertifyingKey( const Key & signer ) {
155  Q_UNUSED( signer );
156 }
157 
158 void CertifyCertificateCommand::setUserIDs( const std::vector<UserID> & uids ) {
159  d->uids = uids;
160  if ( !uids.empty() && d->key().isNull() )
161  setKey( uids.front().parent() );
162 }
163 
164 void CertifyCertificateCommand::setUserID( const UserID & uid ) {
165  setUserIDs( std::vector<UserID>( 1, uid ) );
166 }
167 
168 void CertifyCertificateCommand::doStart() {
169 
170  const std::vector<Key> keys = d->keys();
171  if ( keys.size() != 1 ||
172  keys.front().protocol() != GpgME::OpenPGP ) {
173  d->finished();
174  return;
175  }
176 
177  std::vector<Key> secKeys = KeyCache::instance()->secretKeys();
178  std::vector<Key>::iterator it = std::remove_if( secKeys.begin(), secKeys.end(), !boost::bind( &Key::canCertify, _1 ) );
179  it = std::remove_if( it, secKeys.end(), boost::bind( &Key::protocol, _1 ) != OpenPGP );
180  secKeys.erase( it, secKeys.end() );
181 
182  if ( secKeys.empty() ) {
183  d->error( i18nc( "@info", "To certify other certificates, you first need to create an OpenPGP certificate for yourself. Choose <interface>File->New Certificate...</interface> to create one." ),
184  i18n( "Certification Not Possible" ) );
185  d->finished();
186  return;
187  }
188  const Key & key = keys.front();
189 
190  Q_FOREACH( const UserID & uid, d->uids )
191  if ( qstricmp( uid.parent().primaryFingerprint(), key.primaryFingerprint() ) != 0 ) {
192  kWarning() << "User-ID <-> Key mismatch!";
193  d->finished();
194  return;
195  }
196 
197  d->ensureDialogCreated();
198  assert( d->dialog );
199  d->dialog->setCertificateToCertify( d->key() );
200  d->dialog->setSelectedUserIDs( d->uids );
201  d->dialog->setCertificatesWithSecretKeys( secKeys );
202  d->dialog->show();
203 }
204 
205 void CertifyCertificateCommand::Private::slotDialogRejected() {
206  emit q->canceled();
207  finished();
208 }
209 
210 void CertifyCertificateCommand::Private::slotResult( const Error & err ) {
211  if ( !err && !err.isCanceled() && dialog && dialog->exportableCertificationSelected() && dialog->sendToServer() ) {
212  ExportOpenPGPCertsToServerCommand * const cmd = new ExportOpenPGPCertsToServerCommand( key() );
213  cmd->start();
214  }
215 
216  finished();
217 }
218 
219 void CertifyCertificateCommand::Private::slotCertificationPrepared() {
220  assert( dialog );
221 
222  createJob();
223  assert( job );
224  job->setExportable( dialog->exportableCertificationSelected() );
225  job->setNonRevocable( dialog->nonRevocableCertificationSelected() );
226  job->setUserIDsToSign( dialog->selectedUserIDs() );
227  job->setSigningKey( dialog->selectedSecretKey() );
228  job->setCheckLevel( dialog->selectedCheckLevel() );
229 
230  dialog->connectJob( job );
231 
232  if ( const Error err = job->start( key() ) ) {
233  dialog->setError( err );
234  finished();
235  }
236 }
237 
238 void CertifyCertificateCommand::doCancel() {
239  kDebug();
240  if ( d->job )
241  d->job->slotCancel();
242 }
243 
244 void CertifyCertificateCommand::Private::ensureDialogCreated() {
245  if ( dialog )
246  return;
247 
248  dialog = new CertifyCertificateDialog;
249  applyWindowID( dialog );
250  dialog->setAttribute( Qt::WA_DeleteOnClose );
251 
252  connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
253  connect( dialog, SIGNAL(certificationPrepared()), q, SLOT(slotCertificationPrepared()) );
254 }
255 
256 void CertifyCertificateCommand::Private::createJob() {
257  if ( dialog )
258  disconnect( dialog, SIGNAL(certificationPrepared()), q, SLOT(slotCertificationPrepared()) );
259 
260  assert( !job );
261 
262  assert( key().protocol() == OpenPGP );
263  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key().protocol() );
264  if ( !backend )
265  return;
266 
267  SignKeyJob * const j = backend->signKeyJob();
268  if ( !j )
269  return;
270 
271  connect( j, SIGNAL(progress(QString,int,int)),
272  q, SIGNAL(progress(QString,int,int)) );
273  connect( j, SIGNAL(result(GpgME::Error)),
274  q, SLOT(slotResult(GpgME::Error)) );
275 
276  job = j;
277 }
278 
279 
280 #undef d
281 #undef q
282 
283 #include "moc_certifycertificatecommand.cpp"
QAbstractItemView
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::Commands::CertifyCertificateCommand::setCertificationRevocable
void setCertificationRevocable(bool on)
Definition: certifycertificatecommand.cpp:150
Kleo::KeyListController
Definition: keylistcontroller.h:55
QPointer< CertifyCertificateDialog >
formatting.h
Kleo::Commands::CertifyCertificateCommand::setUserIDs
void setUserIDs(const std::vector< GpgME::UserID > &uids)
Definition: certifycertificatecommand.cpp:158
Kleo::Command::start
void start()
Definition: commands/command.cpp:182
certifycertificatedialog.h
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
Kleo::Commands::CertifyCertificateCommand::~CertifyCertificateCommand
~CertifyCertificateCommand()
Definition: certifycertificatecommand.cpp:144
Kleo::Class::OpenPGP
Definition: classify.h:49
Kleo::Commands::CertifyCertificateCommand::setCertifyingKey
void setCertifyingKey(const GpgME::Key &key)
Definition: certifycertificatecommand.cpp:154
QString
Kleo::Command::setKey
void setKey(const GpgME::Key &key)
Definition: commands/command.cpp:172
exportopenpgpcertstoservercommand.h
Kleo::Commands::CertifyCertificateCommand::CertifyCertificateCommand
CertifyCertificateCommand(QAbstractItemView *view, KeyListController *parent)
Definition: certifycertificatecommand.cpp:114
Kleo::Commands::CertifyCertificateCommand::setCertificationExportable
void setCertificationExportable(bool on)
Definition: certifycertificatecommand.cpp:146
command_p.h
d
#define d
Definition: certifycertificatecommand.cpp:94
Kleo::Commands::CertifyCertificateCommand
Definition: certifycertificatecommand.h:45
Kleo::Dialogs::CertifyCertificateDialog
Definition: certifycertificatedialog.h:54
q
#define q
Definition: certifycertificatecommand.cpp:95
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:190
certifycertificatecommand.h
keycache.h
QObject::parent
QObject * parent() const
Kleo::Commands::CertifyCertificateCommand::setUserID
void setUserID(const GpgME::UserID &uid)
Definition: certifycertificatecommand.cpp:164
Kleo::Command
Definition: commands/command.h:58
Kleo::Commands::ExportOpenPGPCertsToServerCommand
Definition: exportopenpgpcertstoservercommand.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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