Commit 8c53761a authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Fix visibility of sender's signing and encryption keys in mixed mode

GnuPG-bug-id: 5283
parent 755d5283
Pipeline #54677 passed with stage
in 10 minutes and 45 seconds
......@@ -19,6 +19,7 @@
#include <gpgme.h>
#include <memory>
#include <set>
using namespace Kleo;
......@@ -131,6 +132,47 @@ private Q_SLOTS:
}
}
void test_all_resolved_allow_mixed()
{
const QStringList unresolvedSenders;
const QStringList unresolvedRecipients;
const QString sender = QStringLiteral("sender@example.net");
bool allowMixed = true;
GpgME::Protocol forcedProtocol = GpgME::UnknownProtocol;
GpgME::Protocol presetProtocol = GpgME::UnknownProtocol;
const auto resolvedSenders = resolved_senders_openpgp_and_smime();
const auto dialog = std::make_unique<NewKeyApprovalDialog>(resolvedSenders,
resolved_recipients_openpgp_and_smime(),
unresolvedSenders,
unresolvedRecipients,
sender,
allowMixed,
forcedProtocol,
presetProtocol);
dialog->show();
const QList<KeySelectionCombo *> signingKeyWidgets = dialog->findChildren<KeySelectionCombo *>(QStringLiteral("signing key"));
QCOMPARE(signingKeyWidgets.size(), 2);
for (auto widget : signingKeyWidgets) {
QVERIFY2(widget->isVisible(), "signing key widget should be visible");
}
// one signing key widget should default to sender's OpenPGP key, the other to sender's S/MIME key
const std::set<QString> signingKeyFingerprints = {
QString::fromLatin1(resolvedSenders["sender@example.net"][0].primaryFingerprint()),
QString::fromLatin1(resolvedSenders["sender@example.net"][1].primaryFingerprint()),
};
const std::set<QString> defaultKeys = {
signingKeyWidgets[0]->defaultKey(),
signingKeyWidgets[1]->defaultKey()
};
QCOMPARE(defaultKeys, signingKeyFingerprints);
const QList<QWidget *> encryptionKeyWidgets = dialog->findChildren<QWidget *>(QStringLiteral("encryption key"));
QCOMPARE(encryptionKeyWidgets.size(), 4);
for (auto widget : encryptionKeyWidgets) {
QVERIFY2(widget->isVisible(),
qPrintable(QString("encryption key widget should be visible for address %1").arg(widget->property("address").toString())));
}
}
private:
QMap<QString, std::vector<GpgME::Key> > resolved_senders_openpgp_and_smime()
{
......
......@@ -13,7 +13,6 @@
#include "progressdialog.h"
#include "utils/formatting.h"
#include "libkleo_debug.h"
#include <QApplication>
......@@ -407,8 +406,8 @@ public:
void updateFilter()
{
bool isPGP = mFormatBtns->checkedId() == 1;
bool isSMIME = mFormatBtns->checkedId() == 2;
const bool isPGP = !mAllowMixed && mFormatBtns->checkedId() == 1;
const bool isSMIME = !mAllowMixed && mFormatBtns->checkedId() == 2;
if (isSMIME) {
mCurEncFilter = s_smimeFilter;
......@@ -427,7 +426,8 @@ public:
qCDebug(LIBKLEO_LOG) << "Failed to find signature combo widget";
continue;
}
widget->setVisible(widget->fromOverride() == GpgME::UnknownProtocol ||
widget->setVisible(mAllowMixed ||
widget->fromOverride() == GpgME::UnknownProtocol ||
((isSMIME && widget->fromOverride() == GpgME::CMS) ||
(isPGP && widget->fromOverride() == GpgME::OpenPGP)));
}
......@@ -439,7 +439,8 @@ public:
qCDebug(LIBKLEO_LOG) << "Failed to find combo widget";
continue;
}
widget->setVisible(widget->fromOverride() == GpgME::UnknownProtocol ||
widget->setVisible(mAllowMixed ||
widget->fromOverride() == GpgME::UnknownProtocol ||
((isSMIME && widget->fromOverride() == GpgME::CMS) ||
(isPGP && widget->fromOverride() == GpgME::OpenPGP)));
}
......@@ -453,7 +454,12 @@ public:
#endif
combo->setKeyFilter(mCurSigFilter);
if (!key.isNull()) {
combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()), key.protocol());
if (mAllowMixed) {
// do not set the key for a specific protocol if mixed protocols are allowed
combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()));
} else {
combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()), key.protocol());
}
}
if (key.isNull() && mProto != GpgME::CMS) {
combo->appendCustomItem(QIcon::fromTheme(QStringLiteral("document-new")),
......@@ -532,8 +538,12 @@ public:
#endif
combo->setKeyFilter(mCurEncFilter);
if (!key.isNull()) {
combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()),
key.protocol());
if (mAllowMixed) {
// do not set the key for a specific protocol if mixed protocols are allowed
combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()));
} else {
combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()), key.protocol());
}
}
if (mSender == addr && key.isNull()) {
......
Markdown is supported
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