Commit 1a17bc62 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Allow retrieving missing signer keys from Certifications dialog

This enables the user to fetch the keys that were used to certify the
user ids of the displayed key. The button is disabled for expired,
revoked or otherwise "bad" keys. Certifications of "bad" user ids are
ignored.

GnuPG-bug-id: 5805
parent 954c8a20
Pipeline #132646 passed with stage
in 1 minute and 46 seconds
/* SPDX-FileCopyrightText: 2017 Intevation GmbH
/* -*- mode: c++; c-basic-offset:4 -*-
dialogs/weboftrustdialog.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2017 Intevation GmbH
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include "weboftrustdialog.h"
#include "weboftrustwidget.h"
#include "commands/importcertificatefromkeyservercommand.h"
#include <Libkleo/KeyCache>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
......@@ -16,6 +29,9 @@
#include <KSharedConfig>
#include <KConfigGroup>
#include <algorithm>
#include <set>
using namespace Kleo;
WebOfTrustDialog::WebOfTrustDialog(QWidget *parent)
......@@ -33,14 +49,25 @@ WebOfTrustDialog::WebOfTrustDialog(QWidget *parent)
l->addWidget(mWidget);
auto bbox = new QDialogButtonBox(this);
auto btn = bbox->addButton(QDialogButtonBox::Close);
connect(btn, &QPushButton::pressed, this, &QDialog::accept);
mFetchKeysBtn = bbox->addButton(i18nc("@action:button", "Fetch Missing Keys"),
QDialogButtonBox::ActionRole);
mFetchKeysBtn->setToolTip(i18nc("@info:tooltip", "Look up and import all keys that were used to certify the user ids of this key"));
connect(mFetchKeysBtn, &QPushButton::pressed, this, &WebOfTrustDialog::fetchMissingKeys);
#ifndef QGPGME_SUPPORTS_RECEIVING_KEYS_BY_KEY_ID
mFetchKeysBtn->setVisible(false);
#endif
l->addWidget(bbox);
}
void WebOfTrustDialog::setKey(const GpgME::Key &key)
{
mWidget->setKey(key);
mFetchKeysBtn->setEnabled(!key.isBad());
}
GpgME::Key WebOfTrustDialog::key() const
......@@ -54,3 +81,55 @@ WebOfTrustDialog::~WebOfTrustDialog()
dialog.writeEntry("Size", size());
dialog.sync();
}
namespace
{
auto accumulateMissingSignerKeys(const std::vector<GpgME::UserID::Signature> &signatures)
{
return std::accumulate(
std::begin(signatures), std::end(signatures),
std::set<QString>{},
[] (auto &keyIds, const auto &signature) {
if (signature.status() == GpgME::UserID::Signature::NoPublicKey) {
keyIds.insert(QLatin1String{signature.signerKeyID()});
}
return keyIds;
}
);
}
auto accumulateMissingSignerKeys(const std::vector<GpgME::UserID> &userIds)
{
return std::accumulate(
std::begin(userIds), std::end(userIds),
std::set<QString>(),
[] (auto &keyIds, const auto &userID) {
if (!userID.isBad()) {
const auto newKeyIds = accumulateMissingSignerKeys(userID.signatures());
std::copy(std::begin(newKeyIds), std::end(newKeyIds),
std::inserter(keyIds, std::end(keyIds)));
}
return keyIds;
}
);
}
}
void WebOfTrustDialog::fetchMissingKeys()
{
if (key().isNull()) {
return;
}
const auto missingSignerKeys = accumulateMissingSignerKeys(key().userIDs());
auto cmd = new Kleo::ImportCertificateFromKeyserverCommand{QStringList{std::begin(missingSignerKeys), std::end(missingSignerKeys)}};
cmd->setParentWidget(this);
setEnabled(false);
connect(cmd, &Kleo::ImportCertificateFromKeyserverCommand::finished,
this, [this]() {
// Trigger an update when done
setKey(key());
setEnabled(true);
});
cmd->start();
}
/* SPDX-FileCopyrightText: 2017 Intevation GmbH
/* -*- mode: c++; c-basic-offset:4 -*-
dialogs/weboftrustdialog.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2017 Intevation GmbH
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -27,7 +33,11 @@ public:
GpgME::Key key() const;
private:
WebOfTrustWidget *mWidget;
void fetchMissingKeys();
private:
QPushButton *mFetchKeysBtn = nullptr;
WebOfTrustWidget *mWidget = nullptr;
};
} // namespace Kleo
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment