MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

CSharp Driver and CA SSL Cert

Hi.

I am trying to connect to a ScaleGrid cluster (3 nodes replica-set) with following code:

public void Initialize(IEnumerable<(string hostName, int port)> servers, string username, string password, string authenticationDatabase, bool useTLS, X509Certificate2 certificate)
        {

            _dbClient = new MongoClient(new MongoClientSettings()
            {
                Servers = servers.Select(s=>new MongoServerAddress(s.hostName, s.port)),
                UseTls = useTLS,
                AllowInsecureTls = false /*with true everything works as expected */,
                Credential = MongoCredential.CreateCredential(authenticationDatabase, username, password),
                ApplicationName = this.GetType().Name,
                SslSettings = new SslSettings()
                {
                    ClientCertificates = new []{ certificate}
                }
            });

        }

where certificate parameter is initialized calling X509Certificate2 constructor pointing to a ca cert file containing only public key on ScaleGrid (in order to enforce server validation).

Sadly, what I get is following exception:

System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

Any suggestion?

Thanks!