RabbitMQ: Cannot connect over TLS

Viewed 341

i have a problem connecting to my rabbitmq broker on a Ubuntu 18.04 Server over tls. I am using the following code on the client side.

using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Net.Security;
using System.Security.Authentication;
using System.Text;

namespace firstConsumer
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() 
            { 
                HostName = "my-domain.de",
                UserName = "main",
                Password = "1234",
                Port = 5671,
                Ssl = new SslOption
                {
                    Enabled = true,
                    Version = SslProtocols.Tls12,
                    ServerName = "my-domain.de",
                    AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch |
                                            SslPolicyErrors.RemoteCertificateChainErrors |
                                            SslPolicyErrors.RemoteCertificateNotAvailable,
                    
                }
            };



            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "test-queue",
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: true,
                                         arguments: null);

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        var body = ea.Body.ToArray();
                        var message = Encoding.UTF8.GetString(body);
                        Console.WriteLine(" [x] Received {0}", message);
                    };

                    channel.BasicConsume(queue: "test-queue",
                                         autoAck: true,
                                         consumer: consumer);

                    Console.WriteLine(" Press [enter] to exit.");
                    Console.ReadLine();
                }
            }
        }
    }
}

This is one of the example codes from the rabbitmq documentation to connect with the broker with c# over tls.

RabbitMQ is running in a docker container with valid certs from Certbot (Let's Encrypt). It is also listening on the right tls ports:

rabbitmq_1  | 2020-08-01 16:40:42.082 [info] <0.523.0> started TCP listener on [::]:5672
rabbitmq_1  | 2020-08-01 16:40:42.147 [info] <0.540.0> started TLS (SSL) listener on [::]:5671

This is my docker-compose file:

version: '3'

services:
  rabbitmq:
    image: 'rabbitmq:3'
    hostname: 'rabbitmq'
    ports:
      - '4369:4369'
      - '5672:5672'
      - '5671:5671'
      - '25672:25672'
    volumes:
      - ./config/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
      - ./Cert/Cert-tls-gen/:/cert/

And here are my Port setting on ufw

Zu                         Aktion      Von
--                         ------      ---
OpenSSH                    ALLOW       Anywhere
5672                       ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
5671                       ALLOW       Anywhere
20,21,10000:10100/tcp      ALLOW       Anywhere
21                         DENY        Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
5672 (v6)                  ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)
5671 (v6)                  ALLOW       Anywhere (v6)
20,21,10000:10100/tcp (v6) ALLOW       Anywhere (v6)
21 (v6)                    DENY        Anywhere (v6)

I am always getting the following error message when i try to run the C# Code.

IOException: Authentication failed because the remote party has closed the transport stream.

And there are no logs in the rabbitmq log of the attempt of a connection over tls. There just nothing happens. RabbitMQ just does not notice any attempt connection over tls.

The code above works fine when i remove the ssl settings and try to connect just over tcp on the 5672 port. Without tls i also get logs of a connection with my client and everything works fine.

For me it looks like the server is refusing the connection but i don´t know why.

This is a fresh server just with a nginx and this one docker container.

I also tried the Java example with the same result over tls. But is works without the tls settings.

Exception in thread "main" javax.net.ssl.SSLException: Connection reset

I would appreciate it if someone could help me with this problem. I have been trying to solve it for 3 days now.

Thanks

0 Answers
Related