Not able to connect to Redis from .NET 4.6.1 on SSL. From same windows server with java code(jedis) we are able to connect

582 views Asked by At

Not able to connect to Redis from .NET 4.6.1 on SSL. From same windows server with java code(jedis jar) we are able to connect.

Error which I got:

It was not possible to connect to the redis server(s). There was an authentication failure; check that passwords (or client certificates) are configured correctly: (IOException) Authentication failed because the remote party has closed the transport stream..
   at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(ConfigurationOptions configuration, TextWriter log, Nullable`1 serverType, EndPointCollection endpoints)

But with same password and certificate from java (jedis jar) it is able to connect.

public static void StartRedis()
        {
            const string PATH_TO_CERT_FILE = "C:\\\certificate.pfx";

            var host = "server";
            var port = 6379;
            var pass = "password";

            var configString = $"{host}:{port},ssl=true,password={pass}";
            var options = ConfigurationOptions.Parse(configString);
            //options.AbortOnConnectFail = false;

                
                //configuration of Client certificate to authenticate to the DB
                options.CertificateSelection += delegate {
                    Console.WriteLine("Fectching certificate to send to redis");
                    var cert = new X509Certificate2(PATH_TO_CERT_FILE, "password");
                    //Console.WriteLine("Fected certificate to send to redis" + cert);
                    return cert;
                };

                //Configuration of Server certificate validation cusing callback function
                options.CertificateValidation += Options_CertificateValidation;

                //Creation and configuration of the connections group
                ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect(options);

                //Creation of the connection to the DB
                IDatabase conn = muxer.GetDatabase();

                //send SET command
                conn.StringSet("key1", "Hello Redis!");

                //send GET command and print the value
                Console.WriteLine(conn.StringGet("key1"));

                Console.ReadKey();
        }



            //Call back function for Server certificate verification
            private static bool Options_CertificateValidation(object sender, X509Certificate certificate, X509Chain chain,SslPolicyErrors sslPolicyErrors)
            {
                //The test below comparing if the CN of the Root certificate is equal to the Issuer of the Server-certificate presented by dmcproxy.
                X509Certificate2 root_cert = new X509Certificate2("C:\\serverCert.pem");
                bool verdict = (certificate.Issuer == root_cert.Subject);
                Console.WriteLine("Verdict is {0}", verdict);

                if (verdict)
                {
                    return true;
                }

                return false;
                
            }

We tried different TLS versions and from the network logs we see java code is using TLS1.2v and from .NET framework we are using same TSL version.

Tried multiple solutions by enabling CertificateValidation and setting TLSV1.2

0

There are 0 answers