Exception while connecting to ScyllaDB with SSL

I’m trying to connect with our on prem ScyllaDB using ScyllaDBCSharpDriver via our .net 8 web API in visual studio, but i’m getting this exception.

Cassandra.NoHostAvailableException: All hosts tried for query failed (tried x.x.x.x:9042: TimeoutException ‘The timeout period elapsed prior to completion of SSL authentication operation.’; y.y.y.y:9042: TimeoutException ‘The timeout period elapsed prior to completion of SSL authentication operation.’)

This is my code

using Azure.Storage.Blobs;
using Cassandra;
using PigeonPost.Model;
using PigeonPost.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using static PigeonPost.Common.Constants;

namespace PigeonPost.Repository
{
    public class ScyllaClientFactory : IScyllaClientFactory
    {
        public ISession Session { get; }
        public ICluster Cluster { get; }
        public ScyllaClientFactory(ScyllaDbSettings settings, BlobSettings blobSettings)
        {

            var contactPoints = settings.ContactPoints.Split(',');
            var builder = Cassandra.Cluster.Builder()
            .AddContactPoints(contactPoints)
            .WithPort(9042)
            .WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("DC1"));

            if (!string.IsNullOrEmpty(settings.Username))
            {
                builder = builder.WithCredentials(settings.Username, settings.Password);
            }

            var blobServiceClient = new BlobServiceClient(blobSettings.ConnectionString);
            var blobClient = blobServiceClient.GetBlobContainerClient(blobSettings.ScyllaContainerName);
            var response = blobClient.GetBlobClient(blobSettings.ScyllaBlobName).DownloadContent();
            var certBytes = response.Value.Content.ToArray();
            var cert = new X509Certificate2(certBytes, (string)null, X509KeyStorageFlags.MachineKeySet);


            var sslOptions = new SSLOptions(SslProtocols.Tls12, true, (sender, certificate, chain, errors) => true).SetCertificateCollection(new X509CertificateCollection { cert });
            builder = builder.WithSSL(sslOptions);
            
            Cluster = builder.Build();
            Session = Cluster.Connect(settings.Keyspace);
        }
    }
}

The exception is thrown at cluster.Conntect

The port 9042, which you point the driver at, is normally configured for nonencrypted communication. The encrypted counterpart is 9142. Please try specifying 9142 as the connection port in the driver and let me know if it works.

Hi Thanks a lot for the reply. However, I was able to figure this out. There was an issue with the certificate i used.

1 Like