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

kleopatra

  • sources
  • kde-4.12
  • 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 <KLocale>
53 #include <KMessageBox>
54 #include <kdebug.h>
55 
56 #include <boost/bind.hpp>
57 
58 #include <cassert>
59 
60 using namespace Kleo;
61 using namespace Kleo::Commands;
62 using namespace Kleo::Dialogs;
63 using namespace GpgME;
64 
65 class CertifyCertificateCommand::Private : public Command::Private {
66  friend class ::Kleo::Commands::CertifyCertificateCommand;
67  CertifyCertificateCommand * q_func() const { return static_cast<CertifyCertificateCommand*>( q ); }
68 public:
69  explicit Private( CertifyCertificateCommand * qq, KeyListController * c );
70  ~Private();
71 
72  void init();
73 
74 private:
75  void slotDialogRejected();
76  void slotResult( const Error & err );
77  void slotCertificationPrepared();
78 
79 private:
80  void ensureDialogCreated();
81  void createJob();
82 
83 private:
84  std::vector<UserID> uids;
85  QPointer<CertifyCertificateDialog> dialog;
86  QPointer<SignKeyJob> job;
87 };
88 
89 
90 CertifyCertificateCommand::Private * CertifyCertificateCommand::d_func() { return static_cast<Private*>( d.get() ); }
91 const CertifyCertificateCommand::Private * CertifyCertificateCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
92 
93 #define d d_func()
94 #define q q_func()
95 
96 CertifyCertificateCommand::Private::Private( CertifyCertificateCommand * qq, KeyListController * c )
97  : Command::Private( qq, c ),
98  uids(),
99  dialog(),
100  job()
101 {
102 
103 }
104 
105 CertifyCertificateCommand::Private::~Private() { kDebug(); }
106 
107 CertifyCertificateCommand::CertifyCertificateCommand( KeyListController * c )
108  : Command( new Private( this, c ) )
109 {
110  d->init();
111 }
112 
113 CertifyCertificateCommand::CertifyCertificateCommand( QAbstractItemView * v, KeyListController * c )
114  : Command( v, new Private( this, c ) )
115 {
116  d->init();
117 }
118 
119 CertifyCertificateCommand::CertifyCertificateCommand( const Key & key )
120  : Command( key, new Private( this, 0 ) )
121 {
122  d->init();
123 }
124 
125 CertifyCertificateCommand::CertifyCertificateCommand( const UserID & uid )
126  : Command( uid.parent(), new Private( this, 0 ) )
127 {
128  std::vector<UserID>( 1, uid ).swap( d->uids );
129  d->init();
130 }
131 
132 CertifyCertificateCommand::CertifyCertificateCommand( const std::vector<UserID> & uids )
133  : Command( uids.empty() ? Key() : uids.front().parent(), new Private( this, 0 ) )
134 {
135  d->uids = uids;
136  d->init();
137 }
138 
139 void CertifyCertificateCommand::Private::init() {
140 
141 }
142 
143 CertifyCertificateCommand::~CertifyCertificateCommand() { kDebug(); }
144 
145 void CertifyCertificateCommand::setCertificationExportable( bool on ) {
146  Q_UNUSED( on );
147 }
148 
149 void CertifyCertificateCommand::setCertificationRevocable( bool on ) {
150  Q_UNUSED( on );
151 }
152 
153 void CertifyCertificateCommand::setCertifyingKey( const Key & signer ) {
154  Q_UNUSED( signer );
155 }
156 
157 void CertifyCertificateCommand::setUserIDs( const std::vector<UserID> & uids ) {
158  d->uids = uids;
159  if ( !uids.empty() && d->key().isNull() )
160  setKey( uids.front().parent() );
161 }
162 
163 void CertifyCertificateCommand::setUserID( const UserID & uid ) {
164  setUserIDs( std::vector<UserID>( 1, uid ) );
165 }
166 
167 void CertifyCertificateCommand::doStart() {
168 
169  const std::vector<Key> keys = d->keys();
170  if ( keys.size() != 1 ||
171  keys.front().protocol() != GpgME::OpenPGP ) {
172  d->finished();
173  return;
174  }
175 
176  std::vector<Key> secKeys = KeyCache::instance()->secretKeys();
177  std::vector<Key>::iterator it = std::remove_if( secKeys.begin(), secKeys.end(), !boost::bind( &Key::canCertify, _1 ) );
178  it = std::remove_if( it, secKeys.end(), boost::bind( &Key::protocol, _1 ) != OpenPGP );
179  secKeys.erase( it, secKeys.end() );
180 
181  if ( secKeys.empty() ) {
182  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." ),
183  i18n( "Certification Not Possible" ) );
184  d->finished();
185  return;
186  }
187  const Key & key = keys.front();
188 
189  Q_FOREACH( const UserID & uid, d->uids )
190  if ( qstricmp( uid.parent().primaryFingerprint(), key.primaryFingerprint() ) != 0 ) {
191  kWarning() << "User-ID <-> Key mismatch!";
192  d->finished();
193  return;
194  }
195 
196  d->ensureDialogCreated();
197  assert( d->dialog );
198  d->dialog->setCertificateToCertify( d->key() );
199  d->dialog->setSelectedUserIDs( d->uids );
200  d->dialog->setCertificatesWithSecretKeys( secKeys );
201  d->dialog->show();
202 }
203 
204 void CertifyCertificateCommand::Private::slotDialogRejected() {
205  emit q->canceled();
206  finished();
207 }
208 
209 void CertifyCertificateCommand::Private::slotResult( const Error & err ) {
210  if ( !err && !err.isCanceled() && dialog && dialog->exportableCertificationSelected() && dialog->sendToServer() ) {
211  ExportOpenPGPCertsToServerCommand * const cmd = new ExportOpenPGPCertsToServerCommand( key() );
212  cmd->start();
213  }
214 
215  finished();
216 }
217 
218 void CertifyCertificateCommand::Private::slotCertificationPrepared() {
219  assert( dialog );
220 
221  createJob();
222  assert( job );
223  job->setExportable( dialog->exportableCertificationSelected() );
224  job->setNonRevocable( dialog->nonRevocableCertificationSelected() );
225  job->setUserIDsToSign( dialog->selectedUserIDs() );
226  job->setSigningKey( dialog->selectedSecretKey() );
227  job->setCheckLevel( dialog->selectedCheckLevel() );
228 
229  dialog->connectJob( job );
230 
231  if ( const Error err = job->start( key() ) ) {
232  dialog->setError( err );
233  finished();
234  }
235 }
236 
237 void CertifyCertificateCommand::doCancel() {
238  kDebug();
239  if ( d->job )
240  d->job->slotCancel();
241 }
242 
243 void CertifyCertificateCommand::Private::ensureDialogCreated() {
244  if ( dialog )
245  return;
246 
247  dialog = new CertifyCertificateDialog;
248  applyWindowID( dialog );
249  dialog->setAttribute( Qt::WA_DeleteOnClose );
250 
251  connect( dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()) );
252  connect( dialog, SIGNAL(certificationPrepared()), q, SLOT(slotCertificationPrepared()) );
253 }
254 
255 void CertifyCertificateCommand::Private::createJob() {
256  if ( dialog )
257  disconnect( dialog, SIGNAL(certificationPrepared()), q, SLOT(slotCertificationPrepared()) );
258 
259  assert( !job );
260 
261  assert( key().protocol() == OpenPGP );
262  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( key().protocol() );
263  if ( !backend )
264  return;
265 
266  SignKeyJob * const j = backend->signKeyJob();
267  if ( !j )
268  return;
269 
270  connect( j, SIGNAL(progress(QString,int,int)),
271  q, SIGNAL(progress(QString,int,int)) );
272  connect( j, SIGNAL(result(GpgME::Error)),
273  q, SLOT(slotResult(GpgME::Error)) );
274 
275  job = j;
276 }
277 
278 
279 #undef d
280 #undef q
281 
282 #include "moc_certifycertificatecommand.cpp"
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::Commands::CertifyCertificateCommand::setCertificationRevocable
void setCertificationRevocable(bool on)
Definition: certifycertificatecommand.cpp:149
Kleo::KeyListController
Definition: keylistcontroller.h:55
formatting.h
Kleo::Commands::CertifyCertificateCommand::setUserIDs
void setUserIDs(const std::vector< GpgME::UserID > &uids)
Definition: certifycertificatecommand.cpp:157
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:143
Kleo::Class::OpenPGP
Definition: classify.h:49
Kleo::Commands::CertifyCertificateCommand::setCertifyingKey
void setCertifyingKey(const GpgME::Key &key)
Definition: certifycertificatecommand.cpp:153
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:113
Kleo::Commands::CertifyCertificateCommand::setCertificationExportable
void setCertificationExportable(bool on)
Definition: certifycertificatecommand.cpp:145
command_p.h
d
#define d
Definition: certifycertificatecommand.cpp:93
Kleo::Commands::CertifyCertificateCommand
Definition: certifycertificatecommand.h:45
Kleo::Dialogs::CertifyCertificateDialog
Definition: certifycertificatedialog.h:59
q
#define q
Definition: certifycertificatecommand.cpp:94
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:189
certifycertificatecommand.h
keycache.h
Kleo::Commands::CertifyCertificateCommand::setUserID
void setUserID(const GpgME::UserID &uid)
Definition: certifycertificatecommand.cpp:163
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:40 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

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