I cannot seem to get external certificates to work with MSMQ (Windows Server 2012 R2, .NET 4.7.2).
Message msg = new Message(data)
{
UseAuthentication = true,
SenderCertificate = cert.GetRawCertData(),
};
this._queue.Send(msg);
My code is pretty simple to test it, where cert is a X509Certificate which I load from the current user's personal certificate store (although have tried loading from file too, MSMQ requires it in the personal certificate store to work).
When I run this I get an exception:
System.Messaging.MessageQueueException
HResult=0x80004005
Message=Cryptographic function has failed.
Source=System.Messaging
StackTrace:
at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Send(Object obj)
at blah blah...
MessageQueueErrorCode: CorruptedSecurityData
I have tried various certificates (signed by the domain CA, signed by a local CA, self-signed etc), all the same result. I'm generally using an OpenSSL self-signed certificate that has no constraints on usage and is trusted by the local machine root store to ensure it validates (although I'm not sure that's necessary for MSMQ). The certificate is naturally loaded into AD too, but the error doesn't change if it isn't. Have tried various algorithms, currently on SHA512.
If I specify an invalid certificate then the error changes to reflect, so I don't believe there is any issue with selecting the certificate.
I'm struggling to find working examples of people using external certificates with .NET and MSMQ.
User contributions licensed under CC BY-SA 3.0