Connect with client cert throws NoHostAvailableException

146 views
Skip to first unread message

Michael Colussi

unread,
Nov 4, 2016, 9:10:44 PM11/4/16
to DataStax C# Driver for Apache Cassandra User Mailing List
I have a working setup of client certificate auth using Cassandra 3.0.9. I am able to connect using "cqlsh --ssl".

However, when I try to connect with the C# driver (3.0.9) I get:
Cassandra.NoHostAvailableException: None of the hosts tried for query are available (tried: ...)

Am I not loading the cert correctly?  All the cert properties seem fine.

            // Create a collection object and populate it using the PFX file
            var collection = new X509Certificate2Collection();
            collection.Import(@"C:\client.pfx", "PASSWORD", X509KeyStorageFlags.PersistKeySet);
            // prep SSLOptions
            var options = new SSLOptions();
            // assign certs
            options.SetCertificateCollection(collection);
            // skip validation of remote cert (SSL)
            options.SetRemoteCertValidationCallback((a1, a2, a3, a4) => true);
            var cluster = Cluster.Builder()
                    .AddContactPoint(contactPoint)
                    .WithCredentials(user, pass)
                    .WithSSL(options)
                    .Build();
            try {
                var session = cluster.Connect();
            } catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
                throw;
            }

Thanks,
Mike

Mike

unread,
Nov 6, 2016, 8:00:06 PM11/6/16
to DataStax C# Driver for Apache Cassandra User Mailing List
I turned on .net verbose tracing and got a better error:
System.Net Information: 0 : [10224] SecureChannel#52077944 - We have user-provided certificates. The server has specified 2 issuer(s). Looking for certificates that match any of the issuers.
System.Net Information: 0 : [10224] SecureChannel#52077944 - Left with 0 client certificates to choose from.

Also, it works fine with a self-signed cert.  Seems like a .net intermediate cert problem.

Jorge Bay Gondra

unread,
Nov 7, 2016, 3:21:32 AM11/7/16
to csharp-dr...@lists.datastax.com
Hi Mike,
You can check the ssl policy errors that are causing the client validation to fail using the RemoteCertificateValidationCallback.
A common issue is that certificate name must match the machine's hostname.

If you want to disable client/server identification within SSL, you can use a SslOptions instance with no client certificate.

Jorge

--
You received this message because you are subscribed to the Google Groups "DataStax C# Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-user+unsub...@lists.datastax.com.

משה באשר

unread,
Feb 26, 2017, 8:13:03 AM2/26/17
to DataStax C# Driver for Apache Cassandra User Mailing List
Hey, I have the same problem.
I am currently trying to test the 2 way ssl on my local computer and all certificates are self-signed.
(datastax) Cassandra 3.9.0 , cqlsh 5.0.1 , latest c# driver.

I too use client_auth = true and client_encryption = enabled
My code looks almost the same, I just added :

//custom host resolver to resolve server ip to certificate CN
options.SetHostNameResolver((internalIPAddress) =>
            {
                return "my-hostname"; // my hostname is also used as alias and as CN name in keytool so it matches 100%
            });
(+The certificate name matches server hostname..)

I cant find the cause to failure, any suggestions?
P.S: using cqlsh --ssl works!

Jorge Bay Gondra

unread,
Feb 27, 2017, 3:37:46 AM2/27/17
to csharp-dr...@lists.datastax.com
Hi,
You should set use a remote certificate validation handler:

options.SetRemoteCertValidationCallback(handler);

Thanks,
Jorge

To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-user+unsubscribe@lists.datastax.com.

Message has been deleted

משה באשר

unread,
Feb 27, 2017, 6:23:31 AM2/27/17
to DataStax C# Driver for Apache Cassandra User Mailing List
I did, just like Mike.
I just found out that the problem was the way I generated the user's key.. (missing a flag)

What I did wrong: (works with cqlsh --ssl but not with c#)
keytool -importkeystore -srckeystore c:\keystore -destkeystore c:\userkey.p12 -deststoretype PKCS12

Solution:
keytool -importkeystore -srckeystore c:\keystore -destkeystore c:\userkey.p12 -srcstoretype JKS -deststoretype PKCS12

I dont know what the cqlsh doens't care, but the C# driver does.
Hope it helps others as well!
To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-user+unsub...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages