【问题标题】:use TLS 1.2 to connect securely to RabbitMQ使用 TLS 1.2 安全连接到 RabbitMQ
【发布时间】:2019-04-01 13:49:58
【问题描述】:

我正在尝试使用 TLS1.2 连接到 RabbitMQ 服务器,但我似乎做不到。我已验证我的用户名和密码正常,因为我可以连接到 RabbitMQ Web 客户端。

using System;
using System.Net;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace DigitalFulfillmentRabbitMQ
{
    public class RabbitMQService
    {
        public IConnection GetRabbitMqConnection()
        {
            ConnectionFactory connectionFactory = new ConnectionFactory();


           // ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
            // connectionFactory.Ssl.CertificateValidationCallback = CheckValidationResult();
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
            connectionFactory.HostName = ConfigurationManager.AppSettings["RabbitMQServer"].ToString();
            connectionFactory.VirtualHost = ConfigurationManager.AppSettings["RabbitMQVHOST"].ToString();
            connectionFactory.Port = Int32.Parse(ConfigurationManager.AppSettings["RabbitMQPort"].ToString());
            connectionFactory.UserName = ConfigurationManager.AppSettings["RabbitMQAccountUserName"].ToString();
            connectionFactory.Password = ConfigurationManager.AppSettings["RabbitMQAccountPassword"].ToString();
           // connectionFactory.Ssl.ServerName = System.Net.Dns.GetHostName();
            connectionFactory.Ssl.ServerName = ConfigurationManager.AppSettings["RabbitMQServer"].ToString();
            connectionFactory.Ssl.CertPath = ConfigurationManager.AppSettings["RabbitMQSSLCertPath"].ToString();
           // connectionFactory.Ssl.CertPassphrase = ConfigurationManager.AppSettings["RabbitMQSSLCertPassphrase"].ToString();
            connectionFactory.Ssl.Enabled = Convert.ToBoolean(ConfigurationManager.AppSettings["RabbitMQSSLIsEnabled"].ToString());
            connectionFactory.Ssl.Version = System.Security.Authentication.SslProtocols.Tls12;



            return connectionFactory.CreateConnection();
        }
    }
}

证书是我放在客户端上的 .pem 证书。我正在使用端口 8071。证书路径的格式为“D:\RabbitMQ_DF_SIT_Server_certificate\ca_certificate.pem”。我正在使用 NuGet 5.1.0 中的 RabbitMQ 客户端

我怀疑我需要证书验证回调方法,因为据我了解它的单向连接。此应用程序只会消费而不发布。我错过了什么?证书位于客户端服务器上,但本身并未安装。

它会抛出一个错误:

RabbitMQ.Client.Exceptions.BrokerUnreachableException:指定的端点均不可访问---> System.AggregateException:发生一个或多个错误。 ---> System.Security.Authentication.AuthenticationException:对 SSPI 的调用失败,请参阅内部异常。 ---> System.ComponentModel.Win32Exception: 客户端和服务器无法通信,因为它们没有共同的算法

【问题讨论】:

  • 你使用的是什么版本的 Erlang?您可能必须启用额外的密码套件docs。注意:RabbitMQ 团队监控 rabbitmq-users mailing list 并且有时只回答 StackOverflow 上的问题。
  • 我认为我们要做的就是购买一台新的 Windows 2016 服务器。
  • 更新:部署到 Windows 2016 服务器后,我没有任何问题。以前的尝试是使用 Windows 08R2。即使在 Windows 2012 中,其他人也报告了同样的问题。
  • 这是有趣的信息,感谢您的跟进。
  • 请注意,我当时尝试连接的 RabbitMQ 服务器位于某种 Linux 机器上。我的猜测是因为我的应用程序试图从中提取消息的服务器是旧 Windows 旧 Windows -> Linux 可能导致无法协商通用密码的问题。

标签: rabbitmq windows-server-2008-r2 tls1.2 .net-4.7.2


【解决方案1】:

为了将 TLS 与 RabbitMQ 一起使用,必须通过位于 Windows 中 %APPDATA%/RabbitMQ/rabbitmq.conf 文件的 RabbitMQ 配置启用此功能。

根据所使用的 Erlang 版本,配置可以是经典格式/ini 样式。更多详情请参考https://www.rabbitmq.com/configure.html

使用较新的 ini 样式配置格式,配置应如下所示

listeners.ssl.default = 5671

ssl_options.verify               = verify_none
ssl_options.fail_if_no_peer_cert = false
ssl_options.cacertfile           = <location to cacertfile.crt>
ssl_options.certfile             = <location to certfile.crt>
ssl_options.keyfile              = <location to private.key>

以上所有内容都可以通过我为此编写的脚本自动化和验证 https://gist.github.com/skewl84/a72321379a65c4c5cfd447f8806b5188

上面的脚本可以

  • 检查是否安装了 OpenSSL,如果需要,请下载以生成自签名证书
  • 修改 RabbbitMQ 配置以启用 TLS
  • 在 RabbitMQ 上启用 TLS 后使用 OpenSSL 测试 TLS

【讨论】:

  • 很高兴知道。我只参与了让 tls1.2 在消费者方面工作。
猜你喜欢
  • 2018-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-30
  • 2019-10-09
  • 2021-12-26
  • 2021-11-25
  • 2017-10-23
相关资源
最近更新 更多