-
-
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
Decrypting encrypted content without headers #443
Comments
I would recommend using the SecureMimeContext directly. http://www.mimekit.net/docs/html/M_MimeKit_Cryptography_SecureMimeContext_DecryptTo.htm |
Here's how you can use this: public MimeEntity Decrypt (SecureMimeContext ctx, ApplicationPkcs7Mime pkcs7)
{
using (var decryptedData = new MemoryStream ()) {
using (var encryptedData = new MemoryStream ()) {
pkcs7.Content.DecodeTo (encryptedData);
encryptedData.Position = 0;
ctx.DecryptTo (encryptedData, decryptedData);
decryptedData.Position = 0;
}
// now figure out of it has headers or not...
if (dataHasHeaders)
return MimeEntity.Load (decryptedData);
var content = new MemoryStream ();
decryptedData.CopyTo (content);
content.Position = 0;
return new MimePart ("application", "octet-stream") {
Content = new MimeContent (content)
};
}
} |
MimeKit throws in a couple of other places when it fails to parse headers. Thanks for the sample. |
You haven't given me an example so I can't tell you why it isn't. |
Can't share the original, but I think this should show it. Password is "nsoft". So, expecting a compliant message, I go like this: ...
var message = MimeMessage.Load(inputFileName);
var pkcs7 = message.Body as ApplicationPkcs7Mime;
using (var ctxDecrypt = CustomSecureMimeContext.Create(EncryptionCertificateStream, EncryptionCertificatePassword))
{
// this doesn't throw
var decrypted = pkcs7.Decrypt(ctxDecrypt);
// but the content is null
IMimeContent content = (decrypted as MimePart).Content;
... |
I'm getting a (test) encrypted file.
MimeKit decrypts it, but the content comes out empty.
OpenSSL decrypts it and does produce content.
I might be wrong, but from what I can tell, it looks to me that the decrypted message does not have headers and this throws off MimeKit. After decryption, it goes on to scan for headers, doesn't find any, defaults to text/plain, but then doesn't rewind the stream to account for the missing headers and comes up with empty content.
Decrypted message without headers is probably not very compliant.
However, silently "losing" the content also seems wrong.
Perhaps it would make sense (based on ParserOptions being on the strict/loose side or unconditionally), that MimeKit either:
The text was updated successfully, but these errors were encountered: