MQ

 View Only

 MQ Client - Server Connectivity Issue through SSL Certificate

Anil C's profile image
Anil C posted 03/19/26 10:18 AM

We have installed Client and Personal certificates in our windows store and we have written .NET code to connect MQ server from MQ client. We are getting Reason Code 2393 but certificates are already present in windows store. 


My .NET code is 

using System;
using System.Net;
using System.Text.Json;
using IBM.XMS;
 
namespace IBMMQ;
 
/// <summary>
/// Runs IBM MQ tests: connection, send, receive, and round-trip.
/// </summary>
public class MqTestRunner
{
    
    public IConnectionFactory CreateConnectionFactory(MqConfig config)
    {
        if (string.IsNullOrWhiteSpace(config.Channel))
            throw new ArgumentException("Channel is required for MQ connection. Set 'Channel' in App.config or MQ_CHANNEL environment variable.", nameof(config));
 
        var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
        var cf = factoryFactory.CreateConnectionFactory();
 
        cf.SetStringProperty(XMSC.WMQ_HOST_NAME, config.Host ?? "");
        cf.SetIntProperty(XMSC.WMQ_PORT, config.Port);
        cf.SetStringProperty(XMSC.WMQ_CHANNEL, config.Channel!.Trim());
        cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, config.QueueManager ?? "");
        cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
 
        
 
        //if (!string.IsNullOrEmpty(config.UserId))
        //    cf.SetStringProperty(XMSC.USERID, config.UserId);
        //if (!string.IsNullOrEmpty(config.Password))
        //    cf.SetStringProperty(XMSC.PASSWORD, config.Password);
 
        // TLS with client certificate authentication (managed .NET client)
        if (config.UseCertificateAuth)
        {
            // Key repository: *USER = current user cert store, *SYSTEM = local machine
            // Client cert must be in "Personal (My)" store; CA cert in "Trusted Root"
            cf.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, config.SslKeyRepository ?? "*USER");
            // TLS CipherSpec (must match queue manager SVRCONN SSLCIPH - use WMQ_SSL_CIPHER_SPEC for WMQ channels)
            cf.SetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC, config.SslCipherSuite ?? "TLS_RSA_WITH_AES_256_CBC_SHA256");            
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
 
            if (!string.IsNullOrWhiteSpace(config.SslPeerName))
            {
                // Optional: validate server cert (e.g. CN=QueueManagerName)
                var peerName = config.SslPeerName!.Trim();
                if (!peerName.StartsWith("CN=", StringComparison.OrdinalIgnoreCase))
                    peerName = "CN=" + peerName;
                cf.SetStringProperty(XMSC.WMQ_SSL_PEER_NAME, peerName);
            }
        }
 
        Console.WriteLine($"Host={config.Host}, Port={config.Port}, Channel={config.Channel}," +
                                $" QueueManager={config.QueueManager}, UseCertificateAuth={config.UseCertificateAuth}" +
                                $" SslKeyRepository={config.SslKeyRepository}, SslCipherSuite={config.SslCipherSuite}" +
                                $" SslPeerName={config.SslPeerName}");
        Console.ReadLine();
 
        return cf;
    }
 
    /// <summary>
    /// Test 1: Verify connection to the queue manager.
    /// </summary>
    public bool TestConnection(MqConfig config, out string? error)
    {
        error = null;
        try
        {
            Console.WriteLine("Connection test started.");
            Console.ReadLine();
 
           
 
            var cf = CreateConnectionFactory(config);
 
            Console.WriteLine("Connection started after factory.");
            Console.ReadLine();
 
 
 
            Console.WriteLine($"Host={cf.GetStringProperty(XMSC.WMQ_HOST_NAME)}, Port={cf.GetIntProperty(XMSC.WMQ_PORT)}, Channel={cf.GetStringProperty(XMSC.WMQ_CHANNEL)}," +
                               $" QueueManager={cf.GetStringProperty(XMSC.WMQ_QUEUE_MANAGER)}, UseCertificateAuth={config.UseCertificateAuth}" +
                               $" SslKeyRepository={cf.GetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY)}, SslCipherSuite={cf.GetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC)}" +
                               $" SslPeerName={cf.GetStringProperty(XMSC.WMQ_SSL_PEER_NAME)}");
 
            
 
 
            using var connection = cf.CreateConnection();
            connection.Start();
 
            Console.WriteLine("Connection established...");
            Console.ReadLine();
 
            connection.Stop();
            return true;
        }
        catch (XMSException ex)
        {
            error = ex.Message;
 
            Console.WriteLine($"Connection test failed: {error}");
            Console.WriteLine();
            Console.WriteLine("--- Detailed exception trace ---");
            Console.WriteLine(ex.ToString());
            if (ex.InnerException != null)
            {
                Console.WriteLine("--- Inner exception ---");
                Console.WriteLine(ex.InnerException.ToString());
            }
            Console.WriteLine("--------------------------------");
            Console.ReadLine();
 
            return false;
        }
        catch (Exception ex)
        {
            error = ex.Message;
 
            Console.WriteLine($"Connection test failed (unexpected): {error}");
            Console.WriteLine();
            Console.WriteLine("--- Detailed exception trace ---");
            Console.WriteLine(ex.ToString());
            if (ex.InnerException != null)
            {
                Console.WriteLine("--- Inner exception ---");
                Console.WriteLine(ex.InnerException.ToString());
            }
            Console.WriteLine("--------------------------------");
            Console.ReadLine();
 
            return false;
        }
    }
   
}


Request any suggestion If anyone get this same issue..

Morag Hughson's profile image
Morag Hughson IBM Champions

Hi Anil,

You have cropped off the top of the error in your screen shot of your errorlog. I have searched the IBM MQ Docs for some of the text shown and I think the error message number you have suffered is AMQ9637E - but perhaps you can confirm. My answer assumes this the case.

Error message AMQ9637E says "During handshake, the remote partner sent no certificate."

You say that you have installed the client certificate in your Windows store. Can you tell us the label you gave it?

From your code I cannot see anywhere that you have set a certificate label, so this means that the MQ code will be looking for a certificate with the label, the string "ibmwebspheremq" and the current logged on user (in lowercase). If that is not the label of your certificate, then no certificate will be sent to the queue manager and the error you have suffered will be seen.

Read this page, Using certificates for the managed .NET client, for information on how to set the certificate label in your code so that MQ will find and present the certificate you want it to use, when communicating with the queue manager.

Cheers,
Morag

Francois Brandelik's profile image
Francois Brandelik IBM Champions

In addition to what Morag said did you check the following points:

  • The signer chain of your personal certificate is in the queue manager's truststore
  • The queue manager's certificate's signer chain is in the windows truststore

Hope this helps

Anil C's profile image
Anil C

Hi @Morag Hughson & @Francois Brandelik,

I have faced lot of issue with the existing approach then I have sifted to  new approach which is mention below. We are using Mutual SSL certificate. Our customer configured SSLAUTH(REQUIRED) for Queue Manager. I am trying with the Windows store but Still i am getting  the error. Error screen-shot attaching here:

My AppSettings is :

<appSettings>
<add key="QueueManagerName" value="XXIBSSTG" />
<add key="HostName" value="10.10.10.10" />
<add key="Port" value="1421" />
<add key="ChannelName" value="XXIBSSTG.YYY.SCONN" />
<add key="SslCipherSpec" value="TLS_AES_256_GCM_SHA384" />
<add key="SslCertStore" value="*SYSTEM" />
<add key="CertificateLabel" value="ibmwebspheremqxxibsstg" />
<add key="CertificateThumbprint" value="" />
<add key="QueueName" value="Q1" />
<add key="SecurityProtocols" value="Tls12,Tls13" />
<add key="IncludeLegacyTls" value="false" />
</appSettings>

My Complete Code is in Program.cs file.

I have also attached images of windows certificate store personal & Trusted Root Certificate Authority.

Can you please guide what still left to make a connection with MQ Server Queue Manager. We are client and we have written all the client code in program.cs file and share with you.

We have set all the configuration what our Customer provided but still we are not able to communicate with their IBM MQ Queue Manager.

Thanks in Advance for Helping.
Anil Chaudhary & @Dinesh Gandhi @Dinesh Gandhi


Francois Brandelik's profile image
Francois Brandelik IBM Champions

The error is quite specific now. You seem to use mismatched cipher specs. Make sure the cipher specs match at each end of the channel.

Tim Zielke's profile image
Tim Zielke

It is inconsistent and possibly an issue that you are listing a TLS 1.3 CipherSuite here:

<add key="SslCipherSpec" value="TLS_AES_256_GCM_SHA384" />

and specifying both TLS 1.2 and 1.3 here:

<add key="SecurityProtocols" value="Tls12,Tls13" />

Anil C's profile image
Anil C

HI,

Can anyone please provide exact solution for this. We want to know how to setup certificate for Mutual Authentication at client side. 

Thanks,

Anil Chaudhary @Dinesh Gandhi

Morag Hughson's profile image
Morag Hughson IBM Champions

Have you done what Tim suggested? I.e. only list a single protocol, Tls13, in the SecurityProtocols attribute?

Robert (Bobbee) Broderick's profile image
Robert (Bobbee) Broderick

See if this helps.

om prakash's profile image
om prakash IBM Champions

AS it is mTLS from the client to MQ Server; do the below steps.

Client side:

  • Get a Client Cert generated and signed by CA
  • Create a key Repository and bundle the Client Cert, Intermediate certs. It can be a p12/kdb ( p12 is on 9.4 onward)
  • In the application properties set the below environment variables 
    • MQSSLKEYR
    • MQKEYRPWD

Once done, request the Server side team to share the Root CA certificate and public Cert of the queue manager if the Root CA for Client and Server are different. If ti is the same Root CA, skip the ask.

If the Root CA are different, update the KDB or P12 by adding the server side CA and intermediate certs.

Server side

  • Client team will share the CN of the client cert
  • Server team will define the Chlauth as below, map client CN to the Application user authorized to connect.
    SET CHLAUTH('MTLS.SVRCONN') TYPE(SSLPEERMAP) SSLPEER('CN=example-app1') USERSRC(MAP) MCAUSER('app1') ACTION(REPLACE)

Test your connection using the sample MQ program before you test the application.

 export MQCHLTAB=MQCHL.TAB
 export MQSSLKEYR=/tmp/keystore.p12
 export MQCHLLIB=/tmp
 export MQKEYRPWD=tryit
 echo "display qmgr" | runmqsc -c TESTQM

Alternative option is explained as here.

   /opt/mqm/samp/bin/amqssslc -m QM1 -c IN -x "localhost(1414)" -s ANY -k /var/mqm/qmgrs/QM1/ssl/key.p12
Francois Brandelik's profile image
Francois Brandelik IBM Champions

In the original post the cipherspec specified is clearly TLS_RSA... which is a TLS1.2 cipherspec, but the protocol only specifies TLS1.3...

Down the road the client cipherspec is TLS1.3, but there is no indication whether the MQ Server will accept any TLS1.3 cipherspec...

Hope that helps