flymzero/webdav_client

Connect to server using self signed certificate?

stcojo opened this issue · 2 comments

Hi, thanks for a great library!
Does the library have the option to connect to a WebDAV server which uses a self signed certificate?

All I get is a timeout error. I am using it like this:

var client = webdav.Client( uri: "https://someserver/", c: webdav.WdDio(debug: true ), auth: webdav.BasicAuth(user: "user", pwd: "pass"), );

Since the network request uses dio (header reason). You can refer to the documentation.

The following code has not been tested. 😄

var dio = webdav.WdDio(debug: true);

  // The underlying layer is httpClient
  String PEM = 'XXXXX'; // certificate content
  (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
      (client) {
    client.badCertificateCallback =
        (X509Certificate cert, String host, int port) {
      if (cert.pem == PEM) {
        // Verify the certificate
        return true;
      }
      return false;
    };
  };

  var client = webdav.Client(
    uri: "https://someserver/",
    c: dio,
    auth: webdav.BasicAuth(user: "user", pwd: "pass"),
  );

this works, thanks a lot