rebus-org / Rebus.RabbitMq

:bus: RabbitMQ transport for Rebus
https://mookid.dk/category/rebus
Other
62 stars 44 forks source link

Get client certificate from Local Storage on Windows #87

Closed zykindmitry closed 2 years ago

zykindmitry commented 2 years ago

Hi!

I'm trying to run rebus with rabbitMQ transport with ssl auth on windows. I don't see a possibility to provide RabbitMQ client with X509Certificate object (the Certs collection of SslOption in the code below is not populated):

        var sslOption = new SslOption(ssl.ServerName, ssl.CertPath, ssl.Enabled)
        {
            CertPassphrase = ssl.CertPassphrase,
            Version = ssl.Version,
            AcceptablePolicyErrors = ssl.AcceptablePolicyErrors
        };

Can you suggest any other way I can provide client certificate from a local storage on windows.

mookid8000 commented 2 years ago

You can always resort to CustomizeConnectionFactory if you want full control over it - you can replace it completely by doing something like this:

Configure.With(activator)
    .Transport(t => t.UseRabbitMq(connectionString, "queue-name")
        .CustomizeConnectionFactory(conn => new ConnectionFactory
        {
            Ssl = new SslOption
            {
                Certs =
                {
                    // 🙂
                }
            }
        }));
zykindmitry commented 2 years ago

Thank you for the solution. There's only one issue I need your help with. I was able to initialize Certs collection of RabbitMQ.Client.ConnectionFactory however the CreateConnection method failed as if there was no certs provided. Looking into source code I found the reason why.

When the Rebus.Internals.ConnectionManager tries to establish a connection it calls RabbitMQ.Client.ConnectionFactory.CreateConnection like this:

_activeConnection = _connectionFactory.CreateConnection(_amqpTcpEndpoints);

where _amqpTcpEndpoints get their Ssl options from the same SslSettings object which has no Certs. As per RabbitMQ.Client.ConnectionFactory.cs, it uses its Ssl options only if you call CreateConnection(IList hostnames, string clientProvidedName). In that case it creates new instances of endpoints using its Ssl settings.