I am having a issue in .net-core3.1, I have setup a mongodb ssl-tls connection on the server and have done all the configuration on it mongo db config looks like this-
net: port: 27017 bindIpAll: true ssl: mode: preferSSL PEMKeyFile: all.pem CAFile: xyz.pem clusterFile: abc.pem allowInvalidHostnames: true disabledProtocols: TLS1_0,TLS1_1 allowConnectionsWithoutCertificates: true FIPSMode: true
I have written code in .net also which looks like-
var mcs = MongoClientSettings.FromUrl(new MongoUrl(mongoConfigProvider.MongoUrl));
mcs.MinConnectionPoolSize = 1;
mcs.MaxConnectionPoolSize = 500;
mcs.WaitQueueTimeout = new TimeSpan(1, 0, 0);
mcs.IPv6 = mongoConfigProvider.Ipv6;
mcs.UseTls = true;
var cert = new X509Certificate2(certBytes, CertPass);
var sslSettings = new SslSettings
{
ClientCertificates = new[] { cert },
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12,
};
mcs.SslSettings = sslSettings;
}
return new MongoClient(mcs);
when i am trying to connect starts to give the error- MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
I have tried using the ServerCertificateValidationCallback method in SslSettings also and first I was using the .pem certificate but after some research I came to know that we have to use .pfx certificate in .net so I changed it and I have checked the certificate also it is valid and it is not self signed one.
Can anyone please help me to solve the issue, I am checking it from past 3 weeks and not able to find solution for this. Thank you in advance.