• 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
decryptverifycommandemailbase.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/decryptverifycommandemailbase.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 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  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "decryptverifycommandemailbase.h"
36 
37 #include <crypto/decryptverifytask.h>
38 #include <crypto/decryptverifyemailcontroller.h>
39 
40 #include <utils/formatting.h>
41 
42 #include <models/keycache.h>
43 
44 #include <utils/hex.h>
45 #include <utils/input.h>
46 #include <utils/output.h>
47 #include <utils/kleo_assert.h>
48 
49 #include <kleo/exception.h>
50 #include <kleo/cryptobackendfactory.h>
51 
52 #include <gpgme++/error.h>
53 #include <gpgme++/key.h>
54 #include <gpgme++/verificationresult.h>
55 
56 #include <KLocalizedString>
57 
58 #include <gpg-error.h>
59 
60 #include <cassert>
61 
62 using namespace Kleo;
63 using namespace Kleo::Crypto;
64 using namespace Kleo::Formatting;
65 using namespace GpgME;
66 using namespace boost;
67 
68 class DecryptVerifyCommandEMailBase::Private : public QObject {
69  Q_OBJECT
70  friend class ::Kleo::DecryptVerifyCommandEMailBase;
71  DecryptVerifyCommandEMailBase * const q;
72 public:
73  explicit Private( DecryptVerifyCommandEMailBase * qq )
74  : QObject(),
75  q( qq ),
76  controller()
77  {
78  }
79 
80  ~Private() {
81  }
82 
83  void checkForErrors() const;
84 
85 
86 public Q_SLOTS:
87  void slotProgress( const QString & what, int current, int total );
88  void verificationResult( const GpgME::VerificationResult & );
89  void slotDone() { q->done(); }
90  void slotError( int err, const QString & details ) { q->done( err, details ); }
91 
92 public:
93 
94 private:
95  shared_ptr<DecryptVerifyEMailController> controller;
96 };
97 
98 
99 DecryptVerifyCommandEMailBase::DecryptVerifyCommandEMailBase()
100  : AssuanCommandMixin<DecryptVerifyCommandEMailBase>(), d( new Private( this ) )
101 {
102 
103 }
104 
105 
106 DecryptVerifyCommandEMailBase::~DecryptVerifyCommandEMailBase() {}
107 
108 int DecryptVerifyCommandEMailBase::doStart() {
109 
110  d->checkForErrors();
111 
112  d->controller.reset( new DecryptVerifyEMailController( shared_from_this() ) );
113 
114  const QString st = sessionTitle();
115  if ( !st.isEmpty() )
116  Q_FOREACH ( const shared_ptr<Input> & i, inputs() )
117  i->setLabel( st );
118 
119  d->controller->setSessionId( sessionId() );
120  d->controller->setOperation( operation() );
121  d->controller->setVerificationMode( messages().empty() ? Opaque : Detached );
122  d->controller->setInputs( inputs() );
123  d->controller->setSignedData( messages() );
124  d->controller->setOutputs( outputs() );
125  d->controller->setWizardShown( !hasOption("silent") );
126  d->controller->setProtocol( checkProtocol( mode() ) );
127  if ( informativeSenders() )
128  d->controller->setInformativeSenders( senders() );
129  QObject::connect( d->controller.get(), SIGNAL(done()),
130  d.get(), SLOT(slotDone()), Qt::QueuedConnection );
131  QObject::connect( d->controller.get(), SIGNAL(error(int,QString)),
132  d.get(), SLOT(slotError(int,QString)), Qt::QueuedConnection );
133  QObject::connect( d->controller.get(), SIGNAL(verificationResult(GpgME::VerificationResult)),
134  d.get(), SLOT(verificationResult(GpgME::VerificationResult)), Qt::QueuedConnection );
135 
136  d->controller->start();
137 
138  return 0;
139 }
140 
141 void DecryptVerifyCommandEMailBase::Private::checkForErrors() const
142 {
143  if ( !q->senders().empty() && !q->informativeSenders() )
144  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ),
145  i18n("Cannot use non-info SENDER") );
146 
147  if ( !q->recipients().empty() && !q->informativeRecipients() )
148  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ),
149  i18n("Cannot use non-info RECIPIENT") );
150 
151  // ### use informative recipients and senders
152 
153  const unsigned int numInputs = q->inputs().size();
154  const unsigned int numMessages = q->messages().size();
155  const unsigned int numOutputs = q->outputs().size();
156  const unsigned int numInformativeSenders = q->informativeSenders() ? q->senders().size() : 0;
157 
158  const DecryptVerifyOperation op = q->operation();;
159  const GpgME::Protocol proto = q->checkProtocol( q->mode() );
160 
161  const unsigned int numFiles = q->numFiles();
162 
163  if ( numFiles )
164  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ), i18n("FILES present") );
165 
166  if ( !numInputs )
167  throw Kleo::Exception( q->makeError( GPG_ERR_ASS_NO_INPUT ),
168  i18n("At least one INPUT needs to be provided") );
169 
170  if ( numInformativeSenders != 0 )
171  if ( numInformativeSenders != numInputs )
172  throw Kleo::Exception( q->makeError( GPG_ERR_ASS_NO_INPUT ), //TODO use better error code if possible
173  i18n("INPUT/SENDER --info count mismatch") );
174 
175  if ( numMessages ) {
176  if ( numMessages != numInputs )
177  throw Kleo::Exception( q->makeError( GPG_ERR_ASS_NO_INPUT ), //TODO use better error code if possible
178  i18n("INPUT/MESSAGE count mismatch") );
179  else if ( op != Verify )
180  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ),
181  i18n("MESSAGE can only be given for detached signature verification") );
182  }
183 
184  if ( numOutputs ) {
185  if ( numOutputs != numInputs )
186  throw Kleo::Exception( q->makeError( GPG_ERR_ASS_NO_OUTPUT ), //TODO use better error code if possible
187  i18n("INPUT/OUTPUT count mismatch") );
188  else if ( numMessages )
189  throw Kleo::Exception( q->makeError( GPG_ERR_CONFLICT ),
190  i18n("Cannot use OUTPUT and MESSAGE simultaneously") );
191  }
192 
193  kleo_assert( proto != UnknownProtocol );
194 
195  const CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( proto );
196  if ( !backend )
197  throw Kleo::Exception( q->makeError( GPG_ERR_UNSUPPORTED_PROTOCOL ),
198  proto == OpenPGP ? i18n("No backend support for OpenPGP") :
199  proto == CMS ? i18n("No backend support for S/MIME") : QString() );
200 }
201 
202 void DecryptVerifyCommandEMailBase::doCanceled() {
203  if ( d->controller )
204  d->controller->cancel();
205 }
206 
207 
208 void DecryptVerifyCommandEMailBase::Private::slotProgress( const QString& what, int current, int total )
209 {
210  Q_UNUSED( what );
211  Q_UNUSED( current );
212  Q_UNUSED( total );
213  // ### FIXME report progress, via sendStatus()
214 }
215 
216 
217 void DecryptVerifyCommandEMailBase::Private::verificationResult( const VerificationResult & vResult )
218 {
219  try {
220  const std::vector<Signature> sigs = vResult.signatures();
221  const std::vector<Key> signers = KeyCache::instance()->findSigners( vResult );
222  Q_FOREACH ( const Signature & sig, sigs ) {
223  const QString s = signatureToString( sig, DecryptVerifyResult::keyForSignature( sig, signers ) );
224  const char * color = summaryToString( sig.summary() );
225  q->sendStatusEncoded( "SIGSTATUS",
226  color + ( ' ' + hexencode( s.toUtf8().constData() ) ) );
227  }
228  } catch ( ... ) {}
229 }
230 
231 #include "decryptverifycommandemailbase.moc"
Kleo::Detached
Definition: types.h:55
output.h
Kleo::DecryptVerifyCommandEMailBase::~DecryptVerifyCommandEMailBase
~DecryptVerifyCommandEMailBase()
Definition: decryptverifycommandemailbase.cpp:106
input.h
decryptverifytask.h
Kleo::hexencode
std::string hexencode(const char *s)
Definition: hex.cpp:123
formatting.h
Kleo::DecryptVerifyCommandEMailBase
Definition: decryptverifycommandemailbase.h:43
Kleo::AssuanCommandMixin
Definition: assuancommand.h:367
kleo_assert.h
boost::shared_ptr< DecryptVerifyEMailController >
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Crypto::DecryptVerifyEMailController
Definition: decryptverifyemailcontroller.h:69
Kleo::Class::OpenPGP
Definition: classify.h:49
hex.h
Kleo::Verify
Definition: types.h:47
Kleo::DecryptVerifyOperation
DecryptVerifyOperation
Definition: types.h:45
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
Kleo::Class::CMS
Definition: classify.h:48
Kleo::Formatting::summaryToString
const char * summaryToString(const GpgME::Signature::Summary summary)
decryptverifyemailcontroller.h
Kleo::DecryptVerifyCommandEMailBase::DecryptVerifyCommandEMailBase
DecryptVerifyCommandEMailBase()
Definition: decryptverifycommandemailbase.cpp:99
kleo_assert
#define kleo_assert(cond)
Definition: kleo_assert.h:84
decryptverifycommandemailbase.h
Kleo::Formatting::signatureToString
QString signatureToString(const GpgME::Signature &sig, const GpgME::Key &key)
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::KeyCache::instance
static boost::shared_ptr< const KeyCache > instance()
Definition: keycache.cpp:189
Kleo::Opaque
Definition: types.h:54
keycache.h
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