• 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
  • uiserver
signcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/signcommand.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2010 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 Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  you do not wish to do so, delete this exception statement from
29  your version of the file, but you are not obligated to do so. If
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "signcommand.h"
36 
37 #include <crypto/newsignencryptemailcontroller.h>
38 
39 #include <utils/kleo_assert.h>
40 #include <utils/input.h>
41 #include <utils/output.h>
42 
43 #include <kleo/exception.h>
44 
45 #include <KLocale>
46 
47 #include <QTimer>
48 
49 using namespace Kleo;
50 using namespace Kleo::Crypto;
51 using namespace boost;
52 
53 class SignCommand::Private : public QObject {
54  Q_OBJECT
55 private:
56  friend class ::Kleo::SignCommand;
57  SignCommand * const q;
58 public:
59  explicit Private( SignCommand * qq )
60  : q( qq ), controller()
61  {
62 
63  }
64 
65 private:
66  void checkForErrors() const;
67 
68 private Q_SLOTS:
69  void slotSignersResolved();
70  void slotMicAlgDetermined( const QString & );
71  void slotDone();
72  void slotError( int, const QString & );
73 
74 private:
75  shared_ptr<NewSignEncryptEMailController> controller;
76 };
77 
78 SignCommand::SignCommand()
79  : AssuanCommandMixin<SignCommand>(), d( new Private( this ) )
80 {
81 
82 }
83 
84 SignCommand::~SignCommand() {}
85 
86 void SignCommand::Private::checkForErrors() const {
87 
88  if ( q->numFiles() )
89  throw Exception( makeError( GPG_ERR_CONFLICT ),
90  i18n( "SIGN is an email mode command, connection seems to be in filemanager mode" ) );
91 
92  if ( !q->recipients().empty() && !q->informativeRecipients() )
93  throw Exception( makeError( GPG_ERR_CONFLICT ),
94  i18n( "RECIPIENT may not be given prior to SIGN, except with --info" ) );
95 
96  if ( q->inputs().empty() )
97  throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
98  i18n( "At least one INPUT must be present" ) );
99 
100  if ( q->outputs().size() != q->inputs().size() )
101  throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
102  i18n( "INPUT/OUTPUT count mismatch" ) );
103 
104  if ( !q->messages().empty() )
105  throw Exception( makeError( GPG_ERR_INV_VALUE ),
106  i18n( "MESSAGE command is not allowed before SIGN" ) );
107 
108  const shared_ptr<NewSignEncryptEMailController> m = q->mementoContent< shared_ptr<NewSignEncryptEMailController> >( NewSignEncryptEMailController::mementoName() );
109 
110  if ( m && m->isSigning() ) {
111 
112  if ( m->protocol() != q->checkProtocol( EMail ) )
113  throw Exception( makeError( GPG_ERR_CONFLICT ),
114  i18n( "Protocol given conflicts with protocol determined by PREP_ENCRYPT in this session" ) );
115 
116  // ### check that any SENDER here is the same as the one for PREP_ENCRYPT
117 
118  // ### ditto RECIPIENT
119 
120  } else {
121 
122  // ### support the stupid "default signer" semantics of GpgOL
123  // ### where SENDER is missing
124  if ( false )
125  if ( q->senders().empty() || q->informativeSenders() )
126  throw Exception( makeError( GPG_ERR_MISSING_VALUE ),
127  i18n( "No senders given, or only with --info" ) );
128 
129  }
130 
131 }
132 
133 static void connectController( const QObject * controller, const QObject * d ) {
134  QObject::connect( controller, SIGNAL(certificatesResolved()), d, SLOT(slotSignersResolved()) );
135  QObject::connect( controller, SIGNAL(reportMicAlg(QString)), d, SLOT(slotMicAlgDetermined(QString)) );
136  QObject::connect( controller, SIGNAL(done()), d, SLOT(slotDone()) );
137  QObject::connect( controller, SIGNAL(error(int,QString)), d, SLOT(slotError(int,QString)) );
138 }
139 
140 int SignCommand::doStart() {
141 
142  d->checkForErrors();
143 
144  const shared_ptr<NewSignEncryptEMailController> seec = mementoContent< shared_ptr<NewSignEncryptEMailController> >( NewSignEncryptEMailController::mementoName() );
145 
146  if ( seec && seec->isSigning() ) {
147  // reuse the controller from a previous PREP_ENCRYPT --expect-sign, if available:
148  d->controller = seec;
149  connectController( seec.get(), d.get() );
150  if ( !seec->isEncrypting() )
151  removeMemento( NewSignEncryptEMailController::mementoName() );
152  seec->setExecutionContext( shared_from_this() );
153  if ( seec->areCertificatesResolved() )
154  QTimer::singleShot( 0, d.get(), SLOT(slotSignersResolved()) );
155  else
156  kleo_assert( seec->isResolvingInProgress() );
157  } else {
158  // use a new controller
159  d->controller.reset( new NewSignEncryptEMailController( shared_from_this() ) );
160 
161  const QString session = sessionTitle();
162  if ( !session.isEmpty() )
163  d->controller->setSubject( session );
164 
165  d->controller->setSigning( true );
166  d->controller->setEncrypting( false );
167  d->controller->setProtocol( checkProtocol( EMail, AssuanCommand::AllowProtocolMissing ) );
168  connectController( d->controller.get(), d.get() );
169  d->controller->startResolveCertificates( recipients(), senders() );
170  }
171 
172 
173  return 0;
174 }
175 
176 void SignCommand::Private::slotSignersResolved() {
177  //hold local shared_ptr to member as q->done() deletes *this
178  const shared_ptr<NewSignEncryptEMailController> cont( controller );
179 
180  try {
181  const QString sessionTitle = q->sessionTitle();
182  if ( !sessionTitle.isEmpty() )
183  Q_FOREACH ( const shared_ptr<Input> & i, q->inputs() )
184  i->setLabel( sessionTitle );
185 
186  cont->setDetachedSignature( q->hasOption("detached" ) );
187  cont->startSigning( q->inputs(), q->outputs() );
188 
189  return;
190 
191  } catch ( const Exception & e ) {
192  q->done( e.error(), e.message() );
193  } catch ( const std::exception & e ) {
194  q->done( makeError( GPG_ERR_UNEXPECTED ),
195  i18n("Caught unexpected exception in SignCommand::Private::slotRecipientsResolved: %1",
196  QString::fromLocal8Bit( e.what() ) ) );
197  } catch ( ... ) {
198  q->done( makeError( GPG_ERR_UNEXPECTED ),
199  i18n("Caught unknown exception in SignCommand::Private::slotRecipientsResolved") );
200  }
201  cont->cancel();
202 }
203 
204 void SignCommand::Private::slotMicAlgDetermined( const QString & micalg ) {
205  //hold local shared_ptr to member as q->done() deletes *this
206  const shared_ptr<NewSignEncryptEMailController> cont( controller );
207 
208  try {
209 
210  q->sendStatus( "MICALG", micalg );
211  return;
212 
213  } catch ( const Exception & e ) {
214  q->done( e.error(), e.message() );
215  } catch ( const std::exception & e ) {
216  q->done( makeError( GPG_ERR_UNEXPECTED ),
217  i18n("Caught unexpected exception in SignCommand::Private::slotMicAlgDetermined: %1",
218  QString::fromLocal8Bit( e.what() ) ) );
219  } catch ( ... ) {
220  q->done( makeError( GPG_ERR_UNEXPECTED ),
221  i18n("Caught unknown exception in SignCommand::Private::slotMicAlgDetermined") );
222  }
223  cont->cancel();
224 }
225 
226 void SignCommand::Private::slotDone() {
227  q->done();
228 }
229 
230 void SignCommand::Private::slotError( int err, const QString & details ) {
231  q->done( err, details );
232 }
233 
234 void SignCommand::doCanceled() {
235  if ( d->controller )
236  d->controller->cancel();
237 }
238 
239 #include "signcommand.moc"
signcommand.h
output.h
input.h
Kleo::AssuanCommand::AllowProtocolMissing
Definition: assuancommand.h:251
Kleo::SignCommand::SignCommand
SignCommand()
Definition: signcommand.cpp:78
Kleo::AssuanCommandMixin
Definition: assuancommand.h:367
kleo_assert.h
boost::shared_ptr< NewSignEncryptEMailController >
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::SignCommand::~SignCommand
~SignCommand()
Definition: signcommand.cpp:84
newsignencryptemailcontroller.h
connectController
static void connectController(const QObject *controller, const QObject *d)
Definition: signcommand.cpp:133
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
kleo_assert
#define kleo_assert(cond)
Definition: kleo_assert.h:84
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::SignCommand
Definition: signcommand.h:42
Kleo::Crypto::NewSignEncryptEMailController
Definition: newsignencryptemailcontroller.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:42 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