diff --git a/CMakeLists.txt b/CMakeLists.txt index 67f19c7f8..38776f6c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,236 +1,236 @@ # SPDX-FileCopyrightText: none # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(RELEASE_SERVICE_VERSION_MAJOR "22") set(RELEASE_SERVICE_VERSION_MINOR "11") 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 "22") 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.96.0") set(KIDENTITYMANAGEMENT_VERSION "5.21.40") set(KMAILTRANSPORT_VERSION "5.21.40") set(KMIME_VERSION "5.21.40") -set(LIBKLEO_VERSION "5.21.45") +set(LIBKLEO_VERSION "5.21.46") set(QT_REQUIRED_VERSION "5.15.2") set(GPGME_REQUIRED_VERSION "1.16.0") 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 () set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) 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) include(ECMDeprecationSettings) include(KDEClangFormat) # 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 ${Qt${QT_MAJOR_VERSION}DBus_FOUND}) find_package(Gpgmepp ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) if (QT_MAJOR_VERSION STREQUAL "6") find_package(QGpgmeQt6 ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) else() find_package(QGpgme ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) endif() if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.17.0") set(QGPGME_SUPPORTS_CHANGING_EXPIRATION_OF_COMPLETE_KEY 1) set(QGPGME_CRYPTOCONFIGENTRY_HAS_DEFAULT_VALUE 1) set(QGPGME_SUPPORTS_WKDLOOKUP 1) set(QGPGME_SUPPORTS_IMPORT_WITH_FILTER 1) set(QGPGME_SUPPORTS_IMPORT_WITH_KEY_ORIGIN 1) set(QGPGME_SUPPORTS_SECRET_KEY_EXPORT 1) set(QGPGME_SUPPORTS_SECRET_SUBKEY_EXPORT 1) set(QGPGME_SUPPORTS_RECEIVING_KEYS_BY_KEY_ID 1) endif() if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.17.2") set(QGPGME_SUPPORTS_KEY_REVOCATION 1) set(QGPGME_SUPPORTS_KEY_REFRESH 1) set(QGPGME_SUPPORTS_SET_FILENAME 1) set(QGPGME_SUPPORTS_SET_PRIMARY_UID 1) endif() # Kdepimlibs packages find_package(KF5Libkleo ${LIBKLEO_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_WANT_VERSION} CONFIG REQUIRED) find_package(KF5IdentityManagement ${KIDENTITYMANAGEMENT_VERSION} CONFIG) find_package(KF5MailTransport ${KMAILTRANSPORT_VERSION} CONFIG) find_package(KF5MailTransportAkonadi ${KMAILTRANSPORT_VERSION} CONFIG) find_package(Qt${QT_MAJOR_VERSION} ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test Network PrintSupport) find_package(Assuan2 REQUIRED) 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} ${ASSUAN2_INCLUDES} ) add_definitions(-D_ASSUAN_ONLY_GPG_ERRORS) if (WIN32) # On Windows, we need to use stuff deprecated since Qt 5.11, e.g. from QDesktopWidget ecm_set_disabled_deprecation_versions(QT 5.10.0 KF 5.97.0) else () ecm_set_disabled_deprecation_versions(QT 5.14.0 KF 5.97.0) endif () 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) # Disable the use of QStringBuilder for operator+ to prevent crashes when # returning the result of concatenating string temporaries in lambdas. We do # this for example in some std::transform expressions. # This is a known issue: https://bugreports.qt.io/browse/QTBUG-47066 # Alternatively, one would always have to remember to force the lambdas to # return a QString instead of QStringBuilder, but that's just too easy to # forget and, unfortunately, the compiler doesn't issue a warning if one forgets # this. So, it's just too dangerous. # One can still use QStringBuilder explicitly with the operator% if necessary. remove_definitions(-DQT_USE_FAST_OPERATOR_PLUS) remove_definitions(-DQT_USE_QSTRINGBUILDER) 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) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) diff --git a/src/commands/revokecertificationcommand.cpp b/src/commands/revokecertificationcommand.cpp index f278bea98..76f4b92b6 100644 --- a/src/commands/revokecertificationcommand.cpp +++ b/src/commands/revokecertificationcommand.cpp @@ -1,282 +1,357 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/revokecertificationcommand.cpp This file is part of Kleopatra, the KDE keymanager - SPDX-FileCopyrightText: 2020 g10 Code GmbH + SPDX-FileCopyrightText: 2020, 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "revokecertificationcommand.h" #include "command_p.h" #include "exportopenpgpcertstoservercommand.h" -#include "dialogs/revokecertificationdialog.h" + +#include #include #include #include #include +#include +#include +#include +#include + #include #include #include -#include - -#include "kleopatra_debug.h" - using namespace Kleo; using namespace Kleo::Commands; using namespace GpgME; using namespace QGpgME; +namespace +{ + +enum class InputType { + Key, + UserIDs, + Certifications, +}; + +struct CertificationData { + UserID userId; + Key certificationKey; +}; + +static std::vector getCertificationKeys(const GpgME::UserID &userId) +{ + std::vector keys; + if (userId.numSignatures() == 0) { + qCWarning(KLEOPATRA_LOG) << __func__ << "- Error: Signatures of user ID" << QString::fromUtf8(userId.id()) << "not available"; + return keys; + } + std::vector revokableCertifications; + Kleo::copy_if(userId.signatures(), std::back_inserter(revokableCertifications), [](const auto &certification) { + return userCanRevokeCertification(certification) == CertificationCanBeRevoked; + }); + Kleo::transform(revokableCertifications, std::back_inserter(keys), [](const auto &certification) { + return KeyCache::instance()->findByKeyIDOrFingerprint(certification.signerKeyID()); + }); + return keys; +} + +static bool confirmRevocations(QWidget *parent, const std::vector &certifications) +{ + KMessageBox::ButtonCode answer; + if (certifications.size() == 1) { + const auto [userId, certificationKey] = certifications.front(); + const auto message = xi18nc("@info", + "You are about to revoke the certification of user ID%1made with the key%2.", + QString::fromUtf8(userId.id()), + Formatting::formatForComboBox(certificationKey)); + answer = KMessageBox::questionYesNo(parent, + message, + i18nc("@title:window", "Confirm Revocation"), + KGuiItem{i18n("Revoke Certification")}, + KStandardGuiItem::cancel()); + } else { + QStringList l; + Kleo::transform(certifications, std::back_inserter(l), [](const auto &c) { + return i18n("User ID '%1' certified with key %2", QString::fromUtf8(c.userId.id()), Formatting::formatForComboBox(c.certificationKey)); + }); + const auto message = i18np("You are about to revoke the following certification:", // + "You are about to revoke the following %1 certifications:", + certifications.size()); + answer = KMessageBox::questionYesNoList(parent, + message, + l, + i18nc("@title:window", "Confirm Revocation"), + KGuiItem{i18n("Revoke Certifications")}, + KStandardGuiItem::cancel()); + } + return answer == KMessageBox::Yes; +} + +} + class RevokeCertificationCommand::Private : public Command::Private { friend class ::Kleo::Commands::RevokeCertificationCommand; RevokeCertificationCommand *q_func() const { return static_cast(q); } public: - explicit Private(RevokeCertificationCommand *qq, KeyListController *c); - ~Private() override; + Private(InputType i, RevokeCertificationCommand *qq, KeyListController *c = nullptr); void init(); private: - void slotDialogAccepted(); - void slotDialogRejected(); - void slotResult(const Error &err); - -private: - void ensureDialogCreated(); + std::vector getCertificationsToRevoke(); + void scheduleNextRevocation(); QGpgME::QuickJob *createJob(); + void slotResult(const Error &err); private: - Key certificationKey; + InputType inputType = InputType::Key; Key certificationTarget; std::vector uids; - QPointer dialog; + std::vector certificationsToRevoke; + std::vector completedRevocations; QPointer job; }; RevokeCertificationCommand::Private *RevokeCertificationCommand::d_func() { return static_cast(d.get()); } const RevokeCertificationCommand::Private *RevokeCertificationCommand::d_func() const { return static_cast(d.get()); } #define d d_func() #define q q_func() -RevokeCertificationCommand::Private::Private(RevokeCertificationCommand *qq, KeyListController *c) - : Command::Private(qq, c) -{ -} - -RevokeCertificationCommand::Private::~Private() +RevokeCertificationCommand::Private::Private(InputType i, RevokeCertificationCommand *qq, KeyListController *c) + : Command::Private{qq, c} + , inputType{i} { } void RevokeCertificationCommand::Private::init() { const std::vector keys_ = keys(); if (keys_.size() != 1) { - qCWarning(KLEOPATRA_LOG) << "RevokeCertificationCommand::Private::init: Expected exactly one key, but got" << keys_.size(); + qCWarning(KLEOPATRA_LOG) << q << "Expected exactly one key, but got" << keys_.size(); return; } if (keys_.front().protocol() != GpgME::OpenPGP) { - qCWarning(KLEOPATRA_LOG) << "RevokeCertificationCommand::Private::init: Expected OpenPGP key, but got" << keys_.front().protocolAsString(); + qCWarning(KLEOPATRA_LOG) << q << "Expected OpenPGP key, but got" << keys_.front().protocolAsString(); return; } certificationTarget = keys_.front(); } -void RevokeCertificationCommand::Private::slotDialogAccepted() +std::vector RevokeCertificationCommand::Private::getCertificationsToRevoke() { - const auto certificationKey = dialog->selectedCertificationKey(); - const auto selectedUserIDs = dialog->selectedUserIDs(); - if (certificationKey.isNull() || selectedUserIDs.empty()) { - qCDebug(KLEOPATRA_LOG) << "No certification key or no user IDs selected -> skipping revocation"; - finished(); - return; - } + if (inputType != InputType::Certifications) { + // ensure that the certifications of the key have been loaded + if (certificationTarget.userID(0).numSignatures() == 0) { + certificationTarget.update(); + } - job = createJob(); - if (!job) { - qCDebug(KLEOPATRA_LOG) << "Failed to create QuickJob"; - finished(); - return; + // build list of user IDs and revokable certifications + const auto userIDsToConsider = (inputType == InputType::Key) ? certificationTarget.userIDs() : uids; + for (const auto &userId : userIDsToConsider) { + Kleo::transform(getCertificationKeys(userId), std::back_inserter(certificationsToRevoke), [userId](const auto &k) { + return CertificationData{userId, k}; + }); + } } - job->startRevokeSignature(certificationTarget, dialog->selectedCertificationKey(), dialog->selectedUserIDs()); -} -void RevokeCertificationCommand::Private::slotDialogRejected() -{ - canceled(); + Kleo::erase_if(certificationsToRevoke, [](const auto &c) { + return c.certificationKey.isNull(); + }); + + return certificationsToRevoke; } -void RevokeCertificationCommand::Private::slotResult(const Error &err) +void RevokeCertificationCommand::Private::scheduleNextRevocation() { - if (err.isCanceled()) { - // do nothing - } else if (err) { - error(i18n("

An error occurred while trying to revoke the certification of

" - "%1:

\t%2

", - Formatting::formatForComboBox(certificationTarget), - QString::fromUtf8(err.asString())), - i18n("Revocation Error")); + if (!certificationsToRevoke.empty()) { + const auto nextCertification = certificationsToRevoke.back(); + job = createJob(); + if (!job) { + qCWarning(KLEOPATRA_LOG) << q << "Failed to create job"; + finished(); + return; + } + job->startRevokeSignature(certificationTarget, nextCertification.certificationKey, {nextCertification.userId}); } else { - information(i18n("Revocation successful."), - i18n("Revocation Succeeded")); - if (dialog && dialog->sendToServer()) { - auto const cmd = new ExportOpenPGPCertsToServerCommand(certificationTarget); + const auto message = xi18ncp("@info", + "The certification has been revoked successfully." + "Do you want to publish the revocation?", + "%1 certifications have been revoked successfully." + "Do you want to publish the revocations?", + completedRevocations.size()); + const auto yesButton = KGuiItem{i18ncp("@action:button", "Publish Revocation", "Publish Revocations", completedRevocations.size()), + QIcon::fromTheme(QStringLiteral("view-certificate-export-server"))}; + const auto answer = KMessageBox::questionYesNo(parentWidgetOrView(), + message, + i18nc("@title:window", "Confirm Publication"), + yesButton, + KStandardGuiItem::cancel(), + {}, + KMessageBox::Notify | KMessageBox::Dangerous); + if (answer == KMessageBox::Yes) { + const auto cmd = new ExportOpenPGPCertsToServerCommand{certificationTarget}; cmd->start(); } + finished(); } - - finished(); } -void RevokeCertificationCommand::Private::ensureDialogCreated() +void RevokeCertificationCommand::Private::slotResult(const Error &err) { - if (dialog) { + if (err.isCanceled()) { + canceled(); return; } - dialog = new RevokeCertificationDialog; - applyWindowID(dialog); - dialog->setAttribute(Qt::WA_DeleteOnClose); + if (err) { + const auto failedRevocation = certificationsToRevoke.back(); + error(xi18nc("@info", + "The revocation of the certification of user ID%1made with key%2failed:" + "%3", + Formatting::prettyNameAndEMail(failedRevocation.userId), + Formatting::formatForComboBox(failedRevocation.certificationKey), + QString::fromUtf8(err.asString()))); + finished(); + return; + } - connect(dialog, &QDialog::accepted, q, [this]() { slotDialogAccepted(); }); - connect(dialog, &QDialog::rejected, q, [this]() { slotDialogRejected(); }); + completedRevocations.push_back(certificationsToRevoke.back()); + certificationsToRevoke.pop_back(); + scheduleNextRevocation(); } QGpgME::QuickJob *RevokeCertificationCommand::Private::createJob() { - Q_ASSERT(!job); - - Q_ASSERT(certificationTarget.protocol() == OpenPGP); - const auto backend = QGpgME::openpgp(); - if (!backend) { - return nullptr; - } - - QuickJob *const j = backend->quickJob(); + const auto j = QGpgME::openpgp()->quickJob(); if (j) { - connect(j, &Job::progress, - q, &Command::progress); - connect(j, &QGpgME::QuickJob::result, q, [this](const GpgME::Error &error) { slotResult(error); }); + connect(j, &Job::progress, q, &Command::progress); + connect(j, &QGpgME::QuickJob::result, q, [this](const GpgME::Error &error) { + slotResult(error); + }); } return j; } RevokeCertificationCommand::RevokeCertificationCommand(QAbstractItemView *v, KeyListController *c) - : Command(v, new Private(this, c)) + : Command{v, new Private{InputType::Key, this, c}} { d->init(); } RevokeCertificationCommand::RevokeCertificationCommand(const GpgME::Key &key) - : Command(key, new Private(this, nullptr)) + : Command{key, new Private{InputType::Key, this}} { d->init(); } RevokeCertificationCommand::RevokeCertificationCommand(const GpgME::UserID &uid) - : Command(uid.parent(), new Private(this, nullptr)) + : Command{uid.parent(), new Private{InputType::UserIDs, this}} { std::vector(1, uid).swap(d->uids); d->init(); } RevokeCertificationCommand::RevokeCertificationCommand(const std::vector &uids) - : Command{uids.empty() ? Key{} : uids.front().parent(), new Private{this, nullptr}} + : Command{uids.empty() ? Key{} : uids.front().parent(), new Private{InputType::UserIDs, this}} { d->uids = uids; d->init(); } RevokeCertificationCommand::RevokeCertificationCommand(const GpgME::UserID::Signature &signature) - : Command(signature.parent().parent(), new Private(this, nullptr)) + : Command{signature.parent().parent(), new Private{InputType::Certifications, this}} { - std::vector(1, signature.parent()).swap(d->uids); - d->certificationKey = KeyCache::instance()->findByKeyIDOrFingerprint(signature.signerKeyID()); + if (!signature.isNull()) { + const Key certificationKey = KeyCache::instance()->findByKeyIDOrFingerprint(signature.signerKeyID()); + d->certificationsToRevoke = {{signature.parent(), certificationKey}}; + } d->init(); } RevokeCertificationCommand::~RevokeCertificationCommand() { - qCDebug(KLEOPATRA_LOG) << "~RevokeCertificationCommand()"; + qCDebug(KLEOPATRA_LOG) << this << __func__; } // static bool RevokeCertificationCommand::isSupported() { return engineInfo(GpgEngine).engineVersion() >= "2.2.24"; } void RevokeCertificationCommand::doStart() { if (d->certificationTarget.isNull()) { d->finished(); return; } if (!Kleo::all_of(d->uids, userIDBelongsToKey(d->certificationTarget))) { - qCWarning(KLEOPATRA_LOG) << "User ID <-> Key mismatch!"; + qCWarning(KLEOPATRA_LOG) << this << "User ID <-> Key mismatch!"; d->finished(); return; } - // ensure that the certifications of the key have been loaded - if (d->certificationTarget.userID(0).numSignatures() == 0) { - d->certificationTarget.update(); - } - - // check if there are any certifications the user can revoke - const auto userIDsToConsider = d->uids.empty() ? d->certificationTarget.userIDs() : d->uids; - std::vector revokableUserIDs; - std::copy_if(userIDsToConsider.begin(), userIDsToConsider.end(), std::back_inserter(revokableUserIDs), &Kleo::userCanRevokeCertifications); - if (revokableUserIDs.empty()) { - const auto message = d->uids.empty() // - ? i18n("You cannot revoke any certifications of this key.") - : i18np("You cannot revoke any certifications of this user ID.", "You cannot revoke any certifications of these user IDs.", d->uids.size()); - KMessageBox::information(d->parentWidgetOrView(), message); + const auto certificationsToRevoke = d->getCertificationsToRevoke(); + if (certificationsToRevoke.empty()) { + switch (d->inputType) { + case InputType::Key: + d->information(i18n("You cannot revoke any certifications of this key.")); + break; + case InputType::UserIDs: + d->information(i18np("You cannot revoke any certifications of this user ID.", // + "You cannot revoke any certifications of these user IDs.", + d->uids.size())); + break; + case InputType::Certifications: + d->information(i18n("You cannot revoke this certification.")); + break; + } d->finished(); return; } - d->ensureDialogCreated(); - Q_ASSERT(d->dialog); - - d->dialog->setCertificateToRevoke(d->certificationTarget); - d->dialog->setSelectedUserIDs(revokableUserIDs); - if (!d->certificationKey.isNull()) { - d->dialog->setSelectedCertificationKey(d->certificationKey); + if (!confirmRevocations(d->parentWidgetOrView(), certificationsToRevoke)) { + d->canceled(); + return; } - d->dialog->show(); + + d->scheduleNextRevocation(); } void RevokeCertificationCommand::doCancel() { - qCDebug(KLEOPATRA_LOG) << "RevokeCertificationCommand::doCancel()"; + qCDebug(KLEOPATRA_LOG) << this << __func__; if (d->job) { d->job->slotCancel(); } } #undef d #undef q - -#include "moc_revokecertificationcommand.cpp" diff --git a/src/commands/revokecertificationcommand.h b/src/commands/revokecertificationcommand.h index 1b6956d56..f5c3ccf9a 100644 --- a/src/commands/revokecertificationcommand.h +++ b/src/commands/revokecertificationcommand.h @@ -1,52 +1,52 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/revokecertificationcommand.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2020 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once -#include +#include "command.h" #include namespace Kleo { namespace Commands { class RevokeCertificationCommand : public Command { Q_OBJECT public: - explicit RevokeCertificationCommand(QAbstractItemView *view, KeyListController *parent); + RevokeCertificationCommand(QAbstractItemView *view, KeyListController *parent); explicit RevokeCertificationCommand(const GpgME::Key &key); explicit RevokeCertificationCommand(const GpgME::UserID &uid); explicit RevokeCertificationCommand(const std::vector &uids); explicit RevokeCertificationCommand(const GpgME::UserID::Signature &signature); ~RevokeCertificationCommand() override; /* reimp */ static Restrictions restrictions() { return OnlyOneKey | MustBeOpenPGP; } static bool isSupported(); private: void doStart() override; void doCancel() override; private: class Private; inline Private *d_func(); inline const Private *d_func() const; }; } // namespace Commands } // namespace Kleo