Skip to content

Added missing support for S/MIME envloped signing #252

Closed

Description

@cgruber0

Hi,

I have troubles getting the content of an email that is encrypted and signed (see attachment). The email itself only contains one smime.p7m attachment.

I use following code:

FileInputStream f = new FileInputStream(new File("email.eml"));

FileInputStream key = new FileInputStream(new File("keystore.p12"));
FileInputStream key2 = new FileInputStream(new File("keystore.p12"));

SmimeKeyStore smimeKeyStore = new SmimeKeyStore(key, "pw".toCharArray());
String alias = smimeKeyStore.getPrivateKeyAliases().iterator().next();

Pkcs12Config yourPkcs12Config = Pkcs12Config.builder()
        .pkcs12Store(key2) // path, File or InputStream
        .storePassword("pw")
        .keyAlias(alias)
        .keyPassword("pw")
        .build();

Email mergedEmail = EmailConverter.emlToEmail(f, yourPkcs12Config);
List<AttachmentResource> list = mergedEmail.getDecryptedAttachments();

for (AttachmentResource r : list) {
    play.Logger.info(r.readAllData());
}

But the output of r.readAllData() gives me binary data only.

When I open the email in Thunderbird it is decrypted correctly, it contains text only.

Can you please help me to get the actual content?
email.txt

Activity

  1. bbottema commented on Jun 3, 2020

    @bbottema
    Owner

    Hi, my apologies for the late reply, but I'm currently unable to look into this as I have recently become father to our second child. Takes rather lot of attention I'm finding out. On top of that, the topic here is rather complicated and needs some proper debugging and research.

    I'm always open to suggestions and pull requests though. Sorry I don't have better news for the moment...

  2. bbottema commented on Jul 12, 2020

    @bbottema
    Owner

    When I open this file in Thunderbird, I don't see any attachments...

    image

  3. cgruber0 commented on Jul 13, 2020

    @cgruber0
    Author

    If you look at the content of the file (email.txt) you can see a Content-Disposition: attachment; filename="smime.p7m" part.

    That's the actual content (= text) of the email. But it's encrypted.

    Thunderbird is able to decrypt the email without problems and shows the content (private key provided). The library is not.

    You can understand the problem now?

  4. bbottema commented on Jul 19, 2020

    @bbottema
    Owner

    Unless you provide the private key along with the encrypted email, I can't do a root-cause analysis. The sample emails included in Simple Java Mail's tests all work fine, so I have no clue what can go wrong.

    Can you provide the private key, perhaps email it to me directly so I can analyse (I won't publish it in the GIT repo). That would be of great help.

  5. Repository owner deleted a comment from cgruber0 on Jul 19, 2020
  6. bbottema commented on Jul 24, 2020

    @bbottema
    Owner

    I have been provided with a matching keystore and have been analysing the issue. It turns out that S/MIME support was incomplete for the backwards compatible legacy signing protocol: Content-Type: application/x-pkcs7-mime; name=smime.p7m; smime-type=signed-data. Nowadays signing is done using certificate added to an attachment, but legacy style is that the entire attachment content is wrapped similarly to how encrypted content still is wrapped (enveloped content).

    I've fixed the support (that was pretty complex!), but I've got it working nicely now. Wrapping up on the code quality and then I'll be shipping out a new release...

  7. modified the milestones: , 6.4.1 on Jul 24, 2020
  8. added a commit that references this issue on Jul 26, 2020
  9. changed the title [-]Decrypting smime.p7m attachments[/-] [+]Added missing support for S/MIME envloped signing[/+] on Jul 26, 2020
  10. bbottema commented on Jul 26, 2020

    @bbottema
    Owner

    Fix released in 6.4.1. Again, greatly appreciate your trust, I could not have analysed and fixed this without it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions