【问题标题】:Unable to connect to IBM MQ with TLS using .NET standard library无法使用 .NET 标准库通过 TLS 连接到 IBM MQ
【发布时间】:2021-09-25 16:26:21
【问题描述】:

我们在尝试使用 .net 标准 nuget 包 IBMMQDotnetClient 通过 TLS ({"MQRC_HOST_NOT_AVAILABLE"}) 连接到 IBM MQ 时遇到异常。该项目使用 .net 框架 4.7.2。我们可以在不使用 SSL 的情况下进行连接,而且当我们切换到 .net 框架 nuget 包 WebSphereMQClient 时,我们可以使用完全相同的代码和设置进行连接(只需换出 nuget 库就可以使其工作) )。

此外,我无法为 .net 标准库启用跟踪。文档表明需要设置环境变量 MQDOTNET_TRACE_ON,但即使在那之后我也没有生成任何东西。我尝试添加其他变量,例如 MQERRORPATH,但仍然没有看到任何跟踪文件。

代码

var queueManagerName = "QM1";
var hostName = "hostname.com";
var channel = "DEV.APP.SVRCONN";
var queueName = "DEV.QUEUE.1";
var port = "1414";

var sslKeyRepository = "*USER";
var cipherSpec = "TLS_RSA_WITH_AES_256_CBC_SHA256";

Hashtable prop = new Hashtable();

prop.Add(MQC.HOST_NAME_PROPERTY, hostName);
prop.Add(MQC.PORT_PROPERTY, port);
prop.Add(MQC.CHANNEL_PROPERTY, channel);
prop.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT);
prop.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);

prop.Add(MQC.SSL_CERT_STORE_PROPERTY, sslKeyRepository);

prop.Add(MQC.SSL_CIPHER_SPEC_PROPERTY, cipherSpec);
            
try { 
    var queueManager = new MQQueueManager(queueManagerName, prop);
    MQQueue _queue = queueManager.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);

}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

来自客户端 AMKERR01.LOG 的错误:

7/16/2021 7:16:12 PM - Process(15212.1) User(Eric.Kaufman) Program(ConsoleApp1)
                       Host(DLW011309) Installation(Unknown)
                       VRMF(9.2.2.0)
                       Time(2021-07-16T23:16:12.121Z)
                       ArithInsert1(0) ArithInsert2(0)
                       CommentInsert1(hostname.com(1414))
                       CommentInsert2(TCP/IP)
                       CommentInsert3( (Exception))
                      
AMQ9202E: Remote host not available, retry later.

EXPLANATION:
The attempt to allocate a conversation using TCP/IP to host
'hostname.com(1414)' for channel 
(Exception) was not successful. However the error may be a transitory one and
it may be possible to successfully allocate a TCP/IP conversation later. 

In some cases the remote host cannot be determined and so is shown as '????'.
ACTION:
Try the connection again later. If the failure persists, record the error
values and contact your systems administrator. The return code from TCP/IP is 0
(X'0'). The reason for the failure may be that this host cannot reach the
destination host. It may also be possible that the listening program at host
'hostname.com(1414)' was not running.  If
this is the case, perform the relevant operations to start the TCP/IP listening
program, and try again.

来自队列管理器日志的错误

07/16/21 23:16:12 - Process(401.18) User(mqm) Program(amqrmppa)
                    Host(a55a7574679b) Installation(Installation1)
                    VRMF(9.2.2.0) QMgr(QM1)
                    Time(2021-07-16T23:16:12.102Z)
                    RemoteHost(XXX.XXX.XXX.XXX)
                    ArithInsert1(420)
                    CommentInsert1(????)
                    CommentInsert2(gsk_secure_soc_read)
                    CommentInsert3(XXX.XXX.XXX.XXX)

AMQ9665E: SSL connection closed by remote end of channel '????'.

EXPLANATION:
The SSL or TLS connection was closed by the remote host 'XXX.XXX.XXX.XXX'
during the secure socket handshake. The channel is '????'; in some cases its
name cannot be determined and so is shown as '????'. The channel did not start.
ACTION:
Check the remote end of the channel for SSL and TLS errors. Fix them and
restart the channel.
----- amqccisa.c : 11155 ------------------------------------------------------
07/16/21 23:16:12 - Process(401.18) User(mqm) Program(amqrmppa)
                    Host(XXXXXXXXX) Installation(Installation1)
                    VRMF(9.2.2.0) QMgr(QM1)
                    Time(2021-07-16T23:16:12.103Z)
                    CommentInsert1(????)
                    CommentInsert2(401)
                    CommentInsert3(XXX.XXX.XXX.XXX)

AMQ9999E: Channel '????' to host 'XXX.XXX.XXX.XXX' ended abnormally.

EXPLANATION:
The channel program running under process ID 401 for channel '????' ended
abnormally. The host name is 'XXX.XXX.XXX.XXX'; in some cases the host name
cannot be determined and so is shown as '????'.
ACTION:
Look at previous error messages for the channel program in the error logs to
determine the cause of the failure. Note that this message can be excluded
completely or suppressed by tuning the "ExcludeMessage" or "SuppressMessage"
attributes under the "QMErrorLog" stanza in qm.ini. Further information can be
found in the System Administration Guide.

【问题讨论】:

  • 您是否有权访问 MQ 服务器上的日志?他们应该说明握手失败的原因。
  • 什么windows版本?
  • 我可以访问服务器上的日志,但我没有看到任何相关信息(我包含了来自队列管理器的日志,但错误是一般性的)。 windows版本为Microsoft Windows 10 Pro 10.0.17763
  • 因此,我能够使用 .net 标准库进行跟踪,但只能使用 .net core 3.1。 .net 框架和 .net core 2.1 不允许跟踪。
  • 您为启用跟踪做了什么?你从日志中学到了什么新东西吗?

标签: c# .net ssl ibm-mq


【解决方案1】:

这最终是我的用户错误,但我会包括我的步骤,以防它最终对其他人有所帮助。启用跟踪的环境变量确实有效,但需要重新启动 Visual Studio 才能生效。我最终使用的三个是:

MQDOTNET_TRACE_ON = "2",
MQERRORPATH = "C:\MQERRORLOGPATH",
MQTRACEPATH = "C:\MQTRACEPATH"

生成跟踪文件后,我发现了这个异常:

System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

这是因为我使用的是自签名证书。将证书添加到 Windows 证书管理器中的受信任的根证书颁发机构文件夹后,我能够成功连接。

【讨论】:

  • @Erik Kaufman 您在 Windows 证书存储的“个人”文件夹中是否还有另一个证书?
  • 嘿,所以基本上要让两种方式的 SSL 配置正常工作,我必须创建一个证书客户端,然后将该证书添加到 MQ 服务器上的 IBM MQ 密钥数据库,然后还要创建一个IBM MQ 服务器上的证书并将该证书添加到客户端(这是通过 Windows 证书存储完成的)。所以是的,我将 IBM MQ 服务器的证书安装到了个人文件夹中的 Windows 证书存储中(以及中间/根证书)。
  • 我遇到的一个障碍是证书需要包含要使用的私钥,这由证书存储中的密钥图标指示。除非它还包含私钥,否则即使将证书放在个人文件夹中也不起作用。这花了我最长的时间来完成。
猜你喜欢
  • 2019-12-31
  • 2015-01-09
  • 2011-02-09
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 2011-03-04
  • 1970-01-01
  • 2012-03-09
相关资源
最近更新 更多