RabbitMq Broker 不接受 PFX

RabbitMq Broker not accepting PFX

在使用 OpenSSL 生成的证书获得 RabbitMq 优于 SSL 的工作解决方案后,我们的客户要求我 不能 使用 OpenSSL 生成证书。服务器管理员通过 IIS.

创建了证书链

我们在创建后对证书进行了以下操作:

  1. 将服务器证书导出到 PFX 并提取 cert.pemcert.key
  2. 将客户端证书导出到 PFX 并提取 cert.pemcert.key
  3. 将根 CA 导出到 rootca.pem
  4. 更新了 RabbitMq
  5. 的配置文件

为了测试连接和证书是否正确创建,我们检查了 Troubleshooting Steps here.

一切顺利。我们可以使用客户端的 cert.pemcert.key[ 在端口 5671 上使用 openssl s_client 进行连接=52=] 从 client.pfx 生成。我们可以在管理控制台和日志中看到建立的连接,它们来回通信。

现在,在 .NET 客户端中使用 client.pfx,我们收到有关证书验证的错误:

MassTransit.RabbitMqTransport.RabbitMqConnectionException: Connect failed: admin@mitvs-atm01:5671/ ---> RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

我怎么会在使用 client.pfx 时出错,而在使用 cert.pem[=52 时却不出错? =] 和 cert.key 我从中提取的?

此错误消息表示客户端无法验证服务器证书。您的问题可能与 rootca.pem 在您的客户端机器上不受信任有关。按照适当的 OS 指南使根 CA 证书可信。

当使用 s_client 通过 OpenSSL 测试连接时,它不执行验证或执行非常基本的验证,并且 .NET 应用程序可以提供应用任何逻辑的功能。最常见的验证类型是将证书的 CN 与服务器的主机名进行匹配,但实际上可以是任何内容。

因此,即使在受信任的根 CA 上,CN 仍然需要匹配主机名,而主机名不是使用 OpenSSL 命令获取的。

重新生成证书并修改它解决了问题。

此外,您可以有效地添加以下代码,它会忽略此错误:

h.UseSsl(s =>
{
    s.ServerName = SslHostName;
    s.CertificatePath = SslFileLocation;
    s.CertificatePassphrase = SslPassphrase;

    // The below allows the Root CA's CN to be different than the others, but adds vulnerability
    s.AllowPolicyErrors(System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch);
});

请注意 - 忽略错误会使您的系统面临 MITM 攻击的风险(当然,除非您实施自己的不基于 CN/hostname 匹配的验证逻辑)。