Sicos1977 / MSGReader

C# Outlook MSG file reader without the need for Outlook
http://sicos1977.github.io/MSGReader
MIT License
490 stars 168 forks source link

Loading a signed message leads to an exception, signature remains empty #277

Closed edoust closed 3 years ago

edoust commented 3 years ago

Using this code leads to an exception when trying to load a file that contains a signed e-mail message:

using (var message = new Storage.Message(content.File.FullName))
{
   // ...
}

This is the exception: System.PlatformNotSupportedException: 'The OID value cannot be changed from its current value.'

This happens on .NET 5 and may be related to this: Breaking change: System.Security.Cryptography.Oid is functionally init-only

This is the stacktrace until the exception occurs:

System.Security.Cryptography.Encoding.dll!System.Security.Cryptography.Oid.Value.set(string value)  Unknown
System.Security.Cryptography.Pkcs.dll!Internal.Cryptography.PkcsHelpers.DetectInitOnlyOid() Unknown
System.Security.Cryptography.Pkcs.dll!Internal.Cryptography.PkcsHelpers.PkcsHelpers() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Security.Cryptography.Pkcs.dll!Internal.Cryptography.PkcsHelpers.CopyOid(System.Security.Cryptography.Oid oid) Unknown
System.Security.Cryptography.Pkcs.dll!System.Security.Cryptography.Pkcs.SignedCms.MakeEmptyContentInfo() Unknown
MsgReader.dll!MsgReader.Mime.Message.ProcessSignedContent(byte[] data) Unknown
MsgReader.dll!MsgReader.Mime.Message.Message(byte[] rawMessageContent, bool parseBody) Unknown
MsgReader.dll!MsgReader.Mime.Message.Message(byte[] rawMessageContent) Unknown
MsgReader.dll!MsgReader.Mime.Message.Load(System.IO.Stream messageStream) Unknown
MsgReader.dll!MsgReader.Outlook.Storage.Message.LoadClearSignedMessage(OpenMcdf.CFStorage storage) Unknown
MsgReader.dll!MsgReader.Outlook.Storage.Message.LoadStorage(OpenMcdf.CFStorage storage) Unknown
MsgReader.dll!MsgReader.Outlook.Storage.Storage(string storageFilePath, System.IO.FileAccess fileAccess) Unknown
MsgReader.dll!MsgReader.Outlook.Storage.Message.Message(string msgfile, System.IO.FileAccess fileAccess) Unknown
Sicos1977 commented 3 years ago

Can you sent me a copy of the signed msg file? So that I can test this myself? If so then sent it to sicos2002@hotmail.com ... zip the file before sending it to me otherwise Outlook has the bad habbit of converting in to EML format.

Sicos1977 commented 3 years ago

Without an example file I can't see if I can fix it.

edoust commented 3 years ago

Sorry didn't get to it yet, since I have to create a nonconfidential repro and also test against .NET 4.x to see the exact difference in behavior. Will definitely get back to you on this issue