Hi
We enabled peer verification for rabbitmq ( server 3.6.1 erlang OTP 18.2.1 ) however we kept getting this exception. Googling suggested we should upgrade erlang.
RabbitMQ Exception RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted
--- End of inner exception stack trace ---
at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
--- End of inner exception stack trace ---
at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
at RabbitMQ.Client.ConnectionFactory.CreateConnection()
at TestTls.Program.Main(String[] args) in c:\users\thivankaa\documents\visual studio 2017\Projects\TestTls\TestTls\Program.cs:line 44
RabbitMQ Exception System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted
--- End of inner exception stack trace ---
at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
We eventually realised after much trial and error that this error thrown when we provided the CA cert that is used to sign the server certificate, for server certificate validation.
Console.ReadLine();
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "localhost";
factory.Port = 5671;
factory.UserName = "guest";
factory.Password = "guest";
factory.Ssl.Enabled = true;
factory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors; // work around RemoteCertificateChainErrors
factory.Ssl.CertPath = "keycert.p12";
factory.Ssl.CertPassphrase = "passphrase";
factory.Ssl.ServerName = "Test";
// This code segment results in the SSPI Error
//factory.Ssl.Certs = new X509CertificateCollection( new[]
//{
// X509Certificate.CreateFromCertFile("cacert.cer" ),
//} );
try
{
IConnection conn = factory.CreateConnection();
Console.WriteLine( conn.IsOpen );
}
catch (Exception ex)
{
while (ex != null)
{
Console.WriteLine( "RabbitMQ Exception " + ex.Message );
ex = ex.InnerException;
}
}
Console.ReadLine();
}
We want to pass in the default ca, cert because we want TLS connections to work without manually adding the CA Cert to the trusted root authorities in the OS.
Other rabbitmq clients allow you to pass in the CA which is used to verify the server certificate. Is there a way we can do this for the .net client?