Reputation: 89
We cannot connect to Cosmos DB using the MongoDB driver when we deploy our application to a test server.
All our Dev machines have no issue but we are getting the following from test. I get thats its an issue with a cert on the Machine but how do we fix it ?
[{ ServerId: "{ ClusterId : 1, EndPoint :
"Unspecified/xxxxxxxxx.documents.azure.com:10255" }",
EndPoint: "Unspecified/xxxxxxxx.documents.azure.com:10255", State:
"Disconnected", Type: "Unknown", HeartbeatException:
"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.
is the issue here the client cert being invalid ?
We have connections to Azure SQL instances without any issues.
Upvotes: 0
Views: 1392
Reputation: 18465
Per my understanding, you could use SslSettings.ServerCertificateValidationCallback for getting more details about the server certificate validation and check the policy errors to narrow this issue. You could construct your MongoClientSettings
as follows for building your MongoClient
:
MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl("{connection-string-of-your-cosmosdb}"));
settings.SslSettings = new SslSettings()
{
EnabledSslProtocols = SslProtocols.Tls12,
ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
foreach (var element in chain.ChainElements)
{
// Gets the error status of the current X.509 certificate in a chain.
foreach (var status in element.ChainElementStatus)
{
Console.WriteLine($"certificate subject: {element.Certificate.Subject},ChainStatus: {status.StatusInformation}");
}
}
return true; //just for dev, it would bypass certificate errors
}
};
var mongoClient = new MongoClient(settings);
Upvotes: 1