summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/multipartsigned.cpp')
-rw-r--r--framework/src/domain/mime/mimetreeparser/multipartsigned.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp b/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp
new file mode 100644
index 00000000..6ecb09af
--- /dev/null
+++ b/framework/src/domain/mime/mimetreeparser/multipartsigned.cpp
@@ -0,0 +1,96 @@
1/*
2 Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "multipartsigned.h"
21
22#include "objecttreeparser.h"
23#include "messagepart.h"
24
25#include <KMime/Content>
26
27#include <QGpgME/Protocol>
28
29#include "mimetreeparser_debug.h"
30
31#include <QTextCodec>
32
33using namespace MimeTreeParser;
34
35const MultiPartSignedBodyPartFormatter *MultiPartSignedBodyPartFormatter::self;
36
37const Interface::BodyPartFormatter *MultiPartSignedBodyPartFormatter::create()
38{
39 if (!self) {
40 self = new MultiPartSignedBodyPartFormatter();
41 }
42 return self;
43}
44MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart &part) const
45{
46 KMime::Content *node = part.content();
47 if (node->contents().size() != 2) {
48 qCDebug(MIMETREEPARSER_LOG) << "mulitpart/signed must have exactly two child parts!" << endl
49 << "processing as multipart/mixed";
50 if (!node->contents().isEmpty()) {
51 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false));
52 } else {
53 return MessagePart::Ptr();
54 }
55 }
56
57 KMime::Content *signedData = node->contents().at(0);
58 KMime::Content *signature = node->contents().at(1);
59 Q_ASSERT(signedData);
60 Q_ASSERT(signature);
61
62 QString protocolContentType = node->contentType()->parameter(QStringLiteral("protocol")).toLower();
63 const QString signatureContentType = QLatin1String(signature->contentType()->mimeType().toLower());
64 if (protocolContentType.isEmpty()) {
65 qCWarning(MIMETREEPARSER_LOG) << "Message doesn't set the protocol for the multipart/signed content-type, "
66 "using content-type of the signature:" << signatureContentType;
67 protocolContentType = signatureContentType;
68 }
69
70 const QGpgME::Protocol *protocol = nullptr;
71 if (protocolContentType == QLatin1String("application/pkcs7-signature") ||
72 protocolContentType == QLatin1String("application/x-pkcs7-signature")) {
73 protocol = QGpgME::smime();
74 } else if (protocolContentType == QLatin1String("application/pgp-signature") ||
75 protocolContentType == QLatin1String("application/x-pgp-signature")) {
76 protocol = QGpgME::openpgp();
77 }
78
79 if (!protocol) {
80 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false));
81 }
82
83 part.nodeHelper()->setNodeProcessed(signature, true);
84
85 const QByteArray cleartext = KMime::LFtoCRLF(signedData->encodedContent());
86 const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signedData));
87
88 SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(),
89 aCodec->toUnicode(cleartext), protocol,
90 part.nodeHelper()->fromAsString(node), signature, signedData));
91 if (!protocol) {
92 mp->partMetaData()->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED);
93 }
94
95 return mp;
96}