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

The SSL connection example does not work

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: Documentation
    • Labels:
    • Sprint:
      C# Sprint 50, C# Sprint 51, C# Sprint 52, C# Sprint 53, C# Sprint 54, C# Sprint 55, C# Sprint 56, C# Sprint 57

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: