Page MenuHome GnuPG

No OneTemporary

diff --git a/src/kleo/keyresolver.cpp b/src/kleo/keyresolver.cpp
index 196cad31..58b5d7a2 100644
--- a/src/kleo/keyresolver.cpp
+++ b/src/kleo/keyresolver.cpp
@@ -1,751 +1,762 @@
/* -*- c++ -*-
keyresolver.cpp
This file is part of libkleopatra, the KDE keymanagement library
Copyright (c) 2004 Klarälvdalens Datakonsult AB
Copyright (c) 2018 Intevation GmbH
Based on kpgp.cpp
Copyright (C) 2001,2002 the KPGP authors
See file libkdenetwork/AUTHORS.kpgp for details
Libkleopatra is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
Libkleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include <gpgme++/key.h>
#include "libkleo_debug.h"
#include "keyresolver.h"
#include "models/keycache.h"
#include "utils/formatting.h"
#include "ui/newkeyapprovaldialog.h"
#include <QStringList>
using namespace Kleo;
namespace {
static inline bool ValidEncryptionKey(const GpgME::Key &key)
{
if (key.isNull() || key.isRevoked() || key.isExpired() ||
key.isDisabled() || !key.canEncrypt()) {
return false;
}
return true;
}
static inline bool ValidSigningKey(const GpgME::Key &key)
{
if (key.isNull() || key.isRevoked() || key.isExpired() ||
key.isDisabled() || !key.canSign() || !key.hasSecret()) {
return false;
}
return true;
}
} // namespace
class KeyResolver::Private
{
public:
Private(KeyResolver* qq, bool enc, bool sig, CryptoMessageFormat fmt, bool allowMixed) :
q(qq), mFormat(fmt), mEncrypt(enc), mSign(sig), mNag(true),
mAllowMixed(allowMixed),
mCache(KeyCache::instance()),
mDialogWindowFlags(Qt::WindowFlags()),
mPreferredProtocol(GpgME::UnknownProtocol),
mMinimumValidity(GpgME::UserID::Marginal),
mCompliance(Formatting::complianceMode())
{
}
~Private()
{
}
bool isAcceptableSigningKey(const GpgME::Key &key)
{
if (!ValidSigningKey(key)) {
return false;
}
if (mCompliance == QStringLiteral("de-vs")) {
if (!Formatting::isKeyDeVs(key)) {
qCDebug(LIBKLEO_LOG) << "Rejected sig key" << key.primaryFingerprint()
<< "because it is not de-vs compliant.";
return false;
}
}
return true;
}
bool isAcceptableEncryptionKey(const GpgME::Key &key, const QString &address = QString())
{
if (!ValidEncryptionKey(key)) {
return false;
}
if (mCompliance == QStringLiteral("de-vs")) {
if (!Formatting::isKeyDeVs(key)) {
qCDebug(LIBKLEO_LOG) << "Rejected enc key" << key.primaryFingerprint()
<< "because it is not de-vs compliant.";
return false;
}
}
if (address.isEmpty()) {
return true;
}
for (const auto &uid: key.userIDs()) {
if (uid.addrSpec() == address.toStdString()) {
if (uid.validity() >= mMinimumValidity) {
return true;
}
}
}
return false;
}
void addRecpients (const QStringList &addresses, bool hidden)
{
if (!mEncrypt) {
return;
}
// Internally we work with normalized addresses. Normalization
// matches the gnupg one.
for (const auto &addr :addresses) {
// PGP Uids are defined to be UTF-8 (RFC 4880 §5.11)
const auto normalized = GpgME::UserID::addrSpecFromString (addr.toUtf8().constData());
if (normalized.empty()) {
// should not happen bug in the caller, non localized
// error for bug reporting.
mFatalErrors << QStringLiteral("The mail address for '%1' could not be extracted").arg(addr);
continue;
}
const QString normStr = QString::fromUtf8(normalized.c_str());
// Initially mark them as unresolved for both protocols
if (!mUnresolvedCMS.contains(normStr)) {
mUnresolvedCMS << normStr;
}
if (!mUnresolvedPGP.contains(normStr)) {
mUnresolvedPGP << normStr;
}
// Add it to the according recipient lists
if (hidden) {
mHiddenRecipients << normStr;
} else {
mRecipients << normStr;
}
}
}
// Apply the overrides this is also where specific formats come in
void resolveOverrides()
{
if (!mEncrypt) {
// No encryption we are done.
return;
}
for (CryptoMessageFormat fmt: mOverrides.keys()) {
// Iterate over the crypto message formats
if (mFormat != AutoFormat && mFormat != fmt && fmt != AutoFormat) {
// Skip overrides for the wrong format
continue;
}
for (const auto &addr: mOverrides[fmt].keys()) {
// For all address overrides of this format.
for (const auto &fprOrId: mOverrides[fmt][addr]) {
// For all the keys configured for this address.
const auto key = mCache->findByKeyIDOrFingerprint(fprOrId.toUtf8().constData());
if (key.isNull()) {
qCDebug (LIBKLEO_LOG) << "Failed to find override key for:" << addr
<< "fpr:" << fprOrId;
continue;
}
// Now add it to the resolved keys and remove it from our list
// of unresolved keys.
QMap<CryptoMessageFormat, QMap <QString, std::vector<GpgME::Key> > > *targetMap;
if (mRecipients.contains(addr)) {
targetMap = &mEncKeys;
} else if (mHiddenRecipients.contains(addr)) {
targetMap = &mBccKeys;
} else {
qCWarning(LIBKLEO_LOG) << "Override provided for an address that is "
"neither sender nor recipient. Address: " << addr;
continue;
}
CryptoMessageFormat resolvedFmt = fmt;
if (fmt == AutoFormat) {
// Take the format from the key.
if (key.protocol() == GpgME::OpenPGP) {
resolvedFmt = AnyOpenPGP;
} else {
resolvedFmt = AnySMIME;
}
}
auto recpMap = targetMap->value(resolvedFmt);
auto keys = recpMap.value(addr);
keys.push_back(key);
recpMap.insert(addr, keys);
targetMap->insert(resolvedFmt, recpMap);
// Now we can remove it from our unresolved lists.
if (key.protocol() == GpgME::OpenPGP) {
mUnresolvedPGP.removeAll(addr);
} else {
mUnresolvedCMS.removeAll(addr);
}
qCDebug(LIBKLEO_LOG) << "Override" << addr << cryptoMessageFormatToString (resolvedFmt) << fprOrId;
}
}
}
}
void resolveSign(GpgME::Protocol proto)
{
auto fmt = proto == GpgME::OpenPGP ? AnyOpenPGP : AnySMIME;
if (mSigKeys.contains(fmt)) {
// Explicitly set
return;
}
const auto keys = mCache->findBestByMailBox(mSender.toUtf8().constData(),
proto, true, false);
for (const auto &key: keys) {
if (key.isNull()) {
continue;
}
if (!isAcceptableSigningKey(key)) {
qCDebug(LIBKLEO_LOG) << "Unacceptable signing key" << key.primaryFingerprint()
<< "for" << mSender;
return;
}
}
if (!keys.empty() && !keys[0].isNull()) {
mSigKeys.insert(fmt, keys);
}
}
void setSigningKeys(const std::vector<GpgME::Key> &keys)
{
if (mSign) {
for (const auto &key: keys) {
const auto sigFmt = key.protocol() == GpgME::Protocol::OpenPGP ? AnyOpenPGP : AnySMIME;
auto list = mSigKeys.value(sigFmt);
list.push_back(key);
mSigKeys.insert(sigFmt, list);
}
}
}
// Try to find matching keys in the provided protocol for the unresolved addresses
// only updates the any maps.
void resolveEnc(GpgME::Protocol proto)
{
auto fmt = proto == GpgME::OpenPGP ? AnyOpenPGP : AnySMIME;
auto encMap = mEncKeys.value(fmt);
auto hiddenMap = mBccKeys.value(fmt);
QMutableStringListIterator it((proto == GpgME::Protocol::OpenPGP) ? mUnresolvedPGP : mUnresolvedCMS);
while (it.hasNext()) {
const QString addr = it.next();
const auto keys = mCache->findBestByMailBox(addr.toUtf8().constData(),
proto, false, true);
if (keys.empty() || keys[0].isNull()) {
qCDebug(LIBKLEO_LOG) << "Failed to find any"
<< (proto == GpgME::Protocol::OpenPGP ? "OpenPGP" : "CMS")
<< "key for: " << addr;
continue;
}
if (keys.size() == 1) {
if (!isAcceptableEncryptionKey(keys[0], addr)) {
qCDebug(LIBKLEO_LOG) << "key for: " << addr << keys[0].primaryFingerprint()
<< "has not enough validity";
continue;
}
} else {
// If we have one unacceptable group key we reject the
// whole group to avoid the situation where one key is
// skipped or the operation fails.
//
// We are in Autoresolve land here. In the GUI we
// will also show unacceptable group keys so that the
// user can see which key is not acceptable.
bool unacceptable = false;
for (const auto &key: keys) {
if (!isAcceptableEncryptionKey(key)) {
qCDebug(LIBKLEO_LOG) << "group key for: " << addr << keys[0].primaryFingerprint()
<< "has not enough validity";
unacceptable = true;
break;
}
}
if (unacceptable) {
continue;
}
}
if (mHiddenRecipients.contains(addr)) {
hiddenMap.insert(addr, keys);
} else {
encMap.insert(addr, keys);
for (const auto &k: keys) {
if (!k.isNull()) {
qCDebug(LIBKLEO_LOG) << "Resolved encrypt to" << addr
<< "with key" << k.primaryFingerprint();
}
}
}
it.remove();
}
mEncKeys.insert(fmt, encMap);
mBccKeys.insert(fmt, hiddenMap);
}
void encMapToSpecific(CryptoMessageFormat anyFormat, CryptoMessageFormat specificFormat,
QMap<CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > >&encMap)
{
Q_ASSERT(anyFormat & specificFormat);
if (!encMap.contains(anyFormat)) {
return;
}
for (const auto &addr: encMap[anyFormat].keys()) {
if (!encMap.contains(specificFormat)) {
encMap.insert(specificFormat, QMap<QString, std::vector<GpgME::Key> >());
}
encMap[specificFormat].insert(addr, encMap[anyFormat][addr]);
}
encMap.remove(anyFormat);
}
void reduceToSingle(CryptoMessageFormat targetFmt)
{
// We a have a specific format so we need to map any keys
// into that format. This ignores overrides as the format
// was explicitly set.
CryptoMessageFormat srcFmt = (targetFmt & AnySMIME) ? AnySMIME : AnyOpenPGP;
if (mSigKeys.contains(srcFmt)) {
mSigKeys.insert(targetFmt, mSigKeys.take(srcFmt));
}
encMapToSpecific(srcFmt, targetFmt, mEncKeys);
encMapToSpecific(srcFmt, targetFmt, mBccKeys);
}
void updateEncMap(QMap<QString, std::vector<GpgME::Key> > &target,
QMap<QString, std::vector<GpgME::Key> > &src)
{
for (const auto &addr: target.keys()) {
if (src.contains(addr)) {
target.insert(addr, src[addr]);
}
}
}
void updateEncMaps(CryptoMessageFormat target, CryptoMessageFormat src)
{
if (mBccKeys.contains(src) && mBccKeys.contains(target)) {
updateEncMap(mBccKeys[target], mBccKeys[src]);
}
if (mEncKeys.contains(src) && mEncKeys.contains(target)) {
updateEncMap(mEncKeys[target], mEncKeys[src]);
}
}
bool needsFormat(CryptoMessageFormat fmt)
{
return mBccKeys.contains(fmt) || mEncKeys.contains(fmt);
}
void selectFormats()
{
// Check if we can find a single common specific format that works
if (mFormat != AutoFormat && mFormat != AnyOpenPGP && mFormat != AnySMIME) {
reduceToSingle(mFormat);
}
// OpenPGP
// By default prefer OpenPGPMIME
bool needTwoPGP = needsFormat(OpenPGPMIMEFormat) && needsFormat(InlineOpenPGPFormat);
reduceToSingle(OpenPGPMIMEFormat);
if (needTwoPGP) {
// We need two messages as we have conflicting preferences.
// Then we need to check that if we sign the PGP MIME Message we
// also sign the inline one.
if (mSigKeys.contains(OpenPGPMIMEFormat)) {
mSigKeys.insert(InlineOpenPGPFormat,
mSigKeys[OpenPGPMIMEFormat]);
}
// Then it's also possible that a user updated a key in the
// UI so we need to check that too.
updateEncMaps(InlineOpenPGPFormat, OpenPGPMIMEFormat);
}
// Similar for S/MIME
bool needTwoSMIME = needsFormat(SMIMEOpaqueFormat) && needsFormat(SMIMEFormat);
// Here we prefer real S/MIME
reduceToSingle(SMIMEFormat);
if (needTwoSMIME) {
if (mSigKeys.contains(SMIMEFormat)) {
mSigKeys.insert(SMIMEOpaqueFormat,
mSigKeys[SMIMEFormat]);
}
updateEncMaps(SMIMEOpaqueFormat, SMIMEFormat);
}
return;
}
void showApprovalDialog(QWidget *parent)
{
QMap<QString, std::vector<GpgME::Key> > resolvedSig;
QStringList unresolvedSig;
bool pgpOnly = mUnresolvedPGP.empty() && (!mSign || mSigKeys.contains(AnyOpenPGP));
bool cmsOnly = mUnresolvedCMS.empty() && (!mSign || mSigKeys.contains(AnySMIME));
// First handle the signing keys
if (mSign) {
if (mSigKeys.empty()) {
unresolvedSig << mSender;
} else {
std::vector<GpgME::Key> resolvedSigKeys;
for (const auto &keys: mSigKeys) {
for (const auto &key: keys) {
- if ((pgpOnly && key.protocol() != GpgME::OpenPGP) ||
- (cmsOnly && key.protocol() != GpgME::CMS)) {
- continue;
- }
resolvedSigKeys.push_back(key);
}
}
resolvedSig.insert(mSender, resolvedSigKeys);
}
}
// Now build the encryption keys
QMap<QString, std::vector<GpgME::Key> > resolvedRecp;
QStringList unresolvedRecp;
if (mEncrypt) {
// Use all unresolved recipients.
if (!cmsOnly && !pgpOnly) {
if (mFormat & AutoFormat) {
// In Auto Format we can now remove recipients that could
// be resolved either through CMS or PGP
for (const auto &addr: mUnresolvedPGP) {
if (mUnresolvedCMS.contains(addr)) {
unresolvedRecp << addr;
}
}
} else if (mFormat & AnyOpenPGP) {
unresolvedRecp = mUnresolvedPGP;
} else if (mFormat & AnySMIME) {
unresolvedRecp = mUnresolvedCMS;
}
}
// Now Map all resolved encryption keys regardless of the format.
for (const auto &map: mEncKeys.values()) {
// Foreach format
for (const auto &addr: map.keys()) {
// Foreach sender
if (!resolvedRecp.contains(addr) || !resolvedRecp[addr].size()) {
resolvedRecp.insert(addr, map[addr]);
} else {
- qCDebug(LIBKLEO_LOG) << "Replacing resolved keys for" << addr
- << "with keys from new format.";
- resolvedRecp[addr] = map[addr];
+ std::vector<GpgME::Key> merged = resolvedRecp[addr];
+ // Add without duplication
+ for (const auto &k: map[addr]) {
+ const auto it = std::find_if (merged.begin(), merged.end(), [k] (const GpgME::Key &y) {
+ return (k.primaryFingerprint() && y.primaryFingerprint() &&
+ !strcmp (k.primaryFingerprint(), y.primaryFingerprint()));
+ });
+ if (it == merged.end()) {
+ merged.push_back(k);
+ }
+ }
+ resolvedRecp[addr] = merged;
}
}
}
}
// Do we force the protocol?
GpgME::Protocol forcedProto = mFormat == AutoFormat ? GpgME::UnknownProtocol :
mFormat & AnyOpenPGP ? GpgME::OpenPGP :
GpgME::CMS;
// Start with the protocol for which every keys could be found.
- GpgME::Protocol presetProtocol = pgpOnly ? GpgME::OpenPGP :
- cmsOnly ? GpgME::CMS :
- mPreferredProtocol;
+ GpgME::Protocol presetProtocol;
+
+ if (mPreferredProtocol == GpgME::CMS && cmsOnly) {
+ presetProtocol = GpgME::CMS;
+ } else {
+ presetProtocol = pgpOnly ? GpgME::OpenPGP :
+ cmsOnly ? GpgME::CMS :
+ mPreferredProtocol;
+ }
mDialog = std::shared_ptr<NewKeyApprovalDialog>(new NewKeyApprovalDialog(resolvedSig,
resolvedRecp,
unresolvedSig,
unresolvedRecp,
mSender,
mAllowMixed,
forcedProto,
presetProtocol,
parent,
mDialogWindowFlags));
connect (mDialog.get(), &QDialog::accepted, q, [this] () {
dialogAccepted();
});
connect (mDialog.get(), &QDialog::rejected, q, [this] () {
Q_EMIT q->keysResolved(false, false);}
);
mDialog->open();
}
void dialogAccepted()
{
// Update keymaps accordingly
mSigKeys.clear();
for (const auto &key: mDialog->signingKeys()) {
CryptoMessageFormat fmt = key.protocol() == GpgME::OpenPGP ? AnyOpenPGP : AnySMIME;
if (!mSigKeys.contains(fmt)) {
mSigKeys.insert(fmt, std::vector<GpgME::Key>());
}
mSigKeys[fmt].push_back(key);
}
const auto &encMap = mDialog->encryptionKeys();
// First we clear the Any Maps and fill them with
// the results of the dialog. Then we use the sender
// address to determine if a keys in the specific
// maps need updating.
mEncKeys.remove(AnyOpenPGP);
mEncKeys.remove(AnySMIME);
mBccKeys.remove(AnyOpenPGP);
mBccKeys.remove(AnySMIME);
bool isUnresolved = false;
for (const auto &addr: encMap.keys()) {
for (const auto &key: encMap[addr]) {
if (key.isNull()) {
isUnresolved = true;
}
CryptoMessageFormat fmt = key.protocol() == GpgME::OpenPGP ? AnyOpenPGP : AnySMIME;
// Should we add to hidden or normal?
QMap<CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > > *targetMap =
mHiddenRecipients.contains(addr) ? &mBccKeys : &mEncKeys;
if (!targetMap->contains(fmt)) {
targetMap->insert(fmt, QMap<QString, std::vector<GpgME::Key> >());
}
if (!(*targetMap)[fmt].contains(addr)) {
(*targetMap)[fmt].insert(addr, std::vector<GpgME::Key>());
}
qCDebug (LIBKLEO_LOG) << "Adding" << addr << "for" << cryptoMessageFormatToString (fmt)
<< "fpr:" << key.primaryFingerprint();
(*targetMap)[fmt][addr].push_back(key);
}
}
if (isUnresolved) {
// TODO show warning
}
Q_EMIT q->keysResolved(true, false);
}
KeyResolver *q;
QString mSender;
QStringList mRecipients;
QStringList mHiddenRecipients;
QMap<CryptoMessageFormat, std::vector<GpgME::Key> > mSigKeys;
QMap<CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > >mEncKeys;
QMap<CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > >mBccKeys;
QMap<CryptoMessageFormat, QMap<QString, QStringList> > mOverrides;
QStringList mUnresolvedPGP, mUnresolvedCMS;
CryptoMessageFormat mFormat;
QStringList mFatalErrors;
bool mEncrypt, mSign, mNag;
bool mAllowMixed;
// The cache is needed as a member variable to avoid rebuilding
// it between calls if we are the only user.
std::shared_ptr<const KeyCache> mCache;
std::shared_ptr<NewKeyApprovalDialog> mDialog;
Qt::WindowFlags mDialogWindowFlags;
GpgME::Protocol mPreferredProtocol;
int mMinimumValidity;
QString mCompliance;
};
void KeyResolver::start(bool showApproval, QWidget *parentWidget)
{
qCDebug(LIBKLEO_LOG) << "Starting ";
if (!d->mSign && !d->mEncrypt) {
// nothing to do
return Q_EMIT keysResolved(true, true);
}
// First resolve through overrides
d->resolveOverrides();
// Then look for signing / encryption keys
if (d->mFormat & AnyOpenPGP) {
d->resolveSign(GpgME::OpenPGP);
d->resolveEnc(GpgME::OpenPGP);
}
bool pgpOnly = d->mUnresolvedPGP.empty() && (!d->mSign || d->mSigKeys.contains(AnyOpenPGP));
- if (d->mFormat & AnySMIME && !(d->mFormat == AutoFormat && pgpOnly)) {
+ if (d->mFormat & AnySMIME) {
d->resolveSign(GpgME::CMS);
d->resolveEnc(GpgME::CMS);
}
bool cmsOnly = d->mUnresolvedCMS.empty() && (!d->mSign || d->mSigKeys.contains(AnySMIME));
// Check if we need the user to select different keys.
bool needsUser = false;
if (!pgpOnly && !cmsOnly) {
for (const auto &unresolved: d->mUnresolvedPGP) {
if (d->mUnresolvedCMS.contains(unresolved)) {
// We have at least one unresolvable key.
needsUser = true;
break;
}
}
if (d->mSign) {
// So every recipient could be resolved through
// a combination of PGP and S/MIME do we also
// have signing keys for both?
needsUser |= !(d->mSigKeys.contains(AnyOpenPGP) &&
d->mSigKeys.contains(AnySMIME));
}
}
if (!needsUser && !showApproval) {
if (pgpOnly) {
d->mSigKeys.remove(AnySMIME);
d->mEncKeys.remove(AnySMIME);
d->mBccKeys.remove(AnySMIME);
}
if (cmsOnly) {
d->mSigKeys.remove(AnyOpenPGP);
d->mEncKeys.remove(AnyOpenPGP);
d->mBccKeys.remove(AnyOpenPGP);
}
d->selectFormats();
qCDebug(LIBKLEO_LOG) << "Automatic key resolution done.";
Q_EMIT keysResolved(true, false);
return;
} else if (!needsUser) {
qCDebug(LIBKLEO_LOG) << "No need for the user showing approval anyway.";
}
d->showApprovalDialog(parentWidget);
}
KeyResolver::KeyResolver(bool encrypt, bool sign, CryptoMessageFormat fmt, bool allowMixed) :
d(new Private(this, encrypt, sign, fmt, allowMixed))
{
}
void KeyResolver::setRecipients(const QStringList &addresses)
{
d->addRecpients(addresses, false);
}
void KeyResolver::setSender(const QString &address)
{
const auto normalized = GpgME::UserID::addrSpecFromString (address.toUtf8().constData());
if (normalized.empty()) {
// should not happen bug in the caller, non localized
// error for bug reporting.
d->mFatalErrors << QStringLiteral("The sender address '%1' could not be extracted").arg(address);
return;
}
const auto normStr = QString::fromUtf8(normalized.c_str());
if (d->mSign) {
d->mSender = normStr;
}
if (d->mEncrypt) {
if (!d->mUnresolvedCMS.contains(normStr)) {
d->mUnresolvedCMS << normStr;
}
if (!d->mUnresolvedPGP.contains(normStr)) {
d->mUnresolvedPGP << normStr;
}
}
}
void KeyResolver::setHiddenRecipients(const QStringList &addresses)
{
d->addRecpients(addresses, true);
}
void KeyResolver::setOverrideKeys(const QMap<CryptoMessageFormat, QMap<QString, QStringList> > &overrides)
{
QMap<QString, QStringList> normalizedOverrides;
for (const auto fmt: overrides.keys()) {
for (const auto &addr: overrides[fmt].keys()) {
const auto normalized = QString::fromUtf8(
GpgME::UserID::addrSpecFromString (addr.toUtf8().constData()).c_str());
const auto fingerprints = overrides[fmt][addr];
normalizedOverrides.insert(addr, fingerprints);
}
d->mOverrides.insert(fmt, normalizedOverrides);
}
}
QMap <CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > > KeyResolver::encryptionKeys() const
{
return d->mEncKeys;
}
QMap <CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > > KeyResolver::hiddenKeys() const
{
return d->mBccKeys;
}
QMap <CryptoMessageFormat, std::vector<GpgME::Key> > KeyResolver::signingKeys() const
{
return d->mSigKeys;
}
QMap <CryptoMessageFormat, QMap<QString, QStringList> > KeyResolver::overrideKeys() const
{
return d->mOverrides;
}
void KeyResolver::enableNagging(bool value)
{
d->mNag = value;
}
void KeyResolver::setDialogWindowFlags(Qt::WindowFlags flags)
{
d->mDialogWindowFlags = flags;
}
void KeyResolver::setPreferredProtocol(GpgME::Protocol proto)
{
d->mPreferredProtocol = proto;
}
void KeyResolver::setMinimumValidity(int validity)
{
d->mMinimumValidity = validity;
}
diff --git a/src/ui/newkeyapprovaldialog.cpp b/src/ui/newkeyapprovaldialog.cpp
index 41b14a42..3bf2687c 100644
--- a/src/ui/newkeyapprovaldialog.cpp
+++ b/src/ui/newkeyapprovaldialog.cpp
@@ -1,634 +1,712 @@
/* -*- c++ -*-
newkeyapprovaldialog.cpp
This file is part of libkleopatra, the KDE keymanagement library
Copyright (c) 2018 Intevation GmbH
Libkleopatra is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
Libkleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include "newkeyapprovaldialog.h"
#include "kleo/defaultkeyfilter.h"
#include "keyselectioncombo.h"
#include "progressdialog.h"
#include "utils/formatting.h"
#include "libkleo_debug.h"
#include <QApplication>
#include <QButtonGroup>
#include <QDesktopWidget>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QLabel>
#include <QMap>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QGpgME/DefaultKeyGenerationJob>
#include <QGpgME/CryptoConfig>
#include <QGpgME/Protocol>
#include <gpgme++/keygenerationresult.h>
#include <gpgme++/key.h>
#include <KLocalizedString>
#include <KMessageBox>
using namespace Kleo;
namespace {
class OpenPGPFilter: public DefaultKeyFilter
{
public:
OpenPGPFilter() : DefaultKeyFilter()
{
setIsOpenPGP(DefaultKeyFilter::Set);
}
};
static std::shared_ptr<KeyFilter> s_pgpFilter = std::shared_ptr<KeyFilter> (new OpenPGPFilter);
class OpenPGPSignFilter: public DefaultKeyFilter
{
public:
OpenPGPSignFilter() : DefaultKeyFilter()
{
/* Also list unusable keys to make it transparent why they are unusable */
setHasSecret(DefaultKeyFilter::Set);
setIsOpenPGP(DefaultKeyFilter::Set);
}
};
static std::shared_ptr<KeyFilter> s_pgpSignFilter = std::shared_ptr<KeyFilter> (new OpenPGPSignFilter);
class SMIMEFilter: public DefaultKeyFilter
{
public:
SMIMEFilter(): DefaultKeyFilter()
{
setIsOpenPGP(DefaultKeyFilter::NotSet);
}
};
static std::shared_ptr<KeyFilter> s_smimeFilter = std::shared_ptr<KeyFilter> (new SMIMEFilter);
class SMIMESignFilter: public DefaultKeyFilter
{
public:
SMIMESignFilter(): DefaultKeyFilter()
{
setIsOpenPGP(DefaultKeyFilter::NotSet);
setHasSecret(DefaultKeyFilter::Set);
}
};
static std::shared_ptr<KeyFilter> s_smimeSignFilter = std::shared_ptr<KeyFilter> (new SMIMESignFilter);
static std::shared_ptr<KeyFilter> s_defaultFilter= std::shared_ptr<KeyFilter> (new DefaultKeyFilter);
class SignFilter: public DefaultKeyFilter
{
public:
SignFilter(): DefaultKeyFilter()
{
setHasSecret(DefaultKeyFilter::Set);
}
};
static std::shared_ptr<KeyFilter> s_signFilter = std::shared_ptr<KeyFilter> (new SignFilter);
/* Some decoration and a button to remove the filter for a keyselectioncombo */
class ComboWidget: public QWidget
{
Q_OBJECT
public:
explicit ComboWidget(KeySelectionCombo *combo):
mCombo(combo),
- mFilterBtn(new QPushButton)
+ mFilterBtn(new QPushButton),
+ mFromOverride(GpgME::UnknownProtocol)
{
auto hLay = new QHBoxLayout(this);
hLay->addWidget(combo, 1);
hLay->addWidget(mFilterBtn, 0);
// Assume that combos start out with a filter
mFilterBtn->setIcon(QIcon::fromTheme(QStringLiteral("kt-remove-filters")));
mFilterBtn->setToolTip(i18n("Remove Filter"));
// FIXME: This is ugly to enforce but otherwise the
// icon is broken.
combo->setMinimumHeight(22);
mFilterBtn->setMinimumHeight(23);
connect(mFilterBtn, &QPushButton::clicked, this, [this] () {
const QString curFilter = mCombo->idFilter();
if (curFilter.isEmpty()) {
mCombo->setIdFilter(mLastIdFilter);
mLastIdFilter = QString();
mFilterBtn->setIcon(QIcon::fromTheme(QStringLiteral("kt-remove-filters")));
mFilterBtn->setToolTip(i18n("Remove Filter"));
} else {
mLastIdFilter = curFilter;
mFilterBtn->setIcon(QIcon::fromTheme(QStringLiteral("kt-add-filters")));
mFilterBtn->setToolTip(i18n("Add Filter"));
mCombo->setIdFilter(QString());
}
});
}
KeySelectionCombo *combo()
{
return mCombo;
}
+ GpgME::Protocol fromOverride() const
+ {
+ return mFromOverride;
+ }
+
+ void setFromOverride(GpgME::Protocol proto)
+ {
+ mFromOverride = proto;
+ }
+
private:
KeySelectionCombo *mCombo;
QPushButton *mFilterBtn;
QString mLastIdFilter;
+ GpgME::Protocol mFromOverride;
};
static enum GpgME::UserID::Validity keyValidity(const GpgME::Key &key)
{
enum GpgME::UserID::Validity validity = GpgME::UserID::Validity::Unknown;
for (const auto &uid: key.userIDs()) {
if (validity == GpgME::UserID::Validity::Unknown
|| validity > uid.validity()) {
validity = uid.validity();
}
}
return validity;
}
+
+static bool key_has_addr(const GpgME::Key &key, const QString &addr)
+{
+ for (const auto &uid: key.userIDs()) {
+ if (QString::fromStdString(uid.addrSpec()).toLower() == addr.toLower()) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
class NewKeyApprovalDialog::Private
{
private:
enum Action {
Unset,
GenerateKey,
IgnoreKey,
};
public:
Private(NewKeyApprovalDialog *pub,
GpgME::Protocol forcedProtocol,
GpgME::Protocol presetProtocol,
const QString &sender, bool allowMixed):
mProto(forcedProtocol),
mSender(sender),
mAllowMixed(allowMixed),
q(pub)
{
mMainLay = new QVBoxLayout;
QDialogButtonBox *btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
mOkButton = btnBox->button(QDialogButtonBox::Ok);
QObject::connect (btnBox, &QDialogButtonBox::accepted, q, [this] () {
accepted();
});
QObject::connect (btnBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
mScrollArea = new QScrollArea;
mScrollArea->setWidget(new QWidget);
mScrollLayout = new QVBoxLayout;
mScrollArea->widget()->setLayout(mScrollLayout);
mScrollArea->setWidgetResizable(true);
mScrollArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
mScrollArea->setFrameStyle(QFrame::NoFrame);
mScrollLayout->setContentsMargins(0, 0, 0, 0);
q->setWindowTitle(i18n("Security approval"));
auto fmtLayout = new QHBoxLayout;
mFormatBtns = new QButtonGroup;
auto pgpBtn = new QRadioButton(i18n("OpenPGP"));
auto smimeBtn = new QRadioButton(i18n("S/MIME"));
mFormatBtns->addButton(pgpBtn, 1);
mFormatBtns->addButton(smimeBtn, 2);
mFormatBtns->setExclusive(true);
fmtLayout->addStretch(-1);
fmtLayout->addWidget(pgpBtn);
fmtLayout->addWidget(smimeBtn);
mMainLay->addLayout(fmtLayout);
// Handle force / preset
if (forcedProtocol == GpgME::OpenPGP) {
pgpBtn->setChecked(true);
pgpBtn->setVisible(false);
smimeBtn->setVisible(false);
} else if (forcedProtocol == GpgME::CMS) {
smimeBtn->setChecked(true);
pgpBtn->setVisible(false);
smimeBtn->setVisible(false);
} else if (presetProtocol == GpgME::CMS) {
smimeBtn->setChecked(true);
} else if (!mAllowMixed) {
pgpBtn->setChecked(true);
} else if (mAllowMixed) {
smimeBtn->setVisible(false);
pgpBtn->setVisible(false);
}
updateFilter();
QObject::connect (mFormatBtns, static_cast<void (QButtonGroup::*)(int, bool)> (&QButtonGroup::buttonToggled),
q, [this](int, bool) {
updateFilter();
});
mMainLay->addWidget(mScrollArea);
mComplianceLbl = new QLabel;
mComplianceLbl->setVisible(false);
auto btnLayout = new QHBoxLayout;
btnLayout->addWidget(mComplianceLbl);
btnLayout->addWidget(btnBox);
mMainLay->addLayout(btnLayout);
q->setLayout(mMainLay);
}
void generateKey(KeySelectionCombo *combo)
{
const auto &addr = combo->property("address").toString();
auto job = new QGpgME::DefaultKeyGenerationJob(q);
auto progress = new Kleo::ProgressDialog(job, i18n("Generating key for '%1'...", addr) + QStringLiteral("\n\n") +
i18n("This can take several minutes."), q);
progress->setWindowFlags(progress->windowFlags() & ~Qt::WindowContextHelpButtonHint);
progress->setWindowTitle(i18n("Key generation"));
progress->setModal(true);
progress->setAutoClose(true);
progress->setMinimumDuration(0);
progress->setValue(0);
mRunningJobs << job;
connect (job, &QGpgME::DefaultKeyGenerationJob::result, q,
[this, job, combo] (const GpgME::KeyGenerationResult &result) {
handleKeyGenResult(result, job, combo);
});
job->start(addr, QString());
return;
}
void handleKeyGenResult(const GpgME::KeyGenerationResult &result, QGpgME::Job *job, KeySelectionCombo *combo)
{
mLastError = result.error();
if (!mLastError || mLastError.isCanceled()) {
- combo->setDefaultKey(QString::fromLatin1(result.fingerprint()));
+ combo->setDefaultKey(QString::fromLatin1(result.fingerprint()), GpgME::OpenPGP);
connect (combo, &KeySelectionCombo::keyListingFinished, q, [this, job] () {
mRunningJobs.removeAll(job);
});
combo->refreshKeys();
} else {
mRunningJobs.removeAll(job);
}
}
void checkAccepted()
{
if (mLastError || mLastError.isCanceled()) {
KMessageBox::error(q, QString::fromLocal8Bit(mLastError.asString()), i18n("Operation Failed"));
mRunningJobs.clear();
return;
}
- if (mRunningJobs.empty()) {
- q->accept();
+
+ if (!mRunningJobs.empty()) {
+ return;
}
+ /* Save the keys */
+ bool isPGP = mFormatBtns->checkedId() == 1;
+ bool isSMIME = mFormatBtns->checkedId() == 2;
+
+ mAcceptedEnc.clear();
+ mAcceptedSig.clear();
+
+ for (const auto combo: mEncCombos) {
+ const auto &addr = combo->property("address").toString();
+ const auto &key = combo->currentKey();
+ if (!combo->isVisible()) {
+ continue;
+ }
+ if (isSMIME && key.protocol() != GpgME::CMS) {
+ continue;
+ }
+ if (isPGP && key.protocol() != GpgME::OpenPGP) {
+ continue;
+ }
+ if (mAcceptedEnc.contains(addr)) {
+ mAcceptedEnc[addr].push_back(key);
+ } else {
+ std::vector<GpgME::Key> vec;
+ vec.push_back(key);
+ mAcceptedEnc.insert(addr, vec);
+ }
+ }
+ for (const auto combo: mSigningCombos) {
+ const auto key = combo->currentKey();
+ if (!combo->isVisible()) {
+ continue;
+ }
+ if (isSMIME && key.protocol() != GpgME::CMS) {
+ continue;
+ }
+ if (isPGP && key.protocol() != GpgME::OpenPGP) {
+ continue;
+ }
+ mAcceptedSig.push_back(combo->currentKey());
+ }
+
+ q->accept();
}
void accepted()
{
// We can assume everything was validly resolved, otherwise
// the OK button would have been disabled.
// Handle custom items now.
for (auto combo: mAllCombos) {
auto act = combo->currentData(Qt::UserRole).toInt();
if (act == GenerateKey) {
generateKey(combo);
// Only generate once
return;
}
}
checkAccepted();
}
void updateFilter()
{
bool isPGP = mFormatBtns->checkedId() == 1;
bool isSMIME = mFormatBtns->checkedId() == 2;
if (isSMIME) {
mCurEncFilter = s_smimeFilter;
mCurSigFilter = s_smimeSignFilter;
} else if (isPGP) {
mCurEncFilter = s_pgpFilter;
mCurSigFilter = s_pgpSignFilter;
} else {
mCurEncFilter = s_defaultFilter;
mCurSigFilter = s_signFilter;
}
for (auto combo: mSigningCombos) {
combo->setKeyFilter(mCurSigFilter);
+ auto widget = qobject_cast <ComboWidget *>(combo->parentWidget());
+ if (!widget) {
+ qCDebug(LIBKLEO_LOG) << "Failed to find signature combo widget";
+ continue;
+ }
+ widget->setVisible(widget->fromOverride() == GpgME::UnknownProtocol ||
+ ((isSMIME && widget->fromOverride() == GpgME::CMS) ||
+ (isPGP && widget->fromOverride() == GpgME::OpenPGP)));
}
for (auto combo: mEncCombos) {
combo->setKeyFilter(mCurEncFilter);
+
+ auto widget = qobject_cast <ComboWidget *>(combo->parentWidget());
+ if (!widget) {
+ qCDebug(LIBKLEO_LOG) << "Failed to find combo widget";
+ continue;
+ }
+ widget->setVisible(widget->fromOverride() == GpgME::UnknownProtocol ||
+ ((isSMIME && widget->fromOverride() == GpgME::CMS) ||
+ (isPGP && widget->fromOverride() == GpgME::OpenPGP)));
}
}
ComboWidget *createSigningCombo(const QString &addr, const GpgME::Key &key)
{
auto combo = new KeySelectionCombo();
combo->setKeyFilter(mCurSigFilter);
if (!key.isNull()) {
- combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()));
+ combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()), key.protocol());
}
if (key.isNull() && mProto != GpgME::CMS) {
combo->appendCustomItem(QIcon::fromTheme(QStringLiteral("document-new")),
i18n("Generate a new key pair"), GenerateKey);
}
combo->appendCustomItem(QIcon::fromTheme(QStringLiteral("emblem-unavailable")),
i18n("Don't confirm identity and integrity"), IgnoreKey);
mSigningCombos << combo;
mAllCombos << combo;
combo->setProperty("address", addr);
connect(combo, &KeySelectionCombo::currentKeyChanged, q, [this] () {
updateOkButton();
});
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), q, [this] () {
updateOkButton();
});
return new ComboWidget(combo);
}
void addSigningKeys(const QMap<QString, std::vector<GpgME::Key> > &resolved,
const QStringList &unresolved)
{
if (resolved.empty() && unresolved.empty()) {
return;
}
for (const QString &addr: resolved.keys()) {
auto group = new QGroupBox(i18nc("Caption for signing key selection",
"Confirm identity '%1' as:", addr));
group->setAlignment(Qt::AlignLeft);
mScrollLayout->addWidget(group);
auto sigLayout = new QVBoxLayout;
group->setLayout(sigLayout);
for (const auto &key: resolved[addr])
{
auto comboWidget = createSigningCombo(addr, key);
- if (resolved[addr].size() == 1) {
+ if (key_has_addr (key, addr)) {
comboWidget->combo()->setIdFilter(addr);
}
+ if (resolved[addr].size() > 1) {
+ comboWidget->setFromOverride(key.protocol());
+ }
sigLayout->addWidget(comboWidget);
}
}
for (const QString &addr: unresolved) {
auto group = new QGroupBox(i18nc("Caption for signing key selection, no key found",
"No key found for the address '%1':", addr));
group->setAlignment(Qt::AlignLeft);
mScrollLayout->addWidget(group);
auto sigLayout = new QHBoxLayout;
group->setLayout(sigLayout);
auto comboWidget = createSigningCombo(addr, GpgME::Key());
comboWidget->combo()->setIdFilter(addr);
sigLayout->addWidget(comboWidget);
}
}
void addEncryptionAddr(const QString &addr, const std::vector<GpgME::Key> &keys,
QGridLayout *encGrid)
{
encGrid->addWidget(new QLabel(addr), encGrid->rowCount(), 0);
for (const auto &key: keys)
{
auto combo = new KeySelectionCombo(false);
combo->setKeyFilter(mCurEncFilter);
if (!key.isNull()) {
- combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()));
+ combo->setDefaultKey(QString::fromLatin1(key.primaryFingerprint()),
+ key.protocol());
}
if (mSender == addr && key.isNull()) {
combo->appendCustomItem(QIcon::fromTheme(QStringLiteral("document-new")),
i18n("Generate a new key pair"), GenerateKey);
}
combo->appendCustomItem(QIcon::fromTheme(QStringLiteral("emblem-unavailable")),
i18n("Ignore recipient"), IgnoreKey);
- if (keys.size () == 1) {
+ if (key.isNull() || key_has_addr (key, addr)) {
combo->setIdFilter(addr);
}
connect(combo, &KeySelectionCombo::currentKeyChanged, q, [this] () {
updateOkButton();
});
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), q, [this] () {
updateOkButton();
});
mEncCombos << combo;
mAllCombos << combo;
combo->setProperty("address", addr);
auto comboWidget = new ComboWidget(combo);
+ if (keys.size() > 1) {
+ comboWidget->setFromOverride(key.protocol());
+ }
encGrid->addWidget(comboWidget, encGrid->rowCount(), 0, 1, 2);
}
}
void addEncryptionKeys(const QMap<QString, std::vector<GpgME::Key> > &resolved,
const QStringList &unresolved)
{
if (resolved.empty() && unresolved.empty()) {
return;
}
auto group = new QGroupBox(i18n("Encrypt to:"));
group->setAlignment(Qt::AlignLeft);
auto encGrid = new QGridLayout;
group->setLayout(encGrid);
mScrollLayout->addWidget(group);
for (const QString &addr: resolved.keys()) {
addEncryptionAddr(addr, resolved[addr], encGrid);
}
std::vector<GpgME::Key> dummy;
dummy.push_back(GpgME::Key());
for (const QString &addr: unresolved) {
addEncryptionAddr(addr, dummy, encGrid);
}
encGrid->setColumnStretch(1, -1);
mScrollLayout->addStretch(-1);
+
+ // Update filter to hide not matching combowidgets
+ // for a different protocol
+ updateFilter();
}
void updateOkButton()
{
static QString origOkText = mOkButton->text();
bool isGenerate = false;
bool isAllIgnored = true;
// Check if generate is selected.
for (auto combo: mAllCombos) {
auto act = combo->currentData(Qt::UserRole).toInt();
if (act == GenerateKey) {
mOkButton->setText(i18n("Generate"));
isGenerate = true;
}
if (act != IgnoreKey) {
isAllIgnored = false;
}
}
mOkButton->setEnabled(!isAllIgnored);
if (!isGenerate) {
mOkButton->setText(origOkText);
}
if (Formatting::complianceMode() != QStringLiteral("de-vs")) {
return;
}
// Handle compliance
bool de_vs = true;
for (const auto &key: q->signingKeys()) {
if (!Formatting::isKeyDeVs(key) || keyValidity(key) < GpgME::UserID::Validity::Full) {
de_vs = false;
break;
}
}
if (de_vs) {
for (const auto &keys: q->encryptionKeys().values()) {
for (const auto &key: keys) {
if (!Formatting::isKeyDeVs(key) || keyValidity(key) < GpgME::UserID::Validity::Full) {
de_vs = false;
break;
}
}
if (!de_vs) {
break;
}
}
}
mOkButton->setIcon(QIcon::fromTheme(de_vs
? QStringLiteral("security-high")
: QStringLiteral("security-medium")));
mOkButton->setStyleSheet(QStringLiteral("background-color: ") + (de_vs
? QStringLiteral("#D5FAE2") // KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::PositiveBackground).color().name()
: QStringLiteral("#FAE9EB"))); //KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::NegativeBackground).color().name()));
mComplianceLbl->setText(de_vs
? i18nc("VS-NfD-conforming is a German standard for restricted documents for which special restrictions about algorithms apply. The string states that all cryptographic operations necessary for the communication are compliant with that.",
"VS-NfD-compliant communication possible.")
: i18nc("VS-NfD-conforming is a German standard for restricted documents for which special restrictions about algorithms apply. The string states that all cryptographic operations necessary for the communication are compliant with that.",
"VS-NfD-compliant communication not possible."));
mComplianceLbl->setVisible(true);
}
void selectionChanged()
{
bool isPGP = false;
bool isCMS = false;
for (const auto combo: mEncCombos) {
isPGP |= combo->currentKey().protocol() == GpgME::OpenPGP;
isCMS |= combo->currentKey().protocol() == GpgME::CMS;
if (isPGP && isCMS) {
break;
}
}
}
~Private() {}
GpgME::Protocol mProto;
QList<KeySelectionCombo *> mSigningCombos;
QList<KeySelectionCombo *> mEncCombos;
QList<KeySelectionCombo *> mAllCombos;
QScrollArea *mScrollArea;
QVBoxLayout *mScrollLayout;
QPushButton *mOkButton;
QVBoxLayout *mMainLay;
QButtonGroup *mFormatBtns;
std::shared_ptr<KeyFilter> mCurSigFilter;
std::shared_ptr<KeyFilter> mCurEncFilter;
QString mSender;
bool mAllowMixed;
NewKeyApprovalDialog *q;
QList <QGpgME::Job *> mRunningJobs;
GpgME::Error mLastError;
QLabel *mComplianceLbl;
+ QMap<QString, std::vector<GpgME::Key> > mAcceptedEnc;
+ std::vector<GpgME::Key> mAcceptedSig;
};
NewKeyApprovalDialog::NewKeyApprovalDialog(const QMap<QString, std::vector<GpgME::Key> > &resolvedSigningKeys,
const QMap<QString, std::vector<GpgME::Key> > &resolvedRecp,
const QStringList &unresolvedSigKeys,
const QStringList &unresolvedRecp,
const QString &sender,
bool allowMixed,
GpgME::Protocol forcedProtocol,
GpgME::Protocol presetProtocol,
QWidget *parent,
Qt::WindowFlags f): QDialog(parent, f),
d(new Private(this, forcedProtocol, presetProtocol, sender, allowMixed))
{
d->addSigningKeys(resolvedSigningKeys, unresolvedSigKeys);
d->addEncryptionKeys(resolvedRecp, unresolvedRecp);
d->updateOkButton();
const auto size = sizeHint();
const auto desk = QApplication::desktop()->screenGeometry(this);
resize(QSize(desk.width() / 3, qMin(size.height(), desk.height() / 2)));
}
std::vector<GpgME::Key> NewKeyApprovalDialog::signingKeys()
{
- std::vector <GpgME::Key> ret;
-
- for (const auto combo: d->mSigningCombos) {
- ret.push_back(combo->currentKey());
- }
-
- return ret;
+ return d->mAcceptedSig;
}
QMap <QString, std::vector<GpgME::Key> > NewKeyApprovalDialog::encryptionKeys()
{
- QMap <QString, std::vector<GpgME::Key> > ret;
- for (const auto combo: d->mEncCombos) {
- const auto &addr = combo->property("address").toString();
- const auto &key = combo->currentKey();
- if (ret.contains(addr)) {
- ret[addr].push_back(key);
- } else {
- std::vector<GpgME::Key> vec;
- vec.push_back(key);
- ret.insert(addr, vec);
- }
- }
- return ret;
+ return d->mAcceptedEnc;
}
#include "newkeyapprovaldialog.moc"

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 29, 9:15 AM (9 h, 3 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
00/51/faeeb139bdf814d77586bb06a1fd

Event Timeline