Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing support for S/MIME envloped signing #252

Closed
cgruber0 opened this issue Feb 28, 2020 · 6 comments
Closed

Added missing support for S/MIME envloped signing #252

cgruber0 opened this issue Feb 28, 2020 · 6 comments

Comments

@cgruber0
Copy link

cgruber0 commented Feb 28, 2020

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

@bbottema
Copy link
Owner

bbottema commented Jun 3, 2020

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...

@bbottema
Copy link
Owner

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

image

@cgruber0
Copy link
Author

cgruber0 commented Jul 13, 2020

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?

@bbottema
Copy link
Owner

bbottema commented Jul 19, 2020

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.

Repository owner deleted a comment from cgruber0 Jul 19, 2020
@bbottema
Copy link
Owner

bbottema commented Jul 24, 2020

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...

@bbottema bbottema modified the milestones: 6.x.0, 6.4.1 Jul 24, 2020
@bbottema bbottema changed the title Decrypting smime.p7m attachments Added missing support for S/MIME envloped signing Jul 26, 2020
@bbottema
Copy link
Owner

bbottema commented Jul 26, 2020

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
Projects
None yet
Development

No branches or pull requests

2 participants