33 #include <config-kleopatra.h>
49 #include <kleo/exception.h>
50 #include <kleo/cryptobackendfactory.h>
52 #include <gpgme++/error.h>
53 #include <gpgme++/key.h>
54 #include <gpgme++/verificationresult.h>
56 #include <KLocalizedString>
58 #include <gpg-error.h>
63 using namespace Kleo::Crypto;
64 using namespace Kleo::Formatting;
65 using namespace GpgME;
66 using namespace boost;
68 class DecryptVerifyCommandEMailBase::Private :
public QObject {
70 friend class ::Kleo::DecryptVerifyCommandEMailBase;
83 void checkForErrors()
const;
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 ); }
108 int DecryptVerifyCommandEMailBase::doStart() {
114 const QString st = sessionTitle();
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 );
136 d->controller->start();
141 void DecryptVerifyCommandEMailBase::Private::checkForErrors()
const
143 if ( !
q->senders().empty() && !
q->informativeSenders() )
144 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ),
145 i18n(
"Cannot use non-info SENDER") );
147 if ( !
q->recipients().empty() && !
q->informativeRecipients() )
148 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ),
149 i18n(
"Cannot use non-info RECIPIENT") );
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;
159 const GpgME::Protocol proto =
q->checkProtocol(
q->mode() );
161 const unsigned int numFiles =
q->numFiles();
164 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ), i18n(
"FILES present") );
167 throw Kleo::Exception(
q->makeError( GPG_ERR_ASS_NO_INPUT ),
168 i18n(
"At least one INPUT needs to be provided") );
170 if ( numInformativeSenders != 0 )
171 if ( numInformativeSenders != numInputs )
172 throw Kleo::Exception(
q->makeError( GPG_ERR_ASS_NO_INPUT ),
173 i18n(
"INPUT/SENDER --info count mismatch") );
176 if ( numMessages != numInputs )
177 throw Kleo::Exception(
q->makeError( GPG_ERR_ASS_NO_INPUT ),
178 i18n(
"INPUT/MESSAGE count mismatch") );
180 throw Kleo::Exception(
q->makeError( GPG_ERR_CONFLICT ),
181 i18n(
"MESSAGE can only be given for detached signature verification") );
185 if ( numOutputs != numInputs )
186 throw Kleo::Exception(
q->makeError( GPG_ERR_ASS_NO_OUTPUT ),
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") );
195 const CryptoBackend::Protocol *
const backend = CryptoBackendFactory::instance()->protocol( proto );
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() );
202 void DecryptVerifyCommandEMailBase::doCanceled() {
204 d->controller->cancel();
208 void DecryptVerifyCommandEMailBase::Private::slotProgress(
const QString& what,
int current,
int total )
217 void DecryptVerifyCommandEMailBase::Private::verificationResult(
const VerificationResult & vResult )
220 const std::vector<Signature> sigs = vResult.signatures();
222 Q_FOREACH (
const Signature & sig, sigs ) {
223 const QString s =
signatureToString( sig, DecryptVerifyResult::keyForSignature( sig, signers ) );
225 q->sendStatusEncoded(
"SIGSTATUS",
226 color + (
' ' +
hexencode( s.toUtf8().constData() ) ) );
231 #include "decryptverifycommandemailbase.moc"
~DecryptVerifyCommandEMailBase()
std::string hexencode(const char *s)
DecryptVerifyCommandEMailBase()
#define kleo_assert(cond)
static boost::shared_ptr< const KeyCache > instance()