-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Chain not properly set when signing a S/MIME mail with a PKCS#12 file #515
Comments
MimeKit 2.4.0 has just been released with this feature. |
I haven't tested it, but if I read the patch correctly, this does not properly work for chains with >= 3 certificates, since all certificates with the KeyCertSign keyUsage (and thus also intermediates) are used as trust anchors. MimeKit/MimeKit/Cryptography/TemporarySecureMimeContext.cs Lines 173 to 174 in cfe65b7
|
Fair enough. Got any suggestions on what restrictions to use? |
I'd just take all self signed certificates. |
Unfortunately doing that makes quite a few of my S/MIME unit tests fail because Bouncy Castle cannot handle Version 1 certificates as CA certificates. From what I can tell, that's not actually a bug in my code so much as it's a "bug" in my generated certificates that I use for testing. I would appreciate it if you took the time to read over this script: https://github.com/jstedfast/MimeKit/blob/master/UnitTests/TestData/smime/gencerts.sh Assuming that my understanding about Version 1 X.509 certificates is correct and that my generated certificates should be using Version 3, it would be a HUGE help if you could fix my gencerts.sh script to generate them. If not, it'll probably take me a week or more to get to this because I'm not going to make a release where my unit tests fail and I probably won't have time to work on this again until next weekend at the earliest. |
Reopening this for now. |
… chains GetTrustedAnchors() now *only* includes self-signed certificates that have the CertKeySign KeyUsage attribute. GetIntermediates() now *only* includes non-self-signed certificates that have the CertKeySign KeyUsage attribute. Fixes issue #515
Please test this fix by installing a nuget from https://www.myget.org/feed/mimekit/package/nuget/MimeKit You'll need >= v2.4.0.4 |
I can confirm that it works with 2.4.0.8. |
Awesome, thanks for confirming! |
Describe the bug
I tried to sign a S/MIME mail with a key stored in a PKCS#12 file:
The problem is, that the certificate's chain is not included in the signature (even after issue #500 was fixed).
I tried to trace the problem down and found that the GetTrustedAnchors function (which is used in the BuildCertificateChain method) simply returns all certificates imported from the P12 file as trust anchors, resulting in a chain which only contains the signing certificate.
MimeKit/MimeKit/Cryptography/TemporarySecureMimeContext.cs
Lines 167 to 174 in 5c0578b
MimeKit/MimeKit/Cryptography/BouncyCastleSecureMimeContext.cs
Line 438 in cc0efb8
Platform (please complete the following information):
To Reproduce
Run the code above and parse the message produced
Expected behavior
The full certificate chain should be included in the signature
The text was updated successfully, but these errors were encountered: