Sourav Bagchi
Sourav Bagchi

Reputation: 1

Authentication Exception when trying to connect to Amazon Keyspaces using .net core and cassandra csharp driver from linux

I created a keyspace(table) in amazon keyspace and was trying to get the records from it to my .net core application which was running in ubuntu.I have provided every thing required such as ".pem" file username,password and awsEndpoint as mentioned in the aws documentation Using a Cassandra .NET Core Client Driver to Access Amazon Keyspaces Programmatically

But when I ran the code and tried to connect with amazon keyspace, it raises an exception "All hosts tried for query failed (tried 3.6.70.143:9142: AuthenticationException 'Authentication failed, see inner exception.')".

But the same code executes properly and brings back desired result when executed from an windows environment.

X509Certificate2Collection certCollection = new X509Certificate2Collection();
        X509Certificate2 amazoncert = new X509Certificate2(@"./Security/AmazonRootCA1.pem","");
        var userName = "username";
        var pwd = "password";
       
        certCollection.Add(amazoncert);

        var awsEndpoint =  "cassandra.ap-south-1.amazonaws.com" ;  
        try
        {
            var cluster = Cluster.Builder()
                 .AddContactPoints(awsEndpoint)
                 .WithPort(9142)
                 .WithAuthProvider(new PlainTextAuthProvider(userName, pwd))
                 .WithSSL(new SSLOptions().SetCertificateCollection(certCollection))
                 .Build();

        var session = cluster.Connect();
        var rs = session.Execute("select * from tutorialkeyspace.tutorialtable;");

Upvotes: 0

Views: 234

Answers (1)

MikeJPR
MikeJPR

Reputation: 812

Try adding the certificate to the linux truststore.

keytool -import -alias cassandra -keystore cassandra_truststore.jks -file temp_file.der```

Upvotes: 1

Related Questions