public static void Run() { // validator that accepts certificates with an untrusted root CA, as long as that CA matches the one we provide var serverCertificateValidator = new CustomRootCaCertificateValidator( new X509Certificate2(LoadingCertificateManuallyExample.CertificateAuthorityPath)); var cluster = Cluster.Builder() .AddContactPoints(LoadingCertificateManuallyExample.ContactPoints) .WithSSL(new SSLOptions() // set client certificate collection .SetCertificateCollection(new X509Certificate2Collection { // use the following constructor if the certificate is password protected new X509Certificate2( LoadingCertificateManuallyExample.ClientCertificatePath, LoadingCertificateManuallyExample.ClientCertificatePassword), // use the following constructor if the certificate is not password protected //new X509Certificate2(LoadingCertificateManuallyExample.CertificatePath) }) // Set server certificate validator for server auth .SetRemoteCertValidationCallback( (sender, certificate, chain, errors) => serverCertificateValidator.Validate(certificate, chain, errors))) .Build(); var session = cluster.Connect(); var rowSet = session.Execute("select * from system_schema.keyspaces"); Console.WriteLine(string.Join(Environment.NewLine, rowSet.Select(row => row.GetValue <string>("keyspace_name")))); }
public static void Run() { // validator that accepts certificates with an untrusted root CA, as long as that CA matches the one we provide var certificateValidator = new CustomRootCaCertificateValidator( new X509Certificate2(LoadingCertificateManuallyExample.CertificateAuthorityPath)); var cluster = Cluster.Builder() .AddContactPoints(LoadingCertificateManuallyExample.ContactPoints) .WithSSL(new SSLOptions().SetRemoteCertValidationCallback( (sender, certificate, chain, errors) => certificateValidator.Validate(certificate, chain, errors))) .Build(); var session = cluster.Connect(); var rowSet = session.Execute("select * from system_schema.keyspaces"); Console.WriteLine(string.Join(Environment.NewLine, rowSet.Select(row => row.GetValue <string>("keyspace_name")))); }