Fix opening attachments in Opaque S/MIME encrypted messages
ClosedPublic

Authored by dvratil on Jun 20 2016, 6:05 PM.

Details

Reviewers
knauss
Summary

This fixes opening attachments in Opaque S/MIME encrypted messages. The problem is that the verified signed part was not attached to the encrypted part, so that the URL for the attachment was invalid (attachment:0::2?part=body) - because lookup in extraContents() would fail for the intermediate part. By making sure that the signed part is attached to the crypto part, the extraContents lookup is successful for the entire chain and everything works.

Test Plan

Sent myself an Opaque S/MIME encrypted message with attachment and tried opening the attachment.
Tests pass

Diff Detail

Repository
R94 PIM: Message Library
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
dvratil updated this revision to Diff 4647.Jun 20 2016, 6:05 PM
dvratil retitled this revision from to Fix opening attachments in Opaque S/MIME encrypted messages.
dvratil updated this object.
dvratil edited the test plan for this revision. (Show Details)
dvratil added a reviewer: knauss.
dvratil set the repository for this revision to R94 PIM: Message Library.
dvratil added a project: KDE PIM.
Restricted Application added a subscriber: kde-pim. · View Herald TranscriptJun 20 2016, 6:05 PM
knauss edited edge metadata.Jun 21 2016, 8:26 AM

The fix does not makes sense in that what you discribe and addContent is for sure wrong to fix this. We don't want to change the mail it self, we attach a extra part.
I think the problem is that the partent Node (mNode) is not added as extra node. nodehelpertest should be test this.

If it is encrypted this part only CryptoMessagePart::startDecryption(KMime::Content *data) should be called that does decrypt+verification. But maybe you have a "special" opaque SMIME message, that triggers the verification.

Can you places add a test for this.
attachmenttest and/or rendertest (that lives in messageviewer/src/messagepartthemes/default/autotests)

To create a test mail, you can run kmail like we does it for the tests and select than a key in the test keyring:
GNUPGHOME=<BUILDPATH>/messagelib/messagecore/autotests/gnupg_home gpg-agent --daemon kmail

knauss requested changes to this revision.Jun 21 2016, 8:27 AM
knauss edited edge metadata.
This revision now requires changes to proceed.Jun 21 2016, 8:27 AM
dvratil updated this revision to Diff 4747.Jun 26 2016, 6:05 PM
dvratil edited edge metadata.
dvratil edited the test plan for this revision. (Show Details)

Add attachmenttest testcase with opaque S/MIME signed and encrypted email with attachment

dvratil updated this revision to Diff 4748.Jun 26 2016, 6:20 PM
dvratil edited edge metadata.

Use correct key to encrypt the testcase

The test is now able to decrypt the message

So, the problem here is the following. Upon decrypting the message we end up with the current "tree" of parts:

application/pkcs7-mime; smime-type: "enveloped-data"
application/pkcs7-mime; smime-type: "signed-data"
   multipart/mixed
      text/plain
      application/octet-stream; content-disposition: attachment

and the NodeHelper::mExtraContents table is like this:

application/pkcs7-mime; smime-type: "enveloped-data" => [ application/pks-7-mime; smime-type: "signed-data" ]
application/pkcs7-mime; smime-type: "signed-data" => [ multipart/mixed ]

The problem here is that although mExtraContents indicates relation between the signed-data and enveloped-data, in reality the signed-data part is not a child of the enveloped-data message, although it should be (IMO), because the signed-data message is the content of the enveloped-data message, similar to multipart/mixed being the content of signed-data.

The fact that this relationship is not present is visible on the URL of the attachment part:

attachment:0:0::2?place=body

Notice the double colon? That's NodeHelper::persistentIndex() failing to find the position of signed-data within its parent - because it has none!

The problem is that NodeHelper::persistentIndex() is recursive only within the KMime::Content tree hierarchy, but it is not recursive in the terms of mExtraContents relationships.

There are IMO two possible ways to fix this:

  1. Make signed-data a child of the original enveloped-data part.

This is what I tried to do in my initial patch. The problem is that when the signature is being verified we no longer have the parent enveloped-data part available in pointers and such, and it happens in a code that is too generic to be the right place for this. Possibly larger change would be required to make this work

  1. Make NodeHelper::persistentIndex() smarter.

The idea is to support recursive relation lookup through both KMime::Content::parent() as well as the mExtraContents table, using special prefix for the indexes in mExtraContents. As an example, the URL of the attachment with approach would be something like

attachment:0:0:e0:2?place=body

See the "e0"? That indicates that the part is not first child enveloped-data, but is the first element in mExtraContents[enveloped-data-node].

dvratil updated this revision to Diff 4807.Jun 28 2016, 3:51 PM

Fix opening deeply nested attachments

This improves NodeHelper::persistentIndex() in a way that the index can
disambiguate between index retrieved via KMime::Content::node() and
index that refers to position inside mExtraContents (such index is
prefixed with "e").

knauss accepted this revision.Jun 28 2016, 5:40 PM
knauss edited edge metadata.

looks good

This revision is now accepted and ready to land.Jun 28 2016, 5:40 PM
dvratil closed this revision.Jun 28 2016, 10:53 PM

Comitted as 64e1046119cc16101f653fb58fdf98b4d3cf1d98

(I accidentally references a wrong Differential Revision in the commit message)