diff --git a/CMakeLists.txt b/CMakeLists.txt index a62be9060..bfd9d360e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,204 +1,204 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(RELEASE_SERVICE_VERSION_MAJOR "22") set(RELEASE_SERVICE_VERSION_MINOR "03") set(RELEASE_SERVICE_VERSION_MICRO "70") # The RELEASE_SERVICE_VERSION is used by Gpg4win to add the Gpg4win version if (NOT RELEASE_SERVICE_VERSION) set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}") endif() if(RELEASE_SERVICE_VERSION_MICRO LESS 10) set(KDE_APPLICATIONS_COMPACT_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}${RELEASE_SERVICE_VERSION_MINOR}0${RELEASE_SERVICE_VERSION_MICRO}") else() set(KDE_APPLICATIONS_COMPACT_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}${RELEASE_SERVICE_VERSION_MINOR}${RELEASE_SERVICE_VERSION_MICRO}") endif() set(KLEOPATRA_VERSION_MAJOR "3") set(KLEOPATRA_VERSION_MINOR "1") set(KLEOPATRA_VERSION_MICRO "19") set(kleopatra_version "${KLEOPATRA_VERSION_MAJOR}.${KLEOPATRA_VERSION_MINOR}.${KLEOPATRA_VERSION_MICRO}.${KDE_APPLICATIONS_COMPACT_VERSION}") # The following is for Windows set(kleopatra_version_win "${KLEOPATRA_VERSION_MAJOR}.${KLEOPATRA_VERSION_MINOR}.${KLEOPATRA_VERSION_MICRO}") set(kleopatra_fileversion_win "${KLEOPATRA_VERSION_MAJOR},${KLEOPATRA_VERSION_MINOR},${KLEOPATRA_VERSION_MICRO},0") project(kleopatra VERSION ${kleopatra_version}) option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF) # Standalone build. Find / include everything necessary. set(KF5_MIN_VERSION "5.88.0") set(KMIME_VERSION "5.19.40") -set(LIBKLEO_VERSION "5.19.45") +set(LIBKLEO_VERSION "5.19.46") set(QT_REQUIRED_VERSION "5.15.2") set(GPGME_REQUIRED_VERSION "1.13.1") set(BOOST_REQUIRED_VERSION "1.58") if (WIN32) set(KF5_WANT_VERSION "5.70.0") set(KMIME_WANT_VERSION "5.12.0") else () set(KF5_WANT_VERSION ${KF5_MIN_VERSION}) set(KMIME_WANT_VERSION ${KMIME_VERSION}) endif () find_package(ECM ${KF5_WANT_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) include(ECMInstallIcons) include(ECMSetupVersion) include(ECMAddTests) include(GenerateExportHeader) include(ECMGenerateHeaders) include(FeatureSummary) include(CheckFunctionExists) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) # Find KF5 packages find_package(KF5WidgetsAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5ConfigWidgets ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5CoreAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5Config ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5I18n ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5ItemModels ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5WindowSystem ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5DocTools ${KF5_WANT_VERSION} CONFIG) find_package(KF5Crash ${KF5_WANT_VERSION} REQUIRED) set_package_properties(KF5DocTools PROPERTIES DESCRIPTION "Documentation tools" PURPOSE "Required to generate Kleopatra documentation." TYPE OPTIONAL) # Optional packages if (WIN32) # Only a replacement available for Windows so this # is required on other platforms. find_package(KF5DBusAddons ${KF5_WANT_VERSION} CONFIG) set_package_properties(KF5DBusAddons PROPERTIES DESCRIPTION "Support library to work with DBus" PURPOSE "DBus session integration" URL "https://inqlude.org/libraries/kdbusaddons.html" TYPE OPTIONAL) else() find_package(KF5DBusAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) set(_kleopatra_dbusaddons_libs KF5::DBusAddons) endif() set(HAVE_QDBUS ${Qt5DBus_FOUND}) find_package(Gpgmepp ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) if (Gpgmepp_VERSION VERSION_GREATER_EQUAL "1.16.0") set(GPGMEPP_SUPPORTS_TRUST_SIGNATURES 1) endif() find_package(QGpgme ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.16.0") set(QGPGME_SUPPORTS_TRUST_SIGNATURES 1) set(QGPGME_SUPPORTS_SIGNATURE_EXPIRATION 1) endif() if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.16.1") set(QGPGME_SUPPORTS_CHANGING_EXPIRATION_OF_COMPLETE_KEY 1) set(QGPGME_CRYPTOCONFIGENTRY_HAS_DEFAULT_VALUE 1) endif() # Kdepimlibs packages find_package(KF5Libkleo ${LIBKLEO_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_WANT_VERSION} CONFIG REQUIRED) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test Network PrintSupport) find_package(Assuan2 REQUIRED) find_package(Boost ${BOOST_REQUIRED_VERSION} MODULE REQUIRED) find_path(Boost_TOPOLOGICAL_SORT_DIR NAMES boost/graph/topological_sort.hpp PATHS ${Boost_INCLUDE_DIRS}) if(NOT Boost_TOPOLOGICAL_SORT_DIR) message(FATAL_ERROR "The Boost Topological_sort header was NOT found. Should be part of Boost graph module.") endif() set(kleopatra_release FALSE) if(NOT kleopatra_release) find_package(Git) if(GIT_FOUND) execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE rc ERROR_QUIET) if(rc EQUAL 0) execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --format=%h ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE Kleopatra_WC_REVISION) string(REGEX REPLACE "\n" "" Kleopatra_WC_REVISION "${Kleopatra_WC_REVISION}") execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --format=%cI ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE Kleopatra_WC_LAST_CHANGED_DATE) string(REGEX REPLACE "^([0-9]+)-([0-9]+)-([0-9]+)T([0-9]+):([0-9]+):([0-9]+).*$" "\\1\\2\\3T\\4\\5\\6" Kleopatra_WC_LAST_CHANGED_DATE "${Kleopatra_WC_LAST_CHANGED_DATE}") set(kleopatra_version "${kleopatra_version}+git${Kleopatra_WC_LAST_CHANGED_DATE}~${Kleopatra_WC_REVISION}") endif() endif() endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version-kleopatra.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/version-kleopatra.h) include (ConfigureChecks.cmake) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-kleopatra.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kleopatra.h) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${ASSUAN2_INCLUDES} ) add_definitions(-D_ASSUAN_ONLY_GPG_ERRORS) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050e00) add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055900) if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces -Wno-parentheses -Wno-ignored-qualifiers") endif() add_definitions(-DQT_NO_EMIT) remove_definitions(-DQT_NO_FOREACH) kde_enable_exceptions() option(USE_UNITY_CMAKE_SUPPORT "Use UNITY cmake support (speedup compile time)" OFF) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT OFF) if (USE_UNITY_CMAKE_SUPPORT) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT ON) endif() add_subdirectory(pics) add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(tests) add_subdirectory(autotests) endif() ecm_qt_install_logging_categories( EXPORT KLEOPATRA FILE kleopatra.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} ) ki18n_install(po) if(KF5DocTools_FOUND) kdoctools_install(po) add_subdirectory(doc) endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/commands/signclipboardcommand.cpp b/src/commands/signclipboardcommand.cpp index 299ec18e7..3fe3e8c15 100644 --- a/src/commands/signclipboardcommand.cpp +++ b/src/commands/signclipboardcommand.cpp @@ -1,177 +1,187 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/signclipboardcommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "signclipboardcommand.h" #ifndef QT_NO_CLIPBOARD #include "command_p.h" #include #include #include +#include +#include #include #include #include "kleopatra_debug.h" #include #include #include +#include + #include using namespace Kleo; using namespace Kleo::Commands; using namespace Kleo::Crypto; class SignClipboardCommand::Private : public Command::Private { friend class ::Kleo::Commands::SignClipboardCommand; SignClipboardCommand *q_func() const { return static_cast(q); } public: explicit Private(SignClipboardCommand *qq, KeyListController *c); ~Private() override; void init(); private: void slotSignersResolved(); void slotControllerDone() { finished(); } void slotControllerError(int, const QString &) { finished(); } private: std::shared_ptr shared_qq; std::shared_ptr input; SignEMailController controller; }; SignClipboardCommand::Private *SignClipboardCommand::d_func() { return static_cast(d.get()); } const SignClipboardCommand::Private *SignClipboardCommand::d_func() const { return static_cast(d.get()); } #define d d_func() #define q q_func() SignClipboardCommand::Private::Private(SignClipboardCommand *qq, KeyListController *c) : Command::Private(qq, c), shared_qq(qq, [](SignClipboardCommand*){}), input(), controller(SignEMailController::ClipboardMode) { } SignClipboardCommand::Private::~Private() { qCDebug(KLEOPATRA_LOG); } SignClipboardCommand::SignClipboardCommand(GpgME::Protocol protocol, KeyListController *c) : Command(new Private(this, c)) { d->init(); d->controller.setProtocol(protocol); } SignClipboardCommand::SignClipboardCommand(GpgME::Protocol protocol, QAbstractItemView *v, KeyListController *c) : Command(v, new Private(this, c)) { d->init(); d->controller.setProtocol(protocol); } void SignClipboardCommand::Private::init() { controller.setExecutionContext(shared_qq); controller.setDetachedSignature(false); connect(&controller, SIGNAL(done()), q, SLOT(slotControllerDone())); connect(&controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString))); } SignClipboardCommand::~SignClipboardCommand() { qCDebug(KLEOPATRA_LOG); } // static -bool SignClipboardCommand::canSignCurrentClipboard() +bool SignClipboardCommand::canSignCurrentClipboard(GpgME::Protocol protocol) { - if (const QClipboard *clip = QApplication::clipboard()) - if (const QMimeData *mime = clip->mimeData()) { - return mime->hasText(); + bool canSign = false; + if (const QClipboard *const clip = QApplication::clipboard()) { + if (const QMimeData *const mime = clip->mimeData()) { + canSign = mime->hasText(); } - return false; + } + if (canSign) { + canSign &= Kleo::any_of(KeyCache::instance()->secretKeys(), + [](const auto &k) { return k.hasSecret(); }); + } + return canSign; } void SignClipboardCommand::doStart() { try { // snapshot clipboard content here, in case it's being changed... d->input = Input::createFromClipboard(); connect(&d->controller, SIGNAL(signersResolved()), this, SLOT(slotSignersResolved())); d->controller.startResolveSigners(); } catch (const std::exception &e) { d->information(i18n("An error occurred: %1", QString::fromLocal8Bit(e.what())), i18n("Sign Clipboard Error")); d->finished(); } } void SignClipboardCommand::Private::slotSignersResolved() { try { controller.setInputAndOutput(input, Output::createFromClipboard()); input.reset(); // no longer needed, so don't keep a reference controller.start(); } catch (const std::exception &e) { information(i18n("An error occurred: %1", QString::fromLocal8Bit(e.what())), i18n("Sign Clipboard Error")); finished(); } } void SignClipboardCommand::doCancel() { qCDebug(KLEOPATRA_LOG); d->controller.cancel(); } #undef d #undef q #include "moc_signclipboardcommand.cpp" #endif // QT_NO_CLIPBOARD diff --git a/src/commands/signclipboardcommand.h b/src/commands/signclipboardcommand.h index e6aafdb5e..e7dbbf06f 100644 --- a/src/commands/signclipboardcommand.h +++ b/src/commands/signclipboardcommand.h @@ -1,52 +1,52 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/signclipboardcommand.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include #ifndef QT_NO_CLIPBOARD #include #include namespace Kleo { namespace Commands { class SignClipboardCommand : public Command { Q_OBJECT public: explicit SignClipboardCommand(GpgME::Protocol protocol, QAbstractItemView *view, KeyListController *parent); explicit SignClipboardCommand(GpgME::Protocol protocol, KeyListController *parent); ~SignClipboardCommand() override; - static bool canSignCurrentClipboard(); + static bool canSignCurrentClipboard(GpgME::Protocol protocol); private: void doStart() override; void doCancel() override; private: class Private; inline Private *d_func(); inline const Private *d_func() const; Q_PRIVATE_SLOT(d_func(), void slotSignersResolved()) Q_PRIVATE_SLOT(d_func(), void slotControllerDone()) Q_PRIVATE_SLOT(d_func(), void slotControllerError(int, QString)) }; } } #endif // QT_NO_CLIPBOARD diff --git a/src/utils/clipboardmenu.cpp b/src/utils/clipboardmenu.cpp index 3a693cd93..4cfb21698 100644 --- a/src/utils/clipboardmenu.cpp +++ b/src/utils/clipboardmenu.cpp @@ -1,123 +1,123 @@ /* SPDX-FileCopyrightText: 2014-2021 Laurent Montel SPDX-License-Identifier: GPL-2.0-only */ #include "clipboardmenu.h" #include "kdtoolsglobal.h" #include "mainwindow.h" #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Commands; ClipboardMenu::ClipboardMenu(QObject *parent) : QObject{parent} { mClipboardMenu = new KActionMenu(i18n("Clipboard"), this); mImportClipboardAction = new QAction(i18n("Certificate Import"), this); mEncryptClipboardAction = new QAction(i18n("Encrypt..."), this); const Kleo::Settings settings{}; if (settings.cmsEnabled() && settings.cmsSigningAllowed()) { mSmimeSignClipboardAction = new QAction(i18n("S/MIME-Sign..."), this); } mOpenPGPSignClipboardAction = new QAction(i18n("OpenPGP-Sign..."), this); mDecryptVerifyClipboardAction = new QAction(i18n("Decrypt/Verify..."), this); KDAB_SET_OBJECT_NAME(mClipboardMenu); KDAB_SET_OBJECT_NAME(mImportClipboardAction); KDAB_SET_OBJECT_NAME(mEncryptClipboardAction); KDAB_SET_OBJECT_NAME(mSmimeSignClipboardAction); KDAB_SET_OBJECT_NAME(mOpenPGPSignClipboardAction); KDAB_SET_OBJECT_NAME(mDecryptVerifyClipboardAction); connect(mImportClipboardAction, &QAction::triggered, this, &ClipboardMenu::slotImportClipboard); connect(mEncryptClipboardAction, &QAction::triggered, this, &ClipboardMenu::slotEncryptClipboard); if (mSmimeSignClipboardAction) { connect(mSmimeSignClipboardAction, &QAction::triggered, this, &ClipboardMenu::slotSMIMESignClipboard); } connect(mOpenPGPSignClipboardAction, &QAction::triggered, this, &ClipboardMenu::slotOpenPGPSignClipboard); connect(mDecryptVerifyClipboardAction, &QAction::triggered, this, &ClipboardMenu::slotDecryptVerifyClipboard); mClipboardMenu->addAction(mImportClipboardAction); mClipboardMenu->addAction(mEncryptClipboardAction); if (mSmimeSignClipboardAction) { mClipboardMenu->addAction(mSmimeSignClipboardAction); } mClipboardMenu->addAction(mOpenPGPSignClipboardAction); mClipboardMenu->addAction(mDecryptVerifyClipboardAction); connect(QApplication::clipboard(), &QClipboard::changed, this, &ClipboardMenu::slotEnableDisableActions); slotEnableDisableActions(); } ClipboardMenu::~ClipboardMenu() = default; void ClipboardMenu::setMainWindow(MainWindow *window) { mWindow = window; } KActionMenu *ClipboardMenu::clipboardMenu() const { return mClipboardMenu; } void ClipboardMenu::startCommand(Command *cmd) { Q_ASSERT(cmd); cmd->setParent(mWindow); cmd->start(); } void ClipboardMenu::slotImportClipboard() { startCommand(new ImportCertificateFromClipboardCommand(nullptr)); } void ClipboardMenu::slotEncryptClipboard() { startCommand(new EncryptClipboardCommand(nullptr)); } void ClipboardMenu::slotOpenPGPSignClipboard() { startCommand(new SignClipboardCommand(GpgME::OpenPGP, nullptr)); } void ClipboardMenu::slotSMIMESignClipboard() { startCommand(new SignClipboardCommand(GpgME::CMS, nullptr)); } void ClipboardMenu::slotDecryptVerifyClipboard() { startCommand(new DecryptVerifyClipboardCommand(nullptr)); } void ClipboardMenu::slotEnableDisableActions() { const QSignalBlocker blocker(QApplication::clipboard()); mImportClipboardAction->setEnabled(ImportCertificateFromClipboardCommand::canImportCurrentClipboard()); mEncryptClipboardAction->setEnabled(EncryptClipboardCommand::canEncryptCurrentClipboard()); - mOpenPGPSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard()); + mOpenPGPSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard(GpgME::OpenPGP)); if (mSmimeSignClipboardAction) { - mSmimeSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard()); + mSmimeSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard(GpgME::CMS)); } mDecryptVerifyClipboardAction->setEnabled(DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard()); }