How to connect using certificate and ignore certificate errors

I’m trying to connect to a DocumentDB from my local machine using a SSH tunnel.

I’m using the following properties in the connection string:

  • tls=true
  • tlsCAFile=
  • tlsAllowInvalidHostnames=true

These work with mongosh and MongoDB Compass, but not with the C# driver.

With the C# driver, I get System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors in the SslStream .

Is there a way around this?

Apparently, the parsing of the connection string is not aware of the tlsCAFile parameter:

ConnectionString.ParseOption method

It does make the name of the unknow parameters available, through the AllUnknownOptionNames property. But although the value is store here, the value is not available to the user.