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

Make the key resolver agnostic to different crypto message formats

Different crypto message formats (e.g. OpenPGP/MIME, Inline OpenPGP, etc.)
are irrelevant for finding suitable keys for all recipients. Only the
distiction between OpenPGP and S/MIME (i.e. GpgME::Protocol) is
relevant. Handling different crypto message formats is left to using
code that really needs this (i.e. email applications).

GnuPG-bug-id: 5283
parent 0b64e101
This diff is collapsed.
......@@ -91,11 +91,11 @@ public:
*
* @param encrypt: Should encryption keys be selected.
* @param sign: Should signing keys be selected.
* @param format: A specific format for selection. Default Auto.
* @param format: A specific key protocol (OpenPGP, S/MIME) for selection. Default: Both protocols.
* @param allowMixed: Specify if multiple message formats may be resolved.
**/
explicit KeyResolver(bool encrypt, bool sign,
CryptoMessageFormat format = AutoFormat,
GpgME::Protocol format = GpgME::UnknownProtocol,
bool allowMixed = true);
~KeyResolver() override;
......@@ -123,9 +123,9 @@ public:
* addresses. The keys for the fingerprints are looked
* up and used when found. Does not interact with the user.
*
* @param overrides: A map of \<cryptomessageformat\> -> (\<address\> \<fingerprints\>)
* @param overrides: A map of \<protocol\> -> (\<address\> \<fingerprints\>)
*/
void setOverrideKeys(const QMap<CryptoMessageFormat, QMap<QString, QStringList> > &overrides);
void setOverrideKeys(const QMap<GpgME::Protocol, QMap<QString, QStringList> > &overrides);
/**
* Set explicit signing keys. If this was set for a
......@@ -147,7 +147,7 @@ public:
*
* @return the resolved sender / key pairs for encryption by format.
*/
QMap <CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > > encryptionKeys() const;
QMap <GpgME::Protocol, QMap<QString, std::vector<GpgME::Key> > > encryptionKeys() const;
/**
* Get the signing keys to use after resolution.
......@@ -155,7 +155,7 @@ public:
* @return the resolved resolved sender / key pairs for signing
* by format.
*/
QMap <CryptoMessageFormat, std::vector<GpgME::Key> > signingKeys() const;
QMap <GpgME::Protocol, std::vector<GpgME::Key> > signingKeys() const;
/**
* Starts the key resolving procedure. Emits keysResolved on success or
......@@ -173,7 +173,7 @@ public:
* @return A map of email's with new overrides and the according
* cryptoformat / fingerprint. Should be saved somehow.
*/
QMap <CryptoMessageFormat, QMap<QString, QStringList> > overrideKeys() const;
QMap <GpgME::Protocol, QMap<QString, QStringList> > overrideKeys() const;
/**
* Set window flags for a possible dialog.
......
......@@ -10,6 +10,8 @@
#include "kleo/keyresolver.h"
#include "utils/formatting.h"
#include <QCommandLineParser>
#include <QApplication>
#include <QDebug>
......@@ -18,11 +20,12 @@
#include <gpgme++/key.h>
using namespace Kleo;
using namespace GpgME;
void dumpKeys(const QMap <CryptoMessageFormat, QMap<QString, std::vector<GpgME::Key> > > &fmtMap)
void dumpKeys(const QMap <Protocol, QMap<QString, std::vector<Key> > > &fmtMap)
{
for (const CryptoMessageFormat fmt: fmtMap.keys()) {
qDebug () << "Format:" << cryptoMessageFormatToLabel(fmt) << fmt;
for (const Protocol fmt: fmtMap.keys()) {
qDebug () << "Format:" << Formatting::displayName(fmt) << fmt;
for (const auto &mbox: fmtMap[fmt].keys()) {
qDebug() << "Address:" << mbox;
qDebug() << "Keys:";
......@@ -33,10 +36,10 @@ void dumpKeys(const QMap <CryptoMessageFormat, QMap<QString, std::vector<GpgME::
}
}
void dumpSigKeys(const QMap <CryptoMessageFormat, std::vector<GpgME::Key> > &fmtMap)
void dumpSigKeys(const QMap <Protocol, std::vector<Key> > &fmtMap)
{
for (const CryptoMessageFormat fmt: fmtMap.keys()) {
qDebug () << "Format:" << cryptoMessageFormatToLabel(fmt) << fmt;
for (const Protocol fmt: fmtMap.keys()) {
qDebug () << "Format:" << Formatting::displayName(fmt) << fmt;
qDebug() << "Keys:";
for (const auto &key: fmtMap[fmt]) {
qDebug () << key.primaryFingerprint();
......@@ -113,31 +116,23 @@ int main(int argc, char **argv)
resolver.setRecipients(recps);
resolver.setSender(parser.value(QStringLiteral("sender")));
QMap <CryptoMessageFormat, QMap <QString, QStringList> > overrides;
QMap <Protocol, QMap <QString, QStringList> > overrides;
for (const QString &oride: parser.values(QStringLiteral("overrides"))) {
const QStringList split = oride.split(QLatin1Char(':'));
CryptoMessageFormat fmt = AutoFormat;
Protocol fmt = UnknownProtocol;
if (split.size() < 2 || split.size() > 3) {
parser.showHelp(1);
}
if (split.size() == 3) {
const QString fmtStr = split[2].toLower();
if (fmtStr == QLatin1String("inlineopenpgp")) {
fmt = InlineOpenPGPFormat;
} else if (fmtStr == QLatin1String("openpgpmime")) {
fmt = OpenPGPMIMEFormat;
if (fmtStr == QLatin1String("openpgp")) {
fmt = OpenPGP;
} else if (fmtStr == QLatin1String("smime")) {
fmt = SMIMEFormat;
} else if (fmtStr == QLatin1String("smimeopaque")) {
fmt = SMIMEOpaqueFormat;
} else if (fmtStr == QLatin1String("anyopenpgp")) {
fmt = AnyOpenPGP;
} else if (fmtStr == QLatin1String("anysmime")) {
fmt = AnySMIME;
fmt = CMS;
} else if (fmtStr == QLatin1String("auto")) {
fmt = AutoFormat;
fmt = UnknownProtocol;
} else {
parser.showHelp(1);
}
......
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