summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <[email protected]>2016-04-12 16:45:20 +0200
committerAndre Heinecke <[email protected]>2016-04-12 16:45:20 +0200
commit5b82da14911a0c33b8700df70b0995d16f049286 (patch)
tree23815490bc8e2baee726cbced356bb2b694d1ddd
parent5f09636af117333913234ea28aedd151beb329b6 (diff)
Use classification from GpgME as fallback
GpgME offers API to classify content but this is not fully implemented so we still use our old classification code and just use GpgME as fallback.
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/utils/classify.cpp44
2 files changed, 40 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96cb8df..ccd6474 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8.12)
# Standalone build. Find / include everything neccessary.
set(KF5_VERSION "5.17.0")
-set(GPGMEPP_VERSION "5.1.41")
+set(GPGMEPP_VERSION "5.1.42")
set(KMIME_VERSION "5.1.40")
set(LIBKLEO_VERSION "5.1.41")
set(QT_REQUIRED_VERSION "5.4.0")
diff --git a/src/utils/classify.cpp b/src/utils/classify.cpp
index 992b81b..757b2cd 100644
--- a/src/utils/classify.cpp
+++ b/src/utils/classify.cpp
@@ -36,15 +36,21 @@
#include "fileoperationspreferences.h"
+#include "kleopatra_debug.h"
+
#include <QString>
#include <QStringList>
#include <QFile>
#include <QFileInfo>
#include <QtAlgorithms>
#include <QByteArrayMatcher>
+#include <QMap>
#include <boost/range.hpp>
+#include <gpgme++/data.h>
+#include <qgpgme/dataprovider.h>
+
#ifdef __GLIBCXX__
# include <ext/algorithm>
#endif
@@ -82,6 +88,17 @@ static const struct _classification {
{ "sig", OpenPGP | AnyFormat | DetachedSignature },
};
+static const QMap<GpgME::Data::Type, unsigned int> gpgmeTypeMap {
+ { GpgME::Data::PGPSigned, OpenPGP | AnySignature },
+ { GpgME::Data::PGPOther, OpenPGP | CipherText },
+ { GpgME::Data::PGPKey, OpenPGP | Certificate },
+ { GpgME::Data::CMSSigned, CMS | AnySignature },
+ { GpgME::Data::CMSEncrypted, CMS | CipherText },
+ { GpgME::Data::CMSOther, CMS | CipherText }, // ? This is weird.
+ { GpgME::Data::X509Cert, CMS | Certificate},
+ { GpgME::Data::PKCS12, CMS | Binary | ExportedPSM }
+};
+
static const unsigned int defaultClassification = NoClass;
template <template <typename U> class Op>
@@ -186,7 +203,7 @@ unsigned int Kleo::classify(const QString &filename)
/* else */ : it->classification;
QFile file(filename);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ if (!file.open(QIODevice::ReadOnly)) {
return bestGuess;
}
@@ -198,7 +215,7 @@ unsigned int Kleo::classify(const QString &filename)
}
}
-unsigned int Kleo::classifyContent(const QByteArray &data)
+static unsigned int classifyContentInteral(const QByteArray &data)
{
#ifdef __GLIBCXX__
assert(__gnu_cxx::is_sorted(begin(content_classifications), end(content_classifications), ByContent<std::less>(100)));
@@ -226,11 +243,28 @@ unsigned int Kleo::classifyContent(const QByteArray &data)
= qBinaryFind(begin(content_classifications), end(content_classifications),
data.data() + pos, ByContent<std::less>(epos - pos));
- if (cit == end(content_classifications)) {
- return defaultClassification;
- } else {
+ if (cit != end(content_classifications)) {
return cit->classification | (pgp ? OpenPGP : CMS);
}
+ return defaultClassification;
+}
+
+unsigned int Kleo::classifyContent(const QByteArray &data)
+{
+ /* As of Version 1.6.0 GpgME does not distinguish between detached
+ * signatures and signatures. So we prefer kleo's classification and
+ * only use gpgme as fallback.
+ * See https://bugs.gnupg.org/gnupg/issue2314
+ */
+ unsigned int ourClassification = classifyContentInteral(data);
+ if (ourClassification != defaultClassification) {
+ return ourClassification;
+ }
+ QGpgME::QByteArrayDataProvider dp(data);
+ GpgME::Data gpgmeData(&dp);
+ GpgME::Data::Type type = gpgmeData.type();
+
+ return gpgmeTypeMap.value(type, defaultClassification);
}
QString Kleo::printableClassification(unsigned int classification)