SSL
The driver supports SSL connections to MongoDB servers using the underlying support for SSL provided by the .NET Framework. The driver takes a SslStream
. You can configure the use of SSL with the connection string or with MongoClientSettings
.
Connection String
The connection string provides 2 options:
?ssl=true|false
You can turn on SSL using this option, or explicitly turn it off. The default isfalse
.?sslVerifyCertificate=true|false
You can turn off automatic certificate verification using this option. The default istrue
.warning
This option should not be set tofalse
in production. It is important that the server certificate is properly validated.
MongoClientSettings
MongoClientSettings
provides a much fuller and robust solution for configuring SSL. It contains the SslSettings
property which allows the setting of various values. Each of these values will map very strongly to their counterpart in the AuthenticateAsClient
method. For example, to authenticate with a client certificate called “client.pfx”:
var cert = new X509Certificate2("client.pfx", "mySuperSecretPassword");
var settings = new MongoClientSettings
{
SslSettings = new SslSettings
{
ClientCertificates = new[] { cert },
},
UseSsl = true
};