diff --git a/CMakeLists.txt b/CMakeLists.txt index 167872e8f..8564e3eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,167 +1,167 @@ set(kleopatra_version 3.1.12) # The following is for Windows. Keep in line with kleopatra_version. set(kleopatra_fileversion 3,1,12,0) cmake_minimum_required(VERSION 3.5) project(kleopatra VERSION ${kleopatra_version}) # The RELEASE_SERVICE_VERSION is used by Gpg4win to add the Gpg4win version if (NOT RELEASE_SERVICE_VERSION) set (RELEASE_SERVICE_VERSION "20.11.80") endif() option(FORCE_DISABLE_KCMUTILS "Force building Kleopatra without KCMUtils. Doing this will disable configuration KCM Plugins. [default=OFF]" OFF) option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF) # Standalone build. Find / include everything necessary. set(KF5_MIN_VERSION "5.75.0") set(KMIME_VERSION "5.15.40") -set(LIBKLEO_VERSION "5.15.41") +set(LIBKLEO_VERSION "5.15.81") set(QT_REQUIRED_VERSION "5.13.0") set(GPGME_REQUIRED_VERSION "1.11.1") 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(ECMGeneratePriFile) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) # Find KF5 packages if (NOT FORCE_DISABLE_KCMUTILS) find_package(KF5KCMUtils ${KF5_WANT_VERSION} CONFIG REQUIRED) endif() 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" TYPE OPTIONAL PURPOSE "Required to generate Kleopatra documentation.") # 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) find_package(QGpgme ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) # 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) set(HAVE_KCMUTILS ${KF5KCMUtils_FOUND}) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Boost 1.34.0 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) if(GIT_FOUND) execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --format=%h ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${kdepim_SOURCE_DIR}/kleopatra 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 ${kdepim_SOURCE_DIR}/kleopatra OUTPUT_VARIABLE Kleopatra_WC_LAST_CHANGED_DATE) string(REGEX REPLACE " [-0-9:+ ]*\n" "" Kleopatra_WC_LAST_CHANGED_DATE "${Kleopatra_WC_LAST_CHANGED_DATE}") set(kleopatra_version "${kleopatra_version}-git${Kleopatra_WC_REVISION} (${Kleopatra_WC_LAST_CHANGED_DATE})") 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_DIR} ${ASSUAN2_INCLUDES} ) add_definitions(-D_ASSUAN_ONLY_GPG_ERRORS) #add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050f00) add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x054C00) 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) kde_enable_exceptions() 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} ) if(KF5DocTools_FOUND) add_subdirectory(doc) endif() diff --git a/src/dialogs/revokecertificationwidget.cpp b/src/dialogs/revokecertificationwidget.cpp index 782ee31c7..2e3f21071 100644 --- a/src/dialogs/revokecertificationwidget.cpp +++ b/src/dialogs/revokecertificationwidget.cpp @@ -1,261 +1,261 @@ /* -*- mode: c++; c-basic-offset:4 -*- dialogs/revokecertificationwidget.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2020 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> SPDX-License-Identifier: GPL-2.0-or-later */ #include "revokecertificationwidget.h" #include <KConfigGroup> #include <KLocalizedString> #include <KSharedConfig> #include <Libkleo/DefaultKeyFilter> #include <Libkleo/Formatting> #include <Libkleo/KeySelectionCombo> #include <QCheckBox> #include <QFrame> #include <QHBoxLayout> #include <QLabel> #include <QListView> #include <QStandardItemModel> #include <QVBoxLayout> #include <gpgme++/key.h> #include "kleopatra_debug.h" using namespace Kleo; namespace { class CertificationKeyFilter: public DefaultKeyFilter { public: CertificationKeyFilter(const GpgME::Key &certificationTarget); bool matches(const GpgME::Key &key, Kleo::KeyFilter::MatchContexts contexts) const override; private: GpgME::Key mCertificationTarget; // the key to certify or to revoke the certification of }; CertificationKeyFilter::CertificationKeyFilter(const GpgME::Key &certificationTarget) : DefaultKeyFilter() , mCertificationTarget(certificationTarget) { setIsOpenPGP(DefaultKeyFilter::Set); setHasSecret(DefaultKeyFilter::Set); setCanCertify(DefaultKeyFilter::Set); setRevoked(DefaultKeyFilter::NotSet); setExpired(DefaultKeyFilter::NotSet); - setInvalid(DefaultKeyFilter::NotSet); + setIsBad(DefaultKeyFilter::NotSet); setDisabled(DefaultKeyFilter::NotSet); } bool CertificationKeyFilter::matches(const GpgME::Key &key, Kleo::KeyFilter::MatchContexts contexts) const { if (!(availableMatchContexts() & contexts)) { return false; } // exclude certification target from list of certification keys if (qstrcmp(key.primaryFingerprint(), mCertificationTarget.primaryFingerprint()) == 0) { return false; } return DefaultKeyFilter::matches(key, contexts); } static bool uidsAreEqual(const GpgME::UserID &lhs, const GpgME::UserID &rhs) { // use uidhash if available if (lhs.uidhash() && rhs.uidhash()) { return strcmp(lhs.uidhash(), rhs.uidhash()) == 0; } // compare actual user ID string and primary key; this is not unique, but it's all we can do if uidhash is missing return qstrcmp(lhs.id(), rhs.id()) == 0 && qstrcmp(lhs.parent().primaryFingerprint(), rhs.parent().primaryFingerprint()) == 0; } class UserIDModel : public QStandardItemModel { Q_OBJECT public: explicit UserIDModel(QObject *parent = nullptr) : QStandardItemModel(parent) { } void setKey(const GpgME::Key &key) { mKey = key; clear(); const std::vector<GpgME::UserID> uids = key.userIDs(); for (const auto &uid : uids) { QStandardItem *const item = new QStandardItem; item->setText(Formatting::prettyUserID(uid)); item->setCheckable(true); item->setEditable(false); item->setCheckState(Qt::Checked); appendRow(item); } } void setCheckedUserIDs(const std::vector<GpgME::UserID> &checkedUids) { const auto keyUids = mKey.userIDs(); Q_ASSERT(rowCount() == static_cast<int>(keyUids.size())); for (int i = 0; i < rowCount(); ++i) { const auto &keyUid = keyUids[i]; const bool uidIsChecked = std::find_if(checkedUids.cbegin(), checkedUids.cend(), [keyUid](const GpgME::UserID &checkedUid) { return uidsAreEqual(keyUid, checkedUid); }) != checkedUids.cend(); item(i)->setCheckState(uidIsChecked ? Qt::Checked : Qt::Unchecked); } } std::vector<GpgME::UserID> checkedUserIDs() const { const auto keyUids = mKey.userIDs(); Q_ASSERT(rowCount() == static_cast<int>(keyUids.size())); std::vector<GpgME::UserID> checkedUids; for (int i = 0; i < rowCount(); ++i) { if (item(i)->checkState() == Qt::Checked) { checkedUids.push_back(keyUids[i]); } } return checkedUids; } private: GpgME::Key mKey; }; } // unnamed namespace class RevokeCertificationWidget::Private { friend class ::Kleo::RevokeCertificationWidget; RevokeCertificationWidget *const q; QLabel *mFprLabel; KeySelectionCombo *mCertificationKeySelect; QCheckBox *mPublishCB; UserIDModel mUserIDModel; GpgME::Key mTarget; public: Private(RevokeCertificationWidget *qq) : q(qq) , mFprLabel(new QLabel) , mCertificationKeySelect(new KeySelectionCombo(/* secretOnly = */ true)) , mPublishCB(new QCheckBox) { QVBoxLayout *mainLayout = new QVBoxLayout(q); mainLayout->addWidget(mFprLabel); auto certKeyLayout = new QHBoxLayout; { auto label = new QLabel(i18n("Certification key:")); label->setToolTip(i18n("The key whose certifications shall be revoke")); certKeyLayout->addWidget(label); } certKeyLayout->addWidget(mCertificationKeySelect, 1); mainLayout->addLayout(certKeyLayout); auto splitLine = new QFrame; splitLine->setFrameShape(QFrame::HLine); splitLine->setFrameShadow(QFrame::Sunken); splitLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); mainLayout->addWidget(splitLine); auto listView = new QListView; listView->setModel(&mUserIDModel); mainLayout->addWidget(listView, 1); mPublishCB = new QCheckBox(i18n("Publish revocations on keyserver")); mainLayout->addWidget(mPublishCB); loadConfig(); } ~Private() { } void saveConfig() { KConfigGroup conf(KSharedConfig::openConfig(), "RevokeCertificationSettings"); const auto certificationKey = mCertificationKeySelect->currentKey(); if (!certificationKey.isNull()) { conf.writeEntry("LastKey", certificationKey.primaryFingerprint()); } conf.writeEntry("PublishCheckState", mPublishCB->isChecked()); } void loadConfig() { const KConfigGroup conf(KSharedConfig::openConfig(), "RevokeCertificationSettings"); mCertificationKeySelect->setDefaultKey(conf.readEntry("LastKey", QString())); mPublishCB->setChecked(conf.readEntry("PublishCheckState", false)); } }; RevokeCertificationWidget::RevokeCertificationWidget(QWidget *parent) : QWidget(parent) , d(new Private(this)) { } RevokeCertificationWidget::~RevokeCertificationWidget() { } void RevokeCertificationWidget::setTarget(const GpgME::Key &key) { d->mTarget = key; d->mFprLabel->setText(i18n("Fingerprint: <b>%1</b>", Formatting::prettyID(d->mTarget.primaryFingerprint())) + QStringLiteral("<br/>") + i18n("<i>Only the fingerprint clearly identifies the key and its owner.</i>")); d->mCertificationKeySelect->setKeyFilter(std::shared_ptr<KeyFilter>(new CertificationKeyFilter(d->mTarget))); d->mUserIDModel.setKey(d->mTarget); } GpgME::Key RevokeCertificationWidget::target() const { return d->mTarget; } void RevokeCertificationWidget::setSelectUserIDs(const std::vector<GpgME::UserID> &uids) { d->mUserIDModel.setCheckedUserIDs(uids); } std::vector<GpgME::UserID> RevokeCertificationWidget::selectedUserIDs() const { return d->mUserIDModel.checkedUserIDs(); } GpgME::Key RevokeCertificationWidget::certificationKey() const { return d->mCertificationKeySelect->currentKey(); } bool RevokeCertificationWidget::publishSelected() const { return d->mPublishCB->isChecked(); } void Kleo::RevokeCertificationWidget::saveConfig() const { d->saveConfig(); } // for UserIDModel #include "revokecertificationwidget.moc"