Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1927

The SSL connection example does not work

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.10.0
    • Affects Version/s: 2.4
    • Component/s: Documentation

      The C# driver docs has an example on how to connect using SSL in http://mongodb.github.io/mongo-csharp-driver/2.4/reference/driver/ssl/. The code in the page shows:

      var cert = new X509Certificate2("client.pfx", "mySuperSecretPassword");
      
      var settings = new MongoClientSettings
      {
          SslSettings = new SslSettings
          {
              ClientCertificates = new[] { cert },
          },
          UseSsl = true
      };
      

      However I find the code doesn't work when trying to connect to a MongoDB server with requireSSL=true.

      With some help from andrew.ryder I arrived at a working code:

      var cert = new X509Certificate2("client.pfx", "secret");
      
      var settings = new MongoClientSettings {
          Server = new MongoServerAddress("myserver.local", 27017),
          SslSettings = new SslSettings {
              ClientCertificates = certs,
              ClientCertificateSelectionCallback = delegate( object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers ) { return certs[0]; },
              ServerCertificateValidationCallback = delegate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors ) 
      { 
         return true; 
      }
          },
          UseSsl = true,
      };
      

      There seems to be a series of requirements that are not explicit. In light of our push toward a more secure MongoDB deployment, in my opinion the SSL example should be explained more with a working code.

            Assignee:
            vincent.kam@mongodb.com Vincent Kam (Inactive)
            Reporter:
            kevin.adistambha@mongodb.com Kevin Adistambha
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: