.NET使用MQ Classes+SSL连接时出现MQRC_ENVIRONMENT_ERROR(2012)错误
使用.NET 4.7.2、IBM WebSphere MQ Classes for .Net 7.0.1.13(amqmdnet.dll)结合DigiCert SSL证书,执行以下代码连接远程MQ队列管理器时,触发错误2012(MQRC_ENVIRONMENT_ERROR),已验证队列管理器名称、CipherSpec、端口等配置信息:
var properties = new Hashtable { { MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED }, { MQC.HOST_NAME_PROPERTY, "hostname.com" }, { MQC.PORT_PROPERTY, "1417" }, { MQC.CHANNEL_PROPERTY, "12345678_SND.C1" }, { MQC.SSL_CIPHER_SPEC_PROPERTY, "TLS_RSA_WITH_AES_256_CBC_SHA256" }, { MQC.SSL_CERT_STORE_PROPERTY, "C:\\Temp\\my-ssl.pfx" } }; var queueManager = new MQQueueManager("QM", properties);
观察到的两种SSL相关错误场景
- 未指定
SSL_CIPHER_SPEC_PROPERTY时:
Remote CipherSpec error for channel '12345678_SND.C1'. The remote end of channel '12345678_SND.C1' has had a CipherSpec error. The channel did not start. Review the error logs on the remote system to discover the problem with the CipherSpec.
- 指定
SSL_CIPHER_SPEC_PROPERTY但未指定SSL_CERT_STORE_PROPERTY时:
The path and stem name for the SSL key repository have not been specified. The directory path and file stem name for the SSL key repository have not been specified. On a MQ client system there is no default location for this file. SSL connectivity is therefore impossible as this file cannot be accessed. Use the MQSSLKEYR environment variable or MQCONNX API call to specify the directory path and file stem name for the SSL key repository.
问题解答
错误来源说明
- 第一个错误来自队列管理器:客户端未指定CipherSpec时,服务端通道配置要求必须使用匹配的加密套件,协商失败后服务端返回该错误,客户端本地抛出对应提示。
- 第二个错误是客户端本地错误:MQ .NET托管客户端在未配置证书存储路径时,无法加载SSL证书,还未与服务端建立连接就触发本地环境错误。
当前2012错误的核心排查方向
当前代码触发的MQRC_ENVIRONMENT_ERROR属于SSL相关问题,可从以下几点排查:
- 证书密码配置:若PFX证书带密码保护,需添加
MQC.SSL_CERT_STORE_PASSWORD_PROPERTY配置项传入证书密码,否则客户端无法读取证书。 - CipherSpec一致性验证:确认服务端通道配置的CipherSpec与客户端指定的
TLS_RSA_WITH_AES_256_CBC_SHA256完全匹配,部分MQ版本中该算法可能有别名,需核对服务端通道的SSL配置。 - 证书有效性检查:确保PFX证书包含完整信任链、未过期,且服务端队列管理器信任DigiCert根证书(需在服务端信任存储中存在)。
- 证书路径与权限:验证
C:\\Temp\\my-ssl.pfx路径正确,且客户端运行进程有读取该文件的权限。
内容的提问来源于stack exchange,提问作者Mike

