Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-11767

Predefine Certificates on DotNet | Feedback on Managing Connections | Couchbase Docs

    XMLWordPrintable

Details

    Description

      Currently there is no documentation on how to add a predefined certificate in Dot Net.
      While it looks possible, it is not the most straight forward.
      in the API i found that class for it: PredefinedCertificateFactory using that dot net class: X509Certificate2

      https://docs.couchbase.com/sdk-api/couchbase-net-client/api/Couchbase.Core.IO.Authentication.X509.PredefinedCertificateFactory.html

      Please add a description on how to add certificate to the code, as some users do need it.

      Possible way of doing it:

       

       String stringCert= "-----BEGIN CERTIFICATE-----\n" +
                              <SNIP>
                              "-----END CERTIFICATE-----\n";
              X509Certificate2 cert= new X509Certificate2(Encoding.UTF8.GetBytes(stringCert));
              PredefinedCertificateFactory factory = new PredefinedCertificateFactory([cert]);
       
              var options = new ClusterOptions
              {
                  EnableTls= true,
                  KvIgnoreRemoteCertificateNameMismatch=true,
                  UserName = "Administrator",
                  Password = "password",
              }.WithX509CertificateFactory(factory); 

      *please verify with Engineering.

       

       

      note: Java doesn't have that either, in Java this is the code needed: 

      X509Certificate cert = new LazyX509Certificate(
              new String("-----BEGIN CERTIFICATE-----\n" +
                      <SNIP>
                      "-----END CERTIFICATE-----\n").getBytes());
       
      ClusterEnvironment env = ClusterEnvironment.builder()
              .securityConfig(SecurityConfig.enableTls(true)
                      .enableHostnameVerification(false)
                      .trustCertificates(Arrays.asList((cert))))
              .build(); 

      Browser environment: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

      Reporter: Roi Katz
      E-mail: roi.katz@couchbase.com

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard.smedley Richard Smedley
            roi.katz Roi Katz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty