Commit c1133022 authored by Sandro Knauß's avatar Sandro Knauß

Split decrypted and signed messagepart

parent 4dfe01a2
......@@ -920,13 +920,11 @@ public:
Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
QObject block;
if (metaData.isSigned) {
c.insert(QStringLiteral("content"), renderSigned(mp));
} else if (node) {
if (node || mp->hasSubParts()) {
auto _htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
{
HTMLBlock::Ptr rBlock;
if (mp->isRoot()) {
if (node && mp->isRoot()) {
rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data()));
}
renderSubParts(mp, _htmlWriter);
......@@ -956,7 +954,7 @@ public:
return html;
}
QString renderSigned(const CryptoMessagePart::Ptr &mp)
QString renderSigned(const SignedMessagePart::Ptr &mp)
{
KMime::Content *node = mp->mNode;
const auto metaData = mp->mMetaData;
......@@ -1186,29 +1184,46 @@ public:
return html;
}
QString render(const CryptoMessagePart::Ptr &mp)
QString render(const SignedMessagePart::Ptr &mp)
{
auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
const auto metaData = mp->mMetaData;
if (metaData.isEncrypted) {
if (metaData.isSigned) {
{
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
htmlWriter->queue(renderEncrypted(mp));
htmlWriter->queue(renderSigned(mp));
}
return htmlWriter->html;
}
{
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
if (mp->hasSubParts()) {
renderSubParts(mp, htmlWriter);
} else {
htmlWriter->queue(render(mp.dynamicCast<MessagePart>()));
}
}
return htmlWriter->html;
}
QString render(const CryptoMessagePart::Ptr &mp)
{
auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
const auto metaData = mp->mMetaData;
if (metaData.isSigned) {
if (metaData.isEncrypted) {
{
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
htmlWriter->queue(renderSigned(mp));
htmlWriter->queue(renderEncrypted(mp));
}
return htmlWriter->html;
}
......@@ -1219,7 +1234,7 @@ public:
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
if (mp->mNode) {
if (mp->hasSubParts()) {
renderSubParts(mp, htmlWriter);
} else {
htmlWriter->queue(render(mp.dynamicCast<MessagePart>()));
......@@ -1321,6 +1336,11 @@ public:
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::SignedMessagePart")) {
auto mp = msgPart.dynamicCast<SignedMessagePart>();
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::CryptoMessagePart")) {
auto mp = msgPart.dynamicCast<CryptoMessagePart>();
if (mp) {
......
......@@ -4,6 +4,6 @@
* MimeTreeParser::MessagePart
* MimeTreeParser::EncapsulatedRfc822MessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::TextMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::TextMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::TextMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::AttachmentMessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......@@ -5,7 +5,7 @@
* MimeTreeParser::MessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::EncapsulatedRfc822MessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::MimeMessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::AttachmentMessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::MimeMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::EncapsulatedRfc822MessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
* MimeTreeParser::MessagePartList
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::CryptoMessagePart
* MimeTreeParser::SignedMessagePart
* MimeTreeParser::TextMessagePart
* MimeTreeParser::MessagePart
......@@ -87,7 +87,7 @@ Interface::MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Inter
// We try decrypting the content
// if we either *know* that it is an encrypted message part
// or there is neither signed nor encrypted parameter.
CryptoMessagePart::Ptr mp;
MessagePart::Ptr mp;
if (!isSigned) {
if (isEncrypted) {
qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime == S/MIME TYPE: enveloped (encrypted) data";
......@@ -95,24 +95,22 @@ Interface::MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Inter
qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - type unknown - enveloped (encrypted) data ?";
}
mp = CryptoMessagePart::Ptr(new CryptoMessagePart(part.objectTreeParser(),
auto _mp = CryptoMessagePart::Ptr(new CryptoMessagePart(part.objectTreeParser(),
node->decodedText(), smimeCrypto,
NodeHelper::fromAsString(node), node));
mp->setIsEncrypted(true);
mp->setDecryptMessage(part.source()->decryptMessage());
PartMetaData *messagePart(mp->partMetaData());
mp = _mp;
_mp->setIsEncrypted(true);
_mp->setDecryptMessage(part.source()->decryptMessage());
PartMetaData *messagePart(_mp->partMetaData());
if (!part.source()->decryptMessage()) {
isEncrypted = true;
signTestNode = 0; // PENDING(marc) to be abs. sure, we'd need to have to look at the content
} else {
mp->startDecryption();
_mp->startDecryption();
if (messagePart->isDecryptable) {
qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - encryption found - enveloped (encrypted) data !";
isEncrypted = true;
part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
if (messagePart->isSigned) {
part.nodeHelper()->setSignatureState(node, KMMsgFullySigned);
}
signTestNode = 0;
} else {
......@@ -120,7 +118,7 @@ Interface::MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Inter
// decryption failed, or because we didn't know if it was encrypted, tried,
// and failed. If the message was not actually encrypted, we continue
// assuming it's signed
if (mp->passphraseError() || (smimeType.isEmpty() && messagePart->isEncrypted)) {
if (_mp->passphraseError() || (smimeType.isEmpty() && messagePart->isEncrypted)) {
isEncrypted = true;
signTestNode = 0;
}
......@@ -148,24 +146,24 @@ Interface::MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Inter
const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signTestNode));
const QByteArray signaturetext = signTestNode->decodedContent();
mp = CryptoMessagePart::Ptr(new CryptoMessagePart(part.objectTreeParser(),
auto _mp = SignedMessagePart::Ptr(new SignedMessagePart(part.objectTreeParser(),
aCodec->toUnicode(signaturetext), smimeCrypto,
NodeHelper::fromAsString(node), signTestNode));
mp->setDecryptMessage(part.source()->decryptMessage());
mp = _mp;
//mp->setDecryptMessage(part.source()->decryptMessage());
PartMetaData *messagePart(mp->partMetaData());
if (smimeCrypto) {
mp->startVerificationDetached(signaturetext, 0, QByteArray());
_mp->startVerificationDetached(signaturetext, 0, QByteArray());
} else {
messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED);
}
if (messagePart->isSigned) {
if (_mp->isSigned()) {
if (!isSigned) {
qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - signature found - opaque signed data !";
isSigned = true;
}
part.nodeHelper()->setSignatureState(signTestNode, KMMsgFullySigned);
if (signTestNode != node) {
part.nodeHelper()->setSignatureState(node, KMMsgFullySigned);
}
......
......@@ -104,13 +104,6 @@ Interface::MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interfa
if (!messagePart->inProgress) {
part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
if (messagePart->isDecryptable && messagePart->isSigned) {
// Note: Multipart/Encrypted might also be signed
// without encapsulating a nicely formatted
// ~~~~~~~ Multipart/Signed part.
// (see RFC 3156 --> 6.2)
part.nodeHelper()->setSignatureState(node, KMMsgFullySigned);
}
}
}
return mp;
......
......@@ -99,11 +99,10 @@ Interface::MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface:
const QByteArray cleartext = KMime::LFtoCRLF(signedData->encodedContent());
const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signedData));
CryptoMessagePart::Ptr mp(new CryptoMessagePart(part.objectTreeParser(),
SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(),
aCodec->toUnicode(cleartext), protocol,
NodeHelper::fromAsString(node), signature));
PartMetaData *messagePart(mp->partMetaData());
messagePart->isSigned = true;
if (protocol) {
mp->startVerificationDetached(cleartext, signedData, signature->decodedContent());
......
This diff is collapsed.
......@@ -51,6 +51,7 @@ class ObjectTreeParser;
class HtmlWriter;
class HTMLBlock;
typedef QSharedPointer<HTMLBlock> HTMLBlockPtr;
class CryptoBodyPartMemento;
namespace Interface
{
......@@ -303,7 +304,6 @@ class MIMETREEPARSER_EXPORT CryptoMessagePart : public MessagePart
Q_OBJECT
Q_PROPERTY(bool decryptMessage READ decryptMessage WRITE setDecryptMessage)
Q_PROPERTY(bool isEncrypted READ isEncrypted)
Q_PROPERTY(bool isSigned READ isSigned)
Q_PROPERTY(bool passphraseError READ passphraseError)
public:
typedef QSharedPointer<CryptoMessagePart> Ptr;
......@@ -315,24 +315,20 @@ public:
virtual ~CryptoMessagePart();
QString text() const Q_DECL_OVERRIDE;
void setDecryptMessage(bool decrypt);
bool decryptMessage() const;
void setIsEncrypted(bool encrypted);
bool isEncrypted() const;
void setIsSigned(bool isSigned);
bool isSigned() const;
bool passphraseError() const;
void startDecryption(const QByteArray &text, const QTextCodec *aCodec);
void startDecryption(KMime::Content *data = 0);
void startVerification(const QByteArray &text, const QTextCodec *aCodec);
void startVerificationDetached(const QByteArray &text, KMime::Content *textNode, const QByteArray &signature);
QByteArray mDecryptedData;
std::vector<GpgME::Signature> mSignatures;
QString plaintextContent() const Q_DECL_OVERRIDE;
QString htmlContent() const Q_DECL_OVERRIDE;
......@@ -344,24 +340,63 @@ private:
*/
bool okDecryptMIME(KMime::Content &data);
protected:
bool mPassphraseError;
bool mNoSecKey;
const Kleo::CryptoBackend::Protocol *mCryptoProto;
QString mFromAddress;
KMime::Content *mNode;
bool mDecryptMessage;
QByteArray mVerifiedText;
std::vector<GpgME::DecryptionResult::Recipient> mDecryptRecipients;
friend class DefaultRendererPrivate;
};
class MIMETREEPARSER_EXPORT SignedMessagePart : public MessagePart
{
Q_OBJECT
Q_PROPERTY(bool isSigned READ isSigned)
public:
typedef QSharedPointer<SignedMessagePart> Ptr;
SignedMessagePart(ObjectTreeParser *otp,
const QString &text,
const Kleo::CryptoBackend::Protocol *cryptoProto,
const QString &fromAddress,
KMime::Content *node);
virtual ~SignedMessagePart();
void setIsSigned(bool isSigned);
bool isSigned() const;
void startVerification(const QByteArray &text, const QTextCodec *aCodec);
void startVerificationDetached(const QByteArray &text, KMime::Content *textNode, const QByteArray &signature);
QByteArray mDecryptedData;
std::vector<GpgME::Signature> mSignatures;
QString plaintextContent() const Q_DECL_OVERRIDE;
QString htmlContent() const Q_DECL_OVERRIDE;
private:
/** Handles the verification of data
* If signature is empty it is handled as inline signature otherwise as detached signature mode.
* Returns true if the verfication was successfull and the block is signed.
* If used in async mode, check if mMetaData.inProgress is true, it inicates a running verification process.
*/
bool okVerify(const QByteArray &data, const QByteArray &signature);
bool okVerify(const QByteArray &data, const QByteArray &signature, KMime::Content *textNode);
void sigStatusToMetaData();
void setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode);
protected:
bool mPassphraseError;
bool mNoSecKey;
const Kleo::CryptoBackend::Protocol *mCryptoProto;
QString mFromAddress;
KMime::Content *mNode;
bool mDecryptMessage;
QByteArray mVerifiedText;
std::vector<GpgME::DecryptionResult::Recipient> mDecryptRecipients;
friend CryptoMessagePart;
friend class DefaultRendererPrivate;
};
......
......@@ -398,6 +398,7 @@ private:
friend class PartNodeBodyPart;
friend class MessagePart;
friend class CryptoMessagePart;
friend class SignedMessagePart;
friend class EncapsulatedRfc822MessagePart;
friend class TextMessagePart;
friend class HtmlMessagePart;
......
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