Commit 6ac7ef85 authored by Andre Heinecke's avatar Andre Heinecke Committed by Daniel Vrátil
Browse files

API Break: Remove backends from libkleo

Libkleo is now a GUI and Utility Library for QGpgME.
This depends on the branch gpgmepp in gpgme proper where
most of the backend code has been moved into.
parent fc7fe020
......@@ -22,7 +22,6 @@ include(ECMAddTests)
set(PIM_VERSION "5.3.45")
set(LIBKLEO_LIB_VERSION ${PIM_VERSION})
set(QT_REQUIRED_VERSION "5.6.0")
set(GPGMEPP_LIB_VERSION "5.3.40")
set(KDEPIMTEXTEDIT_VERSION "5.3.40")
set(PIMCOMMON_LIB_VERSION "5.3.40")
......@@ -35,9 +34,11 @@ find_package(KF5WindowSystem ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5CoreAddons ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5ItemModels ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Gpgmepp ${GPGMEPP_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5PimTextEdit ${KDEPIMTEXTEDIT_VERSION} CONFIG)
find_package(Gpgmepp 1.7.0)
set_package_properties(Gpgmepp PROPERTIES DESCRIPTION "GpgME++ Library" URL "http://www.gnupg.org" TYPE REQUIRED PURPOSE "GpgME++ is required for OpenPGP support")
find_package(Boost 1.34.0)
set_package_properties(Boost PROPERTIES DESCRIPTION "Boost C++ Libraries" URL "http://www.boost.org" TYPE REQUIRED PURPOSE "Boost is required for building most KDEPIM applications")
......
......@@ -15,67 +15,16 @@ string(REPLACE "-pedantic" "" FOO "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${FOO}")
add_subdirectory( pics )
add_subdirectory( backends )
if (BUILD_TESTING)
add_subdirectory( tests )
endif()
########### next target ###############
set(libkleo_backend_qgpgme_SRCS
backends/qgpgme/gnupgprocessbase.cpp
backends/qgpgme/qgpgmeprogresstokenmapper.cpp
backends/qgpgme/qgpgmebackend.cpp
backends/qgpgme/threadedjobmixin.cpp
backends/qgpgme/qgpgmekeylistjob.cpp
backends/qgpgme/qgpgmelistallkeysjob.cpp
backends/qgpgme/qgpgmekeygenerationjob.cpp
backends/qgpgme/qgpgmeimportjob.cpp
backends/qgpgme/qgpgmeimportfromkeyserverjob.cpp
backends/qgpgme/qgpgmeexportjob.cpp
backends/qgpgme/qgpgmesecretkeyexportjob.cpp
backends/qgpgme/qgpgmechangeexpiryjob.cpp
backends/qgpgme/qgpgmechangeownertrustjob.cpp
backends/qgpgme/qgpgmechangepasswdjob.cpp
backends/qgpgme/qgpgmedownloadjob.cpp
backends/qgpgme/qgpgmedeletejob.cpp
backends/qgpgme/qgpgmeencryptjob.cpp
backends/qgpgme/qgpgmedecryptjob.cpp
backends/qgpgme/qgpgmesignjob.cpp
backends/qgpgme/qgpgmesignkeyjob.cpp
backends/qgpgme/qgpgmeadduseridjob.cpp
backends/qgpgme/qgpgmeverifydetachedjob.cpp
backends/qgpgme/qgpgmeverifyopaquejob.cpp
backends/qgpgme/qgpgmesignencryptjob.cpp
backends/qgpgme/qgpgmedecryptverifyjob.cpp
backends/qgpgme/qgpgmecryptoconfig.cpp
backends/qgpgme/qgpgmenewcryptoconfig.cpp
backends/qgpgme/qgpgmerefreshkeysjob.cpp
backends/qgpgme/qgpgmekeyformailboxjob.cpp
)
ecm_qt_declare_logging_category(libkleo_backend_qgpgme_SRCS HEADER gpgme_backend_debug.h IDENTIFIER GPGPME_BACKEND_LOG CATEGORY_NAME org.kde.pim.gpgme_backend)
set(libkleo_backend_chiasmus_SRCS
backends/chiasmus/config_data.c
backends/chiasmus/obtainkeysjob.cpp
backends/chiasmus/symcryptrunprocessbase.cpp
backends/chiasmus/chiasmusjob.cpp
backends/chiasmus/chiasmuslibrary.cpp
backends/chiasmus/chiasmusbackend.cpp
)
set(libkleo_core_SRCS
kleo/checksumdefinition.cpp
kleo/cryptobackend.cpp
kleo/cryptobackendfactory.cpp
kleo/enum.cpp
kleo/exception.cpp
kleo/dn.cpp
kleo/job.cpp
kleo/multideletejob.cpp
kleo/hierarchicalkeylistjob.cpp
kleo/defaultkeyfilter.cpp
kleo/defaultkeygenerationjob.cpp
kleo/kconfigbasedkeyfilter.cpp
kleo/keyfiltermanager.cpp
models/keycache.cpp
......@@ -117,25 +66,16 @@ ki18n_wrap_ui(libkleo_ui_common_SRCS
ui/directoryserviceswidget.ui
)
set(kleo_LIB_SRCS ${libkleo_core_SRCS} ${libkleo_backend_chiasmus_SRCS}
${libkleo_ui_SRCS}
${libkleo_ui_common_SRCS}
${libkleo_backend_qgpgme_SRCS})
set(kleo_LIB_SRCS ${libkleo_core_SRCS} ${libkleo_ui_SRCS}
${libkleo_ui_common_SRCS})
set(kleo_LIB_LIBS PUBLIC KF5::QGpgme PRIVATE Qt5::Widgets
KF5::I18n
KF5::Completion
KF5::ConfigCore
KF5::CoreAddons
KF5::WindowSystem
KF5::WidgetsAddons
KF5::Codecs
KF5::ItemModels)
if (WIN32)
set(kleo_LIB_LIBS ${kleo_LIB_LIBS} PUBLIC KF5::Gpgmepp)
else()
set(kleo_LIB_LIBS ${kleo_LIB_LIBS} PUBLIC KF5::Gpgmepp-pthread)
endif()
set(kleo_LIB_LIBS PUBLIC QGpgme Gpgmepp PRIVATE Qt5::Widgets
KF5::I18n
KF5::Completion
KF5::ConfigCore
KF5::CoreAddons
KF5::WindowSystem
KF5::WidgetsAddons)
if (KF5PimTextEdit_FOUND)
add_definitions(-DHAVE_PIMTEXTEDIT)
......@@ -169,44 +109,15 @@ target_include_directories(KF5Libkleo INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTA
ecm_generate_headers(libkleo_CamelCase_HEADERS
HEADER_NAMES
AbstractImportJob
AddUserIDJob
ChangeExpiryJob
ChangeOwnerTrustJob
ChangePasswdJob
ChecksumDefinition
CryptoBackend
CryptoBackendFactory
CryptoConfig
DecryptJob
DecryptVerifyJob
DefaultKeyFilter
DefaultKeyGenerationJob
DeleteJob
Dn
EncryptJob
Enum
Stl_Util
Dn
Exception
ExportJob
ImportFromKeyserverJob
ImportJob
Job
KeyFilter
ChecksumDefinition
KeyFilterManager
KeyForMailboxJob
KeyGenerationJob
KeyListJob
ListAllKeysJob
MultiDeleteJob
OidMap
Predicates
SignEncryptJob
SignJob
SignKeyJob
SpecialJob
Stl_Util
VerifyDetachedJob
VerifyOpaqueJob
REQUIRED_HEADERS libkleo_HEADERS
PREFIX Libkleo
RELATIVE kleo
......
add_subdirectory( chiasmus )
if(NOT MSVC)
set(HAVE_C99_INITIALIZERS 1)
endif()
configure_file (config-chiasmus.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-chiasmus.h )
This diff is collapsed.
/*
chiasmusbackend.h
This file is part of libkleopatra, the KDE keymanagement library
Copyright (c) 2005 Klarälvdalens Datakonsult AB
Libkleopatra is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
Libkleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef __KLEO_CHIASMUSBACKEND_H__
#define __KLEO_CHIASMUSBACKEND_H__
#include "libkleo/cryptobackend.h"
namespace Kleo
{
class CryptoConfig;
}
class QString;
namespace Kleo
{
class ChiasmusBackend : public Kleo::CryptoBackend
{
public:
ChiasmusBackend();
~ChiasmusBackend();
static const ChiasmusBackend *instance()
{
return self;
}
QString name() const Q_DECL_OVERRIDE;
QString displayName() const Q_DECL_OVERRIDE;
Kleo::CryptoConfig *config() const Q_DECL_OVERRIDE;
Kleo::CryptoBackend::Protocol *openpgp() const Q_DECL_OVERRIDE
{
return 0;
}
Kleo::CryptoBackend::Protocol *smime() const Q_DECL_OVERRIDE
{
return 0;
}
Kleo::CryptoBackend::Protocol *protocol(const char *name) const Q_DECL_OVERRIDE;
bool checkForOpenPGP(QString *reason = Q_NULLPTR) const Q_DECL_OVERRIDE;
bool checkForSMIME(QString *reason = Q_NULLPTR) const Q_DECL_OVERRIDE;
bool checkForChiasmus(QString *reason = Q_NULLPTR) const;
bool checkForProtocol(const char *name, QString *reason = Q_NULLPTR) const Q_DECL_OVERRIDE;
bool supportsOpenPGP() const Q_DECL_OVERRIDE
{
return false;
}
bool supportsSMIME() const Q_DECL_OVERRIDE
{
return false;
}
bool supportsProtocol(const char *name) const Q_DECL_OVERRIDE;
const char *enumerateProtocols(int i) const Q_DECL_OVERRIDE;
private:
class CryptoConfig;
class Protocol;
mutable CryptoConfig *mCryptoConfig;
mutable Protocol *mProtocol;
static ChiasmusBackend *self;
};
}
#endif // __KLEO_CHIASMUSBACKEND_H__
/*
chiasmusjob.cpp
This file is part of libkleopatra, the KDE keymanagement library
Copyright (c) 2005 Klar�vdalens Datakonsult AB
Libkleopatra is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
Libkleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include "chiasmusjob.h"
#include "chiasmusbackend.h"
#include "symcryptrunprocessbase.h"
#include "libkleo/cryptoconfig.h"
#include <gpgme++/error.h>
#include <kshell.h>
#include <KLocalizedString>
#include <QDebug>
#include <kmessagebox.h>
#include <QTimer>
#include <QVariant>
#include <memory>
#include <cassert>
using namespace GpgME;
Kleo::ChiasmusJob::ChiasmusJob(Mode mode)
: Kleo::SpecialJob(0),
mSymCryptRun(0),
mError(0),
mCanceled(false),
mTimeout(false),
mMode(mode)
{
}
Kleo::ChiasmusJob::~ChiasmusJob() {}
GpgME::Error Kleo::ChiasmusJob::setup()
{
if (!checkPreconditions()) {
return mError = Error::fromCode(GPG_ERR_INV_VALUE);
}
const Kleo::CryptoConfigEntry *class_
= ChiasmusBackend::instance()->config()->entry(QStringLiteral("Chiasmus"), QStringLiteral("General"), QStringLiteral("symcryptrun-class"));
const Kleo::CryptoConfigEntry *chiasmus
= ChiasmusBackend::instance()->config()->entry(QStringLiteral("Chiasmus"), QStringLiteral("General"), QStringLiteral("path"));
const Kleo::CryptoConfigEntry *timeoutEntry
= ChiasmusBackend::instance()->config()->entry(QStringLiteral("Chiasmus"), QStringLiteral("General"), QStringLiteral("timeout"));
if (!class_ || !chiasmus || !timeoutEntry) {
return mError = Error::fromCode(GPG_ERR_INTERNAL);
}
mSymCryptRun = new SymCryptRunProcessBase(class_->stringValue(),
KShell::tildeExpand(chiasmus->urlValue().path()),
mKey, mOptions,
mMode == Encrypt
? SymCryptRunProcessBase::Encrypt
: SymCryptRunProcessBase::Decrypt,
this);
mSymCryptRun->setObjectName(QStringLiteral("symcryptrun"));
QTimer::singleShot(timeoutEntry->uintValue() * 1000, this,
&ChiasmusJob::slotTimeout);
return GpgME::Error();
}
namespace
{
struct LaterDeleter {
QObject *_this;
LaterDeleter(QObject *o) : _this(o) {}
~LaterDeleter()
{
if (_this) {
_this->deleteLater();
}
}
void disable()
{
_this = 0;
}
};
}
GpgME::Error Kleo::ChiasmusJob::start()
{
LaterDeleter d(this);
if (const GpgME::Error err = setup()) {
return mError = err;
}
connect(mSymCryptRun, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(finished()));
if (!mSymCryptRun->launch(mInput)) {
return mError = Error::fromCode(GPG_ERR_ENOENT); // what else?
}
d.disable();
return mError = GpgME::Error();
}
GpgME::Error Kleo::ChiasmusJob::finished()
{
if (!mSymCryptRun) {
mError = Error::fromCode(GPG_ERR_INTERNAL);
} else if (mCanceled) {
mError = Error::fromCode(GPG_ERR_CANCELED);
} else if (mTimeout) {
mError = Error::fromCode(GPG_ERR_TIMEOUT);
} else if (mSymCryptRun->exitStatus() != QProcess::NormalExit) {
mError = Error::fromCode(GPG_ERR_GENERAL);
} else
switch (mSymCryptRun->exitCode()) {
case 0: // success
mOutput = mSymCryptRun->output();
mError = GpgME::Error();
break;
default:
case 1: // Some error occurred
mStderr = mSymCryptRun->stdErr();
mError = Error::fromCode(GPG_ERR_GENERAL);
break;
case 2: // No valid passphrase was provided
mError = Error::fromCode(GPG_ERR_INV_PASSPHRASE);
break;
case 3: // Canceled
mError = Error::fromCode(GPG_ERR_CANCELED);
break;
}
const Kleo::CryptoConfigEntry *showOutput
= ChiasmusBackend::instance()->config()->entry(QStringLiteral("Chiasmus"), QStringLiteral("General"), QStringLiteral("show-output"));
if (showOutput && showOutput->boolValue()) {
showChiasmusOutput();
}
Q_EMIT done();
Q_EMIT SpecialJob::result(mError, QVariant(mOutput));
return mError;
}
void Kleo::ChiasmusJob::showChiasmusOutput()
{
qDebug();
if (mStderr.isEmpty()) {
return;
}
KMessageBox::information(0 /*how to get a parent widget?*/,
mStderr,
i18n("Output from chiasmus"));
}
GpgME::Error Kleo::ChiasmusJob::exec()
{
if (const GpgME::Error err = setup()) {
return mError = err;
}
if (!mSymCryptRun->launch(mInput, true)) {
delete mSymCryptRun; mSymCryptRun = 0;
return mError = Error::fromCode(GPG_ERR_ENOENT); // what else?
}
const GpgME::Error err = finished();
delete mSymCryptRun; mSymCryptRun = 0;
return err;
}
bool Kleo::ChiasmusJob::checkPreconditions() const
{
return !mKey.isEmpty();
}
void Kleo::ChiasmusJob::slotCancel()
{
if (mSymCryptRun) {
mSymCryptRun->kill();
}
mCanceled = true;
}
void Kleo::ChiasmusJob::slotTimeout()
{
if (!mSymCryptRun) {
return;
}
mSymCryptRun->kill();
mTimeout = true;
}
void Kleo::ChiasmusJob::showErrorDialog(QWidget *parent, const QString &caption) const
{
if (!mError) {
return;
}
if (mError.isCanceled()) {
return;
}
const QString reason = QString::fromLocal8Bit(mError.asString());
const QString msg = (mMode == Encrypt
? i18n("Encryption failed: %1", reason)
: i18n("Decryption failed: %1", reason));
if (!mStderr.isEmpty()) {
const QString details = i18n("The following was received on stderr:\n%1", mStderr);
KMessageBox::detailedError(parent, msg, details, caption);
} else {
KMessageBox::error(parent, msg, caption);
}
}
/*
chiasmusjob.h
This file is part of libkleopatra, the KDE keymanagement library
Copyright (c) 2005 Klarälvdalens Datakonsult AB
Libkleopatra is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
Libkleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef __KLEO_CHIASMUSJOB_H__
#define __KLEO_CHIASMUSJOB_H__
#include "libkleo/specialjob.h"
#include <gpgme++/context.h>
namespace Kleo
{
class SymCryptRunProcessBase;
/**
@short SpecialJob for Chiasmus operations
*/
class ChiasmusJob : public Kleo::SpecialJob
{
Q_OBJECT
Q_ENUMS(Mode)
Q_PROPERTY(Mode mode READ mode)
Q_PROPERTY(QString key READ key WRITE setKey)
Q_PROPERTY(QString options READ options WRITE setOptions)
Q_PROPERTY(QByteArray input READ input WRITE setInput)
Q_PROPERTY(QByteArray result READ result)
public:
enum Mode {
Encrypt, Decrypt
};
explicit ChiasmusJob(Mode op);
~ChiasmusJob();
/*!\reimp SpecialJob */
GpgME::Error start() Q_DECL_OVERRIDE;
/*!\reimp SpecialJob */
GpgME::Error exec() Q_DECL_OVERRIDE;
/*!\reimp Kleo::Job */
void showErrorDialog(QWidget *, const QString &) const Q_DECL_OVERRIDE;
Mode mode() const
{
return mMode;
}
QString key() const
{
return mKey;
}
void setKey(const QString &key)
{
mKey = key;
}
QString options() const
{
return mOptions;
}
void setOptions(const QString &options)
{
mOptions = options;
}