首页 > 解决方案 > 在 Linux .net 核心上的 IBM.MQ MQQueueManager 期间安全握手失败

问题描述

我们正在尝试使用 .net core 3.1 应用程序从 RHEL 8.3 连接到 IBM MQ。相同的代码在 Windows 上运行正常——我们能够连接到 QM。
正如我们所相信的,我们正面临一个来自 openssl 的错误:

---> Interop+OpenSsl+SslException:SSL 握手失败并出现 OpenSSL 错误 - SSL_ERROR_SSL。---> Interop+Crypto+OpenSslCryptographicException: error:14094412:SSL routines:ssl3_read_bytes:sslv3 >alert bad certificate --- End of internal exception stack trace --- at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, Byte[] recvBuf , Int32 recvOffset, Int32 >recvCount, Byte[]& sendBuf, Int32& sendCount) 在 >/_/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs:line 278

我们可以看到 MQClient 加载了证书

00000157 12:30:07.116059 536167.15 -----------{ MQEncryptedSocket.MakeSecuredConnection()
00000158 12:30:07.116425 536167.15 创建了 SSLStreams 的实例
00000159 12:30:07.116466 将当前证书存储为 53616。 '
0000015A 12:30:07.116528 536167.15 Linux so use My & CurrentUser
0000015B 12:30:07.116542 536167.15 Created store object to access certificates 0000015C 12:30:07.116780 536167.15 Opened store
0000015D 12:30:07.116795 536167.15 Accessing certificate - ZZZZ
0000015E 12: 30:07.230836 536167.15 商店中的证书数量:5
0000015F 12:30:07.231092 536167.15 支持 TLS12 - True
00000160 12:30:07.233622 536167.15 将 SslProtol 设置为 Tls12
00000161 12:30:07.233652 536167.15 开始 SSL 身份验证

我们有单元测试来验证给定主题的证书是否存在于该商店中并且它通过了。
我们已经做了什么:

  1. 我们构建了 openssl 1.1.1h 并将其链接到系统范围。
  2. 我们验证了证书存储。我们使用的证书是有效的
    var cert = x509Store2.Certificates.Find(X509FindType.FindBySubjectName, mockIbmMqOptions.MqCertificateLabel, true).Count;
    x509Store2.Close();
    x509Store2.Dispose();
    Assert.True(cert > 0);
  1. 我们在 Windows 上成功运行了代码。
  2. 我们在 openssl 源代码中搜索了 sslv3 alert bad certificate,发现除了错误代码为 1420 但未引用的静态数据之外什么也没有。

有任何想法吗?

标签: c#linuxopensslibm-mq.net-standard-2.0

解决方案


谢谢@JoshMc 基于这个问题,我们成功地完成了握手。我认为这是 RHEL 和 IBM MQ 客户端库上 .net 核心的通用解决方案:

  1. 确保 CA 和中间 CA 存储在 /usr/share/pki/ca-trust-source/anchors/ 或 /etc/pki/ca-trust/source/anchors/
  2. 如果您的 pfx 在证书路径中包含证书仅导出私钥和公共证书
  3. 确保将友好名称设置为某个值。
  4. 将导出的 pfx 添加到 .net 核心密钥库certificate-tool add
  1. 将 CertificateLabel 设置为匹配 FriendlyName 或将友好名称设置为 ibmwebspheremq<username_in_lowercase>

推荐阅读